UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

34 lines (33 loc) 1.65 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef, Fragment, memo, useMemo, useRef, useState } from "react"; import { PillRootProvider } from "./root.context.js"; import { PillRowDefault } from "./row-default.js"; function PillRootImpl({ children = PillRowDefault, rows, orientation, onPillRowChange, onPillItemActiveChange, onPillItemThrown, ...p }, ref) { const [cloned, setCloned] = useState(null); const [dragState, setDragState] = useState(null); const prevSwapId = useRef(null); const prevRowId = useRef(null); const movedRef = useRef(null); const value = useMemo(() => { return { orientation: orientation ?? "horizontal", cloned, setCloned, rows: rows, dragState, setDragState, movedRef, prevSwapId, prevRowId, onPillItemActiveChange: onPillItemActiveChange ?? (() => { }), onPillRowChange: onPillRowChange ?? (() => { }), onPillItemThrown: onPillItemThrown ?? (() => { }), }; }, [cloned, dragState, onPillItemActiveChange, onPillItemThrown, onPillRowChange, orientation, rows]); const rendered = useMemo(() => { const r = cloned ?? rows; return r.map((x, i) => _jsx(Fragment, { children: children(x, value) }, i)); }, [children, cloned, rows, value]); return (_jsx(PillRootProvider, { value: value, children: _jsx("div", { ...p, ref: ref, "data-ln-pill-root": true, "data-ln-orientation": orientation ?? "horizontal", children: rendered }) })); } export const PillManager = memo(forwardRef(PillRootImpl));