-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: added support for external shapes
- Loading branch information
1 parent
a8a9485
commit d6ec28f
Showing
6 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters