@sth87/shadcn-design-system 0.1.0 → 0.1.2
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/dist/cjs/components/Checkbox/Checkbox.cjs +1 -1
- package/dist/cjs/components/Checkbox/Checkbox.cjs.map +1 -1
- package/dist/cjs/components/Input/Input.cjs +1 -1
- package/dist/cjs/components/Input/Input.cjs.map +1 -1
- package/dist/cjs/components/Rate/Rate.cjs +1 -1
- package/dist/cjs/components/Rate/Rate.cjs.map +1 -1
- package/dist/cjs/components/Sheet/Sheet.cjs +1 -1
- package/dist/cjs/components/Sheet/Sheet.cjs.map +1 -1
- package/dist/cjs/components/Slider/Slider.cjs +1 -1
- package/dist/cjs/components/Slider/Slider.cjs.map +1 -1
- package/dist/cjs/components/Stepper/Stepper.cjs +1 -1
- package/dist/cjs/components/Stepper/Stepper.cjs.map +1 -1
- package/dist/cjs/components/Stepper/StepperWrapper.cjs +1 -1
- package/dist/cjs/components/Stepper/StepperWrapper.cjs.map +1 -1
- package/dist/cjs/components/Switch/Switch.cjs +1 -1
- package/dist/cjs/components/Switch/Switch.cjs.map +1 -1
- package/dist/cjs/components/Table/data-table-column-header.cjs +1 -1
- package/dist/cjs/components/Table/data-table-column-header.cjs.map +1 -1
- package/dist/cjs/components/Tabs/classes.cjs +1 -1
- package/dist/cjs/components/Tabs/classes.cjs.map +1 -1
- package/dist/cjs/components/TimeGridView.cjs +1 -1
- package/dist/cjs/components/TimeGridView.cjs.map +1 -1
- package/dist/cjs/components/Toast/Toast.cjs +1 -1
- package/dist/cjs/components/Toast/Toast.cjs.map +1 -1
- package/dist/cjs/components/Tooltip/Tooltip.cjs +1 -1
- package/dist/cjs/components/Tooltip/Tooltip.cjs.map +1 -1
- package/dist/cjs/components/WheelColumn.cjs +1 -1
- package/dist/cjs/components/WheelColumn.cjs.map +1 -1
- package/dist/cjs/packages/ui/src/components/calendar.cjs +1 -1
- package/dist/cjs/packages/ui/src/components/calendar.cjs.map +1 -1
- package/dist/cjs/styles/index.css +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +20 -20
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Input/Input.js +43 -43
- package/dist/esm/components/Input/Input.js.map +1 -1
- package/dist/esm/components/Rate/Rate.js +15 -15
- package/dist/esm/components/Rate/Rate.js.map +1 -1
- package/dist/esm/components/Sheet/Sheet.js +25 -25
- package/dist/esm/components/Sheet/Sheet.js.map +1 -1
- package/dist/esm/components/Slider/Slider.js +139 -139
- package/dist/esm/components/Slider/Slider.js.map +1 -1
- package/dist/esm/components/Stepper/Stepper.js +52 -52
- package/dist/esm/components/Stepper/Stepper.js.map +1 -1
- package/dist/esm/components/Stepper/StepperWrapper.js +25 -25
- package/dist/esm/components/Stepper/StepperWrapper.js.map +1 -1
- package/dist/esm/components/Switch/Switch.js +19 -19
- package/dist/esm/components/Switch/Switch.js.map +1 -1
- package/dist/esm/components/Table/data-table-column-header.js +22 -22
- package/dist/esm/components/Table/data-table-column-header.js.map +1 -1
- package/dist/esm/components/Tabs/classes.js +128 -128
- package/dist/esm/components/Tabs/classes.js.map +1 -1
- package/dist/esm/components/TimeGridView.js +27 -27
- package/dist/esm/components/TimeGridView.js.map +1 -1
- package/dist/esm/components/Toast/Toast.js +26 -26
- package/dist/esm/components/Toast/Toast.js.map +1 -1
- package/dist/esm/components/Tooltip/Tooltip.js +42 -42
- package/dist/esm/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/components/WheelColumn.js +9 -9
- package/dist/esm/components/WheelColumn.js.map +1 -1
- package/dist/esm/packages/ui/src/components/calendar.js +73 -73
- package/dist/esm/packages/ui/src/components/calendar.js.map +1 -1
- package/dist/esm/styles/index.css +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as s, jsx as e } from "react/jsx-runtime";
|
|
2
2
|
import u, { useState as D } from "react";
|
|
3
3
|
import { Checkbox as L } from "../../packages/ui/src/components/checkbox.js";
|
|
4
4
|
import "@radix-ui/react-slot";
|
|
@@ -10,7 +10,7 @@ import { Label as V } from "../../packages/ui/src/components/label.js";
|
|
|
10
10
|
import "../../packages/ui/src/components/select.js";
|
|
11
11
|
import "../../packages/ui/src/components/combobox.js";
|
|
12
12
|
import "@radix-ui/react-tooltip";
|
|
13
|
-
import { cn as
|
|
13
|
+
import { cn as a } from "../../packages/ui/src/lib/utils.js";
|
|
14
14
|
import { Info as g } from "lucide-react";
|
|
15
15
|
import "react-day-picker";
|
|
16
16
|
import "../../packages/ui/src/components/popover.js";
|
|
@@ -38,40 +38,40 @@ import { ConfettiPiece as q } from "../../utils/css.js";
|
|
|
38
38
|
const B = u.forwardRef(
|
|
39
39
|
(C, N) => {
|
|
40
40
|
const {
|
|
41
|
-
label:
|
|
41
|
+
label: o,
|
|
42
42
|
infoTooltip: i,
|
|
43
43
|
helperText: r,
|
|
44
|
-
state:
|
|
44
|
+
state: l,
|
|
45
45
|
variant: w = "default",
|
|
46
46
|
size: v = "default",
|
|
47
47
|
color: k,
|
|
48
48
|
labelPosition: t = "right",
|
|
49
|
-
labelAlignment:
|
|
49
|
+
labelAlignment: m = "center",
|
|
50
50
|
icon: y,
|
|
51
51
|
animation: T,
|
|
52
52
|
id: I,
|
|
53
53
|
onCheckedChange: c,
|
|
54
54
|
...j
|
|
55
|
-
} = C, [z, p] = D(!1), A = u.useId(),
|
|
55
|
+
} = C, [z, p] = D(!1), A = u.useId(), d = I || A, P = {
|
|
56
56
|
default: "ds:text-muted-foreground",
|
|
57
57
|
success: "ds:text-success",
|
|
58
58
|
warning: "ds:text-warning",
|
|
59
59
|
error: "ds:text-error"
|
|
60
|
-
}, S = (
|
|
61
|
-
|
|
62
|
-
}, f = t === "top" || t === "bottom", _ = f ? "flex-col" : "flex-row", F = f ? "gap-1.5" : "gap-2", R =
|
|
63
|
-
return /* @__PURE__ */
|
|
64
|
-
/* @__PURE__ */
|
|
65
|
-
(t === "top" || t === "left") &&
|
|
66
|
-
|
|
60
|
+
}, S = (n) => {
|
|
61
|
+
n && (p(!0), setTimeout(() => p(!1), 800)), c?.(n);
|
|
62
|
+
}, f = t === "top" || t === "bottom", _ = f ? "ds:flex-col" : "ds:flex-row", F = f ? "ds:gap-1.5" : "ds:gap-2", R = m === "start" ? "ds:items-start" : m === "center" ? "ds:items-center" : "ds:items-end", h = "ds:flex ds:gap-2 ds:peer-disabled:cursor-not-allowed ds:peer-disabled:opacity-70";
|
|
63
|
+
return /* @__PURE__ */ s("div", { className: a("ds:flex ds:flex-col ds:gap-1.5 ds:relative", {}), children: [
|
|
64
|
+
/* @__PURE__ */ s("div", { className: a("ds:flex", _, F, R), children: [
|
|
65
|
+
(t === "top" || t === "left") && o && /* @__PURE__ */ s("label", { htmlFor: d, className: h, children: [
|
|
66
|
+
o,
|
|
67
67
|
i && /* @__PURE__ */ e(b, { content: i, children: /* @__PURE__ */ e(g, { className: "ds:size-3.5 ds:min-w-3.5" }) })
|
|
68
68
|
] }),
|
|
69
|
-
/* @__PURE__ */
|
|
69
|
+
/* @__PURE__ */ s("div", { className: "ds:relative ds:inline-flex", children: [
|
|
70
70
|
/* @__PURE__ */ e(
|
|
71
71
|
L,
|
|
72
72
|
{
|
|
73
73
|
ref: N,
|
|
74
|
-
id:
|
|
74
|
+
id: d,
|
|
75
75
|
...j,
|
|
76
76
|
variant: w,
|
|
77
77
|
size: v,
|
|
@@ -80,19 +80,19 @@ const B = u.forwardRef(
|
|
|
80
80
|
onCheckedChange: T ? S : c
|
|
81
81
|
}
|
|
82
82
|
),
|
|
83
|
-
/* @__PURE__ */ e($, { children: z && /* @__PURE__ */ e("div", { className: "ds:pointer-events-none ds:absolute ds:inset-0", children: [...Array(12)].map((
|
|
83
|
+
/* @__PURE__ */ e($, { children: z && /* @__PURE__ */ e("div", { className: "ds:pointer-events-none ds:absolute ds:inset-0", children: [...Array(12)].map((n, x) => /* @__PURE__ */ e(q, { index: x }, x)) }) })
|
|
84
84
|
] }),
|
|
85
|
-
(t === "bottom" || t === "right") &&
|
|
86
|
-
|
|
85
|
+
(t === "bottom" || t === "right") && o && /* @__PURE__ */ s(V, { htmlFor: d, className: h, children: [
|
|
86
|
+
o,
|
|
87
87
|
i && /* @__PURE__ */ e(b, { content: i, children: /* @__PURE__ */ e(g, { className: "ds:size-3.5 ds:min-w-3.5" }) })
|
|
88
88
|
] })
|
|
89
89
|
] }),
|
|
90
90
|
r && /* @__PURE__ */ e("div", { className: "ds:flex ds:items-center ds:justify-between ds:text-xs ds:gap-2", children: r && /* @__PURE__ */ e(
|
|
91
91
|
"p",
|
|
92
92
|
{
|
|
93
|
-
className:
|
|
93
|
+
className: a(
|
|
94
94
|
"ds:text-xs",
|
|
95
|
-
|
|
95
|
+
l ? P?.[l] : ""
|
|
96
96
|
),
|
|
97
97
|
children: r
|
|
98
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { Checkbox as SCheckbox } from \"@dsui/ui/components/checkbox\";\nimport { cn } from \"@dsui/ui/index\";\nimport { Tooltip } from \"../Tooltip/Tooltip\";\nimport { Label } from \"../Label\";\nimport { Info } from \"lucide-react\";\nimport { AnimatePresence } from \"motion/react\";\nimport { ConfettiPiece } from \"@/utils/css\";\nimport type { CheckedState } from \"@radix-ui/react-checkbox\";\n\nexport type CheckboxProps = Omit<\n React.ComponentPropsWithoutRef<typeof SCheckbox>,\n \"onCheckedChange\" | \"variant\" | \"size\" | \"color\" | \"icon\"\n> & {\n onCheckedChange?: (checked: CheckedState) => void;\n variant?: \"default\" | \"circle\";\n size?: \"sm\" | \"default\" | \"lg\";\n color?:\n | \"primary\"\n | \"secondary\"\n | \"accent\"\n | \"destructive\"\n | \"muted\"\n | \"success\"\n | \"error\"\n | \"warning\";\n icon?: React.ReactNode;\n label?: React.ReactNode;\n labelPosition?: \"top\" | \"left\" | \"right\" | \"bottom\";\n labelAlignment?: \"start\" | \"center\" | \"end\";\n infoTooltip?: React.ReactNode;\n helperText?: React.ReactNode;\n state?: \"default\" | \"error\" | \"success\" | \"warning\";\n animation?: \"confetti\" | undefined;\n};\n\nconst Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(\n (props, ref) => {\n const {\n label,\n infoTooltip,\n helperText,\n state,\n variant = \"default\",\n size = \"default\",\n color,\n labelPosition = \"right\",\n labelAlignment = \"center\",\n icon,\n animation,\n id,\n onCheckedChange,\n ...rest\n } = props;\n const [showConfetti, setShowConfetti] = useState(false);\n const generatedId = React.useId();\n const inputId = id || generatedId;\n\n // State\n const helperTextStyles = {\n default: \"ds:text-muted-foreground\",\n success: \"ds:text-success\",\n warning: \"ds:text-warning\",\n error: \"ds:text-error\",\n };\n\n const handleCheckedChange = (checked: CheckedState) => {\n if (checked) {\n setShowConfetti(true);\n setTimeout(() => setShowConfetti(false), 800);\n }\n onCheckedChange?.(checked);\n };\n\n const isVertical = labelPosition === \"top\" || labelPosition === \"bottom\";\n const flexDirection = isVertical ? \"flex-col\" : \"flex-row\";\n const gapClass = isVertical ? \"gap-1.5\" : \"gap-2\";\n\n const alignmentClass =\n labelAlignment === \"start\"\n ? \"items-start\"\n : labelAlignment === \"center\"\n ? \"items-center\"\n : \"items-end\";\n\n const labelClass =\n \"flex gap-2 peer-disabled:cursor-not-allowed peer-disabled:opacity-70\";\n\n return (\n <div className={cn(\"ds:flex ds:flex-col ds:gap-1.5 ds:relative\", {})}>\n <div className={cn(\"ds:flex\", flexDirection, gapClass, alignmentClass)}>\n {(labelPosition === \"top\" || labelPosition === \"left\") && label && (\n <label htmlFor={inputId} className={labelClass}>\n {label}\n {infoTooltip && (\n <Tooltip content={infoTooltip}>\n <Info className=\"ds:size-3.5 ds:min-w-3.5\" />\n </Tooltip>\n )}\n </label>\n )}\n\n <div className=\"ds:relative ds:inline-flex\">\n <SCheckbox\n ref={ref}\n id={inputId}\n {...rest}\n variant={variant}\n size={size}\n color={color}\n icon={icon}\n onCheckedChange={\n animation ? handleCheckedChange : onCheckedChange\n }\n />\n\n <AnimatePresence>\n {showConfetti && (\n <div className=\"ds:pointer-events-none ds:absolute ds:inset-0\">\n {[...Array(12)].map((_, i) => (\n <ConfettiPiece key={i} index={i} />\n ))}\n </div>\n )}\n </AnimatePresence>\n </div>\n\n {(labelPosition === \"bottom\" || labelPosition === \"right\") &&\n label && (\n <Label htmlFor={inputId} className={labelClass}>\n {label}\n {infoTooltip && (\n <Tooltip content={infoTooltip}>\n <Info className=\"ds:size-3.5 ds:min-w-3.5\" />\n </Tooltip>\n )}\n </Label>\n )}\n </div>\n\n {helperText && (\n <div className=\"ds:flex ds:items-center ds:justify-between ds:text-xs ds:gap-2\">\n {helperText && (\n <p\n className={cn(\n \"ds:text-xs\",\n state ? helperTextStyles?.[state] : \"\"\n )}\n >\n {helperText}\n </p>\n )}\n </div>\n )}\n </div>\n );\n }\n);\n\nCheckbox.displayName = \"Checkbox\";\nexport default Checkbox;\n"],"names":["Checkbox","React","props","ref","label","infoTooltip","helperText","state","variant","size","color","labelPosition","labelAlignment","icon","animation","id","onCheckedChange","rest","showConfetti","setShowConfetti","useState","generatedId","inputId","helperTextStyles","handleCheckedChange","checked","isVertical","flexDirection","gapClass","alignmentClass","labelClass","cn","jsxs","Tooltip","jsx","Info","SCheckbox","AnimatePresence","_","i","ConfettiPiece","Label"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAMA,IAAWC,EAAM;AAAA,EACrB,CAACC,GAAOC,MAAQ;AACd,UAAM;AAAA,MACJ,OAAAC;AAAA,MACA,aAAAC;AAAA,MACA,YAAAC;AAAA,MACA,OAAAC;AAAA,MACA,SAAAC,IAAU;AAAA,MACV,MAAAC,IAAO;AAAA,MACP,OAAAC;AAAA,MACA,eAAAC,IAAgB;AAAA,MAChB,gBAAAC,IAAiB;AAAA,MACjB,MAAAC;AAAA,MACA,WAAAC;AAAA,MACA,IAAAC;AAAA,MACA,iBAAAC;AAAA,MACA,GAAGC;AAAA,IAAA,IACDf,GACE,CAACgB,GAAcC,CAAe,IAAIC,EAAS,EAAK,GAChDC,IAAcpB,EAAM,MAAA,GACpBqB,IAAUP,KAAMM,GAGhBE,IAAmB;AAAA,MACvB,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IAAA,GAGHC,IAAsB,CAACC,MAA0B;AACrD,MAAIA,MACFN,EAAgB,EAAI,GACpB,WAAW,MAAMA,EAAgB,EAAK,GAAG,GAAG,IAE9CH,IAAkBS,CAAO;AAAA,IAC3B,GAEMC,IAAaf,MAAkB,SAASA,MAAkB,UAC1DgB,IAAgBD,IAAa,
|
|
1
|
+
{"version":3,"file":"Checkbox.js","sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport { Checkbox as SCheckbox } from \"@dsui/ui/components/checkbox\";\nimport { cn } from \"@dsui/ui/index\";\nimport { Tooltip } from \"../Tooltip/Tooltip\";\nimport { Label } from \"../Label\";\nimport { Info } from \"lucide-react\";\nimport { AnimatePresence } from \"motion/react\";\nimport { ConfettiPiece } from \"@/utils/css\";\nimport type { CheckedState } from \"@radix-ui/react-checkbox\";\n\nexport type CheckboxProps = Omit<\n React.ComponentPropsWithoutRef<typeof SCheckbox>,\n \"onCheckedChange\" | \"variant\" | \"size\" | \"color\" | \"icon\"\n> & {\n onCheckedChange?: (checked: CheckedState) => void;\n variant?: \"default\" | \"circle\";\n size?: \"sm\" | \"default\" | \"lg\";\n color?:\n | \"primary\"\n | \"secondary\"\n | \"accent\"\n | \"destructive\"\n | \"muted\"\n | \"success\"\n | \"error\"\n | \"warning\";\n icon?: React.ReactNode;\n label?: React.ReactNode;\n labelPosition?: \"top\" | \"left\" | \"right\" | \"bottom\";\n labelAlignment?: \"start\" | \"center\" | \"end\";\n infoTooltip?: React.ReactNode;\n helperText?: React.ReactNode;\n state?: \"default\" | \"error\" | \"success\" | \"warning\";\n animation?: \"confetti\" | undefined;\n};\n\nconst Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(\n (props, ref) => {\n const {\n label,\n infoTooltip,\n helperText,\n state,\n variant = \"default\",\n size = \"default\",\n color,\n labelPosition = \"right\",\n labelAlignment = \"center\",\n icon,\n animation,\n id,\n onCheckedChange,\n ...rest\n } = props;\n const [showConfetti, setShowConfetti] = useState(false);\n const generatedId = React.useId();\n const inputId = id || generatedId;\n\n // State\n const helperTextStyles = {\n default: \"ds:text-muted-foreground\",\n success: \"ds:text-success\",\n warning: \"ds:text-warning\",\n error: \"ds:text-error\",\n };\n\n const handleCheckedChange = (checked: CheckedState) => {\n if (checked) {\n setShowConfetti(true);\n setTimeout(() => setShowConfetti(false), 800);\n }\n onCheckedChange?.(checked);\n };\n\n const isVertical = labelPosition === \"top\" || labelPosition === \"bottom\";\n const flexDirection = isVertical ? \"ds:flex-col\" : \"ds:flex-row\";\n const gapClass = isVertical ? \"ds:gap-1.5\" : \"ds:gap-2\";\n\n const alignmentClass =\n labelAlignment === \"start\"\n ? \"ds:items-start\"\n : labelAlignment === \"center\"\n ? \"ds:items-center\"\n : \"ds:items-end\";\n\n const labelClass =\n \"ds:flex ds:gap-2 ds:peer-disabled:cursor-not-allowed ds:peer-disabled:opacity-70\";\n\n return (\n <div className={cn(\"ds:flex ds:flex-col ds:gap-1.5 ds:relative\", {})}>\n <div className={cn(\"ds:flex\", flexDirection, gapClass, alignmentClass)}>\n {(labelPosition === \"top\" || labelPosition === \"left\") && label && (\n <label htmlFor={inputId} className={labelClass}>\n {label}\n {infoTooltip && (\n <Tooltip content={infoTooltip}>\n <Info className=\"ds:size-3.5 ds:min-w-3.5\" />\n </Tooltip>\n )}\n </label>\n )}\n\n <div className=\"ds:relative ds:inline-flex\">\n <SCheckbox\n ref={ref}\n id={inputId}\n {...rest}\n variant={variant}\n size={size}\n color={color}\n icon={icon}\n onCheckedChange={\n animation ? handleCheckedChange : onCheckedChange\n }\n />\n\n <AnimatePresence>\n {showConfetti && (\n <div className=\"ds:pointer-events-none ds:absolute ds:inset-0\">\n {[...Array(12)].map((_, i) => (\n <ConfettiPiece key={i} index={i} />\n ))}\n </div>\n )}\n </AnimatePresence>\n </div>\n\n {(labelPosition === \"bottom\" || labelPosition === \"right\") &&\n label && (\n <Label htmlFor={inputId} className={labelClass}>\n {label}\n {infoTooltip && (\n <Tooltip content={infoTooltip}>\n <Info className=\"ds:size-3.5 ds:min-w-3.5\" />\n </Tooltip>\n )}\n </Label>\n )}\n </div>\n\n {helperText && (\n <div className=\"ds:flex ds:items-center ds:justify-between ds:text-xs ds:gap-2\">\n {helperText && (\n <p\n className={cn(\n \"ds:text-xs\",\n state ? helperTextStyles?.[state] : \"\"\n )}\n >\n {helperText}\n </p>\n )}\n </div>\n )}\n </div>\n );\n }\n);\n\nCheckbox.displayName = \"Checkbox\";\nexport default Checkbox;\n"],"names":["Checkbox","React","props","ref","label","infoTooltip","helperText","state","variant","size","color","labelPosition","labelAlignment","icon","animation","id","onCheckedChange","rest","showConfetti","setShowConfetti","useState","generatedId","inputId","helperTextStyles","handleCheckedChange","checked","isVertical","flexDirection","gapClass","alignmentClass","labelClass","cn","jsxs","Tooltip","jsx","Info","SCheckbox","AnimatePresence","_","i","ConfettiPiece","Label"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAMA,IAAWC,EAAM;AAAA,EACrB,CAACC,GAAOC,MAAQ;AACd,UAAM;AAAA,MACJ,OAAAC;AAAA,MACA,aAAAC;AAAA,MACA,YAAAC;AAAA,MACA,OAAAC;AAAA,MACA,SAAAC,IAAU;AAAA,MACV,MAAAC,IAAO;AAAA,MACP,OAAAC;AAAA,MACA,eAAAC,IAAgB;AAAA,MAChB,gBAAAC,IAAiB;AAAA,MACjB,MAAAC;AAAA,MACA,WAAAC;AAAA,MACA,IAAAC;AAAA,MACA,iBAAAC;AAAA,MAC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kB,EAACG,GAAA,EACE,UAAAnB,KACC,gBAAAgB,EAAC,OAAA,EAAI,WAAU,iDACZ,UAAA,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,IAAI,CAACI,GAAGC,MACtB,gBAAAL,EAACM,GAAA,EAAsB,OAAOD,EAAA,GAAVA,CAAa,CAClC,EAAA,CACH,EAAA,CAEJ;AAAA,QAAA,GACF;AAAA,SAEE5B,MAAkB,YAAYA,MAAkB,YAChDP,uBACGqC,GAAA,EAAM,SAASnB,GAAS,WAAWQ,GACjC,UAAA;AAAA,UAAA1B;AAAA,UACAC,uBACE4B,GAAA,EAAQ,SAAS5B,GAChB,UAAA,gBAAA6B,EAACC,GAAA,EAAK,WAAU,2BAAA,CAA2B,EAAA,CAC7C;AAAA,QAAA,EAAA,CAEJ;AAAA,MAAA,GAEN;AAAA,MAEC7B,KACC,gBAAA4B,EAAC,OAAA,EAAI,WAAU,kEACZ,UAAA5B,KACC,gBAAA4B;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAWH;AAAA,YACT;AAAA,YACAxB,IAAQgB,IAAmBhB,CAAK,IAAI;AAAA,UAAA;AAAA,UAGrC,UAAAD;AAAA,QAAA;AAAA,MAAA,EACH,CAEJ;AAAA,IAAA,GAEJ;AAAA,EAEJ;AACF;AAEAN,EAAS,cAAc;"}
|
|
@@ -7,7 +7,7 @@ import { Info as Y, ChevronUp as Z, ChevronDown as T, X as q, EyeOff as F, Eye a
|
|
|
7
7
|
import { withMask as ee } from "use-mask-input";
|
|
8
8
|
import { Tooltip as se } from "../Tooltip/Tooltip.js";
|
|
9
9
|
import { Label as te } from "../../packages/ui/src/components/label.js";
|
|
10
|
-
const
|
|
10
|
+
const de = r.forwardRef(
|
|
11
11
|
({
|
|
12
12
|
className: _,
|
|
13
13
|
label: x,
|
|
@@ -15,7 +15,7 @@ const ne = r.forwardRef(
|
|
|
15
15
|
state: N,
|
|
16
16
|
size: l,
|
|
17
17
|
isFloatLabel: c,
|
|
18
|
-
type:
|
|
18
|
+
type: n,
|
|
19
19
|
mask: g,
|
|
20
20
|
maskOptions: P,
|
|
21
21
|
maxLength: b,
|
|
@@ -32,24 +32,24 @@ const ne = r.forwardRef(
|
|
|
32
32
|
const [f, M] = r.useState(() => typeof e.value == "string" ? e.value.length : typeof e.defaultValue == "string" ? e.defaultValue.length : 0), U = (s) => {
|
|
33
33
|
M(s.target.value.length), e.onChange && e.onChange(s);
|
|
34
34
|
}, X = () => {
|
|
35
|
-
if (
|
|
36
|
-
|
|
35
|
+
if (d.current) {
|
|
36
|
+
d.current.value = "", M(0);
|
|
37
37
|
const s = {
|
|
38
|
-
target:
|
|
39
|
-
currentTarget:
|
|
38
|
+
target: d.current,
|
|
39
|
+
currentTarget: d.current
|
|
40
40
|
};
|
|
41
41
|
e.onChange?.(s), I && I();
|
|
42
42
|
}
|
|
43
|
-
}, y = r.useId(),
|
|
43
|
+
}, y = r.useId(), d = r.useRef(null), $ = r.useCallback(
|
|
44
44
|
(s) => {
|
|
45
|
-
if (
|
|
45
|
+
if (d && (d.current = s), g && s) {
|
|
46
46
|
const m = ee(g, P);
|
|
47
47
|
typeof m == "function" && m(s);
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
[g, P]
|
|
51
51
|
);
|
|
52
|
-
r.useImperativeHandle(H, () =>
|
|
52
|
+
r.useImperativeHandle(H, () => d.current);
|
|
53
53
|
const [R, A] = r.useState(!1), G = {
|
|
54
54
|
default: "ds:text-muted-foreground",
|
|
55
55
|
success: "ds:text-success",
|
|
@@ -57,44 +57,44 @@ const ne = r.forwardRef(
|
|
|
57
57
|
error: "ds:text-error"
|
|
58
58
|
}, z = c ? l === "xl" || l === "lg" ? l : "xl" : l || "normal", k = (() => {
|
|
59
59
|
const s = {
|
|
60
|
-
xs: { prefix: "pl-8", suffix: "pr-8" },
|
|
61
|
-
sm: { prefix: "pl-9", suffix: "pr-9" },
|
|
62
|
-
normal: { prefix: "pl-10", suffix: "pr-10" },
|
|
63
|
-
lg: { prefix: "pl-11", suffix: "pr-11" },
|
|
64
|
-
xl: { prefix: "pl-12", suffix: "pr-12" }
|
|
60
|
+
xs: { prefix: "ds:pl-8", suffix: "ds:pr-8" },
|
|
61
|
+
sm: { prefix: "ds:pl-9", suffix: "ds:pr-9" },
|
|
62
|
+
normal: { prefix: "ds:pl-10", suffix: "ds:pr-10" },
|
|
63
|
+
lg: { prefix: "ds:pl-11", suffix: "ds:pr-11" },
|
|
64
|
+
xl: { prefix: "ds:pl-12", suffix: "ds:pr-12" }
|
|
65
65
|
};
|
|
66
66
|
return s[z] || s.normal;
|
|
67
67
|
})(), j = {
|
|
68
|
-
xs: "size-3",
|
|
69
|
-
sm: "size-3.5",
|
|
70
|
-
normal: "size-4",
|
|
71
|
-
lg: "size-4",
|
|
72
|
-
xl: "size-4"
|
|
73
|
-
}[z] || "size-4", J = () => {
|
|
74
|
-
const s =
|
|
75
|
-
return s && i ?
|
|
68
|
+
xs: "ds:size-3",
|
|
69
|
+
sm: "ds:size-3.5",
|
|
70
|
+
normal: "ds:size-4",
|
|
71
|
+
lg: "ds:size-4",
|
|
72
|
+
xl: "ds:size-4"
|
|
73
|
+
}[z] || "ds:size-4", J = () => {
|
|
74
|
+
const s = n === "number" || n === "password" || n === "datetime" || p && (f > 0 || e?.value);
|
|
75
|
+
return s && i ? n === "password" && p && (f > 0 || e?.value) ? "ds:pr-20" : "ds:pr-16" : s ? n === "password" && p && (f > 0 || e?.value) ? "ds:pr-16" : "ds:pr-10" : i ? k.suffix : "";
|
|
76
76
|
}, D = (() => {
|
|
77
77
|
const s = {
|
|
78
|
-
xs: { left: "left-2.5", right: "right-2.5" },
|
|
79
|
-
sm: { left: "left-3", right: "right-3" },
|
|
80
|
-
normal: { left: "left-3", right: "right-3" },
|
|
81
|
-
lg: { left: "left-3.5", right: "right-3.5" },
|
|
82
|
-
xl: { left: "left-4", right: "right-4" }
|
|
78
|
+
xs: { left: "ds:left-2.5", right: "ds:right-2.5" },
|
|
79
|
+
sm: { left: "ds:left-3", right: "ds:right-3" },
|
|
80
|
+
normal: { left: "ds:left-3", right: "ds:right-3" },
|
|
81
|
+
lg: { left: "ds:left-3.5", right: "ds:right-3.5" },
|
|
82
|
+
xl: { left: "ds:left-4", right: "ds:right-4" }
|
|
83
83
|
};
|
|
84
84
|
return s[z] || s.normal;
|
|
85
85
|
})(), K = () => {
|
|
86
|
-
if (
|
|
87
|
-
const s = Number(e.step || 1), m = e.max ? Number(e.max) : 1 / 0, S = Number(
|
|
88
|
-
|
|
86
|
+
if (d.current) {
|
|
87
|
+
const s = Number(e.step || 1), m = e.max ? Number(e.max) : 1 / 0, S = Number(d.current.value || 0), E = Math.min(S + s, m);
|
|
88
|
+
d.current.value = String(E);
|
|
89
89
|
const h = new Event("input", { bubbles: !0 });
|
|
90
|
-
|
|
90
|
+
d.current.dispatchEvent(h), e.onChange?.(h);
|
|
91
91
|
}
|
|
92
92
|
}, O = () => {
|
|
93
|
-
if (
|
|
94
|
-
const s = Number(e.step || 1), m = e.min ? Number(e.min) : -1 / 0, S = Number(
|
|
95
|
-
|
|
93
|
+
if (d.current) {
|
|
94
|
+
const s = Number(e.step || 1), m = e.min ? Number(e.min) : -1 / 0, S = Number(d.current.value || 0), E = Math.max(S - s, m);
|
|
95
|
+
d.current.value = String(E);
|
|
96
96
|
const h = new Event("input", { bubbles: !0 });
|
|
97
|
-
|
|
97
|
+
d.current.dispatchEvent(h), e.onChange?.(h);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
return /* @__PURE__ */ t("div", { className: _, children: /* @__PURE__ */ o(
|
|
@@ -143,7 +143,7 @@ const ne = r.forwardRef(
|
|
|
143
143
|
"ds:peer",
|
|
144
144
|
{
|
|
145
145
|
"ds:pt-5 ds:pb-1": c && l !== "lg",
|
|
146
|
-
"ds:[&::-webkit-outer-spin-button]:appearance-none ds:[&::-webkit-inner-spin-button]:appearance-none ds:[-moz-appearance:textfield] ds:pr-8":
|
|
146
|
+
"ds:[&::-webkit-outer-spin-button]:appearance-none ds:[&::-webkit-inner-spin-button]:appearance-none ds:[-moz-appearance:textfield] ds:pr-8": n === "number"
|
|
147
147
|
// "[-webkit-text-fill-color:var(--foreground)]": mask,
|
|
148
148
|
},
|
|
149
149
|
u && k.prefix,
|
|
@@ -153,7 +153,7 @@ const ne = r.forwardRef(
|
|
|
153
153
|
),
|
|
154
154
|
state: N,
|
|
155
155
|
size: c ? l === "xl" || l === "lg" ? l : "xl" : l,
|
|
156
|
-
type:
|
|
156
|
+
type: n === "password" ? R ? "text" : "password" : n,
|
|
157
157
|
placeholder: B,
|
|
158
158
|
maxLength: b,
|
|
159
159
|
onChange: U,
|
|
@@ -171,7 +171,7 @@ const ne = r.forwardRef(
|
|
|
171
171
|
children: x
|
|
172
172
|
}
|
|
173
173
|
),
|
|
174
|
-
|
|
174
|
+
n === "number" && /* @__PURE__ */ o("div", { className: "ds:absolute ds:right-1 ds:top-0 ds:h-full ds:flex ds:flex-col ds:gap-0.5", children: [
|
|
175
175
|
/* @__PURE__ */ t(
|
|
176
176
|
"button",
|
|
177
177
|
{
|
|
@@ -201,21 +201,21 @@ const ne = r.forwardRef(
|
|
|
201
201
|
}
|
|
202
202
|
)
|
|
203
203
|
] }),
|
|
204
|
-
p && (f > 0 || e?.value) && !e.disabled &&
|
|
204
|
+
p && (f > 0 || e?.value) && !e.disabled && n !== "number" && /* @__PURE__ */ t(
|
|
205
205
|
"button",
|
|
206
206
|
{
|
|
207
207
|
type: "button",
|
|
208
208
|
tabIndex: -1,
|
|
209
209
|
className: a(
|
|
210
210
|
"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:p-1 ds:rounded ds:hover:bg-accent ds:transition-colors ds:cursor-pointer",
|
|
211
|
-
|
|
211
|
+
n === "password" ? i ? "ds:right-14" : "ds:right-10" : i ? "ds:right-10" : "ds:right-2"
|
|
212
212
|
),
|
|
213
213
|
onClick: X,
|
|
214
214
|
disabled: e.disabled,
|
|
215
215
|
children: /* @__PURE__ */ t(q, { className: "ds:size-4" })
|
|
216
216
|
}
|
|
217
217
|
),
|
|
218
|
-
|
|
218
|
+
n === "password" && /* @__PURE__ */ t(
|
|
219
219
|
"button",
|
|
220
220
|
{
|
|
221
221
|
type: "button",
|
|
@@ -267,8 +267,8 @@ const ne = r.forwardRef(
|
|
|
267
267
|
) });
|
|
268
268
|
}
|
|
269
269
|
);
|
|
270
|
-
|
|
270
|
+
de.displayName = "Input";
|
|
271
271
|
export {
|
|
272
|
-
|
|
272
|
+
de as default
|
|
273
273
|
};
|
|
274
274
|
//# sourceMappingURL=Input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sources":["../../../../src/components/Input/Input.tsx"],"sourcesContent":["import React, { type ChangeEvent } from \"react\";\nimport {\n Input as SInput,\n type InputProps as SInputProps,\n} from \"@dsui/ui/components/input\";\nimport { cn } from \"@dsui/ui/lib/utils\";\nimport { FloatingLabel } from \"@/components/FloatLabel\";\nimport { Eye, EyeOff, ChevronDown, ChevronUp, Info, X } from \"lucide-react\";\nimport { withMask, type Options } from \"use-mask-input\";\nimport { Tooltip } from \"../Tooltip/Tooltip\";\nimport { Label } from \"../Label\";\n\n// Re-export base input props to avoid external dependency issues\nexport type BaseInputProps = Omit<React.ComponentProps<\"input\">, \"size\"> & {\n size?: \"normal\" | \"sm\" | \"xs\" | \"lg\" | \"xl\";\n state?: \"default\" | \"success\" | \"error\" | \"warning\";\n};\n\nexport type InputProps = BaseInputProps & {\n label?: string;\n helperText?: React.ReactNode;\n isFloatLabel?: boolean;\n mask?: string;\n maskOptions?: {\n placeholder?: string;\n inputFormat?: string;\n outputFormat?: string;\n showMaskOnHover?: boolean;\n showMaskOnFocus?: boolean;\n separate?: boolean;\n } & Options;\n maxLength?: number;\n showCharCount?: boolean;\n infoTooltip?: React.ReactNode;\n clearable?: boolean;\n onClear?: () => void;\n prefixIcon?: React.ReactNode;\n suffixIcon?: React.ReactNode;\n required?: boolean;\n};\n\nconst Input = React.forwardRef<HTMLInputElement, InputProps>(\n (\n {\n className,\n label,\n helperText,\n state,\n size,\n isFloatLabel,\n type,\n mask,\n maskOptions,\n maxLength,\n showCharCount,\n infoTooltip,\n clearable,\n onClear,\n prefixIcon,\n suffixIcon,\n placeholder = \" \",\n required,\n ...props\n },\n ref\n ) => {\n // Character count state\n const [charCount, setCharCount] = React.useState(() => {\n if (typeof props.value === \"string\") return props.value.length;\n if (typeof props.defaultValue === \"string\")\n return props.defaultValue.length;\n return 0;\n });\n\n const handleInput = (e: React.ChangeEvent<HTMLInputElement>) => {\n setCharCount(e.target.value.length);\n if (props.onChange) props.onChange(e);\n };\n\n const handleClear = () => {\n if (innerRef.current) {\n innerRef.current.value = \"\";\n setCharCount(0);\n const event = {\n target: innerRef.current,\n currentTarget: innerRef.current,\n } as React.ChangeEvent<HTMLInputElement>;\n props.onChange?.(event);\n if (onClear) onClear();\n }\n };\n\n const inputId = React.useId();\n const innerRef = React.useRef<HTMLInputElement>(null);\n\n // Combine refs\n const combinedRef = React.useCallback(\n (element: HTMLInputElement | null) => {\n // Set innerRef\n if (innerRef) {\n (\n innerRef as React.MutableRefObject<HTMLInputElement | null>\n ).current = element;\n }\n\n // Apply mask if provided\n if (mask && element) {\n const maskRefCallback = withMask(mask, maskOptions);\n if (typeof maskRefCallback === \"function\") {\n maskRefCallback(element);\n }\n }\n },\n [mask, maskOptions]\n );\n\n // Expose ref to parent\n React.useImperativeHandle(ref, () => innerRef.current!);\n\n const [showPassword, setShowPassword] = React.useState(false);\n\n // State\n const helperTextStyles = {\n default: \"ds:text-muted-foreground\",\n success: \"ds:text-success\",\n warning: \"ds:text-warning\",\n error: \"ds:text-error\",\n };\n\n // Calculate current size\n const currentSize = isFloatLabel\n ? size === \"xl\" || size === \"lg\"\n ? size\n : \"xl\"\n : size || \"normal\";\n\n // Calculate padding based on size and icons\n const getPadding = () => {\n const sizeMap = {\n xs: { prefix: \"pl-8\", suffix: \"pr-8\" },\n sm: { prefix: \"pl-9\", suffix: \"pr-9\" },\n normal: { prefix: \"pl-10\", suffix: \"pr-10\" },\n lg: { prefix: \"pl-11\", suffix: \"pr-11\" },\n xl: { prefix: \"pl-12\", suffix: \"pr-12\" },\n };\n\n return sizeMap[currentSize as keyof typeof sizeMap] || sizeMap.normal;\n };\n\n const padding = getPadding();\n\n // Get icon size class based on current size\n const getIconSizeClass = () => {\n const sizeMap = {\n xs: \"size-3\",\n sm: \"size-3.5\",\n normal: \"size-4\",\n lg: \"size-4\",\n xl: \"size-4\",\n };\n return sizeMap[currentSize as keyof typeof sizeMap] || \"size-4\";\n };\n\n const iconSizeClass = getIconSizeClass();\n\n // Calculate right padding considering built-in icons\n const getRightPadding = () => {\n const hasBuiltInSuffix =\n type === \"number\" ||\n type === \"password\" ||\n type === \"datetime\" ||\n (clearable && (charCount > 0 || props?.value));\n\n if (hasBuiltInSuffix && suffixIcon) {\n return type === \"password\" &&\n clearable &&\n (charCount > 0 || props?.value)\n ? \"pr-20\" // password + clear + custom icon\n : \"pr-16\"; // one built-in + custom icon\n }\n\n if (hasBuiltInSuffix) {\n return type === \"password\" &&\n clearable &&\n (charCount > 0 || props?.value)\n ? \"pr-16\" // password + clear\n : \"pr-10\"; // single built-in icon\n }\n\n if (suffixIcon) {\n return padding.suffix;\n }\n\n return \"\";\n };\n\n // Icon position calculations\n const getIconPosition = () => {\n const sizeMap = {\n xs: { left: \"left-2.5\", right: \"right-2.5\" },\n sm: { left: \"left-3\", right: \"right-3\" },\n normal: { left: \"left-3\", right: \"right-3\" },\n lg: { left: \"left-3.5\", right: \"right-3.5\" },\n xl: { left: \"left-4\", right: \"right-4\" },\n };\n\n return sizeMap[currentSize as keyof typeof sizeMap] || sizeMap.normal;\n };\n\n const iconPosition = getIconPosition();\n\n /* Spinner Button Handlers */\n const handleIncrement = () => {\n if (innerRef.current) {\n const step = Number(props.step || 1);\n const max = props.max ? Number(props.max) : Infinity;\n const currentValue = Number(innerRef.current.value || 0);\n const newValue = Math.min(currentValue + step, max);\n\n innerRef.current.value = String(newValue);\n const event = new Event(\"input\", { bubbles: true });\n innerRef.current.dispatchEvent(event);\n props.onChange?.(event as unknown as ChangeEvent<HTMLInputElement>);\n }\n };\n\n const handleDecrement = () => {\n if (innerRef.current) {\n const step = Number(props.step || 1);\n const min = props.min ? Number(props.min) : -Infinity;\n const currentValue = Number(innerRef.current.value || 0);\n const newValue = Math.max(currentValue - step, min);\n\n innerRef.current.value = String(newValue);\n const event = new Event(\"input\", { bubbles: true });\n innerRef.current.dispatchEvent(event);\n props.onChange?.(event as unknown as ChangeEvent<HTMLInputElement>);\n }\n };\n /* End Spinner Button Handlers */\n\n return (\n <div className={className}>\n <div\n className={cn(\"ds:flex ds:flex-col ds:gap-1.5 ds:relative ds:flex-auto\", {\n \"ds:floating-label ds:relative\": isFloatLabel,\n })}\n >\n {!isFloatLabel && label && (\n <Label\n htmlFor={inputId}\n className=\"ds:flex ds:gap-2 ds:text-sm ds:font-medium ds:leading-none ds:peer-disabled:cursor-not-allowed ds:peer-disabled:opacity-70\"\n >\n <span>\n {label}\n {required && <span className=\"ds:text-error ds:ml-0.5\">*</span>}\n </span>\n {infoTooltip && (\n <Tooltip content={infoTooltip}>\n <Info className=\"ds:size-3.5 ds:min-w-3.5\" />\n </Tooltip>\n )}\n </Label>\n )}\n\n <div className=\"ds:relative\">\n {/* Prefix Icon */}\n {prefixIcon && (\n <div\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:text-muted-foreground ds:leading-0\",\n iconPosition.left\n )}\n >\n {React.isValidElement(prefixIcon)\n ? React.cloneElement(prefixIcon, {\n className: cn(\n iconSizeClass,\n (prefixIcon.props as any)?.className\n ),\n } as Partial<unknown>)\n : prefixIcon}\n </div>\n )}\n\n <SInput\n ref={combinedRef}\n id={inputId}\n className={cn(\n \"ds:peer\",\n {\n \"ds:pt-5 ds:pb-1\": isFloatLabel && size !== \"lg\",\n \"ds:[&::-webkit-outer-spin-button]:appearance-none ds:[&::-webkit-inner-spin-button]:appearance-none ds:[-moz-appearance:textfield] ds:pr-8\":\n type === \"number\",\n // \"[-webkit-text-fill-color:var(--foreground)]\": mask,\n },\n prefixIcon && padding.prefix,\n mask && \"ds:placeholder:text-slate-400 ds:placeholder:opacity-100\",\n getRightPadding()\n // className,\n )}\n state={state}\n size={\n isFloatLabel\n ? size === \"xl\" || size === \"lg\"\n ? size\n : \"xl\"\n : size\n }\n type={\n type === \"password\"\n ? showPassword\n ? \"text\"\n : \"password\"\n : type\n }\n placeholder={placeholder}\n maxLength={maxLength}\n onChange={handleInput}\n required={required}\n {...props}\n />\n {isFloatLabel && (\n <FloatingLabel\n htmlFor={inputId}\n size={size}\n infoTooltip={infoTooltip}\n required={required}\n >\n {label}\n </FloatingLabel>\n )}\n\n {/* Spinner Buttons */}\n {type === \"number\" && (\n <div className=\"ds:absolute ds:right-1 ds:top-0 ds:h-full ds:flex ds:flex-col ds:gap-0.5\">\n <button\n type=\"button\"\n onClick={handleIncrement}\n disabled={props.disabled}\n className={cn(\n \"ds:h-1/2 ds:w-6 ds:flex ds:items-center ds:justify-center ds:rounded ds:cursor-pointer ds:hover:scale-150 ds:transition-transform\",\n \"ds:disabled:opacity-50 ds:disabled:cursor-not-allowed ds:disabled:hover:bg-transparent\"\n )}\n tabIndex={-1}\n >\n <ChevronUp className=\"ds:size-3\" />\n </button>\n <button\n type=\"button\"\n onClick={handleDecrement}\n disabled={props.disabled}\n className={cn(\n \"ds:h-1/2 ds:w-6 ds:flex ds:items-center ds:justify-center ds:rounded ds:cursor-pointer ds:hover:scale-150 ds:transition-transform\",\n \"ds:disabled:opacity-50 ds:disabled:cursor-not-allowed ds:disabled:hover:bg-transparent\"\n )}\n tabIndex={-1}\n >\n <ChevronDown className=\"ds:size-3\" />\n </button>\n </div>\n )}\n\n {/* Clear Button */}\n {clearable &&\n (charCount > 0 || props?.value) &&\n !props.disabled &&\n type !== \"number\" && (\n <button\n type=\"button\"\n tabIndex={-1}\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:p-1 ds:rounded ds:hover:bg-accent ds:transition-colors ds:cursor-pointer\",\n type === \"password\"\n ? suffixIcon\n ? \"ds:right-14\"\n : \"ds:right-10\"\n : suffixIcon\n ? \"ds:right-10\"\n : \"ds:right-2\"\n )}\n onClick={handleClear}\n disabled={props.disabled}\n >\n <X className=\"ds:size-4\" />\n </button>\n )}\n\n {/* Show/Hide Password Button */}\n {type === \"password\" && (\n <button\n type=\"button\"\n tabIndex={-1}\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:p-1 ds:rounded ds:hover:bg-accent ds:transition-colors\",\n suffixIcon ? \"ds:right-10\" : \"ds:right-2\"\n )}\n onClick={() => setShowPassword((prev) => !prev)}\n disabled={props.disabled}\n >\n {showPassword ? (\n <EyeOff className=\"ds:size-4\" />\n ) : (\n <Eye className=\"ds:size-4\" />\n )}\n </button>\n )}\n\n {/* Suffix Icon */}\n {suffixIcon && (\n <div\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:text-muted-foreground ds:leading-0\",\n iconPosition.right\n )}\n >\n {React.isValidElement(suffixIcon)\n ? React.cloneElement(suffixIcon, {\n className: cn(\n iconSizeClass,\n (suffixIcon.props as any)?.className\n ),\n } as Partial<unknown>)\n : suffixIcon}\n </div>\n )}\n </div>\n\n {(helperText || (showCharCount && typeof maxLength === \"number\")) && (\n <div className=\"ds:flex ds:items-center ds:justify-between ds:text-xs ds:gap-2\">\n {helperText && (\n <p\n className={cn(\n \"ds:text-xs\",\n state ? helperTextStyles?.[state] : \"\"\n )}\n >\n {helperText}\n </p>\n )}\n {showCharCount && typeof maxLength === \"number\" && (\n <span className=\"ds:ml-auto ds:text-muted-foreground\">\n {charCount} / {maxLength}\n </span>\n )}\n </div>\n )}\n </div>\n </div>\n );\n }\n);\n\nInput.displayName = \"Input\";\nexport default Input;\n"],"names":["Input","React","className","label","helperText","state","size","isFloatLabel","type","mask","maskOptions","maxLength","showCharCount","infoTooltip","clearable","onClear","prefixIcon","suffixIcon","placeholder","required","props","ref","charCount","setCharCount","handleInput","e","handleClear","innerRef","event","inputId","combinedRef","element","maskRefCallback","withMask","showPassword","setShowPassword","helperTextStyles","currentSize","padding","sizeMap","iconSizeClass","getRightPadding","hasBuiltInSuffix","iconPosition","handleIncrement","step","max","currentValue","newValue","handleDecrement","min","jsx","jsxs","cn","Label","Tooltip","Info","SInput","FloatingLabel","ChevronUp","ChevronDown","X","prev","EyeOff","Eye"],"mappings":";;;;;;;;;AAyCA,MAAMA,KAAQC,EAAM;AAAA,EAClB,CACE;AAAA,IACE,WAAAC;AAAA,IACA,OAAAC;AAAA,IACA,YAAAC;AAAA,IACA,OAAAC;AAAA,IACA,MAAAC;AAAA,IACA,cAAAC;AAAA,IACA,MAAAC;AAAA,IACA,MAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,eAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,SAAAC;AAAA,IACA,YAAAC;AAAA,IACA,YAAAC;AAAA,IACA,aAAAC,IAAc;AAAA,IACd,UAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,GAELC,MACG;AAEH,UAAM,CAACC,GAAWC,CAAY,IAAItB,EAAM,SAAS,MAC3C,OAAOmB,EAAM,SAAU,WAAiBA,EAAM,MAAM,SACpD,OAAOA,EAAM,gBAAiB,WACzBA,EAAM,aAAa,SACrB,CACR,GAEKI,IAAc,CAACC,MAA2C;AAC9D,MAAAF,EAAaE,EAAE,OAAO,MAAM,MAAM,GAC9BL,EAAM,YAAUA,EAAM,SAASK,CAAC;AAAA,IACtC,GAEMC,IAAc,MAAM;AACxB,UAAIC,EAAS,SAAS;AACpB,QAAAA,EAAS,QAAQ,QAAQ,IACzBJ,EAAa,CAAC;AACd,cAAMK,IAAQ;AAAA,UACZ,QAAQD,EAAS;AAAA,UACjB,eAAeA,EAAS;AAAA,QAAA;AAE1B,QAAAP,EAAM,WAAWQ,CAAK,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;AAAA,WAEEb,KAAeQ,KAAiB,OAAOD,KAAc,aACrD,gBAAAyC,EAAC,OAAA,EAAI,WAAU,kEACZ,UAAA;AAAA,YAAAhD,KACC,gBAAA+C;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAWE;AAAA,kBACT;AAAA,kBACAhD,IAAQ+B,IAAmB/B,CAAK,IAAI;AAAA,gBAAA;AAAA,gBAGrC,UAAAD;AAAA,cAAA;AAAA,YAAA;AAAA,YAGJQ,KAAiB,OAAOD,KAAc,YACrC,gBAAAyC,EAAC,QAAA,EAAK,WAAU,uCACb,UAAA;AAAA,cAAA9B;AAAA,cAAU;AAAA,cAAIX;AAAA,YAAA,EAAA,CACjB;AAAA,UAAA,EAAA,CAEJ;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,GAGN;AAAA,EAEJ;AACF;AAEAX,GAAM,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Input.js","sources":["../../../../src/components/Input/Input.tsx"],"sourcesContent":["import React, { type ChangeEvent } from \"react\";\nimport {\n Input as SInput,\n type InputProps as SInputProps,\n} from \"@dsui/ui/components/input\";\nimport { cn } from \"@dsui/ui/lib/utils\";\nimport { FloatingLabel } from \"@/components/FloatLabel\";\nimport { Eye, EyeOff, ChevronDown, ChevronUp, Info, X } from \"lucide-react\";\nimport { withMask, type Options } from \"use-mask-input\";\nimport { Tooltip } from \"../Tooltip/Tooltip\";\nimport { Label } from \"../Label\";\n\n// Re-export base input props to avoid external dependency issues\nexport type BaseInputProps = Omit<React.ComponentProps<\"input\">, \"size\"> & {\n size?: \"normal\" | \"sm\" | \"xs\" | \"lg\" | \"xl\";\n state?: \"default\" | \"success\" | \"error\" | \"warning\";\n};\n\nexport type InputProps = BaseInputProps & {\n label?: string;\n helperText?: React.ReactNode;\n isFloatLabel?: boolean;\n mask?: string;\n maskOptions?: {\n placeholder?: string;\n inputFormat?: string;\n outputFormat?: string;\n showMaskOnHover?: boolean;\n showMaskOnFocus?: boolean;\n separate?: boolean;\n } & Options;\n maxLength?: number;\n showCharCount?: boolean;\n infoTooltip?: React.ReactNode;\n clearable?: boolean;\n onClear?: () => void;\n prefixIcon?: React.ReactNode;\n suffixIcon?: React.ReactNode;\n required?: boolean;\n};\n\nconst Input = React.forwardRef<HTMLInputElement, InputProps>(\n (\n {\n className,\n label,\n helperText,\n state,\n size,\n isFloatLabel,\n type,\n mask,\n maskOptions,\n maxLength,\n showCharCount,\n infoTooltip,\n clearable,\n onClear,\n prefixIcon,\n suffixIcon,\n placeholder = \" \",\n required,\n ...props\n },\n ref\n ) => {\n // Character count state\n const [charCount, setCharCount] = React.useState(() => {\n if (typeof props.value === \"string\") return props.value.length;\n if (typeof props.defaultValue === \"string\")\n return props.defaultValue.length;\n return 0;\n });\n\n const handleInput = (e: React.ChangeEvent<HTMLInputElement>) => {\n setCharCount(e.target.value.length);\n if (props.onChange) props.onChange(e);\n };\n\n const handleClear = () => {\n if (innerRef.current) {\n innerRef.current.value = \"\";\n setCharCount(0);\n const event = {\n target: innerRef.current,\n currentTarget: innerRef.current,\n } as React.ChangeEvent<HTMLInputElement>;\n props.onChange?.(event);\n if (onClear) onClear();\n }\n };\n\n const inputId = React.useId();\n const innerRef = React.useRef<HTMLInputElement>(null);\n\n // Combine refs\n const combinedRef = React.useCallback(\n (element: HTMLInputElement | null) => {\n // Set innerRef\n if (innerRef) {\n (\n innerRef as React.MutableRefObject<HTMLInputElement | null>\n ).current = element;\n }\n\n // Apply mask if provided\n if (mask && element) {\n const maskRefCallback = withMask(mask, maskOptions);\n if (typeof maskRefCallback === \"function\") {\n maskRefCallback(element);\n }\n }\n },\n [mask, maskOptions]\n );\n\n // Expose ref to parent\n React.useImperativeHandle(ref, () => innerRef.current!);\n\n const [showPassword, setShowPassword] = React.useState(false);\n\n // State\n const helperTextStyles = {\n default: \"ds:text-muted-foreground\",\n success: \"ds:text-success\",\n warning: \"ds:text-warning\",\n error: \"ds:text-error\",\n };\n\n // Calculate current size\n const currentSize = isFloatLabel\n ? size === \"xl\" || size === \"lg\"\n ? size\n : \"xl\"\n : size || \"normal\";\n\n // Calculate padding based on size and icons\n const getPadding = () => {\n const sizeMap = {\n xs: { prefix: \"ds:pl-8\", suffix: \"ds:pr-8\" },\n sm: { prefix: \"ds:pl-9\", suffix: \"ds:pr-9\" },\n normal: { prefix: \"ds:pl-10\", suffix: \"ds:pr-10\" },\n lg: { prefix: \"ds:pl-11\", suffix: \"ds:pr-11\" },\n xl: { prefix: \"ds:pl-12\", suffix: \"ds:pr-12\" },\n };\n\n return sizeMap[currentSize as keyof typeof sizeMap] || sizeMap.normal;\n };\n\n const padding = getPadding();\n\n // Get icon size class based on current size\n const getIconSizeClass = () => {\n const sizeMap = {\n xs: \"ds:size-3\",\n sm: \"ds:size-3.5\",\n normal: \"ds:size-4\",\n lg: \"ds:size-4\",\n xl: \"ds:size-4\",\n };\n return sizeMap[currentSize as keyof typeof sizeMap] || \"ds:size-4\";\n };\n\n const iconSizeClass = getIconSizeClass();\n\n // Calculate right padding considering built-in icons\n const getRightPadding = () => {\n const hasBuiltInSuffix =\n type === \"number\" ||\n type === \"password\" ||\n type === \"datetime\" ||\n (clearable && (charCount > 0 || props?.value));\n\n if (hasBuiltInSuffix && suffixIcon) {\n return type === \"password\" &&\n clearable &&\n (charCount > 0 || props?.value)\n ? \"ds:pr-20\" // password + clear + custom icon\n : \"ds:pr-16\"; // one built-in + custom icon\n }\n\n if (hasBuiltInSuffix) {\n return type === \"password\" &&\n clearable &&\n (charCount > 0 || props?.value)\n ? \"ds:pr-16\" // password + clear\n : \"ds:pr-10\"; // single built-in icon\n }\n\n if (suffixIcon) {\n return padding.suffix;\n }\n\n return \"\";\n };\n\n // Icon position calculations\n const getIconPosition = () => {\n const sizeMap = {\n xs: { left: \"ds:left-2.5\", right: \"ds:right-2.5\" },\n sm: { left: \"ds:left-3\", right: \"ds:right-3\" },\n normal: { left: \"ds:left-3\", right: \"ds:right-3\" },\n lg: { left: \"ds:left-3.5\", right: \"ds:right-3.5\" },\n xl: { left: \"ds:left-4\", right: \"ds:right-4\" },\n };\n\n return sizeMap[currentSize as keyof typeof sizeMap] || sizeMap.normal;\n };\n\n const iconPosition = getIconPosition();\n\n /* Spinner Button Handlers */\n const handleIncrement = () => {\n if (innerRef.current) {\n const step = Number(props.step || 1);\n const max = props.max ? Number(props.max) : Infinity;\n const currentValue = Number(innerRef.current.value || 0);\n const newValue = Math.min(currentValue + step, max);\n\n innerRef.current.value = String(newValue);\n const event = new Event(\"input\", { bubbles: true });\n innerRef.current.dispatchEvent(event);\n props.onChange?.(event as unknown as ChangeEvent<HTMLInputElement>);\n }\n };\n\n const handleDecrement = () => {\n if (innerRef.current) {\n const step = Number(props.step || 1);\n const min = props.min ? Number(props.min) : -Infinity;\n const currentValue = Number(innerRef.current.value || 0);\n const newValue = Math.max(currentValue - step, min);\n\n innerRef.current.value = String(newValue);\n const event = new Event(\"input\", { bubbles: true });\n innerRef.current.dispatchEvent(event);\n props.onChange?.(event as unknown as ChangeEvent<HTMLInputElement>);\n }\n };\n /* End Spinner Button Handlers */\n\n return (\n <div className={className}>\n <div\n className={cn(\"ds:flex ds:flex-col ds:gap-1.5 ds:relative ds:flex-auto\", {\n \"ds:floating-label ds:relative\": isFloatLabel,\n })}\n >\n {!isFloatLabel && label && (\n <Label\n htmlFor={inputId}\n className=\"ds:flex ds:gap-2 ds:text-sm ds:font-medium ds:leading-none ds:peer-disabled:cursor-not-allowed ds:peer-disabled:opacity-70\"\n >\n <span>\n {label}\n {required && <span className=\"ds:text-error ds:ml-0.5\">*</span>}\n </span>\n {infoTooltip && (\n <Tooltip content={infoTooltip}>\n <Info className=\"ds:size-3.5 ds:min-w-3.5\" />\n </Tooltip>\n )}\n </Label>\n )}\n\n <div className=\"ds:relative\">\n {/* Prefix Icon */}\n {prefixIcon && (\n <div\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:text-muted-foreground ds:leading-0\",\n iconPosition.left\n )}\n >\n {React.isValidElement(prefixIcon)\n ? React.cloneElement(prefixIcon, {\n className: cn(\n iconSizeClass,\n (prefixIcon.props as any)?.className\n ),\n } as Partial<unknown>)\n : prefixIcon}\n </div>\n )}\n\n <SInput\n ref={combinedRef}\n id={inputId}\n className={cn(\n \"ds:peer\",\n {\n \"ds:pt-5 ds:pb-1\": isFloatLabel && size !== \"lg\",\n \"ds:[&::-webkit-outer-spin-button]:appearance-none ds:[&::-webkit-inner-spin-button]:appearance-none ds:[-moz-appearance:textfield] ds:pr-8\":\n type === \"number\",\n // \"[-webkit-text-fill-color:var(--foreground)]\": mask,\n },\n prefixIcon && padding.prefix,\n mask && \"ds:placeholder:text-slate-400 ds:placeholder:opacity-100\",\n getRightPadding()\n // className,\n )}\n state={state}\n size={\n isFloatLabel\n ? size === \"xl\" || size === \"lg\"\n ? size\n : \"xl\"\n : size\n }\n type={\n type === \"password\"\n ? showPassword\n ? \"text\"\n : \"password\"\n : type\n }\n placeholder={placeholder}\n maxLength={maxLength}\n onChange={handleInput}\n required={required}\n {...props}\n />\n {isFloatLabel && (\n <FloatingLabel\n htmlFor={inputId}\n size={size}\n infoTooltip={infoTooltip}\n required={required}\n >\n {label}\n </FloatingLabel>\n )}\n\n {/* Spinner Buttons */}\n {type === \"number\" && (\n <div className=\"ds:absolute ds:right-1 ds:top-0 ds:h-full ds:flex ds:flex-col ds:gap-0.5\">\n <button\n type=\"button\"\n onClick={handleIncrement}\n disabled={props.disabled}\n className={cn(\n \"ds:h-1/2 ds:w-6 ds:flex ds:items-center ds:justify-center ds:rounded ds:cursor-pointer ds:hover:scale-150 ds:transition-transform\",\n \"ds:disabled:opacity-50 ds:disabled:cursor-not-allowed ds:disabled:hover:bg-transparent\"\n )}\n tabIndex={-1}\n >\n <ChevronUp className=\"ds:size-3\" />\n </button>\n <button\n type=\"button\"\n onClick={handleDecrement}\n disabled={props.disabled}\n className={cn(\n \"ds:h-1/2 ds:w-6 ds:flex ds:items-center ds:justify-center ds:rounded ds:cursor-pointer ds:hover:scale-150 ds:transition-transform\",\n \"ds:disabled:opacity-50 ds:disabled:cursor-not-allowed ds:disabled:hover:bg-transparent\"\n )}\n tabIndex={-1}\n >\n <ChevronDown className=\"ds:size-3\" />\n </button>\n </div>\n )}\n\n {/* Clear Button */}\n {clearable &&\n (charCount > 0 || props?.value) &&\n !props.disabled &&\n type !== \"number\" && (\n <button\n type=\"button\"\n tabIndex={-1}\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:p-1 ds:rounded ds:hover:bg-accent ds:transition-colors ds:cursor-pointer\",\n type === \"password\"\n ? suffixIcon\n ? \"ds:right-14\"\n : \"ds:right-10\"\n : suffixIcon\n ? \"ds:right-10\"\n : \"ds:right-2\"\n )}\n onClick={handleClear}\n disabled={props.disabled}\n >\n <X className=\"ds:size-4\" />\n </button>\n )}\n\n {/* Show/Hide Password Button */}\n {type === \"password\" && (\n <button\n type=\"button\"\n tabIndex={-1}\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:p-1 ds:rounded ds:hover:bg-accent ds:transition-colors\",\n suffixIcon ? \"ds:right-10\" : \"ds:right-2\"\n )}\n onClick={() => setShowPassword((prev) => !prev)}\n disabled={props.disabled}\n >\n {showPassword ? (\n <EyeOff className=\"ds:size-4\" />\n ) : (\n <Eye className=\"ds:size-4\" />\n )}\n </button>\n )}\n\n {/* Suffix Icon */}\n {suffixIcon && (\n <div\n className={cn(\n \"ds:absolute ds:top-1/2 ds:-translate-y-1/2 ds:text-muted-foreground ds:leading-0\",\n iconPosition.right\n )}\n >\n {React.isValidElement(suffixIcon)\n ? React.cloneElement(suffixIcon, {\n className: cn(\n iconSizeClass,\n (suffixIcon.props as any)?.className\n ),\n } as Partial<unknown>)\n : suffixIcon}\n </div>\n )}\n </div>\n\n {(helperText || (showCharCount && typeof maxLength === \"number\")) && (\n <div className=\"ds:flex ds:items-center ds:justify-between ds:text-xs ds:gap-2\">\n {helperText && (\n <p\n className={cn(\n \"ds:text-xs\",\n state ? helperTextStyles?.[state] : \"\"\n )}\n >\n {helperText}\n </p>\n )}\n {showCharCount && typeof maxLength === \"number\" && (\n <span className=\"ds:ml-auto ds:text-muted-foreground\">\n {charCount} / {maxLength}\n </span>\n )}\n </div>\n )}\n </div>\n </div>\n );\n }\n);\n\nInput.displayName = \"Input\";\nexport default Input;\n"],"names":["Input","React","className","label","helperText","state","size","isFloatLabel","type","mask","maskOptions","maxLength","showCharCount","infoTooltip","clearable","onClear","prefixIcon","suffixIcon","placeholder","required","props","ref","charCount","setCharCount","handleInput","e","handleClear","innerRef","event","inputId","combinedRef","element","maskRefCallback","withMask","showPassword","setShowPassword","helperTextStyles","currentSize","padding","sizeMap","iconSizeClass","getRightPadding","hasBuiltInSuffix","iconPosition","handleIncrement","step","max","currentValue","newValue","handleDecrement","min","jsx","jsxs","cn","Label","Tooltip","Info","SInput","FloatingLabel","ChevronUp","ChevronDown","X","prev","EyeOff","Eye"],"mappings":";;;;;;;;;AAyCA,MAAMA,KAAQC,EAAM;AAAA,EAClB,CACE;AAAA,IACE,WAAAC;AAAA,IACA,OAAAC;AAAA,IACA,YAAAC;AAAA,IACA,OAAAC;AAAA,IACA,MAAAC;AAAA,IACA,cAAAC;AAAA,IACA,MAAAC;AAAA,IACA,MAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,eAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,SAAAC;AAAA,IACA,YAAAC;AAAA,IACA,YAAAC;AAAA,IACA,aAAAC,IAAc;AAAA,IACd,UAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,GAELC,MACG;AAEH,UAAM,CAACC,GAAWC,CAAY,IAAItB,EAAM,SAAS,MAC3C,OAAOmB,EAAM,SAAU,WAAiBA,EAAM,MAAM,SACpD,OAAOA,EAAM,gBAAiB,WACzBA,EAAM,aAAa,SACrB,CACR,GAEKI,IAAc,CAACC,MAA2C;AAC9D,MAAAF,EAAaE,EAAE,OAAO,MAAM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gBACC,WAAWE;AAAA,kBACT;AAAA,kBACAV,EAAa;AAAA,gBAAA;AAAA,gBAGd,YAAM,eAAe1B,CAAU,IAC5BhB,EAAM,aAAagB,GAAY;AAAA,kBAC7B,WAAWoC;AAAA,oBACTb;AAAA,oBACCvB,EAAW,OAAe;AAAA,kBAAA;AAAA,gBAC7B,CACmB,IACrBA;AAAA,cAAA;AAAA,YAAA;AAAA,UACN,GAEJ;AAAA,WAEEb,KAAeQ,KAAiB,OAAOD,KAAc,aACrD,gBAAAyC,EAAC,OAAA,EAAI,WAAU,kEACZ,UAAA;AAAA,YAAAhD,KACC,gBAAA+C;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAWE;AAAA,kBACT;AAAA,kBACAhD,IAAQ+B,IAAmB/B,CAAK,IAAI;AAAA,gBAAA;AAAA,gBAGrC,UAAAD;AAAA,cAAA;AAAA,YAAA;AAAA,YAGJQ,KAAiB,OAAOD,KAAc,YACrC,gBAAAyC,EAAC,QAAA,EAAK,WAAU,uCACb,UAAA;AAAA,cAAA9B;AAAA,cAAU;AAAA,cAAIX;AAAA,YAAA,EAAA,CACjB;AAAA,UAAA,EAAA,CAEJ;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,GAGN;AAAA,EAEJ;AACF;AAEAX,GAAM,cAAc;"}
|
|
@@ -9,9 +9,9 @@ const Z = Q.forwardRef(
|
|
|
9
9
|
defaultValue: _ = 0,
|
|
10
10
|
allowHalf: a = !1,
|
|
11
11
|
allowClear: k = !0,
|
|
12
|
-
size:
|
|
12
|
+
size: d = "middle",
|
|
13
13
|
color: b = "warning",
|
|
14
|
-
character:
|
|
14
|
+
character: i,
|
|
15
15
|
className: A,
|
|
16
16
|
style: E,
|
|
17
17
|
disabled: l = !1,
|
|
@@ -29,14 +29,14 @@ const Z = Q.forwardRef(
|
|
|
29
29
|
middle: 24,
|
|
30
30
|
large: 32
|
|
31
31
|
}, H = {
|
|
32
|
-
primary: "text-primary [&_svg]:fill-primary",
|
|
33
|
-
secondary: "text-secondary [&_svg]:fill-secondary",
|
|
34
|
-
accent: "text-accent [&_svg]:fill-accent",
|
|
35
|
-
destructive: "text-destructive [&_svg]:fill-destructive",
|
|
36
|
-
muted: "text-muted-foreground [&_svg]:fill-muted-foreground",
|
|
37
|
-
success: "text-success [&_svg]:fill-success",
|
|
38
|
-
error: "text-error [&_svg]:fill-error",
|
|
39
|
-
warning: "text-yellow-400 [&_svg]:fill-yellow-400"
|
|
32
|
+
primary: "ds:text-primary ds:[&_svg]:fill-primary",
|
|
33
|
+
secondary: "ds:text-secondary ds:[&_svg]:fill-secondary",
|
|
34
|
+
accent: "ds:text-accent ds:[&_svg]:fill-accent",
|
|
35
|
+
destructive: "ds:text-destructive ds:[&_svg]:fill-destructive",
|
|
36
|
+
muted: "ds:text-muted-foreground ds:[&_svg]:fill-muted-foreground",
|
|
37
|
+
success: "ds:text-success ds:[&_svg]:fill-success",
|
|
38
|
+
error: "ds:text-error ds:[&_svg]:fill-error",
|
|
39
|
+
warning: "ds:text-yellow-400 ds:[&_svg]:fill-yellow-400"
|
|
40
40
|
}, p = (e, s) => {
|
|
41
41
|
if (l) return;
|
|
42
42
|
const r = s ? e + 0.5 : e + 1;
|
|
@@ -82,15 +82,15 @@ const Z = Q.forwardRef(
|
|
|
82
82
|
if (!a) return !1;
|
|
83
83
|
const r = (o !== null ? o : n) - e;
|
|
84
84
|
return r > 0 && r <= 0.5;
|
|
85
|
-
}, g = (e = !1) => typeof
|
|
85
|
+
}, g = (e = !1) => typeof i == "function" ? i({
|
|
86
86
|
count: c,
|
|
87
87
|
value: n,
|
|
88
88
|
defaultValue: _,
|
|
89
89
|
allowHalf: a,
|
|
90
90
|
allowClear: k,
|
|
91
|
-
size:
|
|
91
|
+
size: d,
|
|
92
92
|
disabled: l
|
|
93
|
-
}) : e ? /* @__PURE__ */ t(X, { className: "ds:w-full ds:h-full" }) :
|
|
93
|
+
}) : e ? /* @__PURE__ */ t(X, { className: "ds:w-full ds:h-full" }) : i || /* @__PURE__ */ t(Y, { className: "ds:w-full ds:h-full" }), J = (e) => {
|
|
94
94
|
if (!(!f || !f[e]))
|
|
95
95
|
return f[e];
|
|
96
96
|
};
|
|
@@ -127,8 +127,8 @@ const Z = Q.forwardRef(
|
|
|
127
127
|
{
|
|
128
128
|
className: "ds:relative ds:inline-flex",
|
|
129
129
|
style: {
|
|
130
|
-
width: `${S[
|
|
131
|
-
height: `${S[
|
|
130
|
+
width: `${S[d]}px`,
|
|
131
|
+
height: `${S[d]}px`
|
|
132
132
|
},
|
|
133
133
|
children: [
|
|
134
134
|
/* @__PURE__ */ t("div", { className: "ds:text-muted-foreground/30 ds:pointer-events-none", children: g(!1) }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rate.js","sources":["../../../../src/components/Rate/Rate.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { useState, useRef } from \"react\";\nimport type { KeyboardEvent } from \"react\";\nimport { Star, StarHalf } from \"lucide-react\";\nimport { cn } from \"@dsui/ui/lib/utils\";\n\nexport interface RateProps {\n // Display\n count?: number;\n value?: number;\n defaultValue?: number;\n allowHalf?: boolean;\n allowClear?: boolean;\n\n // Appearance\n size?: \"small\" | \"middle\" | \"large\";\n color?:\n | \"primary\"\n | \"secondary\"\n | \"accent\"\n | \"destructive\"\n | \"muted\"\n | \"success\"\n | \"error\"\n | \"warning\";\n character?: React.ReactNode | ((rateProps: RateProps) => React.ReactNode);\n className?: string;\n style?: React.CSSProperties;\n\n // Interaction\n disabled?: boolean;\n autoFocus?: boolean;\n keyboard?: boolean;\n\n // Tooltips\n tooltips?: string[];\n\n // Callbacks\n onChange?: (value: number) => void;\n onHoverChange?: (value: number) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;\n}\n\nconst Rate = React.forwardRef<HTMLDivElement, RateProps>(\n (\n {\n count = 5,\n value: controlledValue,\n defaultValue = 0,\n allowHalf = false,\n allowClear = true,\n size = \"middle\",\n color = \"warning\",\n character,\n className,\n style,\n disabled = false,\n autoFocus = false,\n keyboard = true,\n tooltips,\n onChange,\n onHoverChange,\n onFocus,\n onBlur,\n onKeyDown,\n },\n ref\n ) => {\n const [internalValue, setInternalValue] = useState(defaultValue);\n const [hoverValue, setHoverValue] = useState<number | null>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n\n // Use controlled or uncontrolled value\n const value =\n controlledValue !== undefined ? controlledValue : internalValue;\n\n // Size in pixels\n const sizeMap = {\n small: 20,\n middle: 24,\n large: 32,\n };\n\n // Color mapping for filled stars\n const colorMap = {\n primary: \"text-primary [&_svg]:fill-primary\",\n secondary: \"text-secondary [&_svg]:fill-secondary\",\n accent: \"text-accent [&_svg]:fill-accent\",\n destructive: \"text-destructive [&_svg]:fill-destructive\",\n muted: \"text-muted-foreground [&_svg]:fill-muted-foreground\",\n success: \"text-success [&_svg]:fill-success\",\n error: \"text-error [&_svg]:fill-error\",\n warning: \"text-yellow-400 [&_svg]:fill-yellow-400\",\n };\n\n // Handle star click\n const handleStarClick = (starIndex: number, isHalf: boolean) => {\n if (disabled) return;\n\n const newValue = isHalf ? starIndex + 0.5 : starIndex + 1;\n\n // If clicking the same value and allowClear is true, clear the rating\n if (allowClear && newValue === value) {\n setInternalValue(0);\n onChange?.(0);\n } else {\n setInternalValue(newValue);\n onChange?.(newValue);\n }\n };\n\n // Handle star hover\n const handleStarHover = (starIndex: number, isHalf: boolean) => {\n if (disabled) return;\n\n const newHoverValue = isHalf ? starIndex + 0.5 : starIndex + 1;\n setHoverValue(newHoverValue);\n onHoverChange?.(newHoverValue);\n };\n\n // Handle mouse leave\n const handleMouseLeave = () => {\n setHoverValue(null);\n onHoverChange?.(0);\n };\n\n // Handle keyboard navigation\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!keyboard || disabled) return;\n\n onKeyDown?.(event);\n\n const step = allowHalf ? 0.5 : 1;\n let newValue = value;\n\n switch (event.key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n event.preventDefault();\n newValue = Math.min(value + step, count);\n break;\n case \"ArrowLeft\":\n case \"ArrowDown\":\n event.preventDefault();\n newValue = Math.max(value - step, 0);\n break;\n case \"Home\":\n event.preventDefault();\n newValue = allowHalf ? 0.5 : 1;\n break;\n case \"End\":\n event.preventDefault();\n newValue = count;\n break;\n default:\n return;\n }\n\n setInternalValue(newValue);\n onChange?.(newValue);\n };\n\n // Handle focus\n const handleFocus = () => {\n onFocus?.();\n };\n\n // Handle blur\n const handleBlur = () => {\n onBlur?.();\n };\n\n // Get star fill percentage\n const getStarFill = (starIndex: number) => {\n const currentValue = hoverValue !== null ? hoverValue : value;\n\n if (currentValue >= starIndex + 1) {\n return 100; // Full star\n } else if (currentValue > starIndex && currentValue < starIndex + 1) {\n return (currentValue - starIndex) * 100; // Partial star\n }\n return 0; // Empty star\n };\n\n // Check if star should show as half\n const isHalfStar = (starIndex: number) => {\n if (!allowHalf) return false;\n const currentValue = hoverValue !== null ? hoverValue : value;\n const fill = currentValue - starIndex;\n return fill > 0 && fill <= 0.5;\n };\n\n // Render character\n const renderCharacter = (isHalf: boolean = false) => {\n if (typeof character === \"function\") {\n return character({\n count,\n value,\n defaultValue,\n allowHalf,\n allowClear,\n size,\n disabled,\n });\n }\n if (isHalf) {\n return <StarHalf className=\"ds:w-full ds:h-full\" />;\n }\n return character || <Star className=\"ds:w-full ds:h-full\" />;\n };\n\n // Get tooltip for star\n const getTooltip = (starIndex: number) => {\n if (!tooltips || !tooltips[starIndex]) return undefined;\n return tooltips[starIndex];\n };\n\n return (\n <div\n ref={(node) => {\n containerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n className={cn(\n \"ds:inline-flex ds:items-center ds:gap-1\",\n disabled && \"ds:opacity-50 ds:cursor-not-allowed\",\n !disabled && \"ds:cursor-pointer\",\n className\n )}\n style={style}\n onMouseLeave={handleMouseLeave}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n tabIndex={disabled ? -1 : 0}\n role=\"slider\"\n aria-label=\"Rate\"\n aria-valuemin={0}\n aria-valuemax={count}\n aria-valuenow={value}\n aria-disabled={disabled}\n autoFocus={autoFocus}\n >\n {Array.from({ length: count }, (_, index) => {\n const fillPercentage = getStarFill(index);\n const tooltip = getTooltip(index);\n const showHalfStar = isHalfStar(index);\n\n return (\n <div key={index} className=\"ds:relative ds:group\" title={tooltip}>\n {/* Container for half stars */}\n <div\n className=\"ds:relative ds:inline-flex\"\n style={{\n width: `${sizeMap[size]}px`,\n height: `${sizeMap[size]}px`,\n }}\n >\n {/* Empty star background */}\n <div className=\"ds:text-muted-foreground/30 ds:pointer-events-none\">\n {renderCharacter(false)}\n </div>\n\n {/* Filled star overlay */}\n {fillPercentage > 0 && (\n <div\n className={cn(\n \"ds:absolute ds:inset-0 ds:pointer-events-none\",\n colorMap[color]\n )}\n >\n {showHalfStar ? (\n renderCharacter(true)\n ) : (\n <div\n className=\"ds:overflow-hidden\"\n style={{ width: `${fillPercentage}%` }}\n >\n {renderCharacter(false)}\n </div>\n )}\n </div>\n )}\n\n {/* Interactive overlay for clicking and hovering */}\n {!disabled && (\n <>\n {allowHalf ? (\n <>\n {/* Left half */}\n <div\n className=\"ds:absolute ds:inset-0 ds:w-1/2 ds:cursor-pointer\"\n onClick={() => handleStarClick(index, true)}\n onMouseEnter={() => handleStarHover(index, true)}\n />\n {/* Right half */}\n <div\n className=\"ds:absolute ds:inset-0 ds:left-1/2 ds:w-1/2 ds:cursor-pointer\"\n onClick={() => handleStarClick(index, false)}\n onMouseEnter={() => handleStarHover(index, false)}\n />\n </>\n ) : (\n <div\n className=\"ds:absolute ds:inset-0 ds:cursor-pointer\"\n onClick={() => handleStarClick(index, false)}\n onMouseEnter={() => handleStarHover(index, false)}\n />\n )}\n </>\n )}\n </div>\n\n {/* Show tooltip text below star on hover */}\n {tooltip &&\n (hoverValue === index + 1 ||\n (allowHalf && hoverValue === index + 0.5)) && (\n <div className=\"ds:absolute ds:top-full ds:left-1/2 ds:-translate-x-1/2 ds:mt-1 ds:px-2 ds:py-1 ds:text-xs ds:bg-foreground ds:text-background ds:rounded ds:whitespace-nowrap ds:z-10\">\n {tooltip}\n </div>\n )}\n </div>\n );\n })}\n </div>\n );\n }\n);\n\nRate.displayName = \"Rate\";\n\nexport default Rate;\n"],"names":["Rate","React","count","controlledValue","defaultValue","allowHalf","allowClear","size","color","character","className","style","disabled","autoFocus","keyboard","tooltips","onChange","onHoverChange","onFocus","onBlur","onKeyDown","ref","internalValue","setInternalValue","useState","hoverValue","setHoverValue","containerRef","useRef","value","sizeMap","colorMap","handleStarClick","starIndex","isHalf","newValue","handleStarHover","newHoverValue","handleMouseLeave","handleKeyDown","event","step","handleFocus","handleBlur","getStarFill","currentValue","isHalfStar","fill","renderCharacter","jsx","StarHalf","Star","getTooltip","node","cn","_","index","fillPercentage","tooltip","showHalfStar","jsxs","Fragment"],"mappings":";;;;AA8CA,MAAMA,IAAOC,EAAM;AAAA,EACjB,CACE;AAAA,IACE,OAAAC,IAAQ;AAAA,IACR,OAAOC;AAAA,IACP,cAAAC,IAAe;AAAA,IACf,WAAAC,IAAY;AAAA,IACZ,YAAAC,IAAa;AAAA,IACb,MAAAC,IAAO;AAAA,IACP,OAAAC,IAAQ;AAAA,IACR,WAAAC;AAAA,IACA,WAAAC;AAAA,IACA,OAAAC;AAAA,IACA,UAAAC,IAAW;AAAA,IACX,WAAAC,IAAY;AAAA,IACZ,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,eAAAC;AAAA,IACA,SAAAC;AAAA,IACA,QAAAC;AAAA,IACA,WAAAC;AAAA,EAAA,GAEFC,MACG;AACH,UAAM,CAACC,GAAeC,CAAgB,IAAIC,EAASpB,CAAY,GACzD,CAACqB,GAAYC,CAAa,IAAIF,EAAwB,IAAI,GAC1DG,IAAeC,EAAuB,IAAI,GAG1CC,IACJ1B,MAAoB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ML,CAAC7C,KACA,gBAAAqC,EAAAY,GAAA,EACG,UAAAxD,IACC,gBAAAuD,EAAAC,GAAA,EAEE,UAAA;AAAA,oBAAA,gBAAAZ;AAAA,sBAAC;AAAA,sBAAA;AAAA,wBACC,WAAU;AAAA,wBACV,SAAS,MAAMjB,EAAgBwB,GAAO,EAAI;AAAA,wBAC1C,cAAc,MAAMpB,EAAgBoB,GAAO,EAAI;AAAA,sBAAA;AAAA,oBAAA;AAAA,oBAGjD,gBAAAP;AAAA,sBAAC;AAAA,sBAAA;AAAA,wBACC,WAAU;AAAA,wBACV,SAAS,MAAMjB,EAAgBwB,GAAO,EAAK;AAAA,wBAC3C,cAAc,MAAMpB,EAAgBoB,GAAO,EAAK;AAAA,sBAAA;AAAA,oBAAA;AAAA,kBAClD,EAAA,CACF,IAEA,gBAAAP;AAAA,oBAAC;AAAA,oBAAA;AAAA,sBACC,WAAU;AAAA,sBACV,SAAS,MAAMjB,EAAgBwB,GAAO,EAAK;AAAA,sBAC3C,cAAc,MAAMpB,EAAgBoB,GAAO,EAAK;AAAA,oBAAA;AAAA,kBAAA,EAClD,CAEJ;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,YAKHE,MACEjC,MAAe+B,IAAQ,KACrBnD,KAAaoB,MAAe+B,IAAQ,QACrC,gBAAAP,EAAC,OAAA,EAAI,WAAU,0KACZ,UAAAS,EAAA,CACH;AAAA,UAAA,EAAA,GAtEIF,CAwEV;AAAA,QAEJ,CAAC;AAAA,MAAA;AAAA,IAAA;AAAA,EAGP;AACF;AAEAxD,EAAK,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Rate.js","sources":["../../../../src/components/Rate/Rate.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { useState, useRef } from \"react\";\nimport type { KeyboardEvent } from \"react\";\nimport { Star, StarHalf } from \"lucide-react\";\nimport { cn } from \"@dsui/ui/lib/utils\";\n\nexport interface RateProps {\n // Display\n count?: number;\n value?: number;\n defaultValue?: number;\n allowHalf?: boolean;\n allowClear?: boolean;\n\n // Appearance\n size?: \"small\" | \"middle\" | \"large\";\n color?:\n | \"primary\"\n | \"secondary\"\n | \"accent\"\n | \"destructive\"\n | \"muted\"\n | \"success\"\n | \"error\"\n | \"warning\";\n character?: React.ReactNode | ((rateProps: RateProps) => React.ReactNode);\n className?: string;\n style?: React.CSSProperties;\n\n // Interaction\n disabled?: boolean;\n autoFocus?: boolean;\n keyboard?: boolean;\n\n // Tooltips\n tooltips?: string[];\n\n // Callbacks\n onChange?: (value: number) => void;\n onHoverChange?: (value: number) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;\n}\n\nconst Rate = React.forwardRef<HTMLDivElement, RateProps>(\n (\n {\n count = 5,\n value: controlledValue,\n defaultValue = 0,\n allowHalf = false,\n allowClear = true,\n size = \"middle\",\n color = \"warning\",\n character,\n className,\n style,\n disabled = false,\n autoFocus = false,\n keyboard = true,\n tooltips,\n onChange,\n onHoverChange,\n onFocus,\n onBlur,\n onKeyDown,\n },\n ref\n ) => {\n const [internalValue, setInternalValue] = useState(defaultValue);\n const [hoverValue, setHoverValue] = useState<number | null>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n\n // Use controlled or uncontrolled value\n const value =\n controlledValue !== undefined ? controlledValue : internalValue;\n\n // Size in pixels\n const sizeMap = {\n small: 20,\n middle: 24,\n large: 32,\n };\n\n // Color mapping for filled stars\n const colorMap = {\n primary: \"ds:text-primary ds:[&_svg]:fill-primary\",\n secondary: \"ds:text-secondary ds:[&_svg]:fill-secondary\",\n accent: \"ds:text-accent ds:[&_svg]:fill-accent\",\n destructive: \"ds:text-destructive ds:[&_svg]:fill-destructive\",\n muted: \"ds:text-muted-foreground ds:[&_svg]:fill-muted-foreground\",\n success: \"ds:text-success ds:[&_svg]:fill-success\",\n error: \"ds:text-error ds:[&_svg]:fill-error\",\n warning: \"ds:text-yellow-400 ds:[&_svg]:fill-yellow-400\",\n };\n\n // Handle star click\n const handleStarClick = (starIndex: number, isHalf: boolean) => {\n if (disabled) return;\n\n const newValue = isHalf ? starIndex + 0.5 : starIndex + 1;\n\n // If clicking the same value and allowClear is true, clear the rating\n if (allowClear && newValue === value) {\n setInternalValue(0);\n onChange?.(0);\n } else {\n setInternalValue(newValue);\n onChange?.(newValue);\n }\n };\n\n // Handle star hover\n const handleStarHover = (starIndex: number, isHalf: boolean) => {\n if (disabled) return;\n\n const newHoverValue = isHalf ? starIndex + 0.5 : starIndex + 1;\n setHoverValue(newHoverValue);\n onHoverChange?.(newHoverValue);\n };\n\n // Handle mouse leave\n const handleMouseLeave = () => {\n setHoverValue(null);\n onHoverChange?.(0);\n };\n\n // Handle keyboard navigation\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!keyboard || disabled) return;\n\n onKeyDown?.(event);\n\n const step = allowHalf ? 0.5 : 1;\n let newValue = value;\n\n switch (event.key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n event.preventDefault();\n newValue = Math.min(value + step, count);\n break;\n case \"ArrowLeft\":\n case \"ArrowDown\":\n event.preventDefault();\n newValue = Math.max(value - step, 0);\n break;\n case \"Home\":\n event.preventDefault();\n newValue = allowHalf ? 0.5 : 1;\n break;\n case \"End\":\n event.preventDefault();\n newValue = count;\n break;\n default:\n return;\n }\n\n setInternalValue(newValue);\n onChange?.(newValue);\n };\n\n // Handle focus\n const handleFocus = () => {\n onFocus?.();\n };\n\n // Handle blur\n const handleBlur = () => {\n onBlur?.();\n };\n\n // Get star fill percentage\n const getStarFill = (starIndex: number) => {\n const currentValue = hoverValue !== null ? hoverValue : value;\n\n if (currentValue >= starIndex + 1) {\n return 100; // Full star\n } else if (currentValue > starIndex && currentValue < starIndex + 1) {\n return (currentValue - starIndex) * 100; // Partial star\n }\n return 0; // Empty star\n };\n\n // Check if star should show as half\n const isHalfStar = (starIndex: number) => {\n if (!allowHalf) return false;\n const currentValue = hoverValue !== null ? hoverValue : value;\n const fill = currentValue - starIndex;\n return fill > 0 && fill <= 0.5;\n };\n\n // Render character\n const renderCharacter = (isHalf: boolean = false) => {\n if (typeof character === \"function\") {\n return character({\n count,\n value,\n defaultValue,\n allowHalf,\n allowClear,\n size,\n disabled,\n });\n }\n if (isHalf) {\n return <StarHalf className=\"ds:w-full ds:h-full\" />;\n }\n return character || <Star className=\"ds:w-full ds:h-full\" />;\n };\n\n // Get tooltip for star\n const getTooltip = (starIndex: number) => {\n if (!tooltips || !tooltips[starIndex]) return undefined;\n return tooltips[starIndex];\n };\n\n return (\n <div\n ref={(node) => {\n containerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n }}\n className={cn(\n \"ds:inline-flex ds:items-center ds:gap-1\",\n disabled && \"ds:opacity-50 ds:cursor-not-allowed\",\n !disabled && \"ds:cursor-pointer\",\n className\n )}\n style={style}\n onMouseLeave={handleMouseLeave}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n tabIndex={disabled ? -1 : 0}\n role=\"slider\"\n aria-label=\"Rate\"\n aria-valuemin={0}\n aria-valuemax={count}\n aria-valuenow={value}\n aria-disabled={disabled}\n autoFocus={autoFocus}\n >\n {Array.from({ length: count }, (_, index) => {\n const fillPercentage = getStarFill(index);\n const tooltip = getTooltip(index);\n const showHalfStar = isHalfStar(index);\n\n return (\n <div key={index} className=\"ds:relative ds:group\" title={tooltip}>\n {/* Container for half stars */}\n <div\n className=\"ds:relative ds:inline-flex\"\n style={{\n width: `${sizeMap[size]}px`,\n height: `${sizeMap[size]}px`,\n }}\n >\n {/* Empty star background */}\n <div className=\"ds:text-muted-foreground/30 ds:pointer-events-none\">\n {renderCharacter(false)}\n </div>\n\n {/* Filled star overlay */}\n {fillPercentage > 0 && (\n <div\n className={cn(\n \"ds:absolute ds:inset-0 ds:pointer-events-none\",\n colorMap[color]\n )}\n >\n {showHalfStar ? (\n renderCharacter(true)\n ) : (\n <div\n className=\"ds:overflow-hidden\"\n style={{ width: `${fillPercentage}%` }}\n >\n {renderCharacter(false)}\n </div>\n )}\n </div>\n )}\n\n {/* Interactive overlay for clicking and hovering */}\n {!disabled && (\n <>\n {allowHalf ? (\n <>\n {/* Left half */}\n <div\n className=\"ds:absolute ds:inset-0 ds:w-1/2 ds:cursor-pointer\"\n onClick={() => handleStarClick(index, true)}\n onMouseEnter={() => handleStarHover(index, true)}\n />\n {/* Right half */}\n <div\n className=\"ds:absolute ds:inset-0 ds:left-1/2 ds:w-1/2 ds:cursor-pointer\"\n onClick={() => handleStarClick(index, false)}\n onMouseEnter={() => handleStarHover(index, false)}\n />\n </>\n ) : (\n <div\n className=\"ds:absolute ds:inset-0 ds:cursor-pointer\"\n onClick={() => handleStarClick(index, false)}\n onMouseEnter={() => handleStarHover(index, false)}\n />\n )}\n </>\n )}\n </div>\n\n {/* Show tooltip text below star on hover */}\n {tooltip &&\n (hoverValue === index + 1 ||\n (allowHalf && hoverValue === index + 0.5)) && (\n <div className=\"ds:absolute ds:top-full ds:left-1/2 ds:-translate-x-1/2 ds:mt-1 ds:px-2 ds:py-1 ds:text-xs ds:bg-foreground ds:text-background ds:rounded ds:whitespace-nowrap ds:z-10\">\n {tooltip}\n </div>\n )}\n </div>\n );\n })}\n </div>\n );\n }\n);\n\nRate.displayName = \"Rate\";\n\nexport default Rate;\n"],"names":["Rate","React","count","controlledValue","defaultValue","allowHalf","allowClear","size","color","character","className","style","disabled","autoFocus","keyboard","tooltips","onChange","onHoverChange","onFocus","onBlur","onKeyDown","ref","internalValue","setInternalValue","useState","hoverValue","setHoverValue","containerRef","useRef","value","sizeMap","colorMap","handleStarClick","starIndex","isHalf","newValue","handleStarHover","newHoverValue","handleMouseLeave","handleKeyDown","event","step","handleFocus","handleBlur","getStarFill","currentValue","isHalfStar","fill","renderCharacter","jsx","StarHalf","Star","getTooltip","node","cn","_","index","fillPercentage","tooltip","showHalfStar","jsxs","Fragment"],"mappings":";;;;AA8CA,MAAMA,IAAOC,EAAM;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