@codefast/ui 0.3.11 → 0.3.12-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +4 -0
- package/dist/components/accordion.d.ts +11 -29
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +10 -37
- package/dist/components/alert-dialog.d.ts +25 -60
- package/dist/components/alert-dialog.d.ts.map +1 -0
- package/dist/components/alert-dialog.js +16 -69
- package/dist/components/alert.d.ts +16 -27
- package/dist/components/alert.d.ts.map +1 -0
- package/dist/components/alert.js +22 -30
- package/dist/components/aspect-ratio.d.ts +5 -8
- package/dist/components/aspect-ratio.d.ts.map +1 -0
- package/dist/components/aspect-ratio.js +5 -7
- package/dist/components/avatar.d.ts +7 -17
- package/dist/components/avatar.d.ts.map +1 -0
- package/dist/components/avatar.js +7 -18
- package/dist/components/badge.d.ts +15 -21
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +23 -20
- package/dist/components/breadcrumb.d.ts +13 -35
- package/dist/components/breadcrumb.d.ts.map +1 -0
- package/dist/components/breadcrumb.js +13 -49
- package/dist/components/button-group.d.ts +15 -29
- package/dist/components/button-group.d.ts.map +1 -0
- package/dist/components/button-group.js +22 -27
- package/dist/components/button.d.ts +26 -35
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +43 -51
- package/dist/components/calendar.d.ts +10 -24
- package/dist/components/calendar.d.ts.map +1 -0
- package/dist/components/calendar.js +75 -92
- package/dist/components/card.d.ts +11 -34
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +11 -39
- package/dist/components/carousel.d.ts +25 -55
- package/dist/components/carousel.d.ts.map +1 -0
- package/dist/components/carousel.js +82 -114
- package/dist/components/chart.d.ts +37 -72
- package/dist/components/chart.d.ts.map +1 -0
- package/dist/components/chart.js +161 -150
- package/dist/components/checkbox-cards.d.ts +9 -15
- package/dist/components/checkbox-cards.d.ts.map +1 -0
- package/dist/components/checkbox-cards.js +8 -22
- package/dist/components/checkbox-group.d.ts +9 -16
- package/dist/components/checkbox-group.d.ts.map +1 -0
- package/dist/components/checkbox-group.js +7 -19
- package/dist/components/checkbox.d.ts +5 -9
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +6 -14
- package/dist/components/collapsible.d.ts +7 -14
- package/dist/components/collapsible.d.ts.map +1 -0
- package/dist/components/collapsible.js +7 -15
- package/dist/components/command.d.ts +24 -55
- package/dist/components/command.d.ts.map +1 -0
- package/dist/components/command.js +18 -69
- package/dist/components/context-menu.d.ts +23 -72
- package/dist/components/context-menu.d.ts.map +1 -0
- package/dist/components/context-menu.js +21 -89
- package/dist/components/dialog.d.ts +23 -53
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +20 -72
- package/dist/components/drawer.d.ts +29 -60
- package/dist/components/drawer.d.ts.map +1 -0
- package/dist/components/drawer.js +16 -58
- package/dist/components/dropdown-menu.d.ts +23 -73
- package/dist/components/dropdown-menu.d.ts.map +1 -0
- package/dist/components/dropdown-menu.js +21 -96
- package/dist/components/empty.d.ts +16 -37
- package/dist/components/empty.d.ts.map +1 -0
- package/dist/components/empty.js +24 -44
- package/dist/components/field.d.ts +26 -63
- package/dist/components/field.d.ts.map +1 -0
- package/dist/components/field.js +46 -89
- package/dist/components/form.d.ts +16 -37
- package/dist/components/form.d.ts.map +1 -0
- package/dist/components/form.js +50 -66
- package/dist/components/hover-card.d.ts +8 -21
- package/dist/components/hover-card.d.ts.map +1 -0
- package/dist/components/hover-card.js +8 -23
- package/dist/components/input-group.d.ts +29 -53
- package/dist/components/input-group.d.ts.map +1 -0
- package/dist/components/input-group.js +59 -66
- package/dist/components/input-number.d.ts +8 -28
- package/dist/components/input-number.d.ts.map +1 -0
- package/dist/components/input-number.js +14 -55
- package/dist/components/input-otp.d.ts +11 -24
- package/dist/components/input-otp.d.ts.map +1 -0
- package/dist/components/input-otp.js +13 -34
- package/dist/components/input-password.d.ts +6 -12
- package/dist/components/input-password.d.ts.map +1 -0
- package/dist/components/input-password.js +10 -31
- package/dist/components/input-search.d.ts +9 -18
- package/dist/components/input-search.d.ts.map +1 -0
- package/dist/components/input-search.js +16 -44
- package/dist/components/input.d.ts +5 -10
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +5 -9
- package/dist/components/item.d.ts +33 -69
- package/dist/components/item.d.ts.map +1 -0
- package/dist/components/item.js +47 -90
- package/dist/components/kbd.d.ts +6 -13
- package/dist/components/kbd.d.ts.map +1 -0
- package/dist/components/kbd.js +6 -13
- package/dist/components/label.d.ts +5 -9
- package/dist/components/label.d.ts.map +1 -0
- package/dist/components/label.js +5 -8
- package/dist/components/menubar.d.ts +24 -80
- package/dist/components/menubar.d.ts.map +1 -0
- package/dist/components/menubar.js +23 -99
- package/dist/components/native-select.d.ts +7 -16
- package/dist/components/native-select.d.ts.map +1 -0
- package/dist/components/native-select.js +7 -25
- package/dist/components/navigation-menu.d.ts +13 -36
- package/dist/components/navigation-menu.d.ts.map +1 -0
- package/dist/components/navigation-menu.js +25 -61
- package/dist/components/pagination.d.ts +15 -35
- package/dist/components/pagination.d.ts.map +1 -0
- package/dist/components/pagination.js +13 -55
- package/dist/components/popover.d.ts +9 -24
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +9 -27
- package/dist/components/progress-circle.d.ts +89 -106
- package/dist/components/progress-circle.d.ts.map +1 -0
- package/dist/components/progress-circle.js +70 -103
- package/dist/components/progress.d.ts +5 -10
- package/dist/components/progress.d.ts.map +1 -0
- package/dist/components/progress.js +7 -13
- package/dist/components/radio-cards.d.ts +5 -10
- package/dist/components/radio-cards.d.ts.map +1 -0
- package/dist/components/radio-cards.js +7 -21
- package/dist/components/radio-group.d.ts +6 -13
- package/dist/components/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group.js +6 -17
- package/dist/components/radio.d.ts +6 -12
- package/dist/components/radio.d.ts.map +1 -0
- package/dist/components/radio.js +5 -10
- package/dist/components/resizable.d.ts +8 -18
- package/dist/components/resizable.d.ts.map +1 -0
- package/dist/components/resizable.js +7 -21
- package/dist/components/scroll-area.d.ts +21 -33
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +64 -84
- package/dist/components/select.d.ts +17 -50
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +26 -78
- package/dist/components/separator.d.ts +20 -29
- package/dist/components/separator.d.ts.map +1 -0
- package/dist/components/separator.js +27 -36
- package/dist/components/sheet.d.ts +30 -62
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +36 -80
- package/dist/components/sidebar.d.ts +67 -160
- package/dist/components/sidebar.d.ts.map +1 -0
- package/dist/components/sidebar.js +166 -301
- package/dist/components/skeleton.d.ts +5 -9
- package/dist/components/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton.js +5 -8
- package/dist/components/slider.d.ts +5 -13
- package/dist/components/slider.d.ts.map +1 -0
- package/dist/components/slider.js +12 -34
- package/dist/components/sonner.d.ts +8 -10
- package/dist/components/sonner.d.ts.map +1 -0
- package/dist/components/sonner.js +13 -16
- package/dist/components/spinner.d.ts +6 -12
- package/dist/components/spinner.d.ts.map +1 -0
- package/dist/components/spinner.js +20 -33
- package/dist/components/switch.d.ts +5 -9
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +5 -12
- package/dist/components/table.d.ts +12 -37
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +12 -47
- package/dist/components/tabs.d.ts +8 -21
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +8 -23
- package/dist/components/textarea.d.ts +5 -9
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +5 -8
- package/dist/components/toggle-group.d.ts +10 -24
- package/dist/components/toggle-group.d.ts.map +1 -0
- package/dist/components/toggle-group.js +20 -38
- package/dist/components/toggle.d.ts +18 -25
- package/dist/components/toggle.d.ts.map +1 -0
- package/dist/components/toggle.js +24 -29
- package/dist/components/tooltip.d.ts +9 -24
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +9 -28
- package/dist/hooks/use-animated-value.d.ts +2 -4
- package/dist/hooks/use-animated-value.d.ts.map +1 -0
- package/dist/hooks/use-animated-value.js +67 -58
- package/dist/hooks/use-copy-to-clipboard.d.ts +6 -11
- package/dist/hooks/use-copy-to-clipboard.d.ts.map +1 -0
- package/dist/hooks/use-copy-to-clipboard.js +42 -39
- package/dist/hooks/use-is-mobile.d.ts +2 -4
- package/dist/hooks/use-is-mobile.d.ts.map +1 -0
- package/dist/hooks/use-is-mobile.js +20 -23
- package/dist/hooks/use-media-query.d.ts +2 -4
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +49 -46
- package/dist/hooks/use-mutation-observer.d.ts +3 -6
- package/dist/hooks/use-mutation-observer.d.ts.map +1 -0
- package/dist/hooks/use-mutation-observer.js +33 -34
- package/dist/hooks/use-pagination.d.ts +15 -22
- package/dist/hooks/use-pagination.d.ts.map +1 -0
- package/dist/hooks/use-pagination.js +99 -99
- package/dist/index.d.ts +131 -69
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -69
- package/dist/primitives/checkbox-group.d.ts +84 -105
- package/dist/primitives/checkbox-group.d.ts.map +1 -0
- package/dist/primitives/checkbox-group.js +91 -105
- package/dist/primitives/input-number.d.ts +41 -51
- package/dist/primitives/input-number.d.ts.map +1 -0
- package/dist/primitives/input-number.js +417 -473
- package/dist/primitives/input.d.ts +43 -48
- package/dist/primitives/input.d.ts.map +1 -0
- package/dist/primitives/input.js +67 -66
- package/dist/primitives/progress-circle.d.ts +49 -79
- package/dist/primitives/progress-circle.d.ts.map +1 -0
- package/dist/primitives/progress-circle.js +134 -149
- package/package.json +17 -10
- package/{dist → src}/css/preset.css +1 -1
- /package/{dist → src}/css/amber.css +0 -0
- /package/{dist → src}/css/blue.css +0 -0
- /package/{dist → src}/css/cyan.css +0 -0
- /package/{dist → src}/css/emerald.css +0 -0
- /package/{dist → src}/css/fuchsia.css +0 -0
- /package/{dist → src}/css/gray.css +0 -0
- /package/{dist → src}/css/green.css +0 -0
- /package/{dist → src}/css/indigo.css +0 -0
- /package/{dist → src}/css/lime.css +0 -0
- /package/{dist → src}/css/neutral.css +0 -0
- /package/{dist → src}/css/orange.css +0 -0
- /package/{dist → src}/css/pink.css +0 -0
- /package/{dist → src}/css/purple.css +0 -0
- /package/{dist → src}/css/red.css +0 -0
- /package/{dist → src}/css/rose.css +0 -0
- /package/{dist → src}/css/sky.css +0 -0
- /package/{dist → src}/css/slate.css +0 -0
- /package/{dist → src}/css/stone.css +0 -0
- /package/{dist → src}/css/style.css +0 -0
- /package/{dist → src}/css/teal.css +0 -0
- /package/{dist → src}/css/violet.css +0 -0
- /package/{dist → src}/css/yellow.css +0 -0
- /package/{dist → src}/css/zinc.css +0 -0
|
@@ -1,53 +1,35 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { cn } from "@codefast/tailwind-variants";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
4
|
import { createContextScope } from "@radix-ui/react-context";
|
|
6
5
|
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
|
|
7
6
|
import { createToggleGroupScope } from "@radix-ui/react-toggle-group";
|
|
8
|
-
|
|
7
|
+
import { toggleVariants } from "#components/toggle";
|
|
8
|
+
/* -----------------------------------------------------------------------------
|
|
9
|
+
* Context: ToggleGroup
|
|
10
|
+
* -------------------------------------------------------------------------- */
|
|
9
11
|
const TOGGLE_GROUP_NAME = "ToggleGroup";
|
|
10
12
|
const [createToggleGroupContext] = createContextScope(TOGGLE_GROUP_NAME, [createToggleGroupScope]);
|
|
11
13
|
const useToggleGroupScope = createToggleGroupScope();
|
|
12
14
|
const [ToggleGroupProvider, useToggleGroupContext] = createToggleGroupContext(TOGGLE_GROUP_NAME);
|
|
13
15
|
function ToggleGroup({ __scopeToggleGroup, children, className, size, spacing = 0, variant, ...props }) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
scope: __scopeToggleGroup,
|
|
17
|
-
size,
|
|
18
|
-
spacing,
|
|
19
|
-
variant,
|
|
20
|
-
children: /* @__PURE__ */ jsx(ToggleGroupPrimitive.Root, {
|
|
21
|
-
className: cn("group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-lg data-[spacing=default]:data-[variant=outline]:shadow-xs", className),
|
|
22
|
-
"data-size": size,
|
|
23
|
-
"data-slot": "toggle-group",
|
|
24
|
-
"data-spacing": spacing,
|
|
25
|
-
"data-variant": variant,
|
|
26
|
-
style: { "--gap": spacing },
|
|
27
|
-
...toggleGroupScope,
|
|
28
|
-
...props,
|
|
29
|
-
children
|
|
30
|
-
})
|
|
31
|
-
});
|
|
16
|
+
const toggleGroupScope = useToggleGroupScope(__scopeToggleGroup);
|
|
17
|
+
return (_jsx(ToggleGroupProvider, { scope: __scopeToggleGroup, size: size, spacing: spacing, variant: variant, children: _jsx(ToggleGroupPrimitive.Root, { className: cn("group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-lg data-[spacing=default]:data-[variant=outline]:shadow-xs", className), "data-size": size, "data-slot": "toggle-group", "data-spacing": spacing, "data-variant": variant, style: { "--gap": spacing }, ...toggleGroupScope, ...props, children: children }) }));
|
|
32
18
|
}
|
|
19
|
+
/* -----------------------------------------------------------------------------
|
|
20
|
+
* Component: ToggleGroupItem
|
|
21
|
+
* -------------------------------------------------------------------------- */
|
|
33
22
|
const TOGGLE_GROUP_ITEM_NAME = "ToggleGroupItem";
|
|
34
23
|
function ToggleGroupItem({ __scopeToggleGroup, children, className, ...props }) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}), "w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10", "data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-lg data-[spacing=0]:last:rounded-r-lg data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l"),
|
|
43
|
-
"data-size": size,
|
|
44
|
-
"data-slot": "toggle-group-item",
|
|
45
|
-
"data-spacing": spacing,
|
|
46
|
-
"data-variant": variant,
|
|
47
|
-
...toggleGroupScope,
|
|
48
|
-
...props,
|
|
49
|
-
children
|
|
50
|
-
});
|
|
24
|
+
const { size, spacing, variant } = useToggleGroupContext(TOGGLE_GROUP_ITEM_NAME, __scopeToggleGroup);
|
|
25
|
+
const toggleGroupScope = useToggleGroupScope(__scopeToggleGroup);
|
|
26
|
+
return (_jsx(ToggleGroupPrimitive.Item, { className: cn(toggleVariants({
|
|
27
|
+
className,
|
|
28
|
+
size,
|
|
29
|
+
variant,
|
|
30
|
+
}), "w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10", "data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-lg data-[spacing=0]:last:rounded-r-lg data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l"), "data-size": size, "data-slot": "toggle-group-item", "data-spacing": spacing, "data-variant": variant, ...toggleGroupScope, ...props, children: children }));
|
|
51
31
|
}
|
|
52
|
-
|
|
32
|
+
/* -----------------------------------------------------------------------------
|
|
33
|
+
* Exports
|
|
34
|
+
* -------------------------------------------------------------------------- */
|
|
53
35
|
export { ToggleGroup, ToggleGroupItem };
|
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { ComponentProps, JSX } from "react";
|
|
1
|
+
import type { VariantProps } from "@codefast/tailwind-variants";
|
|
2
|
+
import type { ComponentProps, JSX } from "react";
|
|
4
3
|
import * as TogglePrimitive from "@radix-ui/react-toggle";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
outline: string;
|
|
16
|
-
};
|
|
4
|
+
declare const toggleVariants: import("@codefast/tailwind-variants").VariantFunctionType<{
|
|
5
|
+
size: {
|
|
6
|
+
default: string;
|
|
7
|
+
lg: string;
|
|
8
|
+
sm: string;
|
|
9
|
+
};
|
|
10
|
+
variant: {
|
|
11
|
+
default: string;
|
|
12
|
+
outline: string;
|
|
13
|
+
};
|
|
17
14
|
}, Record<string, never>>;
|
|
18
15
|
type ToggleVariants = VariantProps<typeof toggleVariants>;
|
|
19
|
-
interface ToggleProps extends ComponentProps<typeof TogglePrimitive.Root>, ToggleVariants {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
...props
|
|
26
|
-
}: ToggleProps): JSX.Element;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { Toggle, type ToggleProps, type ToggleVariants, toggleVariants };
|
|
16
|
+
interface ToggleProps extends ComponentProps<typeof TogglePrimitive.Root>, ToggleVariants {
|
|
17
|
+
}
|
|
18
|
+
declare function Toggle({ children, className, size, variant, ...props }: ToggleProps): JSX.Element;
|
|
19
|
+
export { Toggle, toggleVariants };
|
|
20
|
+
export type { ToggleProps, ToggleVariants };
|
|
21
|
+
//# sourceMappingURL=toggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../../src/components/toggle.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAGjD,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAM1D,QAAA,MAAM,cAAc;;;;;;;;;;yBAkBlB,CAAC;AAEH,KAAK,cAAc,GAAG,YAAY,CAAC,OAAO,cAAc,CAAC,CAAC;AAM1D,UAAU,WAAY,SAAQ,cAAc,CAAC,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,cAAc;CAAG;AAE5F,iBAAS,MAAM,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAU1F;AAMD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;AAClC,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { tv } from "@codefast/tailwind-variants";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
import * as TogglePrimitive from "@radix-ui/react-toggle";
|
|
5
|
-
|
|
5
|
+
/* -----------------------------------------------------------------------------
|
|
6
|
+
* Variant: Toggle
|
|
7
|
+
* -------------------------------------------------------------------------- */
|
|
6
8
|
const toggleVariants = tv({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
base: "inline-flex items-center justify-center gap-2 rounded-lg text-sm font-medium whitespace-nowrap transition-[color,box-shadow] outline-none hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
10
|
+
variants: {
|
|
11
|
+
size: {
|
|
12
|
+
default: "h-9 min-w-9 px-2",
|
|
13
|
+
lg: "h-10 min-w-10 px-2.5",
|
|
14
|
+
sm: "h-8 min-w-8 px-1.5",
|
|
15
|
+
},
|
|
16
|
+
variant: {
|
|
17
|
+
default: "bg-transparent",
|
|
18
|
+
outline: "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: {
|
|
22
|
+
size: "default",
|
|
23
|
+
variant: "default",
|
|
24
|
+
},
|
|
23
25
|
});
|
|
24
26
|
function Toggle({ children, className, size, variant, ...props }) {
|
|
25
|
-
|
|
26
|
-
className: toggleVariants({
|
|
27
|
-
className,
|
|
28
|
-
size,
|
|
29
|
-
variant
|
|
30
|
-
}),
|
|
31
|
-
"data-slot": "toggle",
|
|
32
|
-
...props,
|
|
33
|
-
children
|
|
34
|
-
});
|
|
27
|
+
return (_jsx(TogglePrimitive.Root, { className: toggleVariants({ className, size, variant }), "data-slot": "toggle", ...props, children: children }));
|
|
35
28
|
}
|
|
36
|
-
|
|
29
|
+
/* -----------------------------------------------------------------------------
|
|
30
|
+
* Exports
|
|
31
|
+
* -------------------------------------------------------------------------- */
|
|
37
32
|
export { Toggle, toggleVariants };
|
|
@@ -1,30 +1,15 @@
|
|
|
1
|
-
import { ComponentProps, JSX } from "react";
|
|
1
|
+
import type { ComponentProps, JSX } from "react";
|
|
2
2
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
3
|
-
|
|
4
|
-
//#region src/components/tooltip.d.ts
|
|
5
3
|
type TooltipProviderProps = ComponentProps<typeof TooltipPrimitive.Provider>;
|
|
6
|
-
declare function TooltipProvider({
|
|
7
|
-
...props
|
|
8
|
-
}: TooltipProviderProps): JSX.Element;
|
|
4
|
+
declare function TooltipProvider({ ...props }: TooltipProviderProps): JSX.Element;
|
|
9
5
|
type TooltipProps = ComponentProps<typeof TooltipPrimitive.Root>;
|
|
10
|
-
declare function Tooltip({
|
|
11
|
-
...props
|
|
12
|
-
}: TooltipProps): JSX.Element;
|
|
6
|
+
declare function Tooltip({ ...props }: TooltipProps): JSX.Element;
|
|
13
7
|
type TooltipTriggerProps = ComponentProps<typeof TooltipPrimitive.Trigger>;
|
|
14
|
-
declare function TooltipTrigger({
|
|
15
|
-
...props
|
|
16
|
-
}: TooltipTriggerProps): JSX.Element;
|
|
8
|
+
declare function TooltipTrigger({ ...props }: TooltipTriggerProps): JSX.Element;
|
|
17
9
|
type TooltipContentProps = ComponentProps<typeof TooltipPrimitive.Content>;
|
|
18
|
-
declare function TooltipContent({
|
|
19
|
-
children,
|
|
20
|
-
className,
|
|
21
|
-
sideOffset,
|
|
22
|
-
...props
|
|
23
|
-
}: TooltipContentProps): JSX.Element;
|
|
10
|
+
declare function TooltipContent({ children, className, sideOffset, ...props }: TooltipContentProps): JSX.Element;
|
|
24
11
|
type TooltipArrowProps = ComponentProps<typeof TooltipPrimitive.Arrow>;
|
|
25
|
-
declare function TooltipArrow({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
export { Tooltip, TooltipArrow, type TooltipArrowProps, TooltipContent, type TooltipContentProps, type TooltipProps, TooltipProvider, type TooltipProviderProps, TooltipTrigger, type TooltipTriggerProps };
|
|
12
|
+
declare function TooltipArrow({ className, ...props }: TooltipArrowProps): JSX.Element;
|
|
13
|
+
export { Tooltip, TooltipArrow, TooltipContent, TooltipProvider, TooltipTrigger };
|
|
14
|
+
export type { TooltipArrowProps, TooltipContentProps, TooltipProps, TooltipProviderProps, TooltipTriggerProps, };
|
|
15
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/components/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAGjD,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAM5D,KAAK,oBAAoB,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AAE7E,iBAAS,eAAe,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,GAAG,GAAG,CAAC,OAAO,CAExE;AAMD,KAAK,YAAY,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAEjE,iBAAS,OAAO,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CAExD;AAMD,KAAK,mBAAmB,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAE3E,iBAAS,cAAc,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAEtE;AAMD,KAAK,mBAAmB,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAE3E,iBAAS,cAAc,CAAC,EACtB,QAAQ,EACR,SAAS,EACT,UAAc,EACd,GAAG,KAAK,EACT,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAmBnC;AAMD,KAAK,iBAAiB,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAEvE,iBAAS,YAAY,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAQ7E;AAMD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAClF,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,GACpB,CAAC"}
|
|
@@ -1,42 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { cn } from "@codefast/tailwind-variants";
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
5
|
-
//#region src/components/tooltip.tsx
|
|
6
5
|
function TooltipProvider({ ...props }) {
|
|
7
|
-
|
|
8
|
-
"data-slot": "tooltip-provider",
|
|
9
|
-
...props
|
|
10
|
-
});
|
|
6
|
+
return _jsx(TooltipPrimitive.Provider, { "data-slot": "tooltip-provider", ...props });
|
|
11
7
|
}
|
|
12
8
|
function Tooltip({ ...props }) {
|
|
13
|
-
|
|
14
|
-
"data-slot": "tooltip",
|
|
15
|
-
...props
|
|
16
|
-
});
|
|
9
|
+
return _jsx(TooltipPrimitive.Root, { "data-slot": "tooltip", ...props });
|
|
17
10
|
}
|
|
18
11
|
function TooltipTrigger({ ...props }) {
|
|
19
|
-
|
|
20
|
-
"data-slot": "tooltip-trigger",
|
|
21
|
-
...props
|
|
22
|
-
});
|
|
12
|
+
return _jsx(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", ...props });
|
|
23
13
|
}
|
|
24
14
|
function TooltipContent({ children, className, sideOffset = 4, ...props }) {
|
|
25
|
-
|
|
26
|
-
className: cn("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md bg-primary px-3 py-1.5 text-xs text-balance text-primary-foreground ease-ui data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:data-[side=bottom]:slide-out-to-top-2 data-[state=closed]:data-[side=left]:slide-out-to-right-2 data-[state=closed]:data-[side=right]:slide-out-to-left-2 data-[state=closed]:data-[side=top]:slide-out-to-bottom-2 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-[state=delayed-open]:data-[side=bottom]:slide-in-from-top-2 data-[state=delayed-open]:data-[side=left]:slide-in-from-right-2 data-[state=delayed-open]:data-[side=right]:slide-in-from-left-2 data-[state=delayed-open]:data-[side=top]:slide-in-from-bottom-2", "max-w-(--radix-tooltip-content-available-width)", className),
|
|
27
|
-
collisionPadding: 8,
|
|
28
|
-
"data-slot": "tooltip-content",
|
|
29
|
-
sideOffset,
|
|
30
|
-
...props,
|
|
31
|
-
children: [children, /* @__PURE__ */ jsx(TooltipArrow, {})]
|
|
32
|
-
}) });
|
|
15
|
+
return (_jsx(TooltipPrimitive.Portal, { children: _jsxs(TooltipPrimitive.Content, { className: cn("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md bg-primary px-3 py-1.5 text-xs text-balance text-primary-foreground ease-ui data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:data-[side=bottom]:slide-out-to-top-2 data-[state=closed]:data-[side=left]:slide-out-to-right-2 data-[state=closed]:data-[side=right]:slide-out-to-left-2 data-[state=closed]:data-[side=top]:slide-out-to-bottom-2 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-[state=delayed-open]:data-[side=bottom]:slide-in-from-top-2 data-[state=delayed-open]:data-[side=left]:slide-in-from-right-2 data-[state=delayed-open]:data-[side=right]:slide-in-from-left-2 data-[state=delayed-open]:data-[side=top]:slide-in-from-bottom-2", "max-w-(--radix-tooltip-content-available-width)", className), collisionPadding: 8, "data-slot": "tooltip-content", sideOffset: sideOffset, ...props, children: [children, _jsx(TooltipArrow, {})] }) }));
|
|
33
16
|
}
|
|
34
17
|
function TooltipArrow({ className, ...props }) {
|
|
35
|
-
|
|
36
|
-
className: cn("fill-primary", className),
|
|
37
|
-
"data-slot": "tooltip-arrow",
|
|
38
|
-
...props
|
|
39
|
-
});
|
|
18
|
+
return (_jsx(TooltipPrimitive.Arrow, { className: cn("fill-primary", className), "data-slot": "tooltip-arrow", ...props }));
|
|
40
19
|
}
|
|
41
|
-
|
|
20
|
+
/* -----------------------------------------------------------------------------
|
|
21
|
+
* Exports
|
|
22
|
+
* -------------------------------------------------------------------------- */
|
|
42
23
|
export { Tooltip, TooltipArrow, TooltipContent, TooltipProvider, TooltipTrigger };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/hooks/use-animated-value.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Produce a smoothly animated numeric value in response to changes.
|
|
4
3
|
*
|
|
@@ -16,6 +15,5 @@
|
|
|
16
15
|
* return <div>{value}%</div>;
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
|
-
declare function useAnimatedValue(targetValue: null | number, duration: number, animate?: boolean): number;
|
|
20
|
-
//#
|
|
21
|
-
export { useAnimatedValue };
|
|
18
|
+
export declare function useAnimatedValue(targetValue: null | number, duration: number, animate?: boolean): number;
|
|
19
|
+
//# sourceMappingURL=use-animated-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-animated-value.d.ts","sourceRoot":"","sources":["../../src/hooks/use-animated-value.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,IAAI,GAAG,MAAM,EAC1B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,OAAO,GAChB,MAAM,CAqER"}
|
|
@@ -1,62 +1,71 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
//#region src/hooks/use-animated-value.ts
|
|
4
3
|
/**
|
|
5
|
-
* Produce a smoothly animated numeric value in response to changes.
|
|
6
|
-
*
|
|
7
|
-
* Applies a time-based easing (easeOutQuad) between the current and target values
|
|
8
|
-
* over the specified duration. When disabled, the value updates immediately.
|
|
9
|
-
*
|
|
10
|
-
* @param targetValue - Target number to animate toward; null resolves to 0.
|
|
11
|
-
* @param duration - Animation duration in milliseconds.
|
|
12
|
-
* @param animate - When false, bypasses animation and sets the value directly.
|
|
13
|
-
* @returns The current (rounded) animated value.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const value = useAnimatedValue(75, 1000, true);
|
|
18
|
-
* return <div>{value}%</div>;
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
function useAnimatedValue(targetValue, duration, animate) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
4
|
+
* Produce a smoothly animated numeric value in response to changes.
|
|
5
|
+
*
|
|
6
|
+
* Applies a time-based easing (easeOutQuad) between the current and target values
|
|
7
|
+
* over the specified duration. When disabled, the value updates immediately.
|
|
8
|
+
*
|
|
9
|
+
* @param targetValue - Target number to animate toward; null resolves to 0.
|
|
10
|
+
* @param duration - Animation duration in milliseconds.
|
|
11
|
+
* @param animate - When false, bypasses animation and sets the value directly.
|
|
12
|
+
* @returns The current (rounded) animated value.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const value = useAnimatedValue(75, 1000, true);
|
|
17
|
+
* return <div>{value}%</div>;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function useAnimatedValue(targetValue, duration, animate) {
|
|
21
|
+
// Default to 0 when targetValue is null
|
|
22
|
+
const actualTargetValue = targetValue ?? 0;
|
|
23
|
+
// Current animated output
|
|
24
|
+
const [animatedValue, setAnimatedValue] = useState(actualTargetValue);
|
|
25
|
+
// Prevent stale closures inside RAF loop
|
|
26
|
+
const animatedValueRef = useRef(actualTargetValue);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
animatedValueRef.current = animatedValue;
|
|
29
|
+
}, [animatedValue]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!animate) {
|
|
32
|
+
setAnimatedValue(actualTargetValue);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Starting value
|
|
36
|
+
const currentValue = animatedValueRef.current;
|
|
37
|
+
// Total delta across the animation
|
|
38
|
+
const valueRange = actualTargetValue - currentValue;
|
|
39
|
+
// Start timestamp
|
|
40
|
+
const startTime = performance.now();
|
|
41
|
+
if (duration <= 0 || valueRange === 0) {
|
|
42
|
+
setAnimatedValue(actualTargetValue);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// requestAnimationFrame id for cleanup
|
|
46
|
+
let animationFrame;
|
|
47
|
+
// RAF step
|
|
48
|
+
const animateValue = (currentTime) => {
|
|
49
|
+
// Elapsed milliseconds
|
|
50
|
+
const elapsedTime = currentTime - startTime;
|
|
51
|
+
if (elapsedTime >= duration) {
|
|
52
|
+
setAnimatedValue(actualTargetValue);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Linear progress (0..1)
|
|
56
|
+
const progress = elapsedTime / duration;
|
|
57
|
+
// easeOutQuad easing
|
|
58
|
+
const easeProgress = 1 - (1 - progress) * (1 - progress);
|
|
59
|
+
// Interpolated value
|
|
60
|
+
const nextValue = currentValue + valueRange * easeProgress;
|
|
61
|
+
setAnimatedValue(nextValue);
|
|
62
|
+
animationFrame = requestAnimationFrame(animateValue);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
animationFrame = requestAnimationFrame(animateValue);
|
|
66
|
+
return () => {
|
|
67
|
+
cancelAnimationFrame(animationFrame);
|
|
68
|
+
};
|
|
69
|
+
}, [actualTargetValue, duration, animate]);
|
|
70
|
+
return Math.round(animatedValue);
|
|
60
71
|
}
|
|
61
|
-
//#endregion
|
|
62
|
-
export { useAnimatedValue };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/hooks/use-copy-to-clipboard.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Provide clipboard copy capability with a transient copied state.
|
|
4
3
|
*
|
|
@@ -16,15 +15,11 @@
|
|
|
16
15
|
* <button onClick={() => copyToClipboard("Hello")}>{isCopied ? "Copied" : "Copy"}</button>
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
|
-
declare function useCopyToClipboard({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}?: {
|
|
23
|
-
onCopy?: () => void;
|
|
24
|
-
timeout?: number;
|
|
18
|
+
export declare function useCopyToClipboard({ onCopy, timeout, }?: {
|
|
19
|
+
onCopy?: () => void;
|
|
20
|
+
timeout?: number;
|
|
25
21
|
}): {
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
copyToClipboard: (value: string) => Promise<void>;
|
|
23
|
+
isCopied: boolean;
|
|
28
24
|
};
|
|
29
|
-
//#
|
|
30
|
-
export { useCopyToClipboard };
|
|
25
|
+
//# sourceMappingURL=use-copy-to-clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-copy-to-clipboard.d.ts","sourceRoot":"","sources":["../../src/hooks/use-copy-to-clipboard.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,OAAc,GACf,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG;IAClD,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,QAAQ,EAAE,OAAO,CAAC;CACnB,CAiCA"}
|
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
-
//#region src/hooks/use-copy-to-clipboard.ts
|
|
4
3
|
/**
|
|
5
|
-
* Provide clipboard copy capability with a transient copied state.
|
|
6
|
-
*
|
|
7
|
-
* Internally uses the Clipboard API when available and sets a temporary
|
|
8
|
-
* `isCopied` flag for UI feedback. A custom callback may be invoked upon copy.
|
|
9
|
-
*
|
|
10
|
-
* @param options - Configuration options.
|
|
11
|
-
* - onCopy: Callback invoked after a successful copy.
|
|
12
|
-
* - timeout: Duration in milliseconds to keep `isCopied` true. Defaults to 2000.
|
|
13
|
-
* @returns An object with a `copyToClipboard` function and an `isCopied` flag.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const { copyToClipboard, isCopied } = useCopyToClipboard({ timeout: 1500 });
|
|
18
|
-
* <button onClick={() => copyToClipboard("Hello")}>{isCopied ? "Copied" : "Copy"}</button>
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
function useCopyToClipboard({ onCopy, timeout =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
4
|
+
* Provide clipboard copy capability with a transient copied state.
|
|
5
|
+
*
|
|
6
|
+
* Internally uses the Clipboard API when available and sets a temporary
|
|
7
|
+
* `isCopied` flag for UI feedback. A custom callback may be invoked upon copy.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Configuration options.
|
|
10
|
+
* - onCopy: Callback invoked after a successful copy.
|
|
11
|
+
* - timeout: Duration in milliseconds to keep `isCopied` true. Defaults to 2000.
|
|
12
|
+
* @returns An object with a `copyToClipboard` function and an `isCopied` flag.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const { copyToClipboard, isCopied } = useCopyToClipboard({ timeout: 1500 });
|
|
17
|
+
* <button onClick={() => copyToClipboard("Hello")}>{isCopied ? "Copied" : "Copy"}</button>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function useCopyToClipboard({ onCopy, timeout = 2000, } = {}) {
|
|
21
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
22
|
+
const copyToClipboard = async (value) => {
|
|
23
|
+
if (typeof window === "undefined" ||
|
|
24
|
+
!("clipboard" in navigator) ||
|
|
25
|
+
typeof navigator.clipboard.writeText !== "function") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!value) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
await navigator.clipboard.writeText(value);
|
|
33
|
+
setIsCopied(true);
|
|
34
|
+
if (onCopy) {
|
|
35
|
+
onCopy();
|
|
36
|
+
}
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
setIsCopied(false);
|
|
39
|
+
}, timeout);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(error);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return { copyToClipboard, isCopied };
|
|
41
46
|
}
|
|
42
|
-
//#endregion
|
|
43
|
-
export { useCopyToClipboard };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/hooks/use-is-mobile.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Determine whether the current viewport should be treated as mobile.
|
|
4
3
|
*
|
|
@@ -17,6 +16,5 @@
|
|
|
17
16
|
* }
|
|
18
17
|
* ```
|
|
19
18
|
*/
|
|
20
|
-
declare function useIsMobile(mobileBreakpoint?: number): boolean;
|
|
21
|
-
//#
|
|
22
|
-
export { useIsMobile };
|
|
19
|
+
export declare function useIsMobile(mobileBreakpoint?: number): boolean;
|
|
20
|
+
//# sourceMappingURL=use-is-mobile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-is-mobile.d.ts","sourceRoot":"","sources":["../../src/hooks/use-is-mobile.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,gBAAgB,SAAM,GAAG,OAAO,CAE3D"}
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useMediaQuery } from "
|
|
3
|
-
//#region src/hooks/use-is-mobile.ts
|
|
2
|
+
import { useMediaQuery } from "#hooks/use-media-query";
|
|
4
3
|
/**
|
|
5
|
-
* Determine whether the current viewport should be treated as mobile.
|
|
6
|
-
*
|
|
7
|
-
* Uses {@link useMediaQuery} to evaluate a max-width media query derived from the
|
|
8
|
-
* provided breakpoint. By default, widths below 768px are considered mobile.
|
|
9
|
-
*
|
|
10
|
-
* @param mobileBreakpoint - Pixel width used as the mobile breakpoint. Values strictly
|
|
11
|
-
* less than this breakpoint are treated as mobile. Defaults to 768.
|
|
12
|
-
* @returns true when the viewport width is less than the given breakpoint; otherwise false.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* const isMobile = useIsMobile();
|
|
17
|
-
* if (isMobile) {
|
|
18
|
-
* // Render compact layout
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
function useIsMobile(mobileBreakpoint = 768) {
|
|
23
|
-
|
|
4
|
+
* Determine whether the current viewport should be treated as mobile.
|
|
5
|
+
*
|
|
6
|
+
* Uses {@link useMediaQuery} to evaluate a max-width media query derived from the
|
|
7
|
+
* provided breakpoint. By default, widths below 768px are considered mobile.
|
|
8
|
+
*
|
|
9
|
+
* @param mobileBreakpoint - Pixel width used as the mobile breakpoint. Values strictly
|
|
10
|
+
* less than this breakpoint are treated as mobile. Defaults to 768.
|
|
11
|
+
* @returns true when the viewport width is less than the given breakpoint; otherwise false.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const isMobile = useIsMobile();
|
|
16
|
+
* if (isMobile) {
|
|
17
|
+
* // Render compact layout
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function useIsMobile(mobileBreakpoint = 768) {
|
|
22
|
+
return useMediaQuery(`(max-width: ${(mobileBreakpoint - 1).toString()}px)`);
|
|
24
23
|
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { useIsMobile };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/hooks/use-media-query.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Subscribe to a CSS media query and receive its match state.
|
|
4
3
|
*
|
|
@@ -13,6 +12,5 @@
|
|
|
13
12
|
* const isNarrow = useMediaQuery("(max-width: 768px)");
|
|
14
13
|
* ```
|
|
15
14
|
*/
|
|
16
|
-
declare function useMediaQuery(query: string): boolean;
|
|
17
|
-
//#
|
|
18
|
-
export { useMediaQuery };
|
|
15
|
+
export declare function useMediaQuery(query: string): boolean;
|
|
16
|
+
//# sourceMappingURL=use-media-query.d.ts.map
|