Skip to content

Commit ad94e8a

Browse files
committed
Patch: further reduced bundle size
1 parent 97f59c9 commit ad94e8a

File tree

10 files changed

+146
-152
lines changed

10 files changed

+146
-152
lines changed

bun.lockb

-5.75 KB
Binary file not shown.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"d3": "7.8.5",
6767
"lodash": "4.17.21",
6868
"lucide-react": "0.316.0",
69-
"react-loader-spinner": "5.3.4",
7069
"react-redux": "9.1.0",
7170
"tailwind-merge": "1.13.2",
7271
"uuid": "9.0.0"

src/components/core/button.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { RotatingLines } from "react-loader-spinner";
21
import { cva } from "class-variance-authority";
32
import { twMerge } from "tailwind-merge";
43

@@ -35,7 +34,22 @@ const Core = ({ variant = "primary", children, loading, className, ...props }: a
3534
loading ? "opacity-100 ml-0" : "opacity-0 pointer-events-none -mr-7"
3635
} transition-all duration-150`}
3736
>
38-
<RotatingLines width="20" strokeColor="white" ariaLabel="button-loading" visible={true} />
37+
<svg
38+
aria-hidden="true"
39+
className="w-[1.125rem] h-[1.125rem] text-gray-500 animate-spin dark:text-gray-600 fill-white"
40+
viewBox="0 0 100 101"
41+
fill="none"
42+
xmlns="http://www.w3.org/2000/svg"
43+
>
44+
<path
45+
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
46+
fill="currentColor"
47+
/>
48+
<path
49+
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
50+
fill="currentFill"
51+
/>
52+
</svg>
3953
</div>
4054
)}
4155
{children}
@@ -46,6 +60,7 @@ const Core = ({ variant = "primary", children, loading, className, ...props }: a
4660
interface ButtonProps extends React.HTMLProps<HTMLButtonElement> {
4761
to?: string;
4862
wrapperClassName?: string;
63+
loading?: boolean;
4964
target?: string;
5065
ariaLabel?: string;
5166
variant?: "primary" | "secondary";

src/components/core/select.tsx

Lines changed: 63 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import * as React from "react";
2-
import * as SelectPrimitive from "@radix-ui/react-select";
2+
import {
3+
Content,
4+
Icon,
5+
Item,
6+
ItemIndicator,
7+
ItemText,
8+
Portal,
9+
Root,
10+
ScrollDownButton,
11+
ScrollUpButton,
12+
Trigger,
13+
Value,
14+
Viewport
15+
} from "@radix-ui/react-select";
316
import { Check, ChevronDown, ChevronUp, ChevronsUpDown } from "lucide-react";
417
import { twMerge } from "tailwind-merge";
518

6-
const Select = SelectPrimitive.Root;
19+
const Select = Root;
720

8-
const SelectGroup = SelectPrimitive.Group;
9-
10-
const SelectValue = SelectPrimitive.Value;
21+
const SelectValue = Value;
1122

1223
const SelectTrigger = React.forwardRef<
13-
React.ElementRef<typeof SelectPrimitive.Trigger>,
14-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
24+
React.ElementRef<typeof Trigger>,
25+
React.ComponentPropsWithoutRef<typeof Trigger>
1526
>(({ className, children, ...props }, ref) => (
16-
<SelectPrimitive.Trigger
27+
<Trigger
1728
ref={ref}
1829
className={twMerge(
1930
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
@@ -22,47 +33,47 @@ const SelectTrigger = React.forwardRef<
2233
{...props}
2334
>
2435
{children}
25-
<SelectPrimitive.Icon asChild>
36+
<Icon asChild>
2637
<ChevronsUpDown className="h-4 w-4 opacity-50" />
27-
</SelectPrimitive.Icon>
28-
</SelectPrimitive.Trigger>
38+
</Icon>
39+
</Trigger>
2940
));
30-
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
41+
SelectTrigger.displayName = Trigger.displayName;
3142

3243
const SelectScrollUpButton = React.forwardRef<
33-
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
34-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
44+
React.ElementRef<typeof ScrollUpButton>,
45+
React.ComponentPropsWithoutRef<typeof ScrollUpButton>
3546
>(({ className, ...props }, ref) => (
36-
<SelectPrimitive.ScrollUpButton
47+
<ScrollUpButton
3748
ref={ref}
3849
className={twMerge("flex cursor-default items-center justify-center py-1", className)}
3950
{...props}
4051
>
4152
<ChevronUp />
42-
</SelectPrimitive.ScrollUpButton>
53+
</ScrollUpButton>
4354
));
44-
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
55+
SelectScrollUpButton.displayName = ScrollUpButton.displayName;
4556

4657
const SelectScrollDownButton = React.forwardRef<
47-
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
48-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
58+
React.ElementRef<typeof ScrollDownButton>,
59+
React.ComponentPropsWithoutRef<typeof ScrollDownButton>
4960
>(({ className, ...props }, ref) => (
50-
<SelectPrimitive.ScrollDownButton
61+
<ScrollDownButton
5162
ref={ref}
5263
className={twMerge("flex cursor-default items-center justify-center py-1", className)}
5364
{...props}
5465
>
5566
<ChevronDown />
56-
</SelectPrimitive.ScrollDownButton>
67+
</ScrollDownButton>
5768
));
58-
SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
69+
SelectScrollDownButton.displayName = ScrollDownButton.displayName;
5970

6071
const SelectContent = React.forwardRef<
61-
React.ElementRef<typeof SelectPrimitive.Content>,
62-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
72+
React.ElementRef<typeof Content>,
73+
React.ComponentPropsWithoutRef<typeof Content>
6374
>(({ className, children, position = "popper", ...props }, ref) => (
64-
<SelectPrimitive.Portal>
65-
<SelectPrimitive.Content
75+
<Portal>
76+
<Content
6677
ref={ref}
6778
className={twMerge(
6879
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
@@ -74,68 +85,40 @@ const SelectContent = React.forwardRef<
7485
{...props}
7586
>
7687
<SelectScrollUpButton />
77-
<SelectPrimitive.Viewport
88+
<Viewport
7889
className={twMerge(
7990
"p-1",
8091
position === "popper" &&
8192
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
8293
)}
8394
>
8495
{children}
85-
</SelectPrimitive.Viewport>
96+
</Viewport>
8697
<SelectScrollDownButton />
87-
</SelectPrimitive.Content>
88-
</SelectPrimitive.Portal>
89-
));
90-
SelectContent.displayName = SelectPrimitive.Content.displayName;
91-
92-
const SelectLabel = React.forwardRef<
93-
React.ElementRef<typeof SelectPrimitive.Label>,
94-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
95-
>(({ className, ...props }, ref) => (
96-
<SelectPrimitive.Label ref={ref} className={twMerge("px-2 py-1.5 text-sm font-semibold", className)} {...props} />
98+
</Content>
99+
</Portal>
97100
));
98-
SelectLabel.displayName = SelectPrimitive.Label.displayName;
101+
SelectContent.displayName = Content.displayName;
99102

100-
const SelectItem = React.forwardRef<
101-
React.ElementRef<typeof SelectPrimitive.Item>,
102-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
103-
>(({ className, children, ...props }, ref) => (
104-
<SelectPrimitive.Item
105-
ref={ref}
106-
className={twMerge(
107-
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
108-
className
109-
)}
110-
{...props}
111-
>
112-
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
113-
<SelectPrimitive.ItemIndicator>
114-
<Check className="h-4 w-4" />
115-
</SelectPrimitive.ItemIndicator>
116-
</span>
117-
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
118-
</SelectPrimitive.Item>
119-
));
120-
SelectItem.displayName = SelectPrimitive.Item.displayName;
121-
122-
const SelectSeparator = React.forwardRef<
123-
React.ElementRef<typeof SelectPrimitive.Separator>,
124-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
125-
>(({ className, ...props }, ref) => (
126-
<SelectPrimitive.Separator ref={ref} className={twMerge("-mx-1 my-1 h-px bg-muted", className)} {...props} />
127-
));
128-
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
103+
const SelectItem = React.forwardRef<React.ElementRef<typeof Item>, React.ComponentPropsWithoutRef<typeof Item>>(
104+
({ className, children, ...props }, ref) => (
105+
<Item
106+
ref={ref}
107+
className={twMerge(
108+
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
109+
className
110+
)}
111+
{...props}
112+
>
113+
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
114+
<ItemIndicator>
115+
<Check className="h-4 w-4" />
116+
</ItemIndicator>
117+
</span>
118+
<ItemText>{children}</ItemText>
119+
</Item>
120+
)
121+
);
122+
SelectItem.displayName = Item.displayName;
129123

130-
export {
131-
Select,
132-
SelectGroup,
133-
SelectValue,
134-
SelectTrigger,
135-
SelectContent,
136-
SelectLabel,
137-
SelectItem,
138-
SelectSeparator,
139-
SelectScrollUpButton,
140-
SelectScrollDownButton
141-
};
124+
export { Select, SelectValue, SelectTrigger, SelectContent, SelectItem };

src/components/core/typography/footnote.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
export { default as Body } from "./body";
22
export { default as Callout } from "./callout";
33
export { default as Caption } from "./caption";
4-
export { default as Footnote } from "./footnote";
5-
export { default as Title } from "./title";

src/components/core/typography/title.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { useState } from "react";
2+
import { Braces } from "lucide-react";
3+
import { twMerge } from "tailwind-merge";
4+
import { useBreakpoint } from "@/hooks";
5+
import { ISTKData } from "@/types";
6+
import { IStyles } from "@/types/styles";
7+
import { stateToJSON } from "@/utils";
8+
import { Button, IconButton } from "../core";
9+
10+
interface IExportActionProps {
11+
text?: string;
12+
onExport?: (data: ISTKData) => Promise<void> | void;
13+
styles?: IStyles;
14+
}
15+
16+
const ExportAction: React.FC<IExportActionProps> = ({ text = "Export JSON", onExport, styles }) => {
17+
const [loading, setLoading] = useState(false);
18+
const { md } = useBreakpoint();
19+
20+
const onExportJson = () => {
21+
const json = stateToJSON();
22+
if (onExport) {
23+
setLoading(true);
24+
const result = onExport(json);
25+
if (result instanceof Promise) {
26+
result.finally(() => setLoading(false));
27+
} else {
28+
setLoading(false);
29+
}
30+
} else {
31+
console.log(json);
32+
sessionStorage.setItem("stk-data", JSON.stringify(json));
33+
navigator.clipboard.writeText(JSON.stringify(json));
34+
}
35+
};
36+
37+
if (md)
38+
return (
39+
<Button
40+
loading={loading}
41+
className={twMerge("py-[0.35rem] text-center", styles?.core?.button?.className)}
42+
style={styles?.core?.button?.properties}
43+
onClick={onExportJson}
44+
>
45+
{text}
46+
</Button>
47+
);
48+
49+
return (
50+
<IconButton
51+
icon={<Braces />}
52+
label={text}
53+
onClick={onExportJson}
54+
className={styles?.core?.button?.className}
55+
style={styles?.core?.button?.properties}
56+
/>
57+
);
58+
};
59+
60+
export default ExportAction;

0 commit comments

Comments
 (0)