@sikka/hawa 0.26.30 → 0.26.32
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/{Toast-pOd4uGZz.d.ts → Toast-YaClwi7z.d.ts} +9 -1
- package/dist/{Toast-VBd4UvlM.d.mts → Toast-ySvjL_-K.d.mts} +9 -1
- package/dist/accordion/index.mjs +7 -4
- package/dist/accordion/index.mjs.map +1 -1
- package/dist/alert/index.js +4 -4
- package/dist/alert/index.js.map +1 -1
- package/dist/alert/index.mjs +11 -8
- package/dist/alert/index.mjs.map +1 -1
- package/dist/appLayout/index.js +2 -1
- package/dist/appLayout/index.js.map +1 -1
- package/dist/appLayout/index.mjs +9 -5
- package/dist/appLayout/index.mjs.map +1 -1
- package/dist/appMenubar/index.mjs +9 -4
- package/dist/appMenubar/index.mjs.map +1 -1
- package/dist/appTabs/index.mjs +9 -4
- package/dist/appTabs/index.mjs.map +1 -1
- package/dist/appTopbar/index.mjs +9 -4
- package/dist/appTopbar/index.mjs.map +1 -1
- package/dist/avatar/index.js +2 -1
- package/dist/avatar/index.js.map +1 -1
- package/dist/avatar/index.mjs +9 -5
- package/dist/avatar/index.mjs.map +1 -1
- package/dist/backToTop/index.js +6 -3
- package/dist/backToTop/index.js.map +1 -1
- package/dist/backToTop/index.mjs +13 -7
- package/dist/backToTop/index.mjs.map +1 -1
- package/dist/badge/index.js +4 -3
- package/dist/badge/index.js.map +1 -1
- package/dist/badge/index.mjs +13 -7
- package/dist/badge/index.mjs.map +1 -1
- package/dist/button/index.mjs +7 -4
- package/dist/button/index.mjs.map +1 -1
- package/dist/card/index.mjs +9 -4
- package/dist/card/index.mjs.map +1 -1
- package/dist/carousel/index.js +10 -10
- package/dist/carousel/index.js.map +1 -1
- package/dist/carousel/index.mjs +19 -14
- package/dist/carousel/index.mjs.map +1 -1
- package/dist/checkbox/index.mjs +9 -4
- package/dist/checkbox/index.mjs.map +1 -1
- package/dist/chip/index.mjs +9 -4
- package/dist/chip/index.mjs.map +1 -1
- package/dist/chunk-A3ERTYS4.mjs +29 -0
- package/dist/codeBlock/index.mjs +83 -23
- package/dist/codeBlock/index.mjs.map +1 -1
- package/dist/collapsible/index.mjs +0 -2
- package/dist/collapsible/index.mjs.map +1 -1
- package/dist/colorPicker/index.js +2 -1
- package/dist/colorPicker/index.js.map +1 -1
- package/dist/colorPicker/index.mjs +92 -20
- package/dist/colorPicker/index.mjs.map +1 -1
- package/dist/combobox/index.js +4 -3
- package/dist/combobox/index.js.map +1 -1
- package/dist/combobox/index.mjs +445 -27
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/command/index.mjs +429 -11
- package/dist/command/index.mjs.map +1 -1
- package/dist/dataTable/index.js +36 -27
- package/dist/dataTable/index.js.map +1 -1
- package/dist/dataTable/index.mjs +43 -31
- package/dist/dataTable/index.mjs.map +1 -1
- package/dist/destroyableCard/index.js +2 -2
- package/dist/destroyableCard/index.js.map +1 -1
- package/dist/destroyableCard/index.mjs +9 -6
- package/dist/destroyableCard/index.mjs.map +1 -1
- package/dist/dialog/index.mjs +9 -4
- package/dist/dialog/index.mjs.map +1 -1
- package/dist/docsLayout/index.js +2 -2
- package/dist/docsLayout/index.js.map +1 -1
- package/dist/docsLayout/index.mjs +9 -6
- package/dist/docsLayout/index.mjs.map +1 -1
- package/dist/docsSidebar/index.js +2 -2
- package/dist/docsSidebar/index.js.map +1 -1
- package/dist/docsSidebar/index.mjs +11 -6
- package/dist/docsSidebar/index.mjs.map +1 -1
- package/dist/dropdownMenu/index.mjs +9 -4
- package/dist/dropdownMenu/index.mjs.map +1 -1
- package/dist/elements/index.d.mts +4 -2
- package/dist/elements/index.d.ts +4 -2
- package/dist/elements/index.js +7 -134
- package/dist/elements/index.mjs +9 -13
- package/dist/fileDropzone/index.js +12 -11
- package/dist/fileDropzone/index.js.map +1 -1
- package/dist/fileDropzone/index.mjs +21 -17
- package/dist/fileDropzone/index.mjs.map +1 -1
- package/dist/fileUploader/index.js +2 -1
- package/dist/fileUploader/index.js.map +1 -1
- package/dist/fileUploader/index.mjs +2 -1
- package/dist/fileUploader/index.mjs.map +1 -1
- package/dist/glow/index.js +24 -17
- package/dist/glow/index.js.map +1 -1
- package/dist/glow/index.mjs +24 -17
- package/dist/glow/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +9 -18
- package/dist/hooks/index.d.ts +9 -18
- package/dist/hooks/index.mjs +146 -27
- package/dist/index.d.mts +18 -17
- package/dist/index.d.ts +18 -17
- package/dist/index.js +166 -171
- package/dist/index.mjs +588 -593
- package/dist/input/index.js +3 -2
- package/dist/input/index.js.map +1 -1
- package/dist/input/index.mjs +118 -19
- package/dist/input/index.mjs.map +1 -1
- package/dist/interfaceSettings/index.js +6 -4
- package/dist/interfaceSettings/index.js.map +1 -1
- package/dist/interfaceSettings/index.mjs +130 -28
- package/dist/interfaceSettings/index.mjs.map +1 -1
- package/dist/label/index.mjs +7 -4
- package/dist/label/index.mjs.map +1 -1
- package/dist/loading/index.mjs +9 -4
- package/dist/loading/index.mjs.map +1 -1
- package/dist/navbar/index.js +3 -2
- package/dist/navbar/index.js.map +1 -1
- package/dist/navbar/index.mjs +10 -6
- package/dist/navbar/index.mjs.map +1 -1
- package/dist/navigationMenu/index.mjs +9 -4
- package/dist/navigationMenu/index.mjs.map +1 -1
- package/dist/pagination/index.mjs +9 -4
- package/dist/pagination/index.mjs.map +1 -1
- package/dist/passwordInput/index.js +3 -2
- package/dist/passwordInput/index.js.map +1 -1
- package/dist/passwordInput/index.mjs +12 -6
- package/dist/passwordInput/index.mjs.map +1 -1
- package/dist/phoneInput/index.js +10 -5
- package/dist/phoneInput/index.js.map +1 -1
- package/dist/phoneInput/index.mjs +19 -11
- package/dist/phoneInput/index.mjs.map +1 -1
- package/dist/pinInput/index.js +3 -3
- package/dist/pinInput/index.js.map +1 -1
- package/dist/pinInput/index.mjs +12 -7
- package/dist/pinInput/index.mjs.map +1 -1
- package/dist/popover/index.mjs +9 -4
- package/dist/popover/index.mjs.map +1 -1
- package/dist/progress/index.mjs +9 -4
- package/dist/progress/index.mjs.map +1 -1
- package/dist/progressCircle/index.js +2 -2
- package/dist/progressCircle/index.js.map +1 -1
- package/dist/progressCircle/index.mjs +11 -6
- package/dist/progressCircle/index.mjs.map +1 -1
- package/dist/radio/index.js +6 -4
- package/dist/radio/index.js.map +1 -1
- package/dist/radio/index.mjs +13 -8
- package/dist/radio/index.mjs.map +1 -1
- package/dist/scrollArea/index.mjs +9 -4
- package/dist/scrollArea/index.mjs.map +1 -1
- package/dist/scrollIndicator/index.js +2 -1
- package/dist/scrollIndicator/index.js.map +1 -1
- package/dist/scrollIndicator/index.mjs +2 -1
- package/dist/scrollIndicator/index.mjs.map +1 -1
- package/dist/select/index.js +6 -2
- package/dist/select/index.js.map +1 -1
- package/dist/select/index.mjs +15 -8
- package/dist/select/index.mjs.map +1 -1
- package/dist/separator/index.mjs +9 -4
- package/dist/separator/index.mjs.map +1 -1
- package/dist/sheet/index.mjs +9 -4
- package/dist/sheet/index.mjs.map +1 -1
- package/dist/sidebar/index.mjs +9 -4
- package/dist/sidebar/index.mjs.map +1 -1
- package/dist/signature/index.js +31 -11
- package/dist/signature/index.js.map +1 -1
- package/dist/signature/index.mjs +40 -15
- package/dist/signature/index.mjs.map +1 -1
- package/dist/simpleTable/index.js +18 -14
- package/dist/simpleTable/index.js.map +1 -1
- package/dist/simpleTable/index.mjs +25 -18
- package/dist/simpleTable/index.mjs.map +1 -1
- package/dist/skeleton/index.mjs +9 -4
- package/dist/skeleton/index.mjs.map +1 -1
- package/dist/slider/index.mjs +9 -4
- package/dist/slider/index.mjs.map +1 -1
- package/dist/sortButton/index.mjs +268 -11
- package/dist/sortButton/index.mjs.map +1 -1
- package/dist/splitButton/index.mjs +267 -12
- package/dist/splitButton/index.mjs.map +1 -1
- package/dist/switch/index.js +2 -1
- package/dist/switch/index.js.map +1 -1
- package/dist/switch/index.mjs +11 -5
- package/dist/switch/index.mjs.map +1 -1
- package/dist/table/index.mjs +9 -4
- package/dist/table/index.mjs.map +1 -1
- package/dist/tabs/index.mjs +7 -4
- package/dist/tabs/index.mjs.map +1 -1
- package/dist/textarea/index.js +4 -4
- package/dist/textarea/index.js.map +1 -1
- package/dist/textarea/index.mjs +11 -8
- package/dist/textarea/index.mjs.map +1 -1
- package/dist/toast/index.d.mts +9 -1
- package/dist/toast/index.d.ts +9 -1
- package/dist/toast/index.js +3 -3
- package/dist/toast/index.js.map +1 -1
- package/dist/toast/index.mjs +145 -10
- package/dist/toast/index.mjs.map +1 -1
- package/dist/toaster/index.d.mts +5 -0
- package/dist/toaster/index.d.ts +5 -0
- package/dist/toaster/index.js +17 -142
- package/dist/toaster/index.js.map +1 -1
- package/dist/toaster/index.mjs +142 -135
- package/dist/toaster/index.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-3ODWQVIA.mjs +0 -12
- package/dist/chunk-3ODWQVIA.mjs.map +0 -1
- package/dist/chunk-53OZVR57.mjs +0 -108
- package/dist/chunk-53OZVR57.mjs.map +0 -1
- package/dist/chunk-CBRGWUZG.mjs +0 -11
- package/dist/chunk-CBRGWUZG.mjs.map +0 -1
- package/dist/chunk-HYXZRCZW.mjs +0 -265
- package/dist/chunk-HYXZRCZW.mjs.map +0 -1
- package/dist/chunk-JNUGOUYJ.mjs +0 -154
- package/dist/chunk-JX5YLRCU.mjs +0 -443
- package/dist/chunk-JX5YLRCU.mjs.map +0 -1
- package/dist/chunk-NV3KR5Y7.mjs +0 -82
- package/dist/chunk-NV3KR5Y7.mjs.map +0 -1
- package/dist/chunk-OQ7MNEYW.mjs +0 -151
- package/dist/chunk-OQ7MNEYW.mjs.map +0 -1
package/dist/pinInput/index.js
CHANGED
@@ -60,7 +60,7 @@ var PinInput = ({
|
|
60
60
|
if (e.key === "Backspace") {
|
61
61
|
e.target.value.length === 0 ? backTo = index - 1 : backTo = index;
|
62
62
|
const previousInput = document.getElementById(`input-${backTo}`);
|
63
|
-
previousInput
|
63
|
+
previousInput == null ? void 0 : previousInput.focus();
|
64
64
|
}
|
65
65
|
};
|
66
66
|
(0, import_react.useEffect)(() => {
|
@@ -81,10 +81,10 @@ var PinInput = ({
|
|
81
81
|
setPin(newPin);
|
82
82
|
if (e.target.value.length === 1) {
|
83
83
|
const nextInput = document.getElementById(`input-${index + 1}`);
|
84
|
-
nextInput
|
84
|
+
nextInput == null ? void 0 : nextInput.focus();
|
85
85
|
} else if (e.target.value.length === 0) {
|
86
86
|
const previousInput = document.getElementById(`input-${index - 1}`);
|
87
|
-
previousInput
|
87
|
+
previousInput == null ? void 0 : previousInput.focus();
|
88
88
|
}
|
89
89
|
}
|
90
90
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../elements/pinInput/index.ts","../../elements/pinInput/PinInput.tsx","../../util/index.ts"],"sourcesContent":["export * from \"./PinInput\";\n","import React, { useEffect, useState, FC } from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype PinInputTypes = {\n /** Label text to display for the Pin Input */\n label?: string;\n /** Icon element to be displayed next to the Pin Input */\n icon?: JSX.Element;\n /** Number of digits in the Pin Input */\n digits: number;\n /** Width of the Pin Input - either 'normal' or 'full' */\n width?: \"normal\" | \"full\";\n /** Function to get the value of pins */\n getPins?: (pins: string[]) => void;\n /** The small red text under the input field to show validation or a hint. */\n helperText?: any;\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport const PinInput: FC<PinInputTypes> = ({\n label,\n icon,\n digits,\n width = \"normal\",\n getPins,\n inputProps,\n ...props\n}) => {\n const [pin, setPin] = useState(Array.from(Array(digits)));\n\n const handleKeyDown = (e: any, index: any) => {\n let backTo = 0;\n if (e.key === \"Backspace\") {\n e.target.value.length === 0 ? (backTo = index - 1) : (backTo = index);\n const previousInput = document.getElementById(`input-${backTo}`);\n previousInput?.focus();\n }\n };\n useEffect(() => {\n let unfilled = pin.includes(undefined);\n if (!unfilled && getPins) {\n getPins(pin);\n }\n });\n const handleChange = (e: any, index: any) => {\n if (!/^\\d*$/.test(e.target.value)) {\n const newPin = [...pin];\n newPin[index] = \"\";\n setPin(newPin);\n return;\n } else {\n const newPin = [...pin];\n newPin[index] = e.target.value;\n setPin(newPin);\n\n if (e.target.value.length === 1) {\n const nextInput = document.getElementById(`input-${index + 1}`);\n nextInput?.focus();\n } else if (e.target.value.length === 0) {\n const previousInput = document.getElementById(`input-${index - 1}`);\n previousInput?.focus();\n }\n }\n };\n\n return (\n <div className=\"hawa-flex hawa-flex-col hawa-gap-2\">\n <div\n className=\"hawa-flex hawa-w-full hawa-flex-row hawa-justify-center hawa-gap-2\"\n dir=\"ltr\"\n >\n {pin.map((value, index) => (\n <input\n key={index}\n type=\"text\"\n maxLength={1}\n value={value}\n inputMode=\"numeric\"\n id={`input-${index}`}\n pattern=\"[0-9]*\"\n className={cn(\n \"hawa-h-10 hawa-rounded hawa-border hawa-bg-background hawa-text-center\",\n width === \"full\" ? \"hawa-w-full\" : \"hawa-w-10\"\n )}\n onChange={(e) => handleChange(e, index)}\n onKeyDown={(e) => handleKeyDown(e, index)}\n onFocus={(e) => e.target.select()}\n {...inputProps}\n />\n ))}\n </div>\n\n <p\n className={cn(\n \"hawa-my-0 hawa-text-start hawa-text-xs hawa-text-helper-color hawa-transition-all\",\n props.helperText\n ? \"hawa-h-4 hawa-opacity-100\"\n : \"hawa-h-0 hawa-opacity-0\"\n )}\n >\n {props.helperText}\n </p>\n </div>\n );\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n// return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA+C;;;ACA/C,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;;;ADeO,IAAM,WAA8B,CAAC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,CAAC,KAAK,MAAM,QAAI,uBAAS,MAAM,KAAK,MAAM,MAAM,CAAC,CAAC;AAExD,QAAM,gBAAgB,CAAC,GAAQ,UAAe;AAC5C,QAAI,SAAS;AACb,QAAI,EAAE,QAAQ,aAAa;AACzB,QAAE,OAAO,MAAM,WAAW,IAAK,SAAS,QAAQ,IAAM,SAAS;AAC/D,YAAM,gBAAgB,SAAS,eAAe,SAAS,MAAM,EAAE;AAC/D,
|
1
|
+
{"version":3,"sources":["../../elements/pinInput/index.ts","../../elements/pinInput/PinInput.tsx","../../util/index.ts"],"sourcesContent":["export * from \"./PinInput\";\n","import React, { useEffect, useState, FC } from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype PinInputTypes = {\n /** Label text to display for the Pin Input */\n label?: string;\n /** Icon element to be displayed next to the Pin Input */\n icon?: JSX.Element;\n /** Number of digits in the Pin Input */\n digits: number;\n /** Width of the Pin Input - either 'normal' or 'full' */\n width?: \"normal\" | \"full\";\n /** Function to get the value of pins */\n getPins?: (pins: string[]) => void;\n /** The small red text under the input field to show validation or a hint. */\n helperText?: any;\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport const PinInput: FC<PinInputTypes> = ({\n label,\n icon,\n digits,\n width = \"normal\",\n getPins,\n inputProps,\n ...props\n}) => {\n const [pin, setPin] = useState(Array.from(Array(digits)));\n\n const handleKeyDown = (e: any, index: any) => {\n let backTo = 0;\n if (e.key === \"Backspace\") {\n e.target.value.length === 0 ? (backTo = index - 1) : (backTo = index);\n const previousInput = document.getElementById(`input-${backTo}`);\n previousInput?.focus();\n }\n };\n useEffect(() => {\n let unfilled = pin.includes(undefined);\n if (!unfilled && getPins) {\n getPins(pin);\n }\n });\n const handleChange = (e: any, index: any) => {\n if (!/^\\d*$/.test(e.target.value)) {\n const newPin = [...pin];\n newPin[index] = \"\";\n setPin(newPin);\n return;\n } else {\n const newPin = [...pin];\n newPin[index] = e.target.value;\n setPin(newPin);\n\n if (e.target.value.length === 1) {\n const nextInput = document.getElementById(`input-${index + 1}`);\n nextInput?.focus();\n } else if (e.target.value.length === 0) {\n const previousInput = document.getElementById(`input-${index - 1}`);\n previousInput?.focus();\n }\n }\n };\n\n return (\n <div className=\"hawa-flex hawa-flex-col hawa-gap-2\">\n <div\n className=\"hawa-flex hawa-w-full hawa-flex-row hawa-justify-center hawa-gap-2\"\n dir=\"ltr\"\n >\n {pin.map((value, index) => (\n <input\n key={index}\n type=\"text\"\n maxLength={1}\n value={value}\n inputMode=\"numeric\"\n id={`input-${index}`}\n pattern=\"[0-9]*\"\n className={cn(\n \"hawa-h-10 hawa-rounded hawa-border hawa-bg-background hawa-text-center\",\n width === \"full\" ? \"hawa-w-full\" : \"hawa-w-10\"\n )}\n onChange={(e) => handleChange(e, index)}\n onKeyDown={(e) => handleKeyDown(e, index)}\n onFocus={(e) => e.target.select()}\n {...inputProps}\n />\n ))}\n </div>\n\n <p\n className={cn(\n \"hawa-my-0 hawa-text-start hawa-text-xs hawa-text-helper-color hawa-transition-all\",\n props.helperText\n ? \"hawa-h-4 hawa-opacity-100\"\n : \"hawa-h-0 hawa-opacity-0\"\n )}\n >\n {props.helperText}\n </p>\n </div>\n );\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n// return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA+C;;;ACA/C,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;;;ADeO,IAAM,WAA8B,CAAC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,CAAC,KAAK,MAAM,QAAI,uBAAS,MAAM,KAAK,MAAM,MAAM,CAAC,CAAC;AAExD,QAAM,gBAAgB,CAAC,GAAQ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AAAA,UACA,UAAU,SAAS,gBAAgB;AAAA,QACrC;AAAA,QACA,UAAU,CAAC,MAAM,aAAa,GAAG,KAAK;AAAA,QACtC,WAAW,CAAC,MAAM,cAAc,GAAG,KAAK;AAAA,QACxC,SAAS,CAAC,MAAM,EAAE,OAAO,OAAO;AAAA,QAC/B,GAAG;AAAA;AAAA,IACN,CACD;AAAA,EACH,GAEA,6BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA,MAAM,aACF,8BACA;AAAA,MACN;AAAA;AAAA,IAEC,MAAM;AAAA,EACT,CACF;AAEJ;","names":["React"]}
|
package/dist/pinInput/index.mjs
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
cn
|
3
|
-
} from "../chunk-CBRGWUZG.mjs";
|
4
|
-
|
5
1
|
// elements/pinInput/PinInput.tsx
|
6
2
|
import React, { useEffect, useState } from "react";
|
3
|
+
|
4
|
+
// util/index.ts
|
5
|
+
import { clsx } from "clsx";
|
6
|
+
import { twMerge } from "tailwind-merge";
|
7
|
+
function cn(...inputs) {
|
8
|
+
return twMerge(clsx(inputs));
|
9
|
+
}
|
10
|
+
|
11
|
+
// elements/pinInput/PinInput.tsx
|
7
12
|
var PinInput = ({
|
8
13
|
label,
|
9
14
|
icon,
|
@@ -19,7 +24,7 @@ var PinInput = ({
|
|
19
24
|
if (e.key === "Backspace") {
|
20
25
|
e.target.value.length === 0 ? backTo = index - 1 : backTo = index;
|
21
26
|
const previousInput = document.getElementById(`input-${backTo}`);
|
22
|
-
previousInput
|
27
|
+
previousInput == null ? void 0 : previousInput.focus();
|
23
28
|
}
|
24
29
|
};
|
25
30
|
useEffect(() => {
|
@@ -40,10 +45,10 @@ var PinInput = ({
|
|
40
45
|
setPin(newPin);
|
41
46
|
if (e.target.value.length === 1) {
|
42
47
|
const nextInput = document.getElementById(`input-${index + 1}`);
|
43
|
-
nextInput
|
48
|
+
nextInput == null ? void 0 : nextInput.focus();
|
44
49
|
} else if (e.target.value.length === 0) {
|
45
50
|
const previousInput = document.getElementById(`input-${index - 1}`);
|
46
|
-
previousInput
|
51
|
+
previousInput == null ? void 0 : previousInput.focus();
|
47
52
|
}
|
48
53
|
}
|
49
54
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../elements/pinInput/PinInput.tsx"],"sourcesContent":["import React, { useEffect, useState, FC } from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype PinInputTypes = {\n /** Label text to display for the Pin Input */\n label?: string;\n /** Icon element to be displayed next to the Pin Input */\n icon?: JSX.Element;\n /** Number of digits in the Pin Input */\n digits: number;\n /** Width of the Pin Input - either 'normal' or 'full' */\n width?: \"normal\" | \"full\";\n /** Function to get the value of pins */\n getPins?: (pins: string[]) => void;\n /** The small red text under the input field to show validation or a hint. */\n helperText?: any;\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport const PinInput: FC<PinInputTypes> = ({\n label,\n icon,\n digits,\n width = \"normal\",\n getPins,\n inputProps,\n ...props\n}) => {\n const [pin, setPin] = useState(Array.from(Array(digits)));\n\n const handleKeyDown = (e: any, index: any) => {\n let backTo = 0;\n if (e.key === \"Backspace\") {\n e.target.value.length === 0 ? (backTo = index - 1) : (backTo = index);\n const previousInput = document.getElementById(`input-${backTo}`);\n previousInput?.focus();\n }\n };\n useEffect(() => {\n let unfilled = pin.includes(undefined);\n if (!unfilled && getPins) {\n getPins(pin);\n }\n });\n const handleChange = (e: any, index: any) => {\n if (!/^\\d*$/.test(e.target.value)) {\n const newPin = [...pin];\n newPin[index] = \"\";\n setPin(newPin);\n return;\n } else {\n const newPin = [...pin];\n newPin[index] = e.target.value;\n setPin(newPin);\n\n if (e.target.value.length === 1) {\n const nextInput = document.getElementById(`input-${index + 1}`);\n nextInput?.focus();\n } else if (e.target.value.length === 0) {\n const previousInput = document.getElementById(`input-${index - 1}`);\n previousInput?.focus();\n }\n }\n };\n\n return (\n <div className=\"hawa-flex hawa-flex-col hawa-gap-2\">\n <div\n className=\"hawa-flex hawa-w-full hawa-flex-row hawa-justify-center hawa-gap-2\"\n dir=\"ltr\"\n >\n {pin.map((value, index) => (\n <input\n key={index}\n type=\"text\"\n maxLength={1}\n value={value}\n inputMode=\"numeric\"\n id={`input-${index}`}\n pattern=\"[0-9]*\"\n className={cn(\n \"hawa-h-10 hawa-rounded hawa-border hawa-bg-background hawa-text-center\",\n width === \"full\" ? \"hawa-w-full\" : \"hawa-w-10\"\n )}\n onChange={(e) => handleChange(e, index)}\n onKeyDown={(e) => handleKeyDown(e, index)}\n onFocus={(e) => e.target.select()}\n {...inputProps}\n />\n ))}\n </div>\n\n <p\n className={cn(\n \"hawa-my-0 hawa-text-start hawa-text-xs hawa-text-helper-color hawa-transition-all\",\n props.helperText\n ? \"hawa-h-4 hawa-opacity-100\"\n : \"hawa-h-0 hawa-opacity-0\"\n )}\n >\n {props.helperText}\n </p>\n </div>\n );\n};\n"],"mappings":"
|
1
|
+
{"version":3,"sources":["../../elements/pinInput/PinInput.tsx","../../util/index.ts"],"sourcesContent":["import React, { useEffect, useState, FC } from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype PinInputTypes = {\n /** Label text to display for the Pin Input */\n label?: string;\n /** Icon element to be displayed next to the Pin Input */\n icon?: JSX.Element;\n /** Number of digits in the Pin Input */\n digits: number;\n /** Width of the Pin Input - either 'normal' or 'full' */\n width?: \"normal\" | \"full\";\n /** Function to get the value of pins */\n getPins?: (pins: string[]) => void;\n /** The small red text under the input field to show validation or a hint. */\n helperText?: any;\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport const PinInput: FC<PinInputTypes> = ({\n label,\n icon,\n digits,\n width = \"normal\",\n getPins,\n inputProps,\n ...props\n}) => {\n const [pin, setPin] = useState(Array.from(Array(digits)));\n\n const handleKeyDown = (e: any, index: any) => {\n let backTo = 0;\n if (e.key === \"Backspace\") {\n e.target.value.length === 0 ? (backTo = index - 1) : (backTo = index);\n const previousInput = document.getElementById(`input-${backTo}`);\n previousInput?.focus();\n }\n };\n useEffect(() => {\n let unfilled = pin.includes(undefined);\n if (!unfilled && getPins) {\n getPins(pin);\n }\n });\n const handleChange = (e: any, index: any) => {\n if (!/^\\d*$/.test(e.target.value)) {\n const newPin = [...pin];\n newPin[index] = \"\";\n setPin(newPin);\n return;\n } else {\n const newPin = [...pin];\n newPin[index] = e.target.value;\n setPin(newPin);\n\n if (e.target.value.length === 1) {\n const nextInput = document.getElementById(`input-${index + 1}`);\n nextInput?.focus();\n } else if (e.target.value.length === 0) {\n const previousInput = document.getElementById(`input-${index - 1}`);\n previousInput?.focus();\n }\n }\n };\n\n return (\n <div className=\"hawa-flex hawa-flex-col hawa-gap-2\">\n <div\n className=\"hawa-flex hawa-w-full hawa-flex-row hawa-justify-center hawa-gap-2\"\n dir=\"ltr\"\n >\n {pin.map((value, index) => (\n <input\n key={index}\n type=\"text\"\n maxLength={1}\n value={value}\n inputMode=\"numeric\"\n id={`input-${index}`}\n pattern=\"[0-9]*\"\n className={cn(\n \"hawa-h-10 hawa-rounded hawa-border hawa-bg-background hawa-text-center\",\n width === \"full\" ? \"hawa-w-full\" : \"hawa-w-10\"\n )}\n onChange={(e) => handleChange(e, index)}\n onKeyDown={(e) => handleKeyDown(e, index)}\n onFocus={(e) => e.target.select()}\n {...inputProps}\n />\n ))}\n </div>\n\n <p\n className={cn(\n \"hawa-my-0 hawa-text-start hawa-text-xs hawa-text-helper-color hawa-transition-all\",\n props.helperText\n ? \"hawa-h-4 hawa-opacity-100\"\n : \"hawa-h-0 hawa-opacity-0\"\n )}\n >\n {props.helperText}\n </p>\n </div>\n );\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n// return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";AAAA,OAAO,SAAS,WAAW,gBAAoB;;;ACA/C,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ADeO,IAAM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,OAAO,UACf;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,MAAK;AAAA,QACL,WAAW;AAAA,QACX;AAAA,QACA,WAAU;AAAA,QACV,IAAI,SAAS,KAAK;AAAA,QAClB,SAAQ;AAAA,QACR,WAAW;AAAA,UACT;AAAA,UACA,UAAU,SAAS,gBAAgB;AAAA,QACrC;AAAA,QACA,UAAU,CAAC,MAAM,aAAa,GAAG,KAAK;AAAA,QACtC,WAAW,CAAC,MAAM,cAAc,GAAG,KAAK;AAAA,QACxC,SAAS,CAAC,MAAM,EAAE,OAAO,OAAO;AAAA,QAC/B,GAAG;AAAA;AAAA,IACN,CACD;AAAA,EACH,GAEA;AAAA,IAAC;AAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA,MAAM,aACF,8BACA;AAAA,MACN;AAAA;AAAA,IAEC,MAAM;AAAA,EACT,CACF;AAEJ;","names":[]}
|
package/dist/popover/index.mjs
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
cn
|
3
|
-
} from "../chunk-CBRGWUZG.mjs";
|
4
|
-
|
5
1
|
// elements/popover/Popover.tsx
|
6
2
|
import * as React from "react";
|
7
3
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
4
|
+
|
5
|
+
// util/index.ts
|
6
|
+
import { clsx } from "clsx";
|
7
|
+
import { twMerge } from "tailwind-merge";
|
8
|
+
function cn(...inputs) {
|
9
|
+
return twMerge(clsx(inputs));
|
10
|
+
}
|
11
|
+
|
12
|
+
// elements/popover/Popover.tsx
|
8
13
|
var PopoverContent = React.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ React.createElement(PopoverPrimitive.Portal, null, /* @__PURE__ */ React.createElement(
|
9
14
|
PopoverPrimitive.Content,
|
10
15
|
{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../elements/popover/Popover.tsx"],"sourcesContent":["import * as React from \"react\";\n\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\n\nimport { PositionType } from \"@_types/commonTypes\";\n\nimport { cn } from \"@util/index\";\n\nconst PopoverContent = React.forwardRef<\n React.ElementRef<typeof PopoverPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>\n>(({ className, align = \"center\", sideOffset = 4, ...props }, ref) => (\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n ref={ref}\n align={align}\n sideOffset={sideOffset}\n className={cn(\n \"dark:dark-shadow hawa-z-50 hawa-rounded hawa-border hawa-bg-popover hawa-text-popover-foreground hawa-shadow-md hawa-outline-none data-[state=open]:hawa-animate-in data-[state=closed]:hawa-animate-out data-[state=closed]:hawa-fade-out-0 data-[state=open]:hawa-fade-in-0 data-[state=closed]:hawa-zoom-out-95 data-[state=open]:hawa-zoom-in-95 data-[side=bottom]:hawa-slide-in-from-top-2 data-[side=left]:hawa-slide-in-from-right-2 data-[side=right]:hawa-slide-in-from-left-2 data-[side=top]:hawa-slide-in-from-bottom-2\",\n className\n )}\n {...props}\n />\n </PopoverPrimitive.Portal>\n));\nPopoverContent.displayName = PopoverPrimitive.Content.displayName;\n\ninterface PopoverProps {\n side?: PositionType;\n align?: \"start\" | \"center\" | \"end\";\n trigger?: React.ReactNode;\n children: React.ReactNode;\n className?: string;\n sideOffset?: number;\n disableTrigger?: any;\n width?: \"trigger\" | \"default\";\n open?: boolean;\n contentProps?: PopoverPrimitive.PopoverContentProps;\n triggerProps?: PopoverPrimitive.PopoverTriggerProps;\n}\n\ntype HawaPopoverTypes = PopoverProps &\n React.ComponentProps<typeof PopoverPrimitive.Root>;\n\nconst Popover: React.FC<HawaPopoverTypes> = ({\n trigger,\n children,\n className,\n align = \"center\",\n side,\n sideOffset = 4,\n open,\n width = \"default\",\n disableTrigger,\n contentProps,\n triggerProps,\n ...props\n}) => {\n let widthStyles = {\n trigger: \"var(--radix-popover-trigger-width)\",\n default: \"auto\"\n };\n\n return (\n <PopoverPrimitive.Root open={open} {...props}>\n <PopoverPrimitive.Trigger\n className=\"hawa-w-full\"\n disabled={disableTrigger}\n {...triggerProps}\n >\n {trigger}\n </PopoverPrimitive.Trigger>\n <PopoverContent\n side={side}\n className={className}\n align={align}\n sideOffset={sideOffset}\n style={{\n width: widthStyles[width]\n }}\n {...contentProps}\n >\n {children}\n </PopoverContent>\n </PopoverPrimitive.Root>\n );\n};\n\nconst PopoverTrigger = PopoverPrimitive.Trigger;\nexport { Popover, PopoverContent, PopoverTrigger };\n"],"mappings":"
|
1
|
+
{"version":3,"sources":["../../elements/popover/Popover.tsx","../../util/index.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\n\nimport { PositionType } from \"@_types/commonTypes\";\n\nimport { cn } from \"@util/index\";\n\nconst PopoverContent = React.forwardRef<\n React.ElementRef<typeof PopoverPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>\n>(({ className, align = \"center\", sideOffset = 4, ...props }, ref) => (\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n ref={ref}\n align={align}\n sideOffset={sideOffset}\n className={cn(\n \"dark:dark-shadow hawa-z-50 hawa-rounded hawa-border hawa-bg-popover hawa-text-popover-foreground hawa-shadow-md hawa-outline-none data-[state=open]:hawa-animate-in data-[state=closed]:hawa-animate-out data-[state=closed]:hawa-fade-out-0 data-[state=open]:hawa-fade-in-0 data-[state=closed]:hawa-zoom-out-95 data-[state=open]:hawa-zoom-in-95 data-[side=bottom]:hawa-slide-in-from-top-2 data-[side=left]:hawa-slide-in-from-right-2 data-[side=right]:hawa-slide-in-from-left-2 data-[side=top]:hawa-slide-in-from-bottom-2\",\n className\n )}\n {...props}\n />\n </PopoverPrimitive.Portal>\n));\nPopoverContent.displayName = PopoverPrimitive.Content.displayName;\n\ninterface PopoverProps {\n side?: PositionType;\n align?: \"start\" | \"center\" | \"end\";\n trigger?: React.ReactNode;\n children: React.ReactNode;\n className?: string;\n sideOffset?: number;\n disableTrigger?: any;\n width?: \"trigger\" | \"default\";\n open?: boolean;\n contentProps?: PopoverPrimitive.PopoverContentProps;\n triggerProps?: PopoverPrimitive.PopoverTriggerProps;\n}\n\ntype HawaPopoverTypes = PopoverProps &\n React.ComponentProps<typeof PopoverPrimitive.Root>;\n\nconst Popover: React.FC<HawaPopoverTypes> = ({\n trigger,\n children,\n className,\n align = \"center\",\n side,\n sideOffset = 4,\n open,\n width = \"default\",\n disableTrigger,\n contentProps,\n triggerProps,\n ...props\n}) => {\n let widthStyles = {\n trigger: \"var(--radix-popover-trigger-width)\",\n default: \"auto\"\n };\n\n return (\n <PopoverPrimitive.Root open={open} {...props}>\n <PopoverPrimitive.Trigger\n className=\"hawa-w-full\"\n disabled={disableTrigger}\n {...triggerProps}\n >\n {trigger}\n </PopoverPrimitive.Trigger>\n <PopoverContent\n side={side}\n className={className}\n align={align}\n sideOffset={sideOffset}\n style={{\n width: widthStyles[width]\n }}\n {...contentProps}\n >\n {children}\n </PopoverContent>\n </PopoverPrimitive.Root>\n );\n};\n\nconst PopoverTrigger = PopoverPrimitive.Trigger;\nexport { Popover, PopoverContent, PopoverTrigger };\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n// return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";AAAA,YAAY,WAAW;AAEvB,YAAY,sBAAsB;;;ACFlC,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ADGA,IAAM,iBAAuB,iBAG3B,CAAC,EAAE,WAAW,QAAQ,UAAU,aAAa,GAAG,GAAG,MAAM,GAAG,QAC5D,oCAAkB,yBAAjB,MACC;AAAA,EAAkB;AAAA,EAAjB;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,IACC,GAAG;AAAA;AACN,CACF,CACD;AACD,eAAe,cAA+B,yBAAQ;AAmBtD,IAAM,UAAsC,CAAC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,cAAc;AAAA,IAChB,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAEA,SACE,oCAAkB,uBAAjB,EAAsB,MAAa,GAAG,SACrC;AAAA,IAAkB;AAAA,IAAjB;AAAA,MACC,WAAU;AAAA,MACV,UAAU;AAAA,MACT,GAAG;AAAA;AAAA,IAEH;AAAA,EACH,GACA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,QACL,OAAO,YAAY,KAAK;AAAA,MAC1B;AAAA,MACC,GAAG;AAAA;AAAA,IAEH;AAAA,EACH,CACF;AAEJ;AAEA,IAAM,iBAAkC;","names":[]}
|
package/dist/progress/index.mjs
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
cn
|
3
|
-
} from "../chunk-CBRGWUZG.mjs";
|
4
|
-
|
5
1
|
// elements/progress/Progress.tsx
|
6
2
|
import * as React from "react";
|
7
3
|
import * as ProgressPrimitive from "@radix-ui/react-progress";
|
4
|
+
|
5
|
+
// util/index.ts
|
6
|
+
import { clsx } from "clsx";
|
7
|
+
import { twMerge } from "tailwind-merge";
|
8
|
+
function cn(...inputs) {
|
9
|
+
return twMerge(clsx(inputs));
|
10
|
+
}
|
11
|
+
|
12
|
+
// elements/progress/Progress.tsx
|
8
13
|
var Progress = React.forwardRef(({ className, value, ...props }, ref) => /* @__PURE__ */ React.createElement(
|
9
14
|
ProgressPrimitive.Root,
|
10
15
|
{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../elements/progress/Progress.tsx"],"sourcesContent":["import * as React from \"react\";\n\nimport * as ProgressPrimitive from \"@radix-ui/react-progress\";\n\nimport { cn } from \"@util/index\";\n\nconst Progress = React.forwardRef<\n React.ElementRef<typeof ProgressPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>\n>(({ className, value, ...props }, ref) => (\n <ProgressPrimitive.Root\n ref={ref}\n className={cn(\n \"hawa-relative hawa-h-4 hawa-w-full hawa-overflow-hidden hawa-rounded hawa-bg-secondary\",\n className\n )}\n {...props}\n >\n <ProgressPrimitive.Indicator\n className=\"hawa-h-full hawa-w-full hawa-flex-1 hawa-bg-primary hawa-transition-all\"\n style={{ transform: `translateX(-${100 - (value || 0)}%)` }}\n />\n </ProgressPrimitive.Root>\n));\nProgress.displayName = ProgressPrimitive.Root.displayName;\n\nexport { Progress };\n"],"mappings":"
|
1
|
+
{"version":3,"sources":["../../elements/progress/Progress.tsx","../../util/index.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport * as ProgressPrimitive from \"@radix-ui/react-progress\";\n\nimport { cn } from \"@util/index\";\n\nconst Progress = React.forwardRef<\n React.ElementRef<typeof ProgressPrimitive.Root>,\n React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>\n>(({ className, value, ...props }, ref) => (\n <ProgressPrimitive.Root\n ref={ref}\n className={cn(\n \"hawa-relative hawa-h-4 hawa-w-full hawa-overflow-hidden hawa-rounded hawa-bg-secondary\",\n className\n )}\n {...props}\n >\n <ProgressPrimitive.Indicator\n className=\"hawa-h-full hawa-w-full hawa-flex-1 hawa-bg-primary hawa-transition-all\"\n style={{ transform: `translateX(-${100 - (value || 0)}%)` }}\n />\n </ProgressPrimitive.Root>\n));\nProgress.displayName = ProgressPrimitive.Root.displayName;\n\nexport { Progress };\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n// return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";AAAA,YAAY,WAAW;AAEvB,YAAY,uBAAuB;;;ACFnC,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ADCA,IAAM,WAAiB,iBAGrB,CAAC,EAAE,WAAW,OAAO,GAAG,MAAM,GAAG,QACjC;AAAA,EAAmB;AAAA,EAAlB;AAAA,IACC;AAAA,IACA,WAAW;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,IACC,GAAG;AAAA;AAAA,EAEJ;AAAA,IAAmB;AAAA,IAAlB;AAAA,MACC,WAAU;AAAA,MACV,OAAO,EAAE,WAAW,eAAe,OAAO,SAAS,EAAE,KAAK;AAAA;AAAA,EAC5D;AACF,CACD;AACD,SAAS,cAAgC,uBAAK;","names":[]}
|
@@ -90,8 +90,8 @@ var ProgressCircle = import_react.default.forwardRef((props, ref) => {
|
|
90
90
|
...other
|
91
91
|
} = props;
|
92
92
|
const value = getLimitedValue(inputValue);
|
93
|
-
const radius = inputRadius
|
94
|
-
const strokeWidth = inputStrokeWidth
|
93
|
+
const radius = inputRadius != null ? inputRadius : size2config[size].radius;
|
94
|
+
const strokeWidth = inputStrokeWidth != null ? inputStrokeWidth : size2config[size].strokeWidth;
|
95
95
|
const normalizedRadius = radius - strokeWidth / 2;
|
96
96
|
const circumference = normalizedRadius * 2 * Math.PI;
|
97
97
|
const strokeDashoffset = value / 100 * circumference;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../elements/progressCircle/index.ts","../../elements/progressCircle/ProgressCircle.tsx","../../util/index.ts"],"sourcesContent":["export * from \"./ProgressCircle\";\n","import React from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype GaugeType = {\n value: number; // Value between 0 and 100\n maxValue: number; // Value between 0 and 100\n design?: \"full-circle\" | \"half-circle\";\n};\n\ntype Size = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\";\n\ninterface ProgressCircleProps extends React.HTMLAttributes<HTMLDivElement> {\n value?: number;\n size?: Size;\n color?: any;\n showAnimation?: boolean;\n tooltip?: string;\n radius?: number;\n strokeWidth?: number;\n children?: React.ReactNode;\n}\n\nconst size2config: Record<Size, { strokeWidth: number; radius: number }> = {\n xs: {\n radius: 15,\n strokeWidth: 3\n },\n sm: {\n radius: 19,\n strokeWidth: 4\n },\n md: {\n radius: 32,\n strokeWidth: 6\n },\n lg: {\n radius: 52,\n strokeWidth: 8\n },\n xl: {\n radius: 80,\n strokeWidth: 10\n }\n};\n\nfunction getLimitedValue(input: number | undefined) {\n if (input === undefined) {\n return 0;\n } else if (input > 100) {\n return 100;\n } else {\n return input;\n }\n}\nexport const ProgressCircle = React.forwardRef<\n HTMLDivElement,\n ProgressCircleProps\n>((props, ref) => {\n const {\n value: inputValue,\n size = \"md\",\n className,\n showAnimation = true,\n color,\n tooltip,\n radius: inputRadius,\n strokeWidth: inputStrokeWidth,\n children,\n ...other\n } = props;\n\n const value = getLimitedValue(inputValue);\n const radius = inputRadius ?? size2config[size].radius;\n const strokeWidth = inputStrokeWidth ?? size2config[size].strokeWidth;\n const normalizedRadius = radius - strokeWidth / 2;\n const circumference = normalizedRadius * 2 * Math.PI;\n const strokeDashoffset = (value / 100) * circumference;\n const offset = circumference - strokeDashoffset;\n\n return (\n <>\n <div\n ref={ref}\n className={cn(\n \"hawa-flex hawa-flex-col hawa-items-center hawa-justify-center\",\n className\n )}\n >\n <svg\n width={radius * 2}\n height={radius * 2}\n viewBox={`0 0 ${radius * 2} ${radius * 2}`}\n className=\"hawa-rotate-180 hawa-transform\"\n >\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \" hawa-stroke-primary/20\"\n )}\n />\n {value > 0 ? (\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n strokeDasharray={circumference + \" \" + circumference}\n strokeDashoffset={offset}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \"hawa-stroke-primary\",\n showAnimation\n ? \"hawa-transition-all hawa-duration-300 hawa-ease-in-out\"\n : \"\"\n )}\n />\n ) : null}\n </svg>\n <div className={cn(\"hawa-absolute hawa-flex\")}>{children}</div>\n </div>\n </>\n );\n});\n\nProgressCircle.displayName = \"ProgressCircle\";\n\n// export const Gauge: React.FC<GaugeType> = ({\n// value = 0,\n// maxValue = 100,\n// children,\n// design = \"full-circle\",\n// }) => {\n// // const radius = 16;\n// // const fullCircumference = 2 * Math.PI * radius; // Full circle circumference\n// // const halfCircumference = Math.PI * radius; // Half circle circumference, updated\n// // const percentage = value / maxValue;\n// // const fullOffset = fullCircumference - percentage * fullCircumference;\n// // const halfOffset = halfCircumference - percentage * halfCircumference; // Updated offset for half-circle\n// // const strokeDasharray = percentage * halfCircumference;\n// // const strokeDashoffset = halfCircumference * (1 - percentage);\n\n// // const FullCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"#009\"\n// // fill=\"none\"\n// // strokeLinecap=\"round\"\n// // strokeDasharray={fullCircumference}\n// // strokeDashoffset={fullOffset}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transform: \"rotate(180deg)\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"50%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"10\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// // const HalfCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"#00f\"\n// // fill=\"none\"\n// // // strokeDasharray={`${strokeDasharray}`}\n// // // strokeDashoffset={`${strokeDashoffset}`}\n// // strokeDasharray={50}\n// // strokeDashoffset={50}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"45%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"8\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// return (\n// <div className=\"hawa-flex hawa-flex-row hawa-gap-x-3\">\n// <div aria-label=\"Gauge\" role=\"status\">\n// {/* {design === \"full-circle\" ? <FullCircle /> : <HalfCircle />} */}\n// <AlmostFullCircle value={value} size=\"lg\">\n// {children}\n// </AlmostFullCircle>\n// </div>\n// </div>\n// );\n// };\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n// return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACAlB,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;;;ADkBA,IAAM,cAAqE;AAAA,EACzE,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;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,QAAC;AAAA;AAAA,UACC,GAAG;AAAA,UACH,IAAI;AAAA,UACJ,IAAI;AAAA,UACJ;AAAA,UACA,iBAAiB,gBAAgB,MAAM;AAAA,UACvC,kBAAkB;AAAA,UAClB,MAAK;AAAA,UACL,QAAO;AAAA,UACP,eAAc;AAAA,UACd,WAAW;AAAA,YACT;AAAA,YACA;AAAA,YACA,gBACI,2DACA;AAAA,UACN;AAAA;AAAA,MACF,IACE;AAAA,IACN;AAAA,IACA,6BAAAA,QAAA,cAAC,SAAI,WAAW,GAAG,yBAAyB,KAAI,QAAS;AAAA,EAC3D,CACF;AAEJ,CAAC;AAED,eAAe,cAAc;","names":["React"]}
|
1
|
+
{"version":3,"sources":["../../elements/progressCircle/index.ts","../../elements/progressCircle/ProgressCircle.tsx","../../util/index.ts"],"sourcesContent":["export * from \"./ProgressCircle\";\n","import React from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype GaugeType = {\n value: number; // Value between 0 and 100\n maxValue: number; // Value between 0 and 100\n design?: \"full-circle\" | \"half-circle\";\n};\n\ntype Size = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\";\n\ninterface ProgressCircleProps extends React.HTMLAttributes<HTMLDivElement> {\n value?: number;\n size?: Size;\n color?: any;\n showAnimation?: boolean;\n tooltip?: string;\n radius?: number;\n strokeWidth?: number;\n children?: React.ReactNode;\n}\n\nconst size2config: Record<Size, { strokeWidth: number; radius: number }> = {\n xs: {\n radius: 15,\n strokeWidth: 3\n },\n sm: {\n radius: 19,\n strokeWidth: 4\n },\n md: {\n radius: 32,\n strokeWidth: 6\n },\n lg: {\n radius: 52,\n strokeWidth: 8\n },\n xl: {\n radius: 80,\n strokeWidth: 10\n }\n};\n\nfunction getLimitedValue(input: number | undefined) {\n if (input === undefined) {\n return 0;\n } else if (input > 100) {\n return 100;\n } else {\n return input;\n }\n}\nexport const ProgressCircle = React.forwardRef<\n HTMLDivElement,\n ProgressCircleProps\n>((props, ref) => {\n const {\n value: inputValue,\n size = \"md\",\n className,\n showAnimation = true,\n color,\n tooltip,\n radius: inputRadius,\n strokeWidth: inputStrokeWidth,\n children,\n ...other\n } = props;\n\n const value = getLimitedValue(inputValue);\n const radius = inputRadius ?? size2config[size].radius;\n const strokeWidth = inputStrokeWidth ?? size2config[size].strokeWidth;\n const normalizedRadius = radius - strokeWidth / 2;\n const circumference = normalizedRadius * 2 * Math.PI;\n const strokeDashoffset = (value / 100) * circumference;\n const offset = circumference - strokeDashoffset;\n\n return (\n <>\n <div\n ref={ref}\n className={cn(\n \"hawa-flex hawa-flex-col hawa-items-center hawa-justify-center\",\n className\n )}\n >\n <svg\n width={radius * 2}\n height={radius * 2}\n viewBox={`0 0 ${radius * 2} ${radius * 2}`}\n className=\"hawa-rotate-180 hawa-transform\"\n >\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \" hawa-stroke-primary/20\"\n )}\n />\n {value > 0 ? (\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n strokeDasharray={circumference + \" \" + circumference}\n strokeDashoffset={offset}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \"hawa-stroke-primary\",\n showAnimation\n ? \"hawa-transition-all hawa-duration-300 hawa-ease-in-out\"\n : \"\"\n )}\n />\n ) : null}\n </svg>\n <div className={cn(\"hawa-absolute hawa-flex\")}>{children}</div>\n </div>\n </>\n );\n});\n\nProgressCircle.displayName = \"ProgressCircle\";\n\n// export const Gauge: React.FC<GaugeType> = ({\n// value = 0,\n// maxValue = 100,\n// children,\n// design = \"full-circle\",\n// }) => {\n// // const radius = 16;\n// // const fullCircumference = 2 * Math.PI * radius; // Full circle circumference\n// // const halfCircumference = Math.PI * radius; // Half circle circumference, updated\n// // const percentage = value / maxValue;\n// // const fullOffset = fullCircumference - percentage * fullCircumference;\n// // const halfOffset = halfCircumference - percentage * halfCircumference; // Updated offset for half-circle\n// // const strokeDasharray = percentage * halfCircumference;\n// // const strokeDashoffset = halfCircumference * (1 - percentage);\n\n// // const FullCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"#009\"\n// // fill=\"none\"\n// // strokeLinecap=\"round\"\n// // strokeDasharray={fullCircumference}\n// // strokeDashoffset={fullOffset}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transform: \"rotate(180deg)\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"50%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"10\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// // const HalfCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"#00f\"\n// // fill=\"none\"\n// // // strokeDasharray={`${strokeDasharray}`}\n// // // strokeDashoffset={`${strokeDashoffset}`}\n// // strokeDasharray={50}\n// // strokeDashoffset={50}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"45%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"8\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// return (\n// <div className=\"hawa-flex hawa-flex-row hawa-gap-x-3\">\n// <div aria-label=\"Gauge\" role=\"status\">\n// {/* {design === \"full-circle\" ? <FullCircle /> : <HalfCircle />} */}\n// <AlmostFullCircle value={value} size=\"lg\">\n// {children}\n// </AlmostFullCircle>\n// </div>\n// </div>\n// );\n// };\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)\n// return replaced\n// };\n\n// export { hexToRgb, getTextColor, replaceAt };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACAlB,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;;;ADkBA,IAAM,cAAqE;AAAA,EACzE,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AACF;AAEA,SAAS,gBAAgB,OAA2B;AAClD,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT,WAAW,QAAQ,KAAK;AACtB,WAAO;AAAA,EACT,OAAO;AACL,WAAO;AAAA,EACT;AACF;AACO,IAAM,iBAAiB,aAAAA,QAAM,WAGlC,CAAC,OAAO,QAAQ;AAChB,QAAM;AAAA,IACJ,OAAO;AAAA,IACP,OAAO;AAAA,IACP;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,aAAa;AA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I,QAAS;AAAA,EAC3D,CACF;AAEJ,CAAC;AAED,eAAe,cAAc;","names":["React"]}
|
@@ -1,9 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
cn
|
3
|
-
} from "../chunk-CBRGWUZG.mjs";
|
4
|
-
|
5
1
|
// elements/progressCircle/ProgressCircle.tsx
|
6
2
|
import React from "react";
|
3
|
+
|
4
|
+
// util/index.ts
|
5
|
+
import { clsx } from "clsx";
|
6
|
+
import { twMerge } from "tailwind-merge";
|
7
|
+
function cn(...inputs) {
|
8
|
+
return twMerge(clsx(inputs));
|
9
|
+
}
|
10
|
+
|
11
|
+
// elements/progressCircle/ProgressCircle.tsx
|
7
12
|
var size2config = {
|
8
13
|
xs: {
|
9
14
|
radius: 15,
|
@@ -49,8 +54,8 @@ var ProgressCircle = React.forwardRef((props, ref) => {
|
|
49
54
|
...other
|
50
55
|
} = props;
|
51
56
|
const value = getLimitedValue(inputValue);
|
52
|
-
const radius = inputRadius
|
53
|
-
const strokeWidth = inputStrokeWidth
|
57
|
+
const radius = inputRadius != null ? inputRadius : size2config[size].radius;
|
58
|
+
const strokeWidth = inputStrokeWidth != null ? inputStrokeWidth : size2config[size].strokeWidth;
|
54
59
|
const normalizedRadius = radius - strokeWidth / 2;
|
55
60
|
const circumference = normalizedRadius * 2 * Math.PI;
|
56
61
|
const strokeDashoffset = value / 100 * circumference;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../elements/progressCircle/ProgressCircle.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype GaugeType = {\n value: number; // Value between 0 and 100\n maxValue: number; // Value between 0 and 100\n design?: \"full-circle\" | \"half-circle\";\n};\n\ntype Size = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\";\n\ninterface ProgressCircleProps extends React.HTMLAttributes<HTMLDivElement> {\n value?: number;\n size?: Size;\n color?: any;\n showAnimation?: boolean;\n tooltip?: string;\n radius?: number;\n strokeWidth?: number;\n children?: React.ReactNode;\n}\n\nconst size2config: Record<Size, { strokeWidth: number; radius: number }> = {\n xs: {\n radius: 15,\n strokeWidth: 3\n },\n sm: {\n radius: 19,\n strokeWidth: 4\n },\n md: {\n radius: 32,\n strokeWidth: 6\n },\n lg: {\n radius: 52,\n strokeWidth: 8\n },\n xl: {\n radius: 80,\n strokeWidth: 10\n }\n};\n\nfunction getLimitedValue(input: number | undefined) {\n if (input === undefined) {\n return 0;\n } else if (input > 100) {\n return 100;\n } else {\n return input;\n }\n}\nexport const ProgressCircle = React.forwardRef<\n HTMLDivElement,\n ProgressCircleProps\n>((props, ref) => {\n const {\n value: inputValue,\n size = \"md\",\n className,\n showAnimation = true,\n color,\n tooltip,\n radius: inputRadius,\n strokeWidth: inputStrokeWidth,\n children,\n ...other\n } = props;\n\n const value = getLimitedValue(inputValue);\n const radius = inputRadius ?? size2config[size].radius;\n const strokeWidth = inputStrokeWidth ?? size2config[size].strokeWidth;\n const normalizedRadius = radius - strokeWidth / 2;\n const circumference = normalizedRadius * 2 * Math.PI;\n const strokeDashoffset = (value / 100) * circumference;\n const offset = circumference - strokeDashoffset;\n\n return (\n <>\n <div\n ref={ref}\n className={cn(\n \"hawa-flex hawa-flex-col hawa-items-center hawa-justify-center\",\n className\n )}\n >\n <svg\n width={radius * 2}\n height={radius * 2}\n viewBox={`0 0 ${radius * 2} ${radius * 2}`}\n className=\"hawa-rotate-180 hawa-transform\"\n >\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \" hawa-stroke-primary/20\"\n )}\n />\n {value > 0 ? (\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n strokeDasharray={circumference + \" \" + circumference}\n strokeDashoffset={offset}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \"hawa-stroke-primary\",\n showAnimation\n ? \"hawa-transition-all hawa-duration-300 hawa-ease-in-out\"\n : \"\"\n )}\n />\n ) : null}\n </svg>\n <div className={cn(\"hawa-absolute hawa-flex\")}>{children}</div>\n </div>\n </>\n );\n});\n\nProgressCircle.displayName = \"ProgressCircle\";\n\n// export const Gauge: React.FC<GaugeType> = ({\n// value = 0,\n// maxValue = 100,\n// children,\n// design = \"full-circle\",\n// }) => {\n// // const radius = 16;\n// // const fullCircumference = 2 * Math.PI * radius; // Full circle circumference\n// // const halfCircumference = Math.PI * radius; // Half circle circumference, updated\n// // const percentage = value / maxValue;\n// // const fullOffset = fullCircumference - percentage * fullCircumference;\n// // const halfOffset = halfCircumference - percentage * halfCircumference; // Updated offset for half-circle\n// // const strokeDasharray = percentage * halfCircumference;\n// // const strokeDashoffset = halfCircumference * (1 - percentage);\n\n// // const FullCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"#009\"\n// // fill=\"none\"\n// // strokeLinecap=\"round\"\n// // strokeDasharray={fullCircumference}\n// // strokeDashoffset={fullOffset}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transform: \"rotate(180deg)\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"50%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"10\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// // const HalfCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"#00f\"\n// // fill=\"none\"\n// // // strokeDasharray={`${strokeDasharray}`}\n// // // strokeDashoffset={`${strokeDashoffset}`}\n// // strokeDasharray={50}\n// // strokeDashoffset={50}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"45%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"8\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// return (\n// <div className=\"hawa-flex hawa-flex-row hawa-gap-x-3\">\n// <div aria-label=\"Gauge\" role=\"status\">\n// {/* {design === \"full-circle\" ? <FullCircle /> : <HalfCircle />} */}\n// <AlmostFullCircle value={value} size=\"lg\">\n// {children}\n// </AlmostFullCircle>\n// </div>\n// </div>\n// );\n// };\n"],"mappings":";;;;;AAAA,OAAO,WAAW;AAuBlB,IAAM,cAAqE;AAAA,EACzE,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AAAA,EACA,IAAI;AAAA,IACF,QAAQ;AAAA,IACR,aAAa;AAAA,EACf;AACF;AAEA,SAAS,gBAAgB,OAA2B;AAClD,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT,WAAW,QAAQ,KAAK;AACtB,WAAO;AAAA,EACT,OAAO;AACL,WAAO;AAAA,EACT;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;AAAA,UACN;AAAA;AAAA,MACF,IACE;AAAA,IACN;AAAA,IACA,oCAAC,SAAI,WAAW,GAAG,yBAAyB,KAAI,QAAS;AAAA,EAC3D,CACF;AAEJ,CAAC;AAED,eAAe,cAAc;","names":[]}
|
1
|
+
{"version":3,"sources":["../../elements/progressCircle/ProgressCircle.tsx","../../util/index.ts"],"sourcesContent":["import React from \"react\";\n\nimport { cn } from \"@util/index\";\n\ntype GaugeType = {\n value: number; // Value between 0 and 100\n maxValue: number; // Value between 0 and 100\n design?: \"full-circle\" | \"half-circle\";\n};\n\ntype Size = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\";\n\ninterface ProgressCircleProps extends React.HTMLAttributes<HTMLDivElement> {\n value?: number;\n size?: Size;\n color?: any;\n showAnimation?: boolean;\n tooltip?: string;\n radius?: number;\n strokeWidth?: number;\n children?: React.ReactNode;\n}\n\nconst size2config: Record<Size, { strokeWidth: number; radius: number }> = {\n xs: {\n radius: 15,\n strokeWidth: 3\n },\n sm: {\n radius: 19,\n strokeWidth: 4\n },\n md: {\n radius: 32,\n strokeWidth: 6\n },\n lg: {\n radius: 52,\n strokeWidth: 8\n },\n xl: {\n radius: 80,\n strokeWidth: 10\n }\n};\n\nfunction getLimitedValue(input: number | undefined) {\n if (input === undefined) {\n return 0;\n } else if (input > 100) {\n return 100;\n } else {\n return input;\n }\n}\nexport const ProgressCircle = React.forwardRef<\n HTMLDivElement,\n ProgressCircleProps\n>((props, ref) => {\n const {\n value: inputValue,\n size = \"md\",\n className,\n showAnimation = true,\n color,\n tooltip,\n radius: inputRadius,\n strokeWidth: inputStrokeWidth,\n children,\n ...other\n } = props;\n\n const value = getLimitedValue(inputValue);\n const radius = inputRadius ?? size2config[size].radius;\n const strokeWidth = inputStrokeWidth ?? size2config[size].strokeWidth;\n const normalizedRadius = radius - strokeWidth / 2;\n const circumference = normalizedRadius * 2 * Math.PI;\n const strokeDashoffset = (value / 100) * circumference;\n const offset = circumference - strokeDashoffset;\n\n return (\n <>\n <div\n ref={ref}\n className={cn(\n \"hawa-flex hawa-flex-col hawa-items-center hawa-justify-center\",\n className\n )}\n >\n <svg\n width={radius * 2}\n height={radius * 2}\n viewBox={`0 0 ${radius * 2} ${radius * 2}`}\n className=\"hawa-rotate-180 hawa-transform\"\n >\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \" hawa-stroke-primary/20\"\n )}\n />\n {value > 0 ? (\n <circle\n r={normalizedRadius}\n cx={radius}\n cy={radius}\n strokeWidth={strokeWidth}\n strokeDasharray={circumference + \" \" + circumference}\n strokeDashoffset={offset}\n fill=\"transparent\"\n stroke=\"\"\n strokeLinecap=\"round\"\n className={cn(\n \"hawa-transition-colors hawa-ease-linear\",\n \"hawa-stroke-primary\",\n showAnimation\n ? \"hawa-transition-all hawa-duration-300 hawa-ease-in-out\"\n : \"\"\n )}\n />\n ) : null}\n </svg>\n <div className={cn(\"hawa-absolute hawa-flex\")}>{children}</div>\n </div>\n </>\n );\n});\n\nProgressCircle.displayName = \"ProgressCircle\";\n\n// export const Gauge: React.FC<GaugeType> = ({\n// value = 0,\n// maxValue = 100,\n// children,\n// design = \"full-circle\",\n// }) => {\n// // const radius = 16;\n// // const fullCircumference = 2 * Math.PI * radius; // Full circle circumference\n// // const halfCircumference = Math.PI * radius; // Half circle circumference, updated\n// // const percentage = value / maxValue;\n// // const fullOffset = fullCircumference - percentage * fullCircumference;\n// // const halfOffset = halfCircumference - percentage * halfCircumference; // Updated offset for half-circle\n// // const strokeDasharray = percentage * halfCircumference;\n// // const strokeDashoffset = halfCircumference * (1 - percentage);\n\n// // const FullCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <circle\n// // cx=\"18\"\n// // cy=\"18\"\n// // r={radius}\n// // strokeWidth=\"2\"\n// // stroke=\"#009\"\n// // fill=\"none\"\n// // strokeLinecap=\"round\"\n// // strokeDasharray={fullCircumference}\n// // strokeDashoffset={fullOffset}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transform: \"rotate(180deg)\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"50%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"10\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// // const HalfCircle = () => (\n// // <svg className={\"hawa-h-36 hawa-w-36\"} viewBox=\"0 0 36 36\">\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"lightgray\"\n// // fill=\"none\"\n// // />\n// // <path\n// // d=\"M 4,18 A 14,14 0 0,1 32,18\"\n// // strokeWidth=\"4\"\n// // stroke=\"#00f\"\n// // fill=\"none\"\n// // // strokeDasharray={`${strokeDasharray}`}\n// // // strokeDashoffset={`${strokeDashoffset}`}\n// // strokeDasharray={50}\n// // strokeDashoffset={50}\n// // style={{\n// // transition: \"stroke-dashoffset 0.35s\",\n// // transformOrigin: \"50% 50%\",\n// // }}\n// // />\n// // <text\n// // x=\"50%\"\n// // y=\"45%\"\n// // alignmentBaseline=\"middle\"\n// // textAnchor=\"middle\"\n// // fontSize=\"8\"\n// // fill=\"#000\"\n// // >\n// // {value}\n// // </text>\n// // </svg>\n// // );\n// return (\n// <div className=\"hawa-flex hawa-flex-row hawa-gap-x-3\">\n// <div aria-label=\"Gauge\" role=\"status\">\n// {/* {design === \"full-circle\" ? <FullCircle /> : <HalfCircle />} */}\n// <AlmostFullCircle value={value} size=\"lg\">\n// {children}\n// </AlmostFullCircle>\n// </div>\n// </div>\n// );\n// };\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\ntype Palette = {\n name: string;\n colors: {\n [key: number]: string;\n };\n};\ntype Rgb = {\n r: number;\n g: number;\n b: number;\n};\nfunction hexToRgb(hex: string): Rgb | null {\n const sanitizedHex = hex.replaceAll(\"##\", \"#\");\n const colorParts = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(\n sanitizedHex\n );\n\n if (!colorParts) {\n return null;\n }\n\n const [, r, g, b] = colorParts;\n\n return {\n r: parseInt(r, 16),\n g: parseInt(g, 16),\n b: parseInt(b, 16)\n } as Rgb;\n}\n\nfunction rgbToHex(r: number, g: number, b: number): string {\n const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);\n return `#${toHex(r)}${toHex(g)}${toHex(b)}`;\n}\n\nexport function getTextColor(color: string): \"#FFF\" | \"#333\" {\n const rgbColor = hexToRgb(color);\n\n if (!rgbColor) {\n return \"#333\";\n }\n\n const { r, g, b } = rgbColor;\n const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;\n\n return luma < 120 ? \"#FFF\" : \"#333\";\n}\n\nfunction lighten(hex: string, intensity: number): string {\n const color = hexToRgb(`#${hex}`);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r + (255 - color.r) * intensity);\n const g = Math.round(color.g + (255 - color.g) * intensity);\n const b = Math.round(color.b + (255 - color.b) * intensity);\n\n return rgbToHex(r, g, b);\n}\n\nfunction darken(hex: string, intensity: number): string {\n const color = hexToRgb(hex);\n\n if (!color) {\n return \"\";\n }\n\n const r = Math.round(color.r * intensity);\n const g = Math.round(color.g * intensity);\n const b = Math.round(color.b * intensity);\n\n return rgbToHex(r, g, b);\n}\nconst parseColor = (color: any) => {\n if (color.startsWith(\"#\")) {\n // Convert hex to RGB\n let r = parseInt(color.slice(1, 3), 16);\n let g = parseInt(color.slice(3, 5), 16);\n let b = parseInt(color.slice(5, 7), 16);\n return [r, g, b];\n } else if (color.startsWith(\"rgb\")) {\n // Extract RGB values from rgb() format\n return color.match(/\\d+/g).map(Number);\n }\n // Default to white if format is unrecognized\n return [255, 255, 255];\n};\nexport const calculateLuminance = (color: any) => {\n const [r, g, b] = parseColor(color)?.map((c: any) => {\n c /= 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\nfunction getPallette(baseColor: string): Palette {\n const name = baseColor;\n\n const response: Palette = {\n name,\n colors: {\n 500: `#${baseColor}`.replace(\"##\", \"#\")\n }\n };\n\n const intensityMap: {\n [key: number]: number;\n } = {\n 50: 0.95,\n 100: 0.9,\n 200: 0.75,\n 300: 0.6,\n 400: 0.3,\n 600: 0.9,\n 700: 0.75,\n 800: 0.6,\n 900: 0.49\n };\n\n [50, 100, 200, 300, 400].forEach((level) => {\n response.colors[level] = lighten(baseColor, intensityMap[level]);\n });\n [600, 700, 800, 900].forEach((level) => {\n response.colors[level] = darken(baseColor, intensityMap[level]);\n });\n\n return response as Palette;\n}\n\nexport { getPallette };\n\n// const hexToRgb = (hex) => {\n// let d = hex?.split(\"#\")[1];\n// var aRgbHex = d?.match(/.{1,2}/g);\n// var aRgb = [\n// parseInt(aRgbHex[0], 16),\n// parseInt(aRgbHex[1], 16),\n// parseInt(aRgbHex[2], 16)\n// ];\n// return aRgb;\n// };\n// const getTextColor = (backColor) => {\n// let rgbArray = hexToRgb(backColor);\n// if (rgbArray[0] * 0.299 + rgbArray[1] * 0.587 + rgbArray[2] * 0.114 > 186) {\n// return \"#000000\";\n// } else {\n// return \"#ffffff\";\n// }\n// };\n// const replaceAt = function (string, index, replacement) {\n// // if (replacement == \"\" || replacement == \" \") {\n// // return (\n// // string.substring(0, index) +\n// // string.substring(index + replacement.length )\n// // );\n// // }\n// const replaced = string.substring(0, index) + replacement + string.substring(index + 1)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AAA,QACT;AAAA,QACA;AAAA,MACF;AAAA;AAAA,IAEA;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,SAAS;AAAA,QAChB,QAAQ,SAAS;AAAA,QACjB,SAAS,OAAO,SAAS,CAAC,IAAI,SAAS,CAAC;AAAA,QACxC,WAAU;AAAA;AAAA,MAEV;AAAA,QAAC;AAAA;AAAA,UACC,GAAG;AAAA,UACH,IAAI;AAAA,UACJ,IAAI;AAAA,UACJ;AAAA,UACA,MAAK;AAAA,UACL,QAAO;AAAA,UACP,eAAc;AAAA,UACd,WAAW;AAAA,YACT;AAAA,YACA;AAAA,UACF;AAAA;AAAA,MACF;AAAA,MACC,QAAQ,IACP;AAAA,QAAC;AAAA;AAAA,UACC,GAAG;AAAA,UACH,IAAI;AAAA,UACJ,IAAI;AAAA,UACJ;AAAA,UACA,iBAAiB,gBAAgB,MAAM;AAAA,UACvC,kBAAkB;AAAA,UAClB,MAAK;AAAA,UACL,QAAO;AAAA,UACP,eAAc;AAAA,UACd,WAAW;AAAA,YACT;AAAA,YACA;AAAA,YACA,gBACI,2DACA;AAAA,UACN;AAAA;AAAA,MACF,IACE;AAAA,IACN;AAAA,IACA,oCAAC,SAAI,WAAW,GAAG,yBAAyB,KAAI,QAAS;AAAA,EAC3D,CACF;AAEJ,CAAC;AAED,eAAe,cAAc;","names":[]}
|
package/dist/radio/index.js
CHANGED
@@ -152,6 +152,7 @@ var Radio = ({
|
|
152
152
|
onChange,
|
153
153
|
...props
|
154
154
|
}) => {
|
155
|
+
var _a, _b, _c;
|
155
156
|
const [selectedOption, setSelectedOption] = (0, import_react2.useState)(props.defaultValue);
|
156
157
|
let activeTabStyle = "hawa-inline-block hawa-w-full hawa-text-primary-foreground hawa-bg-primary hawa-active dark:hawa-bg-primary";
|
157
158
|
let inactiveTabStyle = "hawa-inline-block hawa-w-full hawa-transition-all hover:hawa-bg-muted hawa-bg-primary-foreground dark:hover:hawa-text-white";
|
@@ -175,7 +176,8 @@ var Radio = ({
|
|
175
176
|
);
|
176
177
|
const parentRef = (0, import_react2.useRef)(null);
|
177
178
|
(0, import_react2.useEffect)(() => {
|
178
|
-
|
179
|
+
var _a2;
|
180
|
+
const parentNode = (_a2 = parentRef.current) == null ? void 0 : _a2.parentNode;
|
179
181
|
if (parentNode) {
|
180
182
|
const dir = window.getComputedStyle(parentNode).direction;
|
181
183
|
setParentDirection(dir);
|
@@ -196,14 +198,14 @@ var Radio = ({
|
|
196
198
|
{
|
197
199
|
ref: parentRef,
|
198
200
|
className: cn(
|
199
|
-
props.options && props.options
|
201
|
+
props.options && ((_a = props.options) == null ? void 0 : _a.length) > 2 ? "hawa-flex-wrap xs:hawa-max-w-full xs:hawa-flex-nowrap" : "",
|
200
202
|
"hawa-select-none hawa-whitespace-nowrap hawa-rounded hawa-border hawa-text-center hawa-font-medium",
|
201
203
|
orientationStyle[orientation],
|
202
204
|
widthStyle[width],
|
203
205
|
tabsContainerClassName
|
204
206
|
)
|
205
207
|
},
|
206
|
-
props.options
|
208
|
+
(_b = props.options) == null ? void 0 : _b.map((opt, o) => /* @__PURE__ */ import_react2.default.createElement(
|
207
209
|
"li",
|
208
210
|
{
|
209
211
|
"aria-current": "page",
|
@@ -257,7 +259,7 @@ var Radio = ({
|
|
257
259
|
)
|
258
260
|
))));
|
259
261
|
case "cards":
|
260
|
-
return /* @__PURE__ */ import_react2.default.createElement("ul", { className: cn(orientationStyle[orientation], "hawa-gap-4") }, props.options
|
262
|
+
return /* @__PURE__ */ import_react2.default.createElement("ul", { className: cn(orientationStyle[orientation], "hawa-gap-4") }, (_c = props.options) == null ? void 0 : _c.map((opt, o) => /* @__PURE__ */ import_react2.default.createElement("li", { key: o, onClick: () => handleChange(opt) }, /* @__PURE__ */ import_react2.default.createElement(
|
261
263
|
"input",
|
262
264
|
{
|
263
265
|
type: "radio",
|