Skip to content

Commit

Permalink
Merge pull request #7 from realvjy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
realvjy authored Apr 7, 2024
2 parents 38aedfe + eaf0d21 commit 2031dcd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./lib/shapes";
export { default as shapes, shapeTypes } from "./shapes";
export { default as shapes, shapeTypes, getRandomShape } from "./shapes";
5 changes: 2 additions & 3 deletions src/lib/iconBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import React, {
import NoiseMask from "./noiseMask";

// icon base props
export interface ShapeProps
extends RefAttributes<SVGSVGElement>,
Partial<SVGProps<SVGSVGElement>> {
type svgProps = RefAttributes<SVGSVGElement> & Partial<SVGProps<SVGSVGElement>>;
export interface ShapeProps extends svgProps{
size?: number;
noise?: boolean;
}
Expand Down
19 changes: 9 additions & 10 deletions src/lib/shapes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ const Coolshape: ForwardRefExoticComponent<ShapeOptions> = forwardRef(
(options, ref) => {
const { type, index, random, ...rest } = options;

let initialShape = null;
if (index !== undefined && type) {
initialShape = shapes[type][index];
if (index !== undefined && type && !random) {
const Shape = shapes[type][index];
return <Shape {...rest} ref={ref}/>
}
const [Shape, setShape] = useState<ShapeType | null>(initialShape);

const [RandomShape, setRandomShape] = useState<ShapeType | null>(null);
useEffect(() => {
if (random || !type || index === undefined) {
const shape = getRandomShape({ type }) as ShapeType;
setShape(shape);
}
setRandomShape(shape);
}, []);
if (!Shape) {
return null;
if (!RandomShape) {
return null;
}
return <Shape {...rest} ref={ref} />;
return <RandomShape {...rest} ref={ref} />;
}
);
Coolshape.displayName = "Coolshape";
Expand Down

0 comments on commit 2031dcd

Please sign in to comment.