@puzzle-ui/ui 0.3.0 → 0.5.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/README.md +70 -70
- package/dist/components/actions/button/button.css +5 -2
- package/dist/components/actions/button-group/button-group.css +16 -17
- package/dist/components/data-display/badge/badge.css +15 -2
- package/dist/components/data-display/badge/index.cjs +13 -2
- package/dist/components/data-display/badge/index.cjs.map +1 -1
- package/dist/components/data-display/badge/index.d.cts +7 -2
- package/dist/components/data-display/badge/index.d.ts +7 -2
- package/dist/components/data-display/badge/index.js +13 -2
- package/dist/components/data-display/badge/index.js.map +1 -1
- package/dist/components/data-display/empty-state/empty-state.css +128 -0
- package/dist/components/data-display/empty-state/empty-state.utils.cjs +6 -0
- package/dist/components/data-display/empty-state/empty-state.utils.cjs.map +1 -0
- package/dist/components/data-display/empty-state/empty-state.utils.js +6 -0
- package/dist/components/data-display/empty-state/empty-state.utils.js.map +1 -0
- package/dist/components/data-display/empty-state/index.cjs +49 -0
- package/dist/components/data-display/empty-state/index.cjs.map +1 -0
- package/dist/components/data-display/empty-state/index.d.cts +19 -0
- package/dist/components/data-display/empty-state/index.d.ts +19 -0
- package/dist/components/data-display/empty-state/index.js +44 -0
- package/dist/components/data-display/empty-state/index.js.map +1 -0
- package/dist/components/data-display/rating/index.cjs +84 -0
- package/dist/components/data-display/rating/index.cjs.map +1 -0
- package/dist/components/data-display/rating/index.d.cts +3 -0
- package/dist/components/data-display/rating/index.d.ts +3 -0
- package/dist/components/data-display/rating/index.js +84 -0
- package/dist/components/data-display/rating/index.js.map +1 -0
- package/dist/components/data-display/rating/rating.css +72 -0
- package/dist/components/data-display/rating/rating.types.d.cts +15 -0
- package/dist/components/data-display/rating/rating.types.d.ts +15 -0
- package/dist/components/data-display/rating/rating.utils.cjs +27 -0
- package/dist/components/data-display/rating/rating.utils.cjs.map +1 -0
- package/dist/components/data-display/rating/rating.utils.js +25 -0
- package/dist/components/data-display/rating/rating.utils.js.map +1 -0
- package/dist/components/editors/text-editor/editor.cjs.map +1 -1
- package/dist/components/editors/text-editor/editor.js.map +1 -1
- package/dist/components/editors/text-editor/text-document.cjs.map +1 -1
- package/dist/components/editors/text-editor/text-document.js.map +1 -1
- package/dist/components/editors/text-editor/text-parser.cjs.map +1 -1
- package/dist/components/editors/text-editor/text-parser.js.map +1 -1
- package/dist/components/editors/text-editor/text-renderer.cjs.map +1 -1
- package/dist/components/editors/text-editor/text-renderer.js.map +1 -1
- package/dist/components/forms/autocomplete/index.cjs.map +1 -1
- package/dist/components/forms/autocomplete/index.js.map +1 -1
- package/dist/components/forms/checkbox/checkbox.css +2 -10
- package/dist/components/forms/color-picker/color-picker.css +351 -0
- package/dist/components/forms/color-picker/color-picker.types.d.cts +25 -0
- package/dist/components/forms/color-picker/color-picker.types.d.ts +25 -0
- package/dist/components/forms/color-picker/color-picker.utils.cjs +116 -0
- package/dist/components/forms/color-picker/color-picker.utils.cjs.map +1 -0
- package/dist/components/forms/color-picker/color-picker.utils.js +109 -0
- package/dist/components/forms/color-picker/color-picker.utils.js.map +1 -0
- package/dist/components/forms/color-picker/index.cjs +340 -0
- package/dist/components/forms/color-picker/index.cjs.map +1 -0
- package/dist/components/forms/color-picker/index.d.cts +3 -0
- package/dist/components/forms/color-picker/index.d.ts +3 -0
- package/dist/components/forms/color-picker/index.js +340 -0
- package/dist/components/forms/color-picker/index.js.map +1 -0
- package/dist/components/forms/file-upload/file-upload.utils.cjs.map +1 -1
- package/dist/components/forms/file-upload/file-upload.utils.js.map +1 -1
- package/dist/components/forms/input/number-input.js +5 -5
- package/dist/components/forms/input/number-input.js.map +1 -1
- package/dist/components/forms/input-group/index.d.cts +3 -0
- package/dist/components/forms/input-group/index.d.ts +3 -0
- package/dist/components/forms/input-group/input-group.cjs +18 -0
- package/dist/components/forms/input-group/input-group.cjs.map +1 -0
- package/dist/components/forms/input-group/input-group.css +62 -0
- package/dist/components/forms/input-group/input-group.d.cts +7 -0
- package/dist/components/forms/input-group/input-group.d.ts +7 -0
- package/dist/components/forms/input-group/input-group.js +18 -0
- package/dist/components/forms/input-group/input-group.js.map +1 -0
- package/dist/components/forms/input-group/input-group.types.d.cts +7 -0
- package/dist/components/forms/input-group/input-group.types.d.ts +7 -0
- package/dist/components/forms/input-group/input-group.utils.cjs +5 -0
- package/dist/components/forms/input-group/input-group.utils.cjs.map +1 -0
- package/dist/components/forms/input-group/input-group.utils.js +5 -0
- package/dist/components/forms/input-group/input-group.utils.js.map +1 -0
- package/dist/components/forms/radio-group/index.d.cts +2 -1
- package/dist/components/forms/radio-group/index.d.ts +2 -1
- package/dist/components/forms/select/index.cjs.map +1 -1
- package/dist/components/forms/select/index.js.map +1 -1
- package/dist/components/forms/slider/index.cjs +1 -1
- package/dist/components/forms/slider/index.cjs.map +1 -1
- package/dist/components/forms/slider/index.js +1 -1
- package/dist/components/forms/slider/index.js.map +1 -1
- package/dist/components/forms/stepper/index.d.cts +4 -2
- package/dist/components/forms/stepper/index.d.ts +4 -2
- package/dist/components/forms/time-picker/index.cjs +108 -0
- package/dist/components/forms/time-picker/index.cjs.map +1 -0
- package/dist/components/forms/time-picker/index.d.cts +3 -0
- package/dist/components/forms/time-picker/index.d.ts +3 -0
- package/dist/components/forms/time-picker/index.js +108 -0
- package/dist/components/forms/time-picker/index.js.map +1 -0
- package/dist/components/forms/time-picker/time-picker.css +166 -0
- package/dist/components/forms/time-picker/time-picker.types.d.cts +34 -0
- package/dist/components/forms/time-picker/time-picker.types.d.ts +34 -0
- package/dist/components/forms/time-picker/time-picker.utils.cjs +25 -0
- package/dist/components/forms/time-picker/time-picker.utils.cjs.map +1 -0
- package/dist/components/forms/time-picker/time-picker.utils.js +24 -0
- package/dist/components/forms/time-picker/time-picker.utils.js.map +1 -0
- package/dist/components/forms/token-input/index.cjs +189 -0
- package/dist/components/forms/token-input/index.cjs.map +1 -0
- package/dist/components/forms/token-input/index.d.cts +3 -0
- package/dist/components/forms/token-input/index.d.ts +3 -0
- package/dist/components/forms/token-input/index.js +189 -0
- package/dist/components/forms/token-input/index.js.map +1 -0
- package/dist/components/forms/token-input/token-input.css +145 -0
- package/dist/components/forms/token-input/token-input.types.d.cts +48 -0
- package/dist/components/forms/token-input/token-input.types.d.ts +48 -0
- package/dist/components/forms/token-input/token-input.utils.cjs +30 -0
- package/dist/components/forms/token-input/token-input.utils.cjs.map +1 -0
- package/dist/components/forms/token-input/token-input.utils.js +24 -0
- package/dist/components/forms/token-input/token-input.utils.js.map +1 -0
- package/dist/components/layout/aspect-ratio/aspect-ratio.css +14 -0
- package/dist/components/layout/aspect-ratio/aspect-ratio.utils.cjs +11 -0
- package/dist/components/layout/aspect-ratio/aspect-ratio.utils.cjs.map +1 -0
- package/dist/components/layout/aspect-ratio/aspect-ratio.utils.js +11 -0
- package/dist/components/layout/aspect-ratio/aspect-ratio.utils.js.map +1 -0
- package/dist/components/layout/aspect-ratio/index.cjs +16 -0
- package/dist/components/layout/aspect-ratio/index.cjs.map +1 -0
- package/dist/components/layout/aspect-ratio/index.d.cts +11 -0
- package/dist/components/layout/aspect-ratio/index.d.ts +11 -0
- package/dist/components/layout/aspect-ratio/index.js +16 -0
- package/dist/components/layout/aspect-ratio/index.js.map +1 -0
- package/dist/components/layout/container/container.css +1 -0
- package/dist/components/layout/page-layout/page-layout.css +1 -0
- package/dist/components/layout/resizable-panels/index.cjs +1 -1
- package/dist/components/layout/resizable-panels/index.cjs.map +1 -1
- package/dist/components/layout/resizable-panels/index.js +1 -1
- package/dist/components/layout/resizable-panels/index.js.map +1 -1
- package/dist/components/layout/resizable-panels/resizable-panels.utils.cjs.map +1 -1
- package/dist/components/layout/resizable-panels/resizable-panels.utils.js.map +1 -1
- package/dist/components/layout/scroll-area/index.cjs +27 -0
- package/dist/components/layout/scroll-area/index.cjs.map +1 -0
- package/dist/components/layout/scroll-area/index.d.cts +15 -0
- package/dist/components/layout/scroll-area/index.d.ts +15 -0
- package/dist/components/layout/scroll-area/index.js +27 -0
- package/dist/components/layout/scroll-area/index.js.map +1 -0
- package/dist/components/layout/scroll-area/scroll-area.css +25 -0
- package/dist/components/layout/scroll-area/scroll-area.utils.cjs +8 -0
- package/dist/components/layout/scroll-area/scroll-area.utils.cjs.map +1 -0
- package/dist/components/layout/scroll-area/scroll-area.utils.d.cts +2 -0
- package/dist/components/layout/scroll-area/scroll-area.utils.d.ts +2 -0
- package/dist/components/layout/scroll-area/scroll-area.utils.js +8 -0
- package/dist/components/layout/scroll-area/scroll-area.utils.js.map +1 -0
- package/dist/components/layout/section/index.cjs +10 -4
- package/dist/components/layout/section/index.cjs.map +1 -1
- package/dist/components/layout/section/index.d.cts +1 -1
- package/dist/components/layout/section/index.d.ts +1 -1
- package/dist/components/layout/section/index.js +11 -5
- package/dist/components/layout/section/index.js.map +1 -1
- package/dist/components/layout/section/section.css +9 -3
- package/dist/components/layout/section/types.d.cts +5 -5
- package/dist/components/layout/section/types.d.ts +5 -5
- package/dist/components/layout/separator/index.cjs +18 -0
- package/dist/components/layout/separator/index.cjs.map +1 -0
- package/dist/components/layout/separator/index.d.cts +17 -0
- package/dist/components/layout/separator/index.d.ts +17 -0
- package/dist/components/layout/separator/index.js +18 -0
- package/dist/components/layout/separator/index.js.map +1 -0
- package/dist/components/layout/separator/separator.css +15 -0
- package/dist/components/layout/separator/separator.utils.cjs +11 -0
- package/dist/components/layout/separator/separator.utils.cjs.map +1 -0
- package/dist/components/layout/separator/separator.utils.d.cts +2 -0
- package/dist/components/layout/separator/separator.utils.d.ts +2 -0
- package/dist/components/layout/separator/separator.utils.js +11 -0
- package/dist/components/layout/separator/separator.utils.js.map +1 -0
- package/dist/components/layout/stack/index.cjs +18 -2
- package/dist/components/layout/stack/index.cjs.map +1 -1
- package/dist/components/layout/stack/index.d.cts +8 -6
- package/dist/components/layout/stack/index.d.ts +8 -6
- package/dist/components/layout/stack/index.js +18 -2
- package/dist/components/layout/stack/index.js.map +1 -1
- package/dist/components/layout/stack/stack.css +118 -138
- package/dist/components/navigation/accordion/index.cjs.map +1 -1
- package/dist/components/navigation/accordion/index.js.map +1 -1
- package/dist/components/navigation/carousel/index.cjs +5 -2
- package/dist/components/navigation/carousel/index.cjs.map +1 -1
- package/dist/components/navigation/carousel/index.js +5 -2
- package/dist/components/navigation/carousel/index.js.map +1 -1
- package/dist/components/navigation/pagination/index.cjs +146 -0
- package/dist/components/navigation/pagination/index.cjs.map +1 -0
- package/dist/components/navigation/pagination/index.d.cts +3 -0
- package/dist/components/navigation/pagination/index.d.ts +3 -0
- package/dist/components/navigation/pagination/index.js +146 -0
- package/dist/components/navigation/pagination/index.js.map +1 -0
- package/dist/components/navigation/pagination/pagination.css +134 -0
- package/dist/components/navigation/pagination/pagination.types.d.cts +38 -0
- package/dist/components/navigation/pagination/pagination.types.d.ts +38 -0
- package/dist/components/navigation/pagination/pagination.utils.cjs +54 -0
- package/dist/components/navigation/pagination/pagination.utils.cjs.map +1 -0
- package/dist/components/navigation/pagination/pagination.utils.js +53 -0
- package/dist/components/navigation/pagination/pagination.utils.js.map +1 -0
- package/dist/components/navigation/tabs/index.d.cts +3 -2
- package/dist/components/navigation/tabs/index.d.ts +3 -2
- package/dist/components/navigation/tree-view/index.cjs.map +1 -1
- package/dist/components/navigation/tree-view/index.js.map +1 -1
- package/dist/components/overlays/context-menu/context-menu.css +151 -0
- package/dist/components/overlays/context-menu/context-menu.types.d.cts +69 -0
- package/dist/components/overlays/context-menu/context-menu.types.d.ts +69 -0
- package/dist/components/overlays/context-menu/context-menu.utils.cjs +46 -0
- package/dist/components/overlays/context-menu/context-menu.utils.cjs.map +1 -0
- package/dist/components/overlays/context-menu/context-menu.utils.js +40 -0
- package/dist/components/overlays/context-menu/context-menu.utils.js.map +1 -0
- package/dist/components/overlays/context-menu/index.cjs +830 -0
- package/dist/components/overlays/context-menu/index.cjs.map +1 -0
- package/dist/components/overlays/context-menu/index.d.cts +42 -0
- package/dist/components/overlays/context-menu/index.d.ts +42 -0
- package/dist/components/overlays/context-menu/index.js +818 -0
- package/dist/components/overlays/context-menu/index.js.map +1 -0
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.cjs.map +1 -1
- package/dist/components/overlays/dropdown-menu/dropdown-menu-content.js.map +1 -1
- package/dist/components/overlays/dropdown-menu/dropdown-menu.utils.cjs.map +1 -1
- package/dist/components/overlays/dropdown-menu/dropdown-menu.utils.js.map +1 -1
- package/dist/components/typography/heading.cjs +6 -2
- package/dist/components/typography/heading.cjs.map +1 -1
- package/dist/components/typography/heading.d.cts +3 -2
- package/dist/components/typography/heading.d.ts +3 -2
- package/dist/components/typography/heading.js +6 -2
- package/dist/components/typography/heading.js.map +1 -1
- package/dist/components/typography/text.cjs +6 -2
- package/dist/components/typography/text.cjs.map +1 -1
- package/dist/components/typography/text.d.cts +3 -2
- package/dist/components/typography/text.d.ts +3 -2
- package/dist/components/typography/text.js +6 -2
- package/dist/components/typography/text.js.map +1 -1
- package/dist/components/utilities/preview/index.cjs +89 -21
- package/dist/components/utilities/preview/index.cjs.map +1 -1
- package/dist/components/utilities/preview/index.d.cts +6 -2
- package/dist/components/utilities/preview/index.d.ts +6 -2
- package/dist/components/utilities/preview/index.js +89 -21
- package/dist/components/utilities/preview/index.js.map +1 -1
- package/dist/components/utilities/preview/preview.css +26 -11
- package/dist/components/utilities/transition/index.d.cts +1 -1
- package/dist/components/utilities/transition/index.d.ts +1 -1
- package/dist/index.cjs +136 -97
- package/dist/index.d.cts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +12 -1
- package/package.json +7 -6
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const require_empty_state_utils = require("./empty-state.utils.cjs");
|
|
2
|
+
;/* empty css */
|
|
3
|
+
let _puzzle_ui_core = require("@puzzle-ui/core");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
// src/components/data-display/empty-state/index.tsx
|
|
6
|
+
const EmptyState = ({ size = "md", variant = "default", className, children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
7
|
+
...props,
|
|
8
|
+
className: require_empty_state_utils.getEmptyStateClasses(size, variant, className),
|
|
9
|
+
"data-size": size,
|
|
10
|
+
"data-variant": variant,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
const EmptyStateHeader = ({ className, children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
14
|
+
...props,
|
|
15
|
+
className: (0, _puzzle_ui_core.cn)("puzzle-empty-state__header", className),
|
|
16
|
+
children
|
|
17
|
+
});
|
|
18
|
+
const EmptyStateMedia = ({ variant = "default", className, children, "aria-label": ariaLabel, "aria-hidden": ariaHidden, role, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
19
|
+
...props,
|
|
20
|
+
className: (0, _puzzle_ui_core.cn)("puzzle-empty-state__media", `puzzle-empty-state__media--${variant}`, className),
|
|
21
|
+
"data-variant": variant,
|
|
22
|
+
role: ariaLabel ? role ?? "img" : role,
|
|
23
|
+
"aria-label": ariaLabel,
|
|
24
|
+
"aria-hidden": ariaLabel ? void 0 : ariaHidden ?? true,
|
|
25
|
+
children
|
|
26
|
+
});
|
|
27
|
+
const EmptyStateTitle = ({ className, children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
28
|
+
...props,
|
|
29
|
+
className: (0, _puzzle_ui_core.cn)("puzzle-empty-state__title", className),
|
|
30
|
+
children
|
|
31
|
+
});
|
|
32
|
+
const EmptyStateDescription = ({ className, children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
33
|
+
...props,
|
|
34
|
+
className: (0, _puzzle_ui_core.cn)("puzzle-empty-state__description", className),
|
|
35
|
+
children
|
|
36
|
+
});
|
|
37
|
+
const EmptyStateContent = ({ className, children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
38
|
+
...props,
|
|
39
|
+
className: (0, _puzzle_ui_core.cn)("puzzle-empty-state__content", className),
|
|
40
|
+
children
|
|
41
|
+
});
|
|
42
|
+
exports.EmptyState = EmptyState;
|
|
43
|
+
exports.EmptyStateContent = EmptyStateContent;
|
|
44
|
+
exports.EmptyStateDescription = EmptyStateDescription;
|
|
45
|
+
exports.EmptyStateHeader = EmptyStateHeader;
|
|
46
|
+
exports.EmptyStateMedia = EmptyStateMedia;
|
|
47
|
+
exports.EmptyStateTitle = EmptyStateTitle;
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["getEmptyStateClasses","cn"],"sources":["../../../../src/components/data-display/empty-state/index.tsx"],"sourcesContent":["import type { HTMLAttributes } from \"react\";\nimport { cn } from \"@puzzle-ui/core\";\nimport { getEmptyStateClasses } from \"./empty-state.utils\";\n\nimport \"./empty-state.css\";\n\ntype EmptyStateSize = \"sm\" | \"md\" | \"lg\";\ntype EmptyStateVariant = \"default\" | \"outlined\" | \"filled\";\ntype EmptyStateMediaVariant = \"default\" | \"icon\";\n\ntype EmptyStateProps = HTMLAttributes<HTMLDivElement> & {\n size?: EmptyStateSize;\n variant?: EmptyStateVariant;\n};\n\ntype EmptyStatePartProps = HTMLAttributes<HTMLDivElement>;\n\ntype EmptyStateMediaProps = EmptyStatePartProps & {\n variant?: EmptyStateMediaVariant;\n};\n\nconst EmptyState = ({\n size = \"md\",\n variant = \"default\",\n className,\n children,\n ...props\n}: EmptyStateProps) => (\n <div\n {...props}\n className={getEmptyStateClasses(size, variant, className)}\n data-size={size}\n data-variant={variant}\n >\n {children}\n </div>\n);\n\nconst EmptyStateHeader = ({\n className,\n children,\n ...props\n}: EmptyStatePartProps) => (\n <div {...props} className={cn(\"puzzle-empty-state__header\", className)}>\n {children}\n </div>\n);\n\nconst EmptyStateMedia = ({\n variant = \"default\",\n className,\n children,\n \"aria-label\": ariaLabel,\n \"aria-hidden\": ariaHidden,\n role,\n ...props\n}: EmptyStateMediaProps) => (\n <div\n {...props}\n className={cn(\n \"puzzle-empty-state__media\",\n `puzzle-empty-state__media--${variant}`,\n className,\n )}\n data-variant={variant}\n role={ariaLabel ? (role ?? \"img\") : role}\n aria-label={ariaLabel}\n aria-hidden={ariaLabel ? undefined : (ariaHidden ?? true)}\n >\n {children}\n </div>\n);\n\nconst EmptyStateTitle = ({\n className,\n children,\n ...props\n}: HTMLAttributes<HTMLHeadingElement>) => (\n <h3 {...props} className={cn(\"puzzle-empty-state__title\", className)}>\n {children}\n </h3>\n);\n\nconst EmptyStateDescription = ({\n className,\n children,\n ...props\n}: HTMLAttributes<HTMLParagraphElement>) => (\n <p {...props} className={cn(\"puzzle-empty-state__description\", className)}>\n {children}\n </p>\n);\n\nconst EmptyStateContent = ({\n className,\n children,\n ...props\n}: EmptyStatePartProps) => (\n <div {...props} className={cn(\"puzzle-empty-state__content\", className)}>\n {children}\n </div>\n);\n\nexport {\n EmptyState,\n EmptyStateHeader,\n EmptyStateMedia,\n EmptyStateTitle,\n EmptyStateDescription,\n EmptyStateContent,\n type EmptyStateProps,\n type EmptyStateSize,\n type EmptyStateVariant,\n type EmptyStateMediaProps,\n type EmptyStateMediaVariant,\n};\n"],"mappings":";;;;;AAqBA,MAAM,cAAc,EAClB,OAAO,MACP,UAAU,WACV,WACA,UACA,GAAG,YAEH,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;CACE,GAAI;CACJ,WAAWA,0BAAAA,qBAAqB,MAAM,SAAS,SAAS;CACxD,aAAW;CACX,gBAAc;CAEb;AACE,CAAA;AAGP,MAAM,oBAAoB,EACxB,WACA,UACA,GAAG,YAEH,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;CAAK,GAAI;CAAO,YAAA,GAAWC,gBAAAA,GAAAA,CAAG,8BAA8B,SAAS;CAClE;AACE,CAAA;AAGP,MAAM,mBAAmB,EACvB,UAAU,WACV,WACA,UACA,cAAc,WACd,eAAe,YACf,MACA,GAAG,YAEH,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;CACE,GAAI;CACJ,YAAA,GAAWA,gBAAAA,GAAAA,CACT,6BACA,8BAA8B,WAC9B,SACF;CACA,gBAAc;CACd,MAAM,YAAa,QAAQ,QAAS;CACpC,cAAY;CACZ,eAAa,YAAY,KAAA,IAAa,cAAc;CAEnD;AACE,CAAA;AAGP,MAAM,mBAAmB,EACvB,WACA,UACA,GAAG,YAEH,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD;CAAI,GAAI;CAAO,YAAA,GAAWA,gBAAAA,GAAAA,CAAG,6BAA6B,SAAS;CAChE;AACC,CAAA;AAGN,MAAM,yBAAyB,EAC7B,WACA,UACA,GAAG,YAEH,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;CAAG,GAAI;CAAO,YAAA,GAAWA,gBAAAA,GAAAA,CAAG,mCAAmC,SAAS;CACrE;AACA,CAAA;AAGL,MAAM,qBAAqB,EACzB,WACA,UACA,GAAG,YAEH,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;CAAK,GAAI;CAAO,YAAA,GAAWA,gBAAAA,GAAAA,CAAG,+BAA+B,SAAS;CACnE;AACE,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
type EmptyStateSize = "sm" | "md" | "lg";
|
|
3
|
+
type EmptyStateVariant = "default" | "outlined" | "filled";
|
|
4
|
+
type EmptyStateMediaVariant = "default" | "icon";
|
|
5
|
+
type EmptyStateProps = HTMLAttributes<HTMLDivElement> & {
|
|
6
|
+
size?: EmptyStateSize;
|
|
7
|
+
variant?: EmptyStateVariant;
|
|
8
|
+
};
|
|
9
|
+
type EmptyStatePartProps = HTMLAttributes<HTMLDivElement>;
|
|
10
|
+
type EmptyStateMediaProps = EmptyStatePartProps & {
|
|
11
|
+
variant?: EmptyStateMediaVariant;
|
|
12
|
+
};
|
|
13
|
+
declare const EmptyState: ({ size, variant, className, children, ...props }: EmptyStateProps) => import("react").JSX.Element;
|
|
14
|
+
declare const EmptyStateHeader: ({ className, children, ...props }: EmptyStatePartProps) => import("react").JSX.Element;
|
|
15
|
+
declare const EmptyStateMedia: ({ variant, className, children, "aria-label": ariaLabel, "aria-hidden": ariaHidden, role, ...props }: EmptyStateMediaProps) => import("react").JSX.Element;
|
|
16
|
+
declare const EmptyStateTitle: ({ className, children, ...props }: HTMLAttributes<HTMLHeadingElement>) => import("react").JSX.Element;
|
|
17
|
+
declare const EmptyStateDescription: ({ className, children, ...props }: HTMLAttributes<HTMLParagraphElement>) => import("react").JSX.Element;
|
|
18
|
+
declare const EmptyStateContent: ({ className, children, ...props }: EmptyStatePartProps) => import("react").JSX.Element;
|
|
19
|
+
export { EmptyState, EmptyStateContent, EmptyStateDescription, EmptyStateHeader, EmptyStateMedia, type EmptyStateMediaProps, type EmptyStateMediaVariant, type EmptyStateProps, type EmptyStateSize, EmptyStateTitle, type EmptyStateVariant };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
type EmptyStateSize = "sm" | "md" | "lg";
|
|
3
|
+
type EmptyStateVariant = "default" | "outlined" | "filled";
|
|
4
|
+
type EmptyStateMediaVariant = "default" | "icon";
|
|
5
|
+
type EmptyStateProps = HTMLAttributes<HTMLDivElement> & {
|
|
6
|
+
size?: EmptyStateSize;
|
|
7
|
+
variant?: EmptyStateVariant;
|
|
8
|
+
};
|
|
9
|
+
type EmptyStatePartProps = HTMLAttributes<HTMLDivElement>;
|
|
10
|
+
type EmptyStateMediaProps = EmptyStatePartProps & {
|
|
11
|
+
variant?: EmptyStateMediaVariant;
|
|
12
|
+
};
|
|
13
|
+
declare const EmptyState: ({ size, variant, className, children, ...props }: EmptyStateProps) => import("react").JSX.Element;
|
|
14
|
+
declare const EmptyStateHeader: ({ className, children, ...props }: EmptyStatePartProps) => import("react").JSX.Element;
|
|
15
|
+
declare const EmptyStateMedia: ({ variant, className, children, "aria-label": ariaLabel, "aria-hidden": ariaHidden, role, ...props }: EmptyStateMediaProps) => import("react").JSX.Element;
|
|
16
|
+
declare const EmptyStateTitle: ({ className, children, ...props }: HTMLAttributes<HTMLHeadingElement>) => import("react").JSX.Element;
|
|
17
|
+
declare const EmptyStateDescription: ({ className, children, ...props }: HTMLAttributes<HTMLParagraphElement>) => import("react").JSX.Element;
|
|
18
|
+
declare const EmptyStateContent: ({ className, children, ...props }: EmptyStatePartProps) => import("react").JSX.Element;
|
|
19
|
+
export { EmptyState, EmptyStateContent, EmptyStateDescription, EmptyStateHeader, EmptyStateMedia, type EmptyStateMediaProps, type EmptyStateMediaVariant, type EmptyStateProps, type EmptyStateSize, EmptyStateTitle, type EmptyStateVariant };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getEmptyStateClasses } from "./empty-state.utils.js";
|
|
2
|
+
import "./empty-state.css";
|
|
3
|
+
import { cn } from "@puzzle-ui/core";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/data-display/empty-state/index.tsx
|
|
6
|
+
const EmptyState = ({ size = "md", variant = "default", className, children, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
7
|
+
...props,
|
|
8
|
+
className: getEmptyStateClasses(size, variant, className),
|
|
9
|
+
"data-size": size,
|
|
10
|
+
"data-variant": variant,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
const EmptyStateHeader = ({ className, children, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
14
|
+
...props,
|
|
15
|
+
className: cn("puzzle-empty-state__header", className),
|
|
16
|
+
children
|
|
17
|
+
});
|
|
18
|
+
const EmptyStateMedia = ({ variant = "default", className, children, "aria-label": ariaLabel, "aria-hidden": ariaHidden, role, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
19
|
+
...props,
|
|
20
|
+
className: cn("puzzle-empty-state__media", `puzzle-empty-state__media--${variant}`, className),
|
|
21
|
+
"data-variant": variant,
|
|
22
|
+
role: ariaLabel ? role ?? "img" : role,
|
|
23
|
+
"aria-label": ariaLabel,
|
|
24
|
+
"aria-hidden": ariaLabel ? void 0 : ariaHidden ?? true,
|
|
25
|
+
children
|
|
26
|
+
});
|
|
27
|
+
const EmptyStateTitle = ({ className, children, ...props }) => /* @__PURE__ */ jsx("h3", {
|
|
28
|
+
...props,
|
|
29
|
+
className: cn("puzzle-empty-state__title", className),
|
|
30
|
+
children
|
|
31
|
+
});
|
|
32
|
+
const EmptyStateDescription = ({ className, children, ...props }) => /* @__PURE__ */ jsx("p", {
|
|
33
|
+
...props,
|
|
34
|
+
className: cn("puzzle-empty-state__description", className),
|
|
35
|
+
children
|
|
36
|
+
});
|
|
37
|
+
const EmptyStateContent = ({ className, children, ...props }) => /* @__PURE__ */ jsx("div", {
|
|
38
|
+
...props,
|
|
39
|
+
className: cn("puzzle-empty-state__content", className),
|
|
40
|
+
children
|
|
41
|
+
});
|
|
42
|
+
export { EmptyState, EmptyStateContent, EmptyStateDescription, EmptyStateHeader, EmptyStateMedia, EmptyStateTitle };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/data-display/empty-state/index.tsx"],"sourcesContent":["import type { HTMLAttributes } from \"react\";\nimport { cn } from \"@puzzle-ui/core\";\nimport { getEmptyStateClasses } from \"./empty-state.utils\";\n\nimport \"./empty-state.css\";\n\ntype EmptyStateSize = \"sm\" | \"md\" | \"lg\";\ntype EmptyStateVariant = \"default\" | \"outlined\" | \"filled\";\ntype EmptyStateMediaVariant = \"default\" | \"icon\";\n\ntype EmptyStateProps = HTMLAttributes<HTMLDivElement> & {\n size?: EmptyStateSize;\n variant?: EmptyStateVariant;\n};\n\ntype EmptyStatePartProps = HTMLAttributes<HTMLDivElement>;\n\ntype EmptyStateMediaProps = EmptyStatePartProps & {\n variant?: EmptyStateMediaVariant;\n};\n\nconst EmptyState = ({\n size = \"md\",\n variant = \"default\",\n className,\n children,\n ...props\n}: EmptyStateProps) => (\n <div\n {...props}\n className={getEmptyStateClasses(size, variant, className)}\n data-size={size}\n data-variant={variant}\n >\n {children}\n </div>\n);\n\nconst EmptyStateHeader = ({\n className,\n children,\n ...props\n}: EmptyStatePartProps) => (\n <div {...props} className={cn(\"puzzle-empty-state__header\", className)}>\n {children}\n </div>\n);\n\nconst EmptyStateMedia = ({\n variant = \"default\",\n className,\n children,\n \"aria-label\": ariaLabel,\n \"aria-hidden\": ariaHidden,\n role,\n ...props\n}: EmptyStateMediaProps) => (\n <div\n {...props}\n className={cn(\n \"puzzle-empty-state__media\",\n `puzzle-empty-state__media--${variant}`,\n className,\n )}\n data-variant={variant}\n role={ariaLabel ? (role ?? \"img\") : role}\n aria-label={ariaLabel}\n aria-hidden={ariaLabel ? undefined : (ariaHidden ?? true)}\n >\n {children}\n </div>\n);\n\nconst EmptyStateTitle = ({\n className,\n children,\n ...props\n}: HTMLAttributes<HTMLHeadingElement>) => (\n <h3 {...props} className={cn(\"puzzle-empty-state__title\", className)}>\n {children}\n </h3>\n);\n\nconst EmptyStateDescription = ({\n className,\n children,\n ...props\n}: HTMLAttributes<HTMLParagraphElement>) => (\n <p {...props} className={cn(\"puzzle-empty-state__description\", className)}>\n {children}\n </p>\n);\n\nconst EmptyStateContent = ({\n className,\n children,\n ...props\n}: EmptyStatePartProps) => (\n <div {...props} className={cn(\"puzzle-empty-state__content\", className)}>\n {children}\n </div>\n);\n\nexport {\n EmptyState,\n EmptyStateHeader,\n EmptyStateMedia,\n EmptyStateTitle,\n EmptyStateDescription,\n EmptyStateContent,\n type EmptyStateProps,\n type EmptyStateSize,\n type EmptyStateVariant,\n type EmptyStateMediaProps,\n type EmptyStateMediaVariant,\n};\n"],"mappings":";;;;;AAqBA,MAAM,cAAc,EAClB,OAAO,MACP,UAAU,WACV,WACA,UACA,GAAG,YAEH,oBAAC,OAAD;CACE,GAAI;CACJ,WAAW,qBAAqB,MAAM,SAAS,SAAS;CACxD,aAAW;CACX,gBAAc;CAEb;AACE,CAAA;AAGP,MAAM,oBAAoB,EACxB,WACA,UACA,GAAG,YAEH,oBAAC,OAAD;CAAK,GAAI;CAAO,WAAW,GAAG,8BAA8B,SAAS;CAClE;AACE,CAAA;AAGP,MAAM,mBAAmB,EACvB,UAAU,WACV,WACA,UACA,cAAc,WACd,eAAe,YACf,MACA,GAAG,YAEH,oBAAC,OAAD;CACE,GAAI;CACJ,WAAW,GACT,6BACA,8BAA8B,WAC9B,SACF;CACA,gBAAc;CACd,MAAM,YAAa,QAAQ,QAAS;CACpC,cAAY;CACZ,eAAa,YAAY,KAAA,IAAa,cAAc;CAEnD;AACE,CAAA;AAGP,MAAM,mBAAmB,EACvB,WACA,UACA,GAAG,YAEH,oBAAC,MAAD;CAAI,GAAI;CAAO,WAAW,GAAG,6BAA6B,SAAS;CAChE;AACC,CAAA;AAGN,MAAM,yBAAyB,EAC7B,WACA,UACA,GAAG,YAEH,oBAAC,KAAD;CAAG,GAAI;CAAO,WAAW,GAAG,mCAAmC,SAAS;CACrE;AACA,CAAA;AAGL,MAAM,qBAAqB,EACzB,WACA,UACA,GAAG,YAEH,oBAAC,OAAD;CAAK,GAAI;CAAO,WAAW,GAAG,+BAA+B,SAAS;CACnE;AACE,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_rating_utils = require("./rating.utils.cjs");
|
|
3
|
+
;/* empty css */
|
|
4
|
+
let _puzzle_ui_core = require("@puzzle-ui/core");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let _puzzle_ui_icons = require("@puzzle-ui/icons");
|
|
8
|
+
// src/components/data-display/rating/index.tsx
|
|
9
|
+
const ICONS = {
|
|
10
|
+
full: "ph:star-fill",
|
|
11
|
+
half: "ph:star-half-fill",
|
|
12
|
+
empty: "ph:star"
|
|
13
|
+
};
|
|
14
|
+
const SIZE_MAP = {
|
|
15
|
+
sm: 16,
|
|
16
|
+
md: 20,
|
|
17
|
+
lg: 24
|
|
18
|
+
};
|
|
19
|
+
const Rating = ({ value, defaultValue = 0, onValueChange, max = 5, precision = .5, size = "md", readOnly = false, disabled = false, color = "var(--puzzle-color-warning, #FABC0A)", emptyColor = "var(--puzzle-color-border)", className, style, "aria-label": ariaLabel = "Rating", onKeyDown, ...props }) => {
|
|
20
|
+
if (!Number.isInteger(max) || max < 1 || max > 10) throw new Error("Rating max must be an integer between 1 and 10.");
|
|
21
|
+
const isControlled = value !== void 0;
|
|
22
|
+
const [internalValue, setInternalValue] = (0, react.useState)(() => require_rating_utils.normalizeRating(defaultValue, max, precision));
|
|
23
|
+
const currentValue = require_rating_utils.normalizeRating(isControlled ? value : internalValue, max, precision);
|
|
24
|
+
const commitValue = (nextValue) => {
|
|
25
|
+
if (disabled || readOnly) return;
|
|
26
|
+
const next = require_rating_utils.normalizeRating(nextValue, max, precision);
|
|
27
|
+
if (next === currentValue) return;
|
|
28
|
+
if (!isControlled) setInternalValue(next);
|
|
29
|
+
onValueChange?.(next);
|
|
30
|
+
};
|
|
31
|
+
const handleKeyDown = (event) => {
|
|
32
|
+
onKeyDown?.(event);
|
|
33
|
+
if (event.defaultPrevented || disabled || readOnly) return;
|
|
34
|
+
const nextValue = require_rating_utils.getNextRating(currentValue, event.key, max, precision);
|
|
35
|
+
if (nextValue === void 0) return;
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
commitValue(nextValue);
|
|
38
|
+
};
|
|
39
|
+
const classes = (0, _puzzle_ui_core.cn)("puzzle-rating", disabled && "puzzle-rating-disabled", readOnly && "puzzle-rating-readonly", className);
|
|
40
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
41
|
+
...props,
|
|
42
|
+
className: classes,
|
|
43
|
+
style: {
|
|
44
|
+
...style,
|
|
45
|
+
"--puzzle-rating-color": color,
|
|
46
|
+
"--puzzle-rating-empty-color": emptyColor
|
|
47
|
+
},
|
|
48
|
+
role: readOnly ? "img" : "slider",
|
|
49
|
+
tabIndex: disabled || readOnly ? void 0 : 0,
|
|
50
|
+
"aria-label": readOnly ? `${ariaLabel}: ${currentValue} out of ${max} stars` : ariaLabel,
|
|
51
|
+
"aria-valuemin": readOnly ? void 0 : 0,
|
|
52
|
+
"aria-valuemax": readOnly ? void 0 : max,
|
|
53
|
+
"aria-valuenow": readOnly ? void 0 : currentValue,
|
|
54
|
+
"aria-valuetext": readOnly ? void 0 : `${currentValue} out of ${max} stars`,
|
|
55
|
+
"aria-disabled": disabled || void 0,
|
|
56
|
+
"aria-readonly": readOnly || void 0,
|
|
57
|
+
onKeyDown: handleKeyDown,
|
|
58
|
+
"data-size": size,
|
|
59
|
+
"data-disabled": disabled || void 0,
|
|
60
|
+
"data-readonly": readOnly || void 0,
|
|
61
|
+
children: Array.from({ length: max }, (_, index) => {
|
|
62
|
+
const state = require_rating_utils.getRatingStarState(currentValue, index);
|
|
63
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
64
|
+
className: "puzzle-rating__star",
|
|
65
|
+
"data-state": state,
|
|
66
|
+
"aria-hidden": "true",
|
|
67
|
+
onClick: (event) => {
|
|
68
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
69
|
+
const isHalf = precision === .5 && event.clientX < rect.left + rect.width / 2;
|
|
70
|
+
commitValue(index + (isHalf ? .5 : 1));
|
|
71
|
+
},
|
|
72
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_puzzle_ui_icons.Icon, {
|
|
73
|
+
name: ICONS[state],
|
|
74
|
+
size: SIZE_MAP[size],
|
|
75
|
+
"aria-hidden": "true",
|
|
76
|
+
focusable: "false"
|
|
77
|
+
})
|
|
78
|
+
}, index);
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
exports.Rating = Rating;
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useState","normalizeRating","getNextRating","cn","getRatingStarState","Icon"],"sources":["../../../../src/components/data-display/rating/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, type CSSProperties, type KeyboardEvent } from \"react\";\n\nimport { cn } from \"@puzzle-ui/core\";\nimport { Icon } from \"@puzzle-ui/icons\";\n\nimport type { RatingProps, RatingSize } from \"./rating.types\";\n\nimport {\n getNextRating,\n getRatingStarState,\n normalizeRating,\n} from \"./rating.utils\";\n\nimport \"./rating.css\";\n\nconst ICONS = {\n full: \"ph:star-fill\",\n half: \"ph:star-half-fill\",\n empty: \"ph:star\",\n} as const;\n\nconst SIZE_MAP = {\n sm: 16,\n md: 20,\n lg: 24,\n} as const;\n\nconst Rating = ({\n value,\n defaultValue = 0,\n onValueChange,\n max = 5,\n precision = 0.5,\n size = \"md\",\n readOnly = false,\n disabled = false,\n color = \"var(--puzzle-color-warning, #FABC0A)\",\n emptyColor = \"var(--puzzle-color-border)\",\n className,\n style,\n \"aria-label\": ariaLabel = \"Rating\",\n onKeyDown,\n ...props\n}: RatingProps) => {\n if (!Number.isInteger(max) || max < 1 || max > 10) {\n throw new Error(\"Rating max must be an integer between 1 and 10.\");\n }\n\n const isControlled = value !== undefined;\n\n const [internalValue, setInternalValue] = useState(() =>\n normalizeRating(defaultValue, max, precision),\n );\n\n const currentValue = normalizeRating(\n isControlled ? value : internalValue,\n max,\n precision,\n );\n\n const commitValue = (nextValue: number) => {\n if (disabled || readOnly) {\n return;\n }\n\n const next = normalizeRating(nextValue, max, precision);\n\n if (next === currentValue) {\n return;\n }\n\n if (!isControlled) {\n setInternalValue(next);\n }\n\n onValueChange?.(next);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n\n if (event.defaultPrevented || disabled || readOnly) {\n return;\n }\n\n const nextValue = getNextRating(currentValue, event.key, max, precision);\n\n if (nextValue === undefined) {\n return;\n }\n\n event.preventDefault();\n commitValue(nextValue);\n };\n\n const classes = cn(\n \"puzzle-rating\",\n disabled && \"puzzle-rating-disabled\",\n readOnly && \"puzzle-rating-readonly\",\n className,\n );\n\n return (\n <div\n {...props}\n className={classes}\n style={\n {\n ...style,\n \"--puzzle-rating-color\": color,\n \"--puzzle-rating-empty-color\": emptyColor,\n } as CSSProperties\n }\n role={readOnly ? \"img\" : \"slider\"}\n tabIndex={disabled || readOnly ? undefined : 0}\n aria-label={\n readOnly\n ? `${ariaLabel}: ${currentValue} out of ${max} stars`\n : ariaLabel\n }\n aria-valuemin={readOnly ? undefined : 0}\n aria-valuemax={readOnly ? undefined : max}\n aria-valuenow={readOnly ? undefined : currentValue}\n aria-valuetext={\n readOnly ? undefined : `${currentValue} out of ${max} stars`\n }\n aria-disabled={disabled || undefined}\n aria-readonly={readOnly || undefined}\n onKeyDown={handleKeyDown}\n data-size={size}\n data-disabled={disabled || undefined}\n data-readonly={readOnly || undefined}\n >\n {Array.from({ length: max }, (_, index) => {\n const state = getRatingStarState(currentValue, index);\n\n return (\n <span\n key={index}\n className=\"puzzle-rating__star\"\n data-state={state}\n aria-hidden=\"true\"\n onClick={(event) => {\n const rect = event.currentTarget.getBoundingClientRect();\n\n const isHalf =\n precision === 0.5 && event.clientX < rect.left + rect.width / 2;\n\n commitValue(index + (isHalf ? 0.5 : 1));\n }}\n >\n <Icon\n name={ICONS[state]}\n size={SIZE_MAP[size]}\n aria-hidden=\"true\"\n focusable=\"false\"\n />\n </span>\n );\n })}\n </div>\n );\n};\n\nexport { Rating, type RatingProps, type RatingSize };\n"],"mappings":";;;;;;;;AAiBA,MAAM,QAAQ;CACZ,MAAM;CACN,MAAM;CACN,OAAO;AACT;AAEA,MAAM,WAAW;CACf,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,MAAM,UAAU,EACd,OACA,eAAe,GACf,eACA,MAAM,GACN,YAAY,IACZ,OAAO,MACP,WAAW,OACX,WAAW,OACX,QAAQ,wCACR,aAAa,8BACb,WACA,OACA,cAAc,YAAY,UAC1B,WACA,GAAG,YACc;CACjB,IAAI,CAAC,OAAO,UAAU,GAAG,KAAK,MAAM,KAAK,MAAM,IAC7C,MAAM,IAAI,MAAM,iDAAiD;CAGnE,MAAM,eAAe,UAAU,KAAA;CAE/B,MAAM,CAAC,eAAe,qBAAA,GAAoBA,MAAAA,SAAAA,OACxCC,qBAAAA,gBAAgB,cAAc,KAAK,SAAS,CAC9C;CAEA,MAAM,eAAeA,qBAAAA,gBACnB,eAAe,QAAQ,eACvB,KACA,SACF;CAEA,MAAM,eAAe,cAAsB;EACzC,IAAI,YAAY,UACd;EAGF,MAAM,OAAOA,qBAAAA,gBAAgB,WAAW,KAAK,SAAS;EAEtD,IAAI,SAAS,cACX;EAGF,IAAI,CAAC,cACH,iBAAiB,IAAI;EAGvB,gBAAgB,IAAI;CACtB;CAEA,MAAM,iBAAiB,UAAyC;EAC9D,YAAY,KAAK;EAEjB,IAAI,MAAM,oBAAoB,YAAY,UACxC;EAGF,MAAM,YAAYC,qBAAAA,cAAc,cAAc,MAAM,KAAK,KAAK,SAAS;EAEvE,IAAI,cAAc,KAAA,GAChB;EAGF,MAAM,eAAe;EACrB,YAAY,SAAS;CACvB;CAEA,MAAM,WAAA,GAAUC,gBAAAA,GAAAA,CACd,iBACA,YAAY,0BACZ,YAAY,0BACZ,SACF;CAEA,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACE,GAAI;EACJ,WAAW;EACX,OACE;GACE,GAAG;GACH,yBAAyB;GACzB,+BAA+B;EACjC;EAEF,MAAM,WAAW,QAAQ;EACzB,UAAU,YAAY,WAAW,KAAA,IAAY;EAC7C,cACE,WACI,GAAG,UAAU,IAAI,aAAa,UAAU,IAAI,UAC5C;EAEN,iBAAe,WAAW,KAAA,IAAY;EACtC,iBAAe,WAAW,KAAA,IAAY;EACtC,iBAAe,WAAW,KAAA,IAAY;EACtC,kBACE,WAAW,KAAA,IAAY,GAAG,aAAa,UAAU,IAAI;EAEvD,iBAAe,YAAY,KAAA;EAC3B,iBAAe,YAAY,KAAA;EAC3B,WAAW;EACX,aAAW;EACX,iBAAe,YAAY,KAAA;EAC3B,iBAAe,YAAY,KAAA;EAE1B,UAAA,MAAM,KAAK,EAAE,QAAQ,IAAI,IAAI,GAAG,UAAU;GACzC,MAAM,QAAQC,qBAAAA,mBAAmB,cAAc,KAAK;GAEpD,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IAEE,WAAU;IACV,cAAY;IACZ,eAAY;IACZ,UAAU,UAAU;KAClB,MAAM,OAAO,MAAM,cAAc,sBAAsB;KAEvD,MAAM,SACJ,cAAc,MAAO,MAAM,UAAU,KAAK,OAAO,KAAK,QAAQ;KAEhE,YAAY,SAAS,SAAS,KAAM,EAAE;IACxC;IAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,iBAAAA,MAAD;KACE,MAAM,MAAM;KACZ,MAAM,SAAS;KACf,eAAY;KACZ,WAAU;IACX,CAAA;GACG,GAnBC,KAmBD;EAEV,CAAC;CACE,CAAA;AAET"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { RatingProps, RatingSize } from "./rating.types.cjs";
|
|
2
|
+
declare const Rating: ({ value, defaultValue, onValueChange, max, precision, size, readOnly, disabled, color, emptyColor, className, style, "aria-label": ariaLabel, onKeyDown, ...props }: RatingProps) => import("react").JSX.Element;
|
|
3
|
+
export { Rating, type RatingProps, type RatingSize };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { RatingProps, RatingSize } from "./rating.types.js";
|
|
2
|
+
declare const Rating: ({ value, defaultValue, onValueChange, max, precision, size, readOnly, disabled, color, emptyColor, className, style, "aria-label": ariaLabel, onKeyDown, ...props }: RatingProps) => import("react").JSX.Element;
|
|
3
|
+
export { Rating, type RatingProps, type RatingSize };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { getNextRating, getRatingStarState, normalizeRating } from "./rating.utils.js";
|
|
3
|
+
import "./rating.css";
|
|
4
|
+
import { cn } from "@puzzle-ui/core";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { Icon } from "@puzzle-ui/icons";
|
|
8
|
+
// src/components/data-display/rating/index.tsx
|
|
9
|
+
const ICONS = {
|
|
10
|
+
full: "ph:star-fill",
|
|
11
|
+
half: "ph:star-half-fill",
|
|
12
|
+
empty: "ph:star"
|
|
13
|
+
};
|
|
14
|
+
const SIZE_MAP = {
|
|
15
|
+
sm: 16,
|
|
16
|
+
md: 20,
|
|
17
|
+
lg: 24
|
|
18
|
+
};
|
|
19
|
+
const Rating = ({ value, defaultValue = 0, onValueChange, max = 5, precision = .5, size = "md", readOnly = false, disabled = false, color = "var(--puzzle-color-warning, #FABC0A)", emptyColor = "var(--puzzle-color-border)", className, style, "aria-label": ariaLabel = "Rating", onKeyDown, ...props }) => {
|
|
20
|
+
if (!Number.isInteger(max) || max < 1 || max > 10) throw new Error("Rating max must be an integer between 1 and 10.");
|
|
21
|
+
const isControlled = value !== void 0;
|
|
22
|
+
const [internalValue, setInternalValue] = useState(() => normalizeRating(defaultValue, max, precision));
|
|
23
|
+
const currentValue = normalizeRating(isControlled ? value : internalValue, max, precision);
|
|
24
|
+
const commitValue = (nextValue) => {
|
|
25
|
+
if (disabled || readOnly) return;
|
|
26
|
+
const next = normalizeRating(nextValue, max, precision);
|
|
27
|
+
if (next === currentValue) return;
|
|
28
|
+
if (!isControlled) setInternalValue(next);
|
|
29
|
+
onValueChange?.(next);
|
|
30
|
+
};
|
|
31
|
+
const handleKeyDown = (event) => {
|
|
32
|
+
onKeyDown?.(event);
|
|
33
|
+
if (event.defaultPrevented || disabled || readOnly) return;
|
|
34
|
+
const nextValue = getNextRating(currentValue, event.key, max, precision);
|
|
35
|
+
if (nextValue === void 0) return;
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
commitValue(nextValue);
|
|
38
|
+
};
|
|
39
|
+
const classes = cn("puzzle-rating", disabled && "puzzle-rating-disabled", readOnly && "puzzle-rating-readonly", className);
|
|
40
|
+
return /* @__PURE__ */ jsx("div", {
|
|
41
|
+
...props,
|
|
42
|
+
className: classes,
|
|
43
|
+
style: {
|
|
44
|
+
...style,
|
|
45
|
+
"--puzzle-rating-color": color,
|
|
46
|
+
"--puzzle-rating-empty-color": emptyColor
|
|
47
|
+
},
|
|
48
|
+
role: readOnly ? "img" : "slider",
|
|
49
|
+
tabIndex: disabled || readOnly ? void 0 : 0,
|
|
50
|
+
"aria-label": readOnly ? `${ariaLabel}: ${currentValue} out of ${max} stars` : ariaLabel,
|
|
51
|
+
"aria-valuemin": readOnly ? void 0 : 0,
|
|
52
|
+
"aria-valuemax": readOnly ? void 0 : max,
|
|
53
|
+
"aria-valuenow": readOnly ? void 0 : currentValue,
|
|
54
|
+
"aria-valuetext": readOnly ? void 0 : `${currentValue} out of ${max} stars`,
|
|
55
|
+
"aria-disabled": disabled || void 0,
|
|
56
|
+
"aria-readonly": readOnly || void 0,
|
|
57
|
+
onKeyDown: handleKeyDown,
|
|
58
|
+
"data-size": size,
|
|
59
|
+
"data-disabled": disabled || void 0,
|
|
60
|
+
"data-readonly": readOnly || void 0,
|
|
61
|
+
children: Array.from({ length: max }, (_, index) => {
|
|
62
|
+
const state = getRatingStarState(currentValue, index);
|
|
63
|
+
return /* @__PURE__ */ jsx("span", {
|
|
64
|
+
className: "puzzle-rating__star",
|
|
65
|
+
"data-state": state,
|
|
66
|
+
"aria-hidden": "true",
|
|
67
|
+
onClick: (event) => {
|
|
68
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
69
|
+
const isHalf = precision === .5 && event.clientX < rect.left + rect.width / 2;
|
|
70
|
+
commitValue(index + (isHalf ? .5 : 1));
|
|
71
|
+
},
|
|
72
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
73
|
+
name: ICONS[state],
|
|
74
|
+
size: SIZE_MAP[size],
|
|
75
|
+
"aria-hidden": "true",
|
|
76
|
+
focusable: "false"
|
|
77
|
+
})
|
|
78
|
+
}, index);
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
export { Rating };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/data-display/rating/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, type CSSProperties, type KeyboardEvent } from \"react\";\n\nimport { cn } from \"@puzzle-ui/core\";\nimport { Icon } from \"@puzzle-ui/icons\";\n\nimport type { RatingProps, RatingSize } from \"./rating.types\";\n\nimport {\n getNextRating,\n getRatingStarState,\n normalizeRating,\n} from \"./rating.utils\";\n\nimport \"./rating.css\";\n\nconst ICONS = {\n full: \"ph:star-fill\",\n half: \"ph:star-half-fill\",\n empty: \"ph:star\",\n} as const;\n\nconst SIZE_MAP = {\n sm: 16,\n md: 20,\n lg: 24,\n} as const;\n\nconst Rating = ({\n value,\n defaultValue = 0,\n onValueChange,\n max = 5,\n precision = 0.5,\n size = \"md\",\n readOnly = false,\n disabled = false,\n color = \"var(--puzzle-color-warning, #FABC0A)\",\n emptyColor = \"var(--puzzle-color-border)\",\n className,\n style,\n \"aria-label\": ariaLabel = \"Rating\",\n onKeyDown,\n ...props\n}: RatingProps) => {\n if (!Number.isInteger(max) || max < 1 || max > 10) {\n throw new Error(\"Rating max must be an integer between 1 and 10.\");\n }\n\n const isControlled = value !== undefined;\n\n const [internalValue, setInternalValue] = useState(() =>\n normalizeRating(defaultValue, max, precision),\n );\n\n const currentValue = normalizeRating(\n isControlled ? value : internalValue,\n max,\n precision,\n );\n\n const commitValue = (nextValue: number) => {\n if (disabled || readOnly) {\n return;\n }\n\n const next = normalizeRating(nextValue, max, precision);\n\n if (next === currentValue) {\n return;\n }\n\n if (!isControlled) {\n setInternalValue(next);\n }\n\n onValueChange?.(next);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n\n if (event.defaultPrevented || disabled || readOnly) {\n return;\n }\n\n const nextValue = getNextRating(currentValue, event.key, max, precision);\n\n if (nextValue === undefined) {\n return;\n }\n\n event.preventDefault();\n commitValue(nextValue);\n };\n\n const classes = cn(\n \"puzzle-rating\",\n disabled && \"puzzle-rating-disabled\",\n readOnly && \"puzzle-rating-readonly\",\n className,\n );\n\n return (\n <div\n {...props}\n className={classes}\n style={\n {\n ...style,\n \"--puzzle-rating-color\": color,\n \"--puzzle-rating-empty-color\": emptyColor,\n } as CSSProperties\n }\n role={readOnly ? \"img\" : \"slider\"}\n tabIndex={disabled || readOnly ? undefined : 0}\n aria-label={\n readOnly\n ? `${ariaLabel}: ${currentValue} out of ${max} stars`\n : ariaLabel\n }\n aria-valuemin={readOnly ? undefined : 0}\n aria-valuemax={readOnly ? undefined : max}\n aria-valuenow={readOnly ? undefined : currentValue}\n aria-valuetext={\n readOnly ? undefined : `${currentValue} out of ${max} stars`\n }\n aria-disabled={disabled || undefined}\n aria-readonly={readOnly || undefined}\n onKeyDown={handleKeyDown}\n data-size={size}\n data-disabled={disabled || undefined}\n data-readonly={readOnly || undefined}\n >\n {Array.from({ length: max }, (_, index) => {\n const state = getRatingStarState(currentValue, index);\n\n return (\n <span\n key={index}\n className=\"puzzle-rating__star\"\n data-state={state}\n aria-hidden=\"true\"\n onClick={(event) => {\n const rect = event.currentTarget.getBoundingClientRect();\n\n const isHalf =\n precision === 0.5 && event.clientX < rect.left + rect.width / 2;\n\n commitValue(index + (isHalf ? 0.5 : 1));\n }}\n >\n <Icon\n name={ICONS[state]}\n size={SIZE_MAP[size]}\n aria-hidden=\"true\"\n focusable=\"false\"\n />\n </span>\n );\n })}\n </div>\n );\n};\n\nexport { Rating, type RatingProps, type RatingSize };\n"],"mappings":";;;;;;;;AAiBA,MAAM,QAAQ;CACZ,MAAM;CACN,MAAM;CACN,OAAO;AACT;AAEA,MAAM,WAAW;CACf,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,MAAM,UAAU,EACd,OACA,eAAe,GACf,eACA,MAAM,GACN,YAAY,IACZ,OAAO,MACP,WAAW,OACX,WAAW,OACX,QAAQ,wCACR,aAAa,8BACb,WACA,OACA,cAAc,YAAY,UAC1B,WACA,GAAG,YACc;CACjB,IAAI,CAAC,OAAO,UAAU,GAAG,KAAK,MAAM,KAAK,MAAM,IAC7C,MAAM,IAAI,MAAM,iDAAiD;CAGnE,MAAM,eAAe,UAAU,KAAA;CAE/B,MAAM,CAAC,eAAe,oBAAoB,eACxC,gBAAgB,cAAc,KAAK,SAAS,CAC9C;CAEA,MAAM,eAAe,gBACnB,eAAe,QAAQ,eACvB,KACA,SACF;CAEA,MAAM,eAAe,cAAsB;EACzC,IAAI,YAAY,UACd;EAGF,MAAM,OAAO,gBAAgB,WAAW,KAAK,SAAS;EAEtD,IAAI,SAAS,cACX;EAGF,IAAI,CAAC,cACH,iBAAiB,IAAI;EAGvB,gBAAgB,IAAI;CACtB;CAEA,MAAM,iBAAiB,UAAyC;EAC9D,YAAY,KAAK;EAEjB,IAAI,MAAM,oBAAoB,YAAY,UACxC;EAGF,MAAM,YAAY,cAAc,cAAc,MAAM,KAAK,KAAK,SAAS;EAEvE,IAAI,cAAc,KAAA,GAChB;EAGF,MAAM,eAAe;EACrB,YAAY,SAAS;CACvB;CAEA,MAAM,UAAU,GACd,iBACA,YAAY,0BACZ,YAAY,0BACZ,SACF;CAEA,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,WAAW;EACX,OACE;GACE,GAAG;GACH,yBAAyB;GACzB,+BAA+B;EACjC;EAEF,MAAM,WAAW,QAAQ;EACzB,UAAU,YAAY,WAAW,KAAA,IAAY;EAC7C,cACE,WACI,GAAG,UAAU,IAAI,aAAa,UAAU,IAAI,UAC5C;EAEN,iBAAe,WAAW,KAAA,IAAY;EACtC,iBAAe,WAAW,KAAA,IAAY;EACtC,iBAAe,WAAW,KAAA,IAAY;EACtC,kBACE,WAAW,KAAA,IAAY,GAAG,aAAa,UAAU,IAAI;EAEvD,iBAAe,YAAY,KAAA;EAC3B,iBAAe,YAAY,KAAA;EAC3B,WAAW;EACX,aAAW;EACX,iBAAe,YAAY,KAAA;EAC3B,iBAAe,YAAY,KAAA;EAE1B,UAAA,MAAM,KAAK,EAAE,QAAQ,IAAI,IAAI,GAAG,UAAU;GACzC,MAAM,QAAQ,mBAAmB,cAAc,KAAK;GAEpD,OACE,oBAAC,QAAD;IAEE,WAAU;IACV,cAAY;IACZ,eAAY;IACZ,UAAU,UAAU;KAClB,MAAM,OAAO,MAAM,cAAc,sBAAsB;KAEvD,MAAM,SACJ,cAAc,MAAO,MAAM,UAAU,KAAK,OAAO,KAAK,QAAQ;KAEhE,YAAY,SAAS,SAAS,KAAM,EAAE;IACxC;IAEA,UAAA,oBAAC,MAAD;KACE,MAAM,MAAM;KACZ,MAAM,SAAS;KACf,eAAY;KACZ,WAAU;IACX,CAAA;GACG,GAnBC,KAmBD;EAEV,CAAC;CACE,CAAA;AAET"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
.puzzle-rating {
|
|
2
|
+
align-items: center;
|
|
3
|
+
gap: var(--puzzle-space-1, .25rem);
|
|
4
|
+
width: fit-content;
|
|
5
|
+
color: var(--puzzle-rating-color);
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
touch-action: manipulation;
|
|
8
|
+
-webkit-tap-highlight-color: transparent;
|
|
9
|
+
direction: ltr;
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.puzzle-rating__star {
|
|
14
|
+
color: var(--puzzle-rating-empty-color);
|
|
15
|
+
user-select: none;
|
|
16
|
+
flex: none;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
align-items: center;
|
|
19
|
+
line-height: 1;
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.puzzle-rating__star[data-state="full"], .puzzle-rating__star[data-state="half"] {
|
|
24
|
+
color: var(--puzzle-rating-color);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.puzzle-rating__star svg {
|
|
28
|
+
display: block;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.puzzle-rating:focus-visible {
|
|
32
|
+
outline: 2px solid var(--puzzle-color-ring);
|
|
33
|
+
outline-offset: 3px;
|
|
34
|
+
border-radius: var(--puzzle-radius-sm, .25rem);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.puzzle-rating-disabled {
|
|
38
|
+
cursor: not-allowed;
|
|
39
|
+
opacity: .55;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.puzzle-rating-readonly {
|
|
43
|
+
cursor: default;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.puzzle-rating[data-size="sm"] {
|
|
47
|
+
gap: var(--puzzle-space-1, .25rem);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.puzzle-rating[data-size="lg"] {
|
|
51
|
+
gap: var(--puzzle-space-2, .5rem);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@media (forced-colors: active) {
|
|
55
|
+
.puzzle-rating__star {
|
|
56
|
+
color: graytext;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.puzzle-rating__star[data-state="full"], .puzzle-rating__star[data-state="half"] {
|
|
60
|
+
color: highlight;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.puzzle-rating:focus-visible {
|
|
64
|
+
outline-color: highlight;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@media (prefers-reduced-motion: reduce) {
|
|
69
|
+
.puzzle-rating, .puzzle-rating__star {
|
|
70
|
+
transition: none;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from "react";
|
|
2
|
+
type RatingSize = "sm" | "md" | "lg";
|
|
3
|
+
type RatingProps = Omit<ComponentPropsWithRef<"div">, "children" | "defaultValue" | "role" | "value"> & {
|
|
4
|
+
value?: number;
|
|
5
|
+
defaultValue?: number;
|
|
6
|
+
onValueChange?: (value: number) => void;
|
|
7
|
+
max?: number;
|
|
8
|
+
precision?: 0.5 | 1;
|
|
9
|
+
size?: RatingSize;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
color?: string;
|
|
13
|
+
emptyColor?: string;
|
|
14
|
+
};
|
|
15
|
+
export type { RatingProps, RatingSize };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentPropsWithRef } from "react";
|
|
2
|
+
type RatingSize = "sm" | "md" | "lg";
|
|
3
|
+
type RatingProps = Omit<ComponentPropsWithRef<"div">, "children" | "defaultValue" | "role" | "value"> & {
|
|
4
|
+
value?: number;
|
|
5
|
+
defaultValue?: number;
|
|
6
|
+
onValueChange?: (value: number) => void;
|
|
7
|
+
max?: number;
|
|
8
|
+
precision?: 0.5 | 1;
|
|
9
|
+
size?: RatingSize;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
color?: string;
|
|
13
|
+
emptyColor?: string;
|
|
14
|
+
};
|
|
15
|
+
export type { RatingProps, RatingSize };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/components/data-display/rating/rating.utils.ts
|
|
2
|
+
const normalizeRating = (value, max, precision) => {
|
|
3
|
+
if (!Number.isFinite(value)) return 0;
|
|
4
|
+
return Math.round(Math.min(max, Math.max(0, value)) / precision) * precision;
|
|
5
|
+
};
|
|
6
|
+
const getRatingStarState = (value, index) => {
|
|
7
|
+
const remainder = value - index;
|
|
8
|
+
if (remainder >= 1) return "full";
|
|
9
|
+
if (remainder >= .5) return "half";
|
|
10
|
+
return "empty";
|
|
11
|
+
};
|
|
12
|
+
const getNextRating = (value, key, max, precision) => {
|
|
13
|
+
switch (key) {
|
|
14
|
+
case "ArrowRight":
|
|
15
|
+
case "ArrowUp": return normalizeRating(value + precision, max, precision);
|
|
16
|
+
case "ArrowLeft":
|
|
17
|
+
case "ArrowDown": return normalizeRating(value - precision, max, precision);
|
|
18
|
+
case "Home": return 0;
|
|
19
|
+
case "End": return max;
|
|
20
|
+
default: return;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.getNextRating = getNextRating;
|
|
24
|
+
exports.getRatingStarState = getRatingStarState;
|
|
25
|
+
exports.normalizeRating = normalizeRating;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=rating.utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rating.utils.cjs","names":[],"sources":["../../../../src/components/data-display/rating/rating.utils.ts"],"sourcesContent":["const normalizeRating = (value: number, max: number, precision: 0.5 | 1) => {\n if (!Number.isFinite(value)) {\n return 0;\n }\n\n const clamped = Math.min(max, Math.max(0, value));\n\n return Math.round(clamped / precision) * precision;\n};\n\nconst getRatingStarState = (value: number, index: number) => {\n const remainder = value - index;\n\n if (remainder >= 1) {\n return \"full\" as const;\n }\n\n if (remainder >= 0.5) {\n return \"half\" as const;\n }\n\n return \"empty\" as const;\n};\n\nconst getNextRating = (\n value: number,\n key: string,\n max: number,\n precision: 0.5 | 1,\n) => {\n switch (key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n return normalizeRating(value + precision, max, precision);\n\n case \"ArrowLeft\":\n case \"ArrowDown\":\n return normalizeRating(value - precision, max, precision);\n\n case \"Home\":\n return 0;\n\n case \"End\":\n return max;\n\n default:\n return undefined;\n }\n};\n\nexport { normalizeRating, getRatingStarState, getNextRating };\n"],"mappings":";AAAA,MAAM,mBAAmB,OAAe,KAAa,cAAuB;CAC1E,IAAI,CAAC,OAAO,SAAS,KAAK,GACxB,OAAO;CAKT,OAAO,KAAK,MAFI,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,CAEvB,IAAI,SAAS,IAAI;AAC3C;AAEA,MAAM,sBAAsB,OAAe,UAAkB;CAC3D,MAAM,YAAY,QAAQ;CAE1B,IAAI,aAAa,GACf,OAAO;CAGT,IAAI,aAAa,IACf,OAAO;CAGT,OAAO;AACT;AAEA,MAAM,iBACJ,OACA,KACA,KACA,cACG;CACH,QAAQ,KAAR;EACE,KAAK;EACL,KAAK,WACH,OAAO,gBAAgB,QAAQ,WAAW,KAAK,SAAS;EAE1D,KAAK;EACL,KAAK,aACH,OAAO,gBAAgB,QAAQ,WAAW,KAAK,SAAS;EAE1D,KAAK,QACH,OAAO;EAET,KAAK,OACH,OAAO;EAET,SACE;CACJ;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/components/data-display/rating/rating.utils.ts
|
|
2
|
+
const normalizeRating = (value, max, precision) => {
|
|
3
|
+
if (!Number.isFinite(value)) return 0;
|
|
4
|
+
return Math.round(Math.min(max, Math.max(0, value)) / precision) * precision;
|
|
5
|
+
};
|
|
6
|
+
const getRatingStarState = (value, index) => {
|
|
7
|
+
const remainder = value - index;
|
|
8
|
+
if (remainder >= 1) return "full";
|
|
9
|
+
if (remainder >= .5) return "half";
|
|
10
|
+
return "empty";
|
|
11
|
+
};
|
|
12
|
+
const getNextRating = (value, key, max, precision) => {
|
|
13
|
+
switch (key) {
|
|
14
|
+
case "ArrowRight":
|
|
15
|
+
case "ArrowUp": return normalizeRating(value + precision, max, precision);
|
|
16
|
+
case "ArrowLeft":
|
|
17
|
+
case "ArrowDown": return normalizeRating(value - precision, max, precision);
|
|
18
|
+
case "Home": return 0;
|
|
19
|
+
case "End": return max;
|
|
20
|
+
default: return;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export { getNextRating, getRatingStarState, normalizeRating };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=rating.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rating.utils.js","names":[],"sources":["../../../../src/components/data-display/rating/rating.utils.ts"],"sourcesContent":["const normalizeRating = (value: number, max: number, precision: 0.5 | 1) => {\n if (!Number.isFinite(value)) {\n return 0;\n }\n\n const clamped = Math.min(max, Math.max(0, value));\n\n return Math.round(clamped / precision) * precision;\n};\n\nconst getRatingStarState = (value: number, index: number) => {\n const remainder = value - index;\n\n if (remainder >= 1) {\n return \"full\" as const;\n }\n\n if (remainder >= 0.5) {\n return \"half\" as const;\n }\n\n return \"empty\" as const;\n};\n\nconst getNextRating = (\n value: number,\n key: string,\n max: number,\n precision: 0.5 | 1,\n) => {\n switch (key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n return normalizeRating(value + precision, max, precision);\n\n case \"ArrowLeft\":\n case \"ArrowDown\":\n return normalizeRating(value - precision, max, precision);\n\n case \"Home\":\n return 0;\n\n case \"End\":\n return max;\n\n default:\n return undefined;\n }\n};\n\nexport { normalizeRating, getRatingStarState, getNextRating };\n"],"mappings":";AAAA,MAAM,mBAAmB,OAAe,KAAa,cAAuB;CAC1E,IAAI,CAAC,OAAO,SAAS,KAAK,GACxB,OAAO;CAKT,OAAO,KAAK,MAFI,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,CAEvB,IAAI,SAAS,IAAI;AAC3C;AAEA,MAAM,sBAAsB,OAAe,UAAkB;CAC3D,MAAM,YAAY,QAAQ;CAE1B,IAAI,aAAa,GACf,OAAO;CAGT,IAAI,aAAa,IACf,OAAO;CAGT,OAAO;AACT;AAEA,MAAM,iBACJ,OACA,KACA,KACA,cACG;CACH,QAAQ,KAAR;EACE,KAAK;EACL,KAAK,WACH,OAAO,gBAAgB,QAAQ,WAAW,KAAK,SAAS;EAE1D,KAAK;EACL,KAAK,aACH,OAAO,gBAAgB,QAAQ,WAAW,KAAK,SAAS;EAE1D,KAAK,QACH,OAAO;EAET,KAAK,OACH,OAAO;EAET,SACE;CACJ;AACF"}
|