-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshapes.ts
27 lines (24 loc) · 864 Bytes
/
shapes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { useMemo } from "react";
import { shapeList } from "@/components/controls/shapes/shape-list";
import { ISTKProps } from "@/types";
export const getMergedShapes = (options: ISTKProps["options"]) => {
if (!options?.shapes) return shapeList;
if (options?.shapes.icons.length === 0) return shapeList;
if (options?.shapes.overrideDefaultIconset) return options.shapes.icons;
return [...shapeList, ...options.shapes.icons];
};
export const useShapes = ({ options }: Pick<ISTKProps, "options">) => {
return useMemo(() => {
return getMergedShapes(options);
}, [options?.shapes]);
};
export const useShapeMap = ({ options }: Pick<ISTKProps, "options">) => {
return useMemo(
() =>
getMergedShapes(options).reduce((acc, shape) => {
acc[shape.displayName] = shape;
return acc;
}, {}),
[options?.shapes]
);
};