motion-v
Version:
<p align="center"> <img width="100" height="100" alt="Motion logo" src="https://user-images.githubusercontent.com/7850794/164965523-3eced4c4-6020-467e-acde-f11b7900ad62.png" /> </p> <h1 align="center">Motion for Vue</h1>
37 lines (36 loc) • 1.2 kB
JavaScript
import { injectLayoutGroup, provideLayoutGroup } from "./context.mjs";
import { useForceUpdate } from "./use-force-update.mjs";
import { nodeGroup } from "./group.mjs";
function useLayoutGroupProvider(props) {
const parentGroup = injectLayoutGroup(null);
const [forceRender, key] = useForceUpdate();
const context = {
id: getGroupId(props, parentGroup),
group: getGroup(props, parentGroup),
forceRender,
key
};
provideLayoutGroup(context);
return context;
}
function useLayoutGroup() {
const { forceRender } = injectLayoutGroup({ forceRender: () => {
} });
return { forceRender };
}
function getGroupId(props, parentGroup) {
const shouldInherit = props.inherit === true || props.inherit === "id";
const parentId = parentGroup == null ? void 0 : parentGroup.id;
if (shouldInherit && parentId) {
return props.id ? `${parentId}-${props.id}` : parentId;
}
return props.id;
}
function getGroup(props, parentGroup) {
const shouldInherit = props.inherit === true || props.inherit === "group";
return shouldInherit ? (parentGroup == null ? void 0 : parentGroup.group) || nodeGroup() : nodeGroup();
}
export {
useLayoutGroup,
useLayoutGroupProvider
};