Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use functionnal component on Demo list card #216

Open
c0ncentus opened this issue Nov 21, 2023 · 0 comments
Open

cannot use functionnal component on Demo list card #216

c0ncentus opened this issue Nov 21, 2023 · 0 comments

Comments

@c0ncentus
Copy link

import { useState } from "react";
import { Flipped, Flipper, spring } from "react-flip-toolkit";


const DATA_FILTER = [
  { id: 1, title: "Twas brillig and the slithy toves" },
  { id: 2, title: "Did gyre and gimbel in the wabe" },
  { id: 3, title: "All mimsy were the borogroves" },
  {
    id: 4,
    title: "The mome raths outgrabe"
  },
  {
    id: 5,
    title: "Beware the jabberwock my son!!"
  },
  { id: 6, title: "The jaws that bite, the claws that snatch" }
];




function Card({ id, title, type, stagger, addToFilteredIds }: { id, title: string, type, stagger, addToFilteredIds }) {
  const onElementAppear = (el, index) => spring({ onUpdate: val => { el.style.opacity = val; }, delay: index * 50 });

  const onExit = type => (el: HTMLElement, index: number, removeElement: () => void) => {
    spring({
      config: { overshootClamping: true },
      onUpdate: val => { el.style.transform = `scale${type === "grid" ? "X" : "Y"}(${1 - (val as any)})`; },
      delay: index * 50,
      onComplete: removeElement
    });
    return () => {
      el.style.opacity = "";
      removeElement();
    };
  };
  const onGridExit = onExit("grid");
  const onListExit = onExit("list");
  const shouldFlip = (prev, current) => {
    if (prev.type !== current.type) { return true; }
    return false;
  };
  const flipId = `item-${id}`;
  return (
    <Flipped flipId={flipId} onAppear={onElementAppear} onExit={type === "grid" ? onGridExit : onListExit} key={flipId} stagger={stagger} shouldInvert={shouldFlip}>
      <li className="fm-item">
        <Flipped inverseFlipId={flipId}>
          <div>
            <Flipped flipId={`${flipId}-content`} translate shouldFlip={shouldFlip} delayUntil={flipId}> <div> <h3>{title}</h3> <p>{title}</p></div></Flipped>
            <Flipped flipId={`${flipId}-button`} shouldFlip={shouldFlip} delayUntil={flipId}>
              <button className="fm-remove" onClick={() => addToFilteredIds(id)}>&times;</button>
            </Flipped>
          </div>
        </Flipped>
      </li>
    </Flipped>
  );
}


export function ListExample() {
  const [sort, setSort] = useState<"asc" | "desc">("asc")
  const [filteredIds, setFilteredIds] = useState<any[]>([])

  const state = { type: "grid", sort: sort, filteredIds: filteredIds, stagger: "none", spring: "noWobble" };

  const addToFilteredIds = id => { setFilteredIds([...filteredIds, id]) };

  return (
    <div className="fm-example">
      <Flipper
        flipKey={`${state.type}-${state.sort}-${JSON.stringify(state.filteredIds)}-${JSON.stringify(state.stagger)}`}
        spring={state.spring}
        staggerConfig={{ default: { reverse: state.stagger !== "forward", speed: 1 } }}
        decisionData={state}
      >
        <div className="fm-flex-container">
          <fieldset>
            <legend>Sort</legend>
            <label onClick={() => { setSort('asc') }}>
              <input type="radio" name="sort" checked={state.sort === "asc"} />
              asc
            </label>
            <label onClick={() => { setSort('desc') }}>
              <input type="radio" name="sort" checked={state.sort === "desc"} />
              desc
            </label>
          </fieldset>
        </div>
        <div>
          {!!state.filteredIds.length && (
            <button className="fm-show-all" onClick={() => { setFilteredIds([]) }}>
              show all cards
            </button>
          )}
        </div>

        <Flipped flipId="list">
          <div className={state.type === "grid" ? "fm-grid" : "fm-list"}>
            <Flipped inverseFlipId="list">
              <ul className="list-contents">
                {[...DATA_FILTER]
                  .filter(d => state.filteredIds.includes(d.id)===false)
                  .sort((a, b) => {
                    if (state.sort === "asc") { return a.id - b.id; }
                    else { return b.id - a.id; }
                  })
                  .map(({ title, id }) => (<Card id={id} title={title} stagger={state.stagger} type={state.type} key={id} addToFilteredIds={addToFilteredIds}/>))}
              </ul>
            </Flipped>
          </div>
        </Flipped>
      </Flipper>
    </div>
  );
}
Each Flipped component must wrap a single child

I also test without remoove button and again error ...
no error on my lint*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant