@studiocubics/components 0.0.13 → 0.0.15
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/Display/IdentityDisplay/IdentityDisplay.d.ts +1 -1
- package/dist/Display/IdentityDisplay/IdentityDisplay.js +1 -1
- package/dist/Display/IdentityDisplay/IdentityDisplay.js.map +1 -1
- package/dist/Display/List/List.d.ts +2 -2
- package/dist/Display/List/List.js +1 -1
- package/dist/Display/List/List.js.map +1 -1
- package/dist/Display/Toast/Toaster.d.ts +0 -2
- package/dist/Display/Toast/Toaster.js +1 -1
- package/dist/Display/Toast/Toaster.js.map +1 -1
- package/dist/Forms/ConfirmationForm/ConfirmationForm.d.ts +4 -1
- package/dist/Forms/ConfirmationForm/ConfirmationForm.js +1 -1
- package/dist/Forms/ConfirmationForm/ConfirmationForm.js.map +1 -1
- package/dist/Forms/ConfirmationForm/ConfirmationForm.module.css.js +1 -1
- package/dist/Inputs/Checkbox/Checkbox.d.ts +2 -2
- package/dist/Inputs/Checkbox/Checkbox.js +1 -1
- package/dist/Inputs/Checkbox/Checkbox.js.map +1 -1
- package/dist/Inputs/CloseButton/CloseButton.d.ts +0 -2
- package/dist/Inputs/CloseButton/CloseButton.js +1 -1
- package/dist/Inputs/CloseButton/CloseButton.js.map +1 -1
- package/dist/Inputs/PasswordInput/PasswordInput.d.ts +1 -1
- package/dist/Inputs/PasswordInput/PasswordInput.js +1 -1
- package/dist/Inputs/PasswordInput/PasswordInput.js.map +1 -1
- package/dist/Inputs/SearchInput/SearchInput.d.ts +0 -4
- package/dist/Inputs/SearchInput/SearchInput.js +1 -1
- package/dist/Inputs/SearchInput/SearchInput.js.map +1 -1
- package/dist/Inputs/Select/Select.js +1 -1
- package/dist/Inputs/Select/Select.js.map +1 -1
- package/dist/Inputs/Switch/Switch.js +1 -1
- package/dist/Inputs/Switch/Switch.js.map +1 -1
- package/dist/Inputs/TextAreaInput/TextAreaInput.d.ts +1 -1
- package/dist/Inputs/TextAreaInput/TextAreaInput.js +1 -1
- package/dist/Inputs/TextAreaInput/TextAreaInput.js.map +1 -1
- package/dist/Inputs/TextInput/TextInput.d.ts +1 -1
- package/dist/Inputs/TextInput/TextInput.js +1 -1
- package/dist/Inputs/TextInput/TextInput.js.map +1 -1
- package/dist/Layout/Drawer/Drawer.d.ts +1 -1
- package/dist/Layout/Drawer/Drawer.js +1 -1
- package/dist/Layout/Drawer/Drawer.js.map +1 -1
- package/dist/Navigation/Breadcrumbs/Breadcrumbs.d.ts +0 -2
- package/dist/Navigation/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/Navigation/Breadcrumbs/Breadcrumbs.js.map +1 -1
- package/dist/Navigation/Pagination/Pagination.js +1 -1
- package/dist/Navigation/Pagination/Pagination.js.map +1 -1
- package/dist/Typography/CopyableText/CopyableText.d.ts +1 -2
- package/dist/Typography/CopyableText/CopyableText.js +1 -1
- package/dist/Typography/CopyableText/CopyableText.js.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchInput.js","sources":["../../../src/Inputs/SearchInput/SearchInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn, mergeRefs } from \"@studiocubics/utils\";\nimport { useRef, useState, type ComponentProps } from \"react\";\nimport styles from \"./SearchInput.module.css\";\nimport { type ButtonProps, Button } from \"../Button/Button\";\nimport { type TextInputProps, TextInput } from \"../TextInput/TextInput\";\n\nexport interface SearchInputProps extends Omit<TextInputProps, \"slotProps\"> {\n variant?: \"collapsible\" | \"default\";\n slotProps?: TextInputProps[\"slotProps\"] & {\n searchInputRoot?: ComponentProps<\"div\">;\n searchCollapseToggle?: ButtonProps;\n searchButton?: ButtonProps;\n clearButton?: ButtonProps;\n };\n onSearch?: (query: string) => void;\n onClear?: () => void;\n // inputVariant:TextInputProps[\"variant\"]\n}\n\nexport function SearchOpenIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n {/* <path d=\"m13 13.5 2-2.5-2-2.5\" /> */}\n <path d=\"m21 21-4.3-4.3\" />\n <path d=\"M9 8.5 7 11l2 2.5\" />\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n </svg>\n );\n}\nexport function SearchIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n {/* <path d=\"m13 13.5 2-2.5-2-2.5\" /> */}\n <path d=\"m21 21-4.3-4.3\" />\n {/* <path d=\"M9 8.5 7 11l2 2.5\" /> */}\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n </svg>\n );\n}\nexport function SearchCloseIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <path d=\"m13 13.5 2-2.5-2-2.5\" />\n <path d=\"m21 21-4.3-4.3\" />\n {/* <path d=\"M9 8.5 7 11l2 2.5\" /> */}\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n </svg>\n );\n}\nexport function ClearIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <path d=\"M18 6 6 18\" />\n <path d=\"m6 6 12 12\" />\n </svg>\n );\n}\n\nexport function SearchInput(props: SearchInputProps) {\n const {\n ref,\n className,\n size = \"sm\",\n variant = \"default\",\n disabled,\n disableEndIconGutters,\n disableStartIconGutters,\n disableInputGutters,\n slotProps = {},\n value,\n onChange,\n onSearch,\n onClear,\n ...rest\n } = props;\n\n const [collapsed, setCollapsed] = useState(variant == \"collapsible\");\n const [internalValue, setInternalValue] = useState(\"\");\n const inputRef = useRef<HTMLInputElement>(null);\n\n // Use controlled value if provided, otherwise use internal state\n const isControlled = value !== undefined;\n const currentValue = isControlled ? value : internalValue;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!isControlled) {\n setInternalValue(e.target.value);\n }\n onChange?.(e);\n };\n\n const handleClear = (e: React.MouseEvent<HTMLButtonElement>) => {\n if (!isControlled) {\n setInternalValue(\"\");\n }\n slotProps.clearButton?.onClick?.(e);\n onClear?.();\n };\n\n return (\n <div\n {...slotProps.searchInputRoot}\n className={cn(\n styles.root,\n collapsed ? styles.collapsed : \"\",\n slotProps.searchInputRoot?.className,\n )}\n >\n {String(currentValue).trim() ? (\n <Button\n {...slotProps.clearButton}\n size={slotProps.clearButton?.size || size}\n className={cn(styles.clearButton, slotProps.clearButton?.className)}\n disabled={slotProps.clearButton?.disabled || collapsed}\n onClick={handleClear}\n type={slotProps.clearButton?.type || \"button\"}\n >\n {slotProps.clearButton?.children ?? <ClearIcon />}\n </Button>\n ) : (\n <Button\n {...slotProps.searchCollapseToggle}\n size={slotProps.searchCollapseToggle?.size || size}\n onClick={(e) => {\n slotProps.searchCollapseToggle?.onClick?.(e);\n setCollapsed(!collapsed);\n }}\n disabled={\n slotProps.searchCollapseToggle?.disabled || variant != \"collapsible\"\n }\n type={slotProps.searchCollapseToggle?.type || \"button\"}\n >\n {variant == \"collapsible\" ? (\n collapsed ? (\n <SearchOpenIcon />\n ) : (\n <SearchCloseIcon />\n )\n ) : (\n <SearchIcon />\n )}\n </Button>\n )}\n <TextInput\n type=\"search\"\n ref={mergeRefs(inputRef, ref)}\n className={cn(styles.input, className)}\n size={size}\n disableStartIconGutters={disableStartIconGutters || collapsed}\n disableEndIconGutters={disableEndIconGutters || collapsed}\n disableInputGutters={disableInputGutters || collapsed}\n disabled={disabled || collapsed}\n value={currentValue}\n onChange={handleChange}\n slotProps={{\n ...slotProps,\n inputWrapper: {\n ...slotProps.inputWrapper,\n className: cn(\n slotProps.inputWrapper?.className,\n collapsed ? styles.inputWrapper : \"\",\n ),\n },\n }}\n {...rest}\n />\n\n <Button\n {...slotProps.searchButton}\n size={slotProps.searchButton?.size || size}\n className={cn(styles.searchButton, slotProps.searchButton?.className)}\n disabled={\n slotProps.searchButton?.disabled ||\n collapsed ||\n !String(currentValue).trim()\n }\n onClick={(e) => {\n slotProps.searchButton?.onClick?.(e);\n if (inputRef.current?.value) onSearch?.(inputRef.current?.value);\n }}\n >\n {slotProps.searchButton?.children ?? \"Search\"}\n </Button>\n </div>\n );\n}\n"],"names":["SearchOpenIcon","props","width","height","rest","_jsxs","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","xmlns","viewBox","_jsx","d","cx","cy","r","SearchIcon","children","SearchCloseIcon","ClearIcon","SearchInput","ref","className","size","variant","disabled","disableEndIconGutters","disableStartIconGutters","disableInputGutters","slotProps","value","onChange","onSearch","onClear","collapsed","setCollapsed","useState","internalValue","setInternalValue","inputRef","useRef","isControlled","undefined","currentValue","searchInputRoot","cn","styles","root","String","trim","Button","clearButton","onClick","e","type","searchCollapseToggle","TextInput","mergeRefs","input","target","inputWrapper","searchButton","current"],"mappings":"kTAqBM,SAAUA,EAAeC,GAC7B,MAAMC,MAAEA,EAAQ,GAAEC,OAAEA,EAASD,KAAUE,GAASH,EAChD,O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EALgB,CAAA,KASvBL,EAAC6C,EAAS,CACRF,KAAK,SACLjC,IAAKoC,EAAUlB,EAAUlB,GACzBC,UAAWuB,EAAGC,EAAOY,MAAOpC,GAC5BC,KAAMA,EACNI,wBAAyBA,GAA2BO,EACpDR,sBAAuBA,GAAyBQ,EAChDN,oBAAqBA,GAAuBM,EAC5CT,SAAUA,GAAYS,EACtBJ,MAAOa,EACPZ,SArEgBsB,IACfZ,GACHH,EAAiBe,EAAEM,OAAO7B,OAE5BC,IAAWsB,IAkEPxB,UAAW,IACNA,EACH+B,aAAc,IACT/B,EAAU+B,aACbtC,UAAWuB,EACThB,EAAU+B,cAActC,UACxBY,EAAYY,EAAOc,aAAe,SAIpC1D,IAGNS,EAACuC,EAAM,IACDrB,EAAUgC,aACdtC,KAAMM,EAAUgC,cAActC,MAAQA,EACtCD,UAAWuB,EAAGC,EAAOe,aAAchC,EAAUgC,cAAcvC,WAC3DG,SACEI,EAAUgC,cAAcpC,UACxBS,IACCc,OAAOL,GAAcM,OAExBG,QAAUC,IACRxB,EAAUgC,cAAcT,UAAUC,GAC9Bd,EAASuB,SAAShC,OAAOE,IAAWO,EAASuB,SAAShC,QAC3Db,SAEAY,EAAUgC,cAAc5C,UAAY,aAI7C"}
|
|
1
|
+
{"version":3,"file":"SearchInput.js","sources":["../../../src/Inputs/SearchInput/SearchInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn, mergeRefs } from \"@studiocubics/utils\";\nimport { useRef, useState, type ComponentProps } from \"react\";\nimport styles from \"./SearchInput.module.css\";\nimport { type ButtonProps, Button } from \"../Button/Button\";\nimport { type TextInputProps, TextInput } from \"../TextInput/TextInput\";\n\nexport interface SearchInputProps extends Omit<TextInputProps, \"slotProps\"> {\n variant?: \"collapsible\" | \"default\";\n slotProps?: TextInputProps[\"slotProps\"] & {\n searchInputRoot?: ComponentProps<\"div\">;\n searchCollapseToggle?: ButtonProps;\n searchButton?: ButtonProps;\n clearButton?: ButtonProps;\n };\n onSearch?: (query: string) => void;\n onClear?: () => void;\n // inputVariant:TextInputProps[\"variant\"]\n}\n\nfunction SearchOpenIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n {/* <path d=\"m13 13.5 2-2.5-2-2.5\" /> */}\n <path d=\"m21 21-4.3-4.3\" />\n <path d=\"M9 8.5 7 11l2 2.5\" />\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n </svg>\n );\n}\nfunction SearchIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n {/* <path d=\"m13 13.5 2-2.5-2-2.5\" /> */}\n <path d=\"m21 21-4.3-4.3\" />\n {/* <path d=\"M9 8.5 7 11l2 2.5\" /> */}\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n </svg>\n );\n}\nfunction SearchCloseIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <path d=\"m13 13.5 2-2.5-2-2.5\" />\n <path d=\"m21 21-4.3-4.3\" />\n {/* <path d=\"M9 8.5 7 11l2 2.5\" /> */}\n <circle cx=\"11\" cy=\"11\" r=\"8\" />\n </svg>\n );\n}\nfunction ClearIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <path d=\"M18 6 6 18\" />\n <path d=\"m6 6 12 12\" />\n </svg>\n );\n}\n\nexport function SearchInput(props: SearchInputProps) {\n const {\n ref,\n className,\n size = \"sm\",\n variant = \"default\",\n disabled,\n disableEndIconGutters,\n disableStartIconGutters,\n disableInputGutters,\n slotProps = {},\n value,\n onChange,\n onSearch,\n onClear,\n ...rest\n } = props;\n\n const [collapsed, setCollapsed] = useState(variant == \"collapsible\");\n const [internalValue, setInternalValue] = useState(\"\");\n const inputRef = useRef<HTMLInputElement>(null);\n\n // Use controlled value if provided, otherwise use internal state\n const isControlled = value !== undefined;\n const currentValue = isControlled ? value : internalValue;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!isControlled) {\n setInternalValue(e.target.value);\n }\n onChange?.(e);\n };\n\n const handleClear = (e: React.MouseEvent<HTMLButtonElement>) => {\n if (!isControlled) {\n setInternalValue(\"\");\n }\n slotProps.clearButton?.onClick?.(e);\n onClear?.();\n };\n\n return (\n <div\n {...slotProps.searchInputRoot}\n className={cn(\n styles.root,\n collapsed ? styles.collapsed : \"\",\n slotProps.searchInputRoot?.className,\n )}\n >\n {String(currentValue).trim() ? (\n <Button\n {...slotProps.clearButton}\n size={slotProps.clearButton?.size || size}\n className={cn(styles.clearButton, slotProps.clearButton?.className)}\n disabled={slotProps.clearButton?.disabled || collapsed}\n onClick={handleClear}\n type={slotProps.clearButton?.type || \"button\"}\n >\n {slotProps.clearButton?.children ?? <ClearIcon />}\n </Button>\n ) : (\n <Button\n {...slotProps.searchCollapseToggle}\n size={slotProps.searchCollapseToggle?.size || size}\n onClick={(e) => {\n slotProps.searchCollapseToggle?.onClick?.(e);\n setCollapsed(!collapsed);\n }}\n disabled={\n slotProps.searchCollapseToggle?.disabled || variant != \"collapsible\"\n }\n type={slotProps.searchCollapseToggle?.type || \"button\"}\n >\n {variant == \"collapsible\" ? (\n collapsed ? (\n <SearchOpenIcon />\n ) : (\n <SearchCloseIcon />\n )\n ) : (\n <SearchIcon />\n )}\n </Button>\n )}\n <TextInput\n type=\"search\"\n ref={mergeRefs(inputRef, ref)}\n className={cn(styles.input, className)}\n size={size}\n disableStartIconGutters={disableStartIconGutters || collapsed}\n disableEndIconGutters={disableEndIconGutters || collapsed}\n disableInputGutters={disableInputGutters || collapsed}\n disabled={disabled || collapsed}\n value={currentValue}\n onChange={handleChange}\n slotProps={{\n ...slotProps,\n inputWrapper: {\n ...slotProps.inputWrapper,\n className: cn(\n slotProps.inputWrapper?.className,\n collapsed ? styles.inputWrapper : \"\",\n ),\n },\n }}\n {...rest}\n />\n\n <Button\n {...slotProps.searchButton}\n size={slotProps.searchButton?.size || size}\n className={cn(styles.searchButton, slotProps.searchButton?.className)}\n disabled={\n slotProps.searchButton?.disabled ||\n collapsed ||\n !String(currentValue).trim()\n }\n onClick={(e) => {\n slotProps.searchButton?.onClick?.(e);\n if (inputRef.current?.value) onSearch?.(inputRef.current?.value);\n }}\n >\n {slotProps.searchButton?.children ?? \"Search\"}\n </Button>\n </div>\n );\n}\n"],"names":["SearchOpenIcon","props","width","height","rest","_jsxs","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","xmlns","viewBox","_jsx","d","cx","cy","r","SearchIcon","children","SearchCloseIcon","ClearIcon","SearchInput","ref","className","size","variant","disabled","disableEndIconGutters","disableStartIconGutters","disableInputGutters","slotProps","value","onChange","onSearch","onClear","collapsed","setCollapsed","useState","internalValue","setInternalValue","inputRef","useRef","isControlled","undefined","currentValue","searchInputRoot","cn","styles","root","String","trim","Button","clearButton","onClick","e","type","searchCollapseToggle","TextInput","mergeRefs","input","target","inputWrapper","searchButton","current"],"mapp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zB,EAAU0B,sBAAsBD,MAAQ,SAAQrC,SAIlDN,EAFQ,eAAXa,EACCU,EACGpC,EAEAoB,EAGFF,EALgB,CAAA,KASvBL,EAAC6C,EAAS,CACRF,KAAK,SACLjC,IAAKoC,EAAUlB,EAAUlB,GACzBC,UAAWuB,EAAGC,EAAOY,MAAOpC,GAC5BC,KAAMA,EACNI,wBAAyBA,GAA2BO,EACpDR,sBAAuBA,GAAyBQ,EAChDN,oBAAqBA,GAAuBM,EAC5CT,SAAUA,GAAYS,EACtBJ,MAAOa,EACPZ,SArEgBsB,IACfZ,GACHH,EAAiBe,EAAEM,OAAO7B,OAE5BC,IAAWsB,IAkEPxB,UAAW,IACNA,EACH+B,aAAc,IACT/B,EAAU+B,aACbtC,UAAWuB,EACThB,EAAU+B,cAActC,UACxBY,EAAYY,EAAOc,aAAe,SAIpC1D,IAGNS,EAACuC,EAAM,IACDrB,EAAUgC,aACdtC,KAAMM,EAAUgC,cAActC,MAAQA,EACtCD,UAAWuB,EAAGC,EAAOe,aAAchC,EAAUgC,cAAcvC,WAC3DG,SACEI,EAAUgC,cAAcpC,UACxBS,IACCc,OAAOL,GAAcM,OAExBG,QAAUC,IACRxB,EAAUgC,cAAcT,UAAUC,GAC9Bd,EAASuB,SAAShC,OAAOE,IAAWO,EAASuB,SAAShC,QAC3Db,SAEAY,EAAUgC,cAAc5C,UAAY,aAI7C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsxs as e,jsx as r}from"react/jsx-runtime";import{cn as
|
|
1
|
+
"use client";import{jsxs as e,jsx as r}from"react/jsx-runtime";import{toCamelCase as s,cn as t}from"@studiocubics/utils";import{useState as l,useEffect as o}from"react";import a from"./Select.module.css.js";import{useRipple as i,eventWithRipple as n}from"../../Misc/Ripple/Ripple.js";import{InputErrors as c}from"../../Display/InputErrors/InputErrors.js";function p(p){const{startIcon:m,endIcon:d,label:u,error:N,fullWidth:h,disableEndIconGutters:b=!1,disableStartIconGutters:I=!1,size:f="md",htmlSize:v,onTouchStart:S,onClick:W,onBlur:j,slotProps:z,className:C,...E}=p,G=z??{},{rippleElements:x,createRipple:R}=i(G.ripple),[T,g]=l(N&&!!N.length),k=p.id??s(u);return o(()=>{g(N&&!!N.length)},[N]),e("div",{...G.root,className:t(G.root?.className,a.root,a[`size_${f}`],h?a.fullWidth:void 0,T?a.errored:void 0),children:[u&&r("label",{...G.label,htmlFor:k,className:t(G.label?.className,a.label),children:u}),e("div",{...G.inputWrapper,className:t(G.inputWrapper?.className,a.inputWrapper),children:[m&&r("span",{...G.startIcon,className:t(a.iconContainer,G.startIcon?.className,I?a.disableGutters:void 0),children:m}),r("select",{className:t(C,a.input),onTouchStart:n(R,S),onClick:n(R,W),onBlur:e=>{g(!1),j?.(e)},id:k,size:v,...E}),d&&r("span",{...G.endIcon,className:t(a.iconContainer,G.endIcon?.className,b?a.disableGutters:void 0),children:d}),x]}),T&&r(c,{...G.error,className:t(G.error?.className,a.errorText),error:N})]})}export{p as Select};
|
|
2
2
|
//# sourceMappingURL=Select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.js","sources":["../../../src/Inputs/Select/Select.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn } from \"@studiocubics/utils\";\nimport {\n useEffect,\n useState,\n type ComponentProps,\n type ReactNode,\n} from \"react\";\nimport styles from \"./Select.module.css\";\nimport {\n eventWithRipple,\n useRipple,\n type UseRippleProps,\n} from \"../../Misc/Ripple/Ripple\";\nimport {\n InputErrors,\n type InputErrorsProps,\n} from \"../../Display/InputErrors/InputErrors\";\n\nexport interface SelectProps extends Omit<ComponentProps<\"select\">, \"size\"> {\n startIcon?: ReactNode;\n endIcon?: ReactNode;\n label?: string;\n error?: string | string[];\n fullWidth?: boolean;\n disableEndIconGutters?: boolean;\n disableStartIconGutters?: boolean;\n size?: \"sm\" | \"md\" | \"lg\";\n htmlSize?: ComponentProps<\"select\">[\"size\"];\n slotProps?: {\n ripple?: UseRippleProps;\n startIcon?: ComponentProps<\"span\">;\n endIcon?: ComponentProps<\"span\">;\n root?: ComponentProps<\"div\">;\n inputWrapper?: ComponentProps<\"div\">;\n label?: ComponentProps<\"label\">;\n error?: InputErrorsProps;\n };\n}\n\nexport function Select(props: SelectProps) {\n const {\n startIcon,\n endIcon,\n label,\n error,\n fullWidth,\n disableEndIconGutters = false,\n disableStartIconGutters = false,\n size = \"md\",\n htmlSize,\n onTouchStart,\n onClick,\n onBlur,\n slotProps: _slotProps,\n className: inputClass,\n ...inputProps\n } = props;\n const slotProps: NonNullable<SelectProps[\"slotProps\"]> = _slotProps ?? {};\n const { rippleElements, createRipple } = useRipple<HTMLSelectElement>(\n slotProps.ripple,\n );\n const [isErrored, setIsErrored] = useState(error && !!error.length);\n\n useEffect(() => {\n setIsErrored(error && !!error.length);\n }, [error]);\n\n return (\n <div\n {...slotProps.root}\n className={cn(\n slotProps.root?.className,\n styles.root,\n styles[`size_${size}`],\n fullWidth ? styles.fullWidth : undefined,\n isErrored ? styles.errored : undefined,\n )}\n >\n {label && (\n <label\n {...slotProps.label}\n htmlFor={
|
|
1
|
+
{"version":3,"file":"Select.js","sources":["../../../src/Inputs/Select/Select.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn, toCamelCase } from \"@studiocubics/utils\";\nimport {\n useEffect,\n useState,\n type ComponentProps,\n type ReactNode,\n} from \"react\";\nimport styles from \"./Select.module.css\";\nimport {\n eventWithRipple,\n useRipple,\n type UseRippleProps,\n} from \"../../Misc/Ripple/Ripple\";\nimport {\n InputErrors,\n type InputErrorsProps,\n} from \"../../Display/InputErrors/InputErrors\";\n\nexport interface SelectProps extends Omit<ComponentProps<\"select\">, \"size\"> {\n startIcon?: ReactNode;\n endIcon?: ReactNode;\n label?: string;\n error?: string | string[];\n fullWidth?: boolean;\n disableEndIconGutters?: boolean;\n disableStartIconGutters?: boolean;\n size?: \"sm\" | \"md\" | \"lg\";\n htmlSize?: ComponentProps<\"select\">[\"size\"];\n slotProps?: {\n ripple?: UseRippleProps;\n startIcon?: ComponentProps<\"span\">;\n endIcon?: ComponentProps<\"span\">;\n root?: ComponentProps<\"div\">;\n inputWrapper?: ComponentProps<\"div\">;\n label?: ComponentProps<\"label\">;\n error?: InputErrorsProps;\n };\n}\n\nexport function Select(props: SelectProps) {\n const {\n startIcon,\n endIcon,\n label,\n error,\n fullWidth,\n disableEndIconGutters = false,\n disableStartIconGutters = false,\n size = \"md\",\n htmlSize,\n onTouchStart,\n onClick,\n onBlur,\n slotProps: _slotProps,\n className: inputClass,\n ...inputProps\n } = props;\n const slotProps: NonNullable<SelectProps[\"slotProps\"]> = _slotProps ?? {};\n const { rippleElements, createRipple } = useRipple<HTMLSelectElement>(\n slotProps.ripple,\n );\n const [isErrored, setIsErrored] = useState(error && !!error.length);\n const id = props.id ?? toCamelCase(label);\n\n useEffect(() => {\n setIsErrored(error && !!error.length);\n }, [error]);\n\n return (\n <div\n {...slotProps.root}\n className={cn(\n slotProps.root?.className,\n styles.root,\n styles[`size_${size}`],\n fullWidth ? styles.fullWidth : undefined,\n isErrored ? styles.errored : undefined,\n )}\n >\n {label && (\n <label\n {...slotProps.label}\n htmlFor={id}\n className={cn(slotProps.label?.className, styles.label)}\n >\n {label}\n </label>\n )}\n <div\n {...slotProps.inputWrapper}\n className={cn(slotProps.inputWrapper?.className, styles.inputWrapper)}\n >\n {startIcon && (\n <span\n {...slotProps.startIcon}\n className={cn(\n styles.iconContainer,\n slotProps.startIcon?.className,\n disableStartIconGutters ? styles.disableGutters : undefined,\n )}\n >\n {startIcon}\n </span>\n )}\n <select\n className={cn(inputClass, styles.input)}\n onTouchStart={eventWithRipple(createRipple, onTouchStart)}\n //TODO Causes issue on Firefox where the ripple fires after closing the dropdown\n onClick={eventWithRipple(createRipple, onClick)}\n onBlur={(e) => {\n setIsErrored(false);\n onBlur?.(e);\n }}\n id={id}\n size={htmlSize}\n {...inputProps}\n />\n {endIcon && (\n <span\n {...slotProps.endIcon}\n className={cn(\n styles.iconContainer,\n slotProps.endIcon?.className,\n disableEndIconGutters ? styles.disableGutters : undefined,\n )}\n >\n {endIcon}\n </span>\n )}\n {rippleElements}\n </div>\n {isErrored && (\n <InputErrors\n {...slotProps.error}\n className={cn(slotProps.error?.className, styles.errorText)}\n error={error}\n />\n )}\n </div>\n );\n}\n"],"names":["Select","props","startIcon","endIcon","label","error","fullWidth","disableEndIconGutters","disableStartIconGutters","size","htmlSize","onTouchStart","onClick","onBlur","slotProps","_slotProps","className","inputClass","inputProps","rippleElements","createRipple","useRipple","ripple","isErrored","setIsErrored","useState","length","id","toCamelCase","useEffect","_jsxs","root","cn","styles","undefined","errored","_jsx","htmlFor","children","inputWrapper","iconContainer","disableGutters","input","eventWithRipple","e","InputErrors","errorText"],"mappings":"mWAyCM,SAAUA,EAAOC,GACrB,MAAMC,UACJA,EAASC,QACTA,EAAOC,MACPA,EAAKC,MACLA,EAAKC,UACLA,EAASC,sBACTA,GAAwB,EAAKC,wBAC7BA,GAA0B,EAAKC,KAC/BA,EAAO,KAAIC,SACXA,EAAQC,aACRA,EAAYC,QACZA,EAAOC,OACPA,EACAC,UAAWC,EACXC,UAAWC,KACRC,GACDjB,EACEa,EAAmDC,GAAc,CAAA,GACjEI,eAAEA,EAAcC,aAAEA,GAAiBC,EACvCP,EAAUQ,SAELC,EAAWC,GAAgBC,EAASpB,KAAWA,EAAMqB,QACtDC,EAAK1B,EAAM0B,IAAMC,EAAYxB,GAMnC,OAJAyB,EAAU,KACRL,EAAanB,KAAWA,EAAMqB,SAC7B,CAACrB,IAGFyB,EAAA,MAAA,IACMhB,EAAUiB,KACdf,UAAWgB,EACTlB,EAAUiB,MAAMf,UAChBiB,EAAOF,KACPE,EAAO,QAAQxB,KACfH,EAAY2B,EAAO3B,eAAY4B,EAC/BX,EAAYU,EAAOE,aAAUD,aAG9B9B,GACCgC,EAAA,QAAA,IACMtB,EAAUV,MACdiC,QAASV,EACTX,UAAWgB,EAAGlB,EAAUV,OAAOY,UAAWiB,EAAO7B,OAAMkC,SAEtDlC,IAGL0B,EAAA,MAAA,IACMhB,EAAUyB,aACdvB,UAAWgB,EAAGlB,EAAUyB,cAAcvB,UAAWiB,EAAOM,wBAEvDrC,GACCkC,EAAA,OAAA,IACMtB,EAAUZ,UACdc,UAAWgB,EACTC,EAAOO,cACP1B,EAAUZ,WAAWc,UACrBR,EAA0ByB,EAAOQ,oBAAiBP,GACnDI,SAEApC,IAGLkC,EAAA,SAAA,CACEpB,UAAWgB,EAAGf,EAAYgB,EAAOS,OACjC/B,aAAcgC,EAAgBvB,EAAcT,GAE5CC,QAAS+B,EAAgBvB,EAAcR,GACvCC,OAAS+B,IACPpB,GAAa,GACbX,IAAS+B,IAEXjB,GAAIA,EACJlB,KAAMC,KACFQ,IAELf,GACCiC,EAAA,OAAA,IACMtB,EAAUX,QACda,UAAWgB,EACTC,EAAOO,cACP1B,EAAUX,SAASa,UACnBT,EAAwB0B,EAAOQ,oBAAiBP,GACjDI,SAEAnC,IAGJgB,KAEFI,GACCa,EAACS,MACK/B,EAAUT,MACdW,UAAWgB,EAAGlB,EAAUT,OAAOW,UAAWiB,EAAOa,WACjDzC,MAAOA,MAKjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useRef as r,useState as c,useEffect as n,useCallback as o}from"react";import a from"./Switch.module.css.js";import{
|
|
1
|
+
"use client";import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useRef as r,useState as c,useEffect as n,useCallback as o}from"react";import a from"./Switch.module.css.js";import{toCamelCase as s,cn as u,mergeRefs as i}from"@studiocubics/utils";function l(l){const{value:d,defaultValue:m,type:h="checkbox",onChange:p,className:v,ref:b,label:f,"aria-label":k,icon:E,disabled:N,slotProps:L={},color:g,size:w="md",htmlSize:z,...C}=l,X=r(null),x=r(null),S=void 0!==d,[W,j]=c(m??!1),y=S?d??!1:W,M=r(!1),T=r(!1),D=r(0),F=r(y),P=l.id??s(f);n(()=>{F.current=y},[y]);const V=o(e=>{if(S||j(e),X.current&&p){const t=X.current;t.checked=e;const r=new Event("change",{bubbles:!0});t.dispatchEvent(r)}},[S,p]),q=o(e=>{N||(M.current=!0,T.current=!1,D.current=e)},[N]),A=o(e=>{if(!M.current||N)return;const t=e-D.current;if(Math.abs(t)>10){T.current=!0;const e=t>0;e!==F.current&&V(e)}},[N,V]),B=o(()=>{M.current=!1},[]);return n(()=>{const e=e=>A(e.clientX),t=e=>A(e.touches[0].clientX);return document.addEventListener("mousemove",e),document.addEventListener("mouseup",B),document.addEventListener("touchmove",t),document.addEventListener("touchend",B),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",B),document.removeEventListener("touchmove",t),document.removeEventListener("touchend",B)}},[A,B]),e("div",{...L.root,"data-color":g,"data-size":w,className:u(L.root?.className,v,a.root,N?a.disabled:""),children:[e("div",{...L.inputWrapper,className:u(a.inputWrapper,L.inputWrapper?.className),children:[t("input",{...C,id:P,size:z,type:h,ref:i(b,X),className:a.input,role:"switch","aria-checked":y,"aria-label":k??f,checked:S?y:void 0,defaultChecked:S?void 0:m,disabled:N,onChange:e=>{const t=e.currentTarget.checked;S||j(t),p&&p(e,t)}}),t("span",{className:u(a.track,y?a.checked:""),onClick:()=>{T.current?T.current=!1:X.current?.click()},"aria-hidden":"true",children:t("span",{ref:x,className:a.thumb,onMouseDown:e=>q(e.clientX),onTouchStart:e=>q(e.touches[0].clientX),children:E})})]}),f&&t("label",{...L.label,htmlFor:P,className:u(L.label?.className,a.label),children:f})]})}export{l as Switch};
|
|
2
2
|
//# sourceMappingURL=Switch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.js","sources":["../../../src/Inputs/Switch/Switch.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ChangeEvent,\n type ComponentProps,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n useCallback,\n} from \"react\";\nimport styles from \"./Switch.module.css\";\nimport { cn, mergeRefs, toCamelCase } from \"@studiocubics/utils\";\n\n/**\n * Props for the Switch component\n *\n * @group switch\n * @category inputs\n */\nexport interface SwitchProps\n extends Omit<\n ComponentProps<\"input\">,\n \"defaultValue\" | \"value\" | \"onChange\" | \"size\"\n > {\n /**\n * Default value of the switch in boolean\n */\n defaultValue?: boolean;\n /**\n * Value of the switch in boolean\n */\n value?: boolean | null;\n /**\n * Event handler for when the value of the switch changes\n */\n onChange?: (e: ChangeEvent<HTMLInputElement>, checked: boolean) => void;\n /**\n * Label for the switch\n */\n label?: string;\n /**\n * Icon to render in the thumb of the switch\n */\n icon?: ReactNode;\n /**\n * Switch slots props\n */\n slotProps?: {\n root?: ComponentProps<\"div\">;\n inputWrapper?: ComponentProps<\"div\">;\n label?: ComponentProps<\"label\">;\n track?: ComponentProps<\"span\">;\n };\n color?: \"primary\" | \"secondary\" | \"error\";\n size?: \"sm\" | \"md\" | \"lg\";\n htmlSize?: ComponentProps<\"input\">[\"size\"];\n}\n\n/**\n * A switch can be used to show on/off state for form inputs, theme toggles etc.\n *\n * @group switch\n * @category inputs\n */\nexport function Switch(props: SwitchProps) {\n const {\n value,\n defaultValue,\n type = \"checkbox\",\n onChange,\n className,\n ref,\n label,\n \"aria-label\": ariaLabel,\n icon,\n disabled,\n slotProps = {},\n color,\n size = \"md\",\n htmlSize,\n ...rest\n } = props;\n\n const inputRef = useRef<HTMLInputElement>(null);\n const thumbRef = useRef<HTMLSpanElement>(null);\n\n const isControlled = value !== undefined;\n const [internalChecked, setInternalChecked] = useState<boolean>(\n defaultValue ?? false,\n );\n const checked = isControlled ? (value ?? false) : internalChecked;\n\n const isDragging = useRef(false);\n const didDrag = useRef(false);\n const dragStartX = useRef(0);\n\n const checkedRef = useRef(checked);\n useEffect(() => {\n checkedRef.current = checked;\n }, [checked]);\n\n const triggerChange = useCallback(\n (newChecked: boolean) => {\n if (!isControlled) setInternalChecked(newChecked);\n if (inputRef.current && onChange) {\n const nativeInput = inputRef.current;\n nativeInput.checked = newChecked;\n const nativeEvent = new Event(\"change\", { bubbles: true });\n nativeInput.dispatchEvent(nativeEvent);\n }\n },\n [isControlled, onChange],\n );\n\n const handleDragStart = useCallback(\n (clientX: number) => {\n if (disabled) return;\n isDragging.current = true;\n didDrag.current = false;\n dragStartX.current = clientX;\n },\n [disabled],\n );\n\n const handleDragMove = useCallback(\n (clientX: number) => {\n if (!isDragging.current || disabled) return;\n\n const delta = clientX - dragStartX.current;\n const threshold = 10; // Minimum drag distance to trigger change\n\n if (Math.abs(delta) > threshold) {\n didDrag.current = true;\n const newChecked = delta > 0;\n if (newChecked !== checkedRef.current) {\n triggerChange(newChecked);\n }\n }\n },\n [disabled, triggerChange],\n );\n\n const handleDragEnd = useCallback(() => {\n isDragging.current = false;\n // didDrag.current is intentionally NOT reset here;\n // it stays true until the subsequent click event reads and clears it\n }, []);\n\n useEffect(() => {\n const handleMouseMove = (e: MouseEvent) => handleDragMove(e.clientX);\n const handleTouchMove = (e: TouchEvent) =>\n handleDragMove(e.touches[0].clientX);\n\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseup\", handleDragEnd);\n document.addEventListener(\"touchmove\", handleTouchMove);\n document.addEventListener(\"touchend\", handleDragEnd);\n\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseup\", handleDragEnd);\n document.removeEventListener(\"touchmove\", handleTouchMove);\n document.removeEventListener(\"touchend\", handleDragEnd);\n };\n }, [handleDragMove, handleDragEnd]);\n\n return (\n <div\n {...slotProps.root}\n data-color={color}\n data-size={size}\n className={cn(\n slotProps.root?.className,\n className,\n styles.root,\n disabled ? styles.disabled : \"\",\n )}\n >\n <div\n {...slotProps.inputWrapper}\n className={cn(styles.inputWrapper, slotProps.inputWrapper?.className)}\n >\n <input\n {...rest}\n size={htmlSize}\n type={type}\n ref={mergeRefs(ref, inputRef)}\n className={styles.input}\n role=\"switch\"\n aria-checked={checked}\n aria-label={ariaLabel ?? label}\n checked={isControlled ? checked : undefined}\n defaultChecked={!isControlled ? defaultValue : undefined}\n disabled={disabled}\n onChange={(e) => {\n const c = e.currentTarget.checked;\n if (!isControlled) setInternalChecked(c);\n if (onChange) onChange(e, c);\n }}\n />\n <span\n className={cn(styles.track, checked ? styles.checked : \"\")}\n onClick={() => {\n if (didDrag.current) {\n didDrag.current = false;\n return;\n }\n inputRef.current?.click();\n }}\n aria-hidden=\"true\"\n >\n <span\n ref={thumbRef}\n className={styles.thumb}\n onMouseDown={(e) => handleDragStart(e.clientX)}\n onTouchStart={(e) => handleDragStart(e.touches[0].clientX)}\n >\n {icon}\n </span>\n </span>\n </div>\n {label && (\n <label\n {...slotProps.label}\n htmlFor={
|
|
1
|
+
{"version":3,"file":"Switch.js","sources":["../../../src/Inputs/Switch/Switch.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ChangeEvent,\n type ComponentProps,\n type ReactNode,\n useEffect,\n useRef,\n useState,\n useCallback,\n} from \"react\";\nimport styles from \"./Switch.module.css\";\nimport { cn, mergeRefs, toCamelCase } from \"@studiocubics/utils\";\n\n/**\n * Props for the Switch component\n *\n * @group switch\n * @category inputs\n */\nexport interface SwitchProps\n extends Omit<\n ComponentProps<\"input\">,\n \"defaultValue\" | \"value\" | \"onChange\" | \"size\"\n > {\n /**\n * Default value of the switch in boolean\n */\n defaultValue?: boolean;\n /**\n * Value of the switch in boolean\n */\n value?: boolean | null;\n /**\n * Event handler for when the value of the switch changes\n */\n onChange?: (e: ChangeEvent<HTMLInputElement>, checked: boolean) => void;\n /**\n * Label for the switch\n */\n label?: string;\n /**\n * Icon to render in the thumb of the switch\n */\n icon?: ReactNode;\n /**\n * Switch slots props\n */\n slotProps?: {\n root?: ComponentProps<\"div\">;\n inputWrapper?: ComponentProps<\"div\">;\n label?: ComponentProps<\"label\">;\n track?: ComponentProps<\"span\">;\n };\n color?: \"primary\" | \"secondary\" | \"error\";\n size?: \"sm\" | \"md\" | \"lg\";\n htmlSize?: ComponentProps<\"input\">[\"size\"];\n}\n\n/**\n * A switch can be used to show on/off state for form inputs, theme toggles etc.\n *\n * @group switch\n * @category inputs\n */\nexport function Switch(props: SwitchProps) {\n const {\n value,\n defaultValue,\n type = \"checkbox\",\n onChange,\n className,\n ref,\n label,\n \"aria-label\": ariaLabel,\n icon,\n disabled,\n slotProps = {},\n color,\n size = \"md\",\n htmlSize,\n ...rest\n } = props;\n\n const inputRef = useRef<HTMLInputElement>(null);\n const thumbRef = useRef<HTMLSpanElement>(null);\n\n const isControlled = value !== undefined;\n const [internalChecked, setInternalChecked] = useState<boolean>(\n defaultValue ?? false,\n );\n const checked = isControlled ? (value ?? false) : internalChecked;\n\n const isDragging = useRef(false);\n const didDrag = useRef(false);\n const dragStartX = useRef(0);\n\n const checkedRef = useRef(checked);\n const id = props.id ?? toCamelCase(label);\n\n useEffect(() => {\n checkedRef.current = checked;\n }, [checked]);\n\n const triggerChange = useCallback(\n (newChecked: boolean) => {\n if (!isControlled) setInternalChecked(newChecked);\n if (inputRef.current && onChange) {\n const nativeInput = inputRef.current;\n nativeInput.checked = newChecked;\n const nativeEvent = new Event(\"change\", { bubbles: true });\n nativeInput.dispatchEvent(nativeEvent);\n }\n },\n [isControlled, onChange],\n );\n\n const handleDragStart = useCallback(\n (clientX: number) => {\n if (disabled) return;\n isDragging.current = true;\n didDrag.current = false;\n dragStartX.current = clientX;\n },\n [disabled],\n );\n\n const handleDragMove = useCallback(\n (clientX: number) => {\n if (!isDragging.current || disabled) return;\n\n const delta = clientX - dragStartX.current;\n const threshold = 10; // Minimum drag distance to trigger change\n\n if (Math.abs(delta) > threshold) {\n didDrag.current = true;\n const newChecked = delta > 0;\n if (newChecked !== checkedRef.current) {\n triggerChange(newChecked);\n }\n }\n },\n [disabled, triggerChange],\n );\n\n const handleDragEnd = useCallback(() => {\n isDragging.current = false;\n // didDrag.current is intentionally NOT reset here;\n // it stays true until the subsequent click event reads and clears it\n }, []);\n\n useEffect(() => {\n const handleMouseMove = (e: MouseEvent) => handleDragMove(e.clientX);\n const handleTouchMove = (e: TouchEvent) =>\n handleDragMove(e.touches[0].clientX);\n\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseup\", handleDragEnd);\n document.addEventListener(\"touchmove\", handleTouchMove);\n document.addEventListener(\"touchend\", handleDragEnd);\n\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseup\", handleDragEnd);\n document.removeEventListener(\"touchmove\", handleTouchMove);\n document.removeEventListener(\"touchend\", handleDragEnd);\n };\n }, [handleDragMove, handleDragEnd]);\n\n return (\n <div\n {...slotProps.root}\n data-color={color}\n data-size={size}\n className={cn(\n slotProps.root?.className,\n className,\n styles.root,\n disabled ? styles.disabled : \"\",\n )}\n >\n <div\n {...slotProps.inputWrapper}\n className={cn(styles.inputWrapper, slotProps.inputWrapper?.className)}\n >\n <input\n {...rest}\n id={id}\n size={htmlSize}\n type={type}\n ref={mergeRefs(ref, inputRef)}\n className={styles.input}\n role=\"switch\"\n aria-checked={checked}\n aria-label={ariaLabel ?? label}\n checked={isControlled ? checked : undefined}\n defaultChecked={!isControlled ? defaultValue : undefined}\n disabled={disabled}\n onChange={(e) => {\n const c = e.currentTarget.checked;\n if (!isControlled) setInternalChecked(c);\n if (onChange) onChange(e, c);\n }}\n />\n <span\n className={cn(styles.track, checked ? styles.checked : \"\")}\n onClick={() => {\n if (didDrag.current) {\n didDrag.current = false;\n return;\n }\n inputRef.current?.click();\n }}\n aria-hidden=\"true\"\n >\n <span\n ref={thumbRef}\n className={styles.thumb}\n onMouseDown={(e) => handleDragStart(e.clientX)}\n onTouchStart={(e) => handleDragStart(e.touches[0].clientX)}\n >\n {icon}\n </span>\n </span>\n </div>\n {label && (\n <label\n {...slotProps.label}\n htmlFor={id}\n className={cn(slotProps.label?.className, styles.label)}\n >\n {label}\n </label>\n )}\n </div>\n );\n}\n"],"names":["Switch","props","value","defaultValue","type","onChange","className","ref","label","ariaLabel","icon","disabled","slotProps","color","size","htmlSize","rest","inputRef","useRef","thumbRef","isControlled","undefined","internalChecked","setInternalChecked","useState","checked","isDragging","didDrag","dragStartX","checkedRef","id","toCamelCase","useEffect","current","triggerChange","useCallback","newChecked","nativeInput","nativeEvent","Event","bubbles","dispatchEvent","handleDragStart","clientX","handleDragMove","delta","Math","abs","handleDragEnd","handleMouseMove","e","handleTouchMove","touches","document","addEventListener","removeEventListener","_jsxs","root","cn","styles","children","inputWrapper","_jsx","mergeRefs","input","role","defaultChecked","c","currentTarget","track","onClick","click","thumb","onMouseDown","onTouchStart","htmlFor"],"mappings":"2PAiEM,SAAUA,EAAOC,GACrB,MAAMC,MACJA,EAAKC,aACLA,EAAYC,KACZA,EAAO,WAAUC,SACjBA,EAAQC,UACRA,EAASC,IACTA,EAAGC,MACHA,EACA,aAAcC,EAASC,KACvBA,EAAIC,SACJA,EAAQC,UACRA,EAAY,CAAA,EAAEC,MACdA,EAAKC,KACLA,EAAO,KAAIC,SACXA,KACGC,GACDf,EAEEgB,EAAWC,EAAyB,MACpCC,EAAWD,EAAwB,MAEnCE,OAAyBC,IAAVnB,GACdoB,EAAiBC,GAAsBC,EAC5CrB,IAAgB,GAEZsB,EAAUL,EAAgBlB,IAAS,EAASoB,EAE5CI,EAAaR,GAAO,GACpBS,EAAUT,GAAO,GACjBU,EAAaV,EAAO,GAEpBW,EAAaX,EAAOO,GACpBK,EAAK7B,EAAM6B,IAAMC,EAAYvB,GAEnCwB,EAAU,KACRH,EAAWI,QAAUR,GACpB,CAACA,IAEJ,MAAMS,EAAgBC,EACnBC,IAEC,GADKhB,GAAcG,EAAmBa,GAClCnB,EAASgB,SAAW5B,EAAU,CAChC,MAAMgC,EAAcpB,EAASgB,QAC7BI,EAAYZ,QAAUW,EACtB,MAAME,EAAc,IAAIC,MAAM,SAAU,CAAEC,SAAS,IACnDH,EAAYI,cAAcH,EAC5B,GAEF,CAAClB,EAAcf,IAGXqC,EAAkBP,EACrBQ,IACKhC,IACJe,EAAWO,SAAU,EACrBN,EAAQM,SAAU,EAClBL,E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SAAUA,EACVN,SAAW6C,IACT,MAAMiB,EAAIjB,EAAEkB,cAAc3C,QACrBL,GAAcG,EAAmB4C,GAClC9D,GAAUA,EAAS6C,EAAGiB,MAG9BL,EAAA,OAAA,CACExD,UAAWoD,EAAGC,EAAOU,MAAO5C,EAAUkC,EAAOlC,QAAU,IACvD6C,QAAS,KACH3C,EAAQM,QACVN,EAAQM,SAAU,EAGpBhB,EAASgB,SAASsC,uBAER,OAAMX,SAElBE,UACEvD,IAAKY,EACLb,UAAWqD,EAAOa,MAClBC,YAAcvB,GAAMR,EAAgBQ,EAAEP,SACtC+B,aAAexB,GAAMR,EAAgBQ,EAAEE,QAAQ,GAAGT,SAAQiB,SAEzDlD,SAINF,GACCsD,cACMlD,EAAUJ,MACdmE,QAAS7C,EACTxB,UAAWoD,EAAG9C,EAAUJ,OAAOF,UAAWqD,EAAOnD,OAAMoD,SAEtDpD,MAKX"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ComponentProps } from "react";
|
|
2
2
|
import { type UseRippleProps } from "../../Misc/Ripple/Ripple";
|
|
3
|
-
import { type InputErrorsProps } from "../../Display/
|
|
3
|
+
import { type InputErrorsProps } from "../../Display/InputErrors/InputErrors";
|
|
4
4
|
export interface TextAreaInputProps extends ComponentProps<"textarea"> {
|
|
5
5
|
label?: string;
|
|
6
6
|
error?: string | string[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsxs as r,jsx as
|
|
1
|
+
"use client";import{jsxs as r,jsx as e}from"react/jsx-runtime";import{toCamelCase as l,cn as o}from"@studiocubics/utils";import{useState as s,useEffect as t}from"react";import{useRipple as i,eventWithRipple as a}from"../../Misc/Ripple/Ripple.js";import p from"./TextAreaInput.module.css.js";import{InputErrors as c}from"../../Display/InputErrors/InputErrors.js";function m(m){const{label:n,error:u,fullWidth:d,disableResize:h=!1,onTouchStart:N,onClick:f,onBlur:b,slotProps:v={},className:x,...R}=m,{rippleElements:W,createRipple:j}=i(v.ripple),[T,E]=s(u&&!!u.length),I=m.id??l(n);return t(()=>{E(u&&!!u.length)},[u]),r("div",{...v.root,className:o(v.root?.className,p.root,d?p.fullWidth:void 0,T?p.errored:void 0),children:[n&&e("label",{...v.label,htmlFor:I,className:o(v.label?.className,p.label),children:n}),r("div",{...v.inputWrapper,className:o(v.inputWrapper?.className,p.inputWrapper),children:[e("textarea",{...R,id:I,className:o(x,p.input,h?p.disableResize:void 0),onTouchStart:a(j,N),onClick:a(j,f),onBlur:r=>{E(!1),b?.(r)}}),W]}),T&&e(c,{...v.error,className:o(v.error?.className,p.errorText),error:u})]})}export{m as TextAreaInput};
|
|
2
2
|
//# sourceMappingURL=TextAreaInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAreaInput.js","sources":["../../../src/Inputs/TextAreaInput/TextAreaInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn } from \"@studiocubics/utils\";\nimport { useEffect, useState, type ComponentProps } from \"react\";\nimport {\n eventWithRipple,\n useRipple,\n type UseRippleProps,\n} from \"../../Misc/Ripple/Ripple\";\nimport styles from \"./TextAreaInput.module.css\";\nimport {
|
|
1
|
+
{"version":3,"file":"TextAreaInput.js","sources":["../../../src/Inputs/TextAreaInput/TextAreaInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn, toCamelCase } from \"@studiocubics/utils\";\nimport { useEffect, useState, type ComponentProps } from \"react\";\nimport {\n eventWithRipple,\n useRipple,\n type UseRippleProps,\n} from \"../../Misc/Ripple/Ripple\";\nimport styles from \"./TextAreaInput.module.css\";\nimport {\n InputErrors,\n type InputErrorsProps,\n} from \"../../Display/InputErrors/InputErrors\";\n\nexport interface TextAreaInputProps extends ComponentProps<\"textarea\"> {\n label?: string;\n error?: string | string[];\n disableResize?: boolean;\n fullWidth?: boolean;\n slotProps?: {\n ripple?: UseRippleProps;\n root?: ComponentProps<\"div\">;\n inputWrapper?: ComponentProps<\"div\">;\n label?: ComponentProps<\"label\">;\n error?: InputErrorsProps;\n };\n}\n\nexport function TextAreaInput(props: TextAreaInputProps) {\n const {\n label,\n error,\n fullWidth,\n disableResize = false,\n onTouchStart,\n onClick,\n onBlur,\n slotProps = {},\n className: inputClass,\n ...inputProps\n } = props;\n\n const { rippleElements, createRipple } = useRipple(slotProps.ripple);\n const [isErrored, setIsErrored] = useState(error && !!error.length);\n const id = props.id ?? toCamelCase(label);\n\n useEffect(() => {\n setIsErrored(error && !!error.length);\n }, [error]);\n\n return (\n <div\n {...slotProps.root}\n className={cn(\n slotProps.root?.className,\n styles.root,\n fullWidth ? styles.fullWidth : undefined,\n isErrored ? styles.errored : undefined,\n )}\n >\n {label && (\n <label\n {...slotProps.label}\n htmlFor={id}\n className={cn(slotProps.label?.className, styles.label)}\n >\n {label}\n </label>\n )}\n <div\n {...slotProps.inputWrapper}\n className={cn(slotProps.inputWrapper?.className, styles.inputWrapper)}\n >\n <textarea\n {...inputProps}\n id={id}\n className={cn(\n inputClass,\n styles.input,\n disableResize ? styles.disableResize : undefined,\n )}\n onTouchStart={eventWithRipple(createRipple, onTouchStart)}\n onClick={eventWithRipple(createRipple, onClick)}\n onBlur={(e) => {\n setIsErrored(false);\n onBlur?.(e);\n }}\n />\n {rippleElements}\n </div>\n {isErrored && (\n <InputErrors\n {...slotProps.error}\n className={cn(slotProps.error?.className, styles.errorText)}\n error={error}\n />\n )}\n </div>\n );\n}\n"],"names":["TextAreaInput","props","label","error","fullWidth","disableResize","onTouchStart","onClick","onBlur","slotProps","className","inputClass","inputProps","rippleElements","createRipple","useRipple","ripple","isErrored","setIsErrored","useState","length","id","toCamelCase","useEffect","_jsxs","root","cn","styles","undefined","errored","children","_jsx","htmlFor","inputWrapper","input","eventWithRipple","e","InputErrors","errorText"],"mappings":"0WA6BM,SAAUA,EAAcC,GAC5B,MAAMC,MACJA,EAAKC,MACLA,EAAKC,UACLA,EAASC,cACTA,GAAgB,EAAKC,aACrBA,EAAYC,QACZA,EAAOC,OACPA,EAAMC,UACNA,EAAY,CAAA,EACZC,UAAWC,KACRC,GACDX,GAEEY,eAAEA,EAAcC,aAAEA,GAAiBC,EAAUN,EAAUO,SACtDC,EAAWC,GAAgBC,EAAShB,KAAWA,EAAMiB,QACtDC,EAAKpB,EAAMoB,IAAMC,EAAYpB,GAMnC,OAJAqB,EAAU,KACRL,EAAaf,KAAWA,EAAMiB,SAC7B,CAACjB,IAGFqB,EAAA,MAAA,IACMf,EAAUgB,KACdf,UAAWgB,EACTjB,EAAUgB,MAAMf,UAChBiB,EAAOF,KACPrB,EAAYuB,EAAOvB,eAAYwB,EAC/BX,EAAYU,EAAOE,aAAUD,GAC9BE,SAAA,CAEA5B,GACC6B,EAAA,QAAA,IACMtB,EAAUP,MACd8B,QAASX,EACTX,UAAWgB,EAAGjB,EAAUP,OAAOQ,UAAWiB,EAAOzB,gBAEhDA,IAGLsB,EAAA,MAAA,IACMf,EAAUwB,aACdvB,UAAWgB,EAAGjB,EAAUwB,cAAcvB,UAAWiB,EAAOM,cAAaH,SAAA,CAErEC,EAAA,WAAA,IACMnB,EACJS,GAAIA,EACJX,UAAWgB,EACTf,EACAgB,EAAOO,MACP7B,EAAgBsB,EAAOtB,mBAAgBuB,GAEzCtB,aAAc6B,EAAgBrB,EAAcR,GAC5CC,QAAS4B,EAAgBrB,EAAcP,GACvCC,OAAS4B,IACPlB,GAAa,GACbV,IAAS4B,MAGZvB,KAEFI,GACCc,EAACM,MACK5B,EAAUN,MACdO,UAAWgB,EAAGjB,EAAUN,OAAOO,UAAWiB,EAAOW,WACjDnC,MAAOA,MAKjB"}
|
|
@@ -11,7 +11,7 @@ export interface TextInputProps extends Omit<ComponentProps<"input">, "size"> {
|
|
|
11
11
|
* Use inputSize for <input size="10"/>
|
|
12
12
|
*/
|
|
13
13
|
size?: "sm" | "md" | "lg";
|
|
14
|
-
|
|
14
|
+
htmlSize?: ComponentProps<"input">["size"];
|
|
15
15
|
disableEndIconGutters?: boolean;
|
|
16
16
|
disableStartIconGutters?: boolean;
|
|
17
17
|
disableInputGutters?: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsxs as e,jsx as r}from"react/jsx-runtime";import{cn as
|
|
1
|
+
"use client";import{jsxs as e,jsx as r}from"react/jsx-runtime";import{toCamelCase as t,cn as s}from"@studiocubics/utils";import{useState as l,useEffect as o}from"react";import{useRipple as a,eventWithRipple as i}from"../../Misc/Ripple/Ripple.js";import n from"./TextInput.module.css.js";import{InputErrors as c}from"../../Display/InputErrors/InputErrors.js";function p(p){const{startIcon:m,endIcon:d,label:u,error:N,fullWidth:h,disableEndIconGutters:b=!1,disableStartIconGutters:I=!1,disableInputGutters:f,size:v="md",htmlSize:G,onTouchStart:x,onClick:W,onBlur:j,slotProps:z={},className:C,...E}=p,{rippleElements:S,createRipple:T}=a(z.ripple),[R,g]=l(N&&!!N.length),k=p.id??t(u);return o(()=>{g(N&&!!N.length)},[N]),e("div",{...z.root,className:s(z.root?.className,n.root,n[`size_${v}`],h?n.fullWidth:void 0,R?n.errored:void 0),children:[u&&r("label",{...z.label,htmlFor:k,className:s(z.label?.className,n.label),children:u}),e("div",{...z.inputWrapper,className:s(z.inputWrapper?.className,n.inputWrapper),children:[m&&r("span",{...z.startIcon,className:s(n.iconContainer,z.startIcon?.className,I?n.disableGutters:void 0),children:m}),r("input",{...E,id:k,type:"text",className:s(C,n.input,f?n.disableGutters:""),onTouchStart:i(T,x),onClick:i(T,W),onBlur:e=>{g(!1),j?.(e)},size:G}),d&&r("span",{...z.endIcon,className:s(n.iconContainer,z.endIcon?.className,b?n.disableGutters:void 0),children:d}),S]}),R&&r(c,{...z.error,className:s(z.error?.className,n.errorText),error:N})]})}export{p as TextInput};
|
|
2
2
|
//# sourceMappingURL=TextInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextInput.js","sources":["../../../src/Inputs/TextInput/TextInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn } from \"@studiocubics/utils\";\nimport {\n useEffect,\n useState,\n type ComponentProps,\n type ReactNode,\n} from \"react\";\nimport {\n eventWithRipple,\n useRipple,\n type UseRippleProps,\n} from \"../../Misc/Ripple/Ripple\";\nimport styles from \"./TextInput.module.css\";\nimport {\n InputErrors,\n type InputErrorsProps,\n} from \"../../Display/InputErrors/InputErrors\";\n\nexport interface TextInputProps extends Omit<ComponentProps<\"input\">, \"size\"> {\n startIcon?: ReactNode;\n endIcon?: ReactNode;\n label?: string;\n error?: string | string[];\n fullWidth?: boolean;\n /**\n * Use inputSize for <input size=\"10\"/>\n */\n size?: \"sm\" | \"md\" | \"lg\";\n
|
|
1
|
+
{"version":3,"file":"TextInput.js","sources":["../../../src/Inputs/TextInput/TextInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { cn, toCamelCase } from \"@studiocubics/utils\";\nimport {\n useEffect,\n useState,\n type ComponentProps,\n type ReactNode,\n} from \"react\";\nimport {\n eventWithRipple,\n useRipple,\n type UseRippleProps,\n} from \"../../Misc/Ripple/Ripple\";\nimport styles from \"./TextInput.module.css\";\nimport {\n InputErrors,\n type InputErrorsProps,\n} from \"../../Display/InputErrors/InputErrors\";\n\nexport interface TextInputProps extends Omit<ComponentProps<\"input\">, \"size\"> {\n startIcon?: ReactNode;\n endIcon?: ReactNode;\n label?: string;\n error?: string | string[];\n fullWidth?: boolean;\n /**\n * Use inputSize for <input size=\"10\"/>\n */\n size?: \"sm\" | \"md\" | \"lg\";\n htmlSize?: ComponentProps<\"input\">[\"size\"];\n disableEndIconGutters?: boolean;\n disableStartIconGutters?: boolean;\n disableInputGutters?: boolean;\n slotProps?: {\n ripple?: UseRippleProps;\n startIcon?: ComponentProps<\"span\">;\n endIcon?: ComponentProps<\"span\">;\n root?: ComponentProps<\"div\">;\n inputWrapper?: ComponentProps<\"div\">;\n label?: ComponentProps<\"label\">;\n error?: InputErrorsProps;\n };\n}\n\nexport function TextInput(props: TextInputProps) {\n const {\n startIcon,\n endIcon,\n label,\n error,\n fullWidth,\n disableEndIconGutters = false,\n disableStartIconGutters = false,\n disableInputGutters,\n size = \"md\",\n htmlSize,\n onTouchStart,\n onClick,\n onBlur,\n slotProps = {},\n className: inputClass,\n ...inputProps\n } = props;\n const { rippleElements, createRipple } = useRipple(slotProps.ripple);\n const [isErrored, setIsErrored] = useState(error && !!error.length);\n const id = props.id ?? toCamelCase(label);\n\n useEffect(() => {\n setIsErrored(error && !!error.length);\n }, [error]);\n\n return (\n <div\n {...slotProps.root}\n className={cn(\n slotProps.root?.className,\n styles.root,\n styles[`size_${size}`],\n fullWidth ? styles.fullWidth : undefined,\n isErrored ? styles.errored : undefined,\n )}\n >\n {label && (\n <label\n {...slotProps.label}\n htmlFor={id}\n className={cn(slotProps.label?.className, styles.label)}\n >\n {label}\n </label>\n )}\n <div\n {...slotProps.inputWrapper}\n className={cn(slotProps.inputWrapper?.className, styles.inputWrapper)}\n >\n {startIcon && (\n <span\n {...slotProps.startIcon}\n className={cn(\n styles.iconContainer,\n slotProps.startIcon?.className,\n disableStartIconGutters ? styles.disableGutters : undefined,\n )}\n >\n {startIcon}\n </span>\n )}\n <input\n {...inputProps}\n id={id}\n type=\"text\"\n className={cn(\n inputClass,\n styles.input,\n disableInputGutters ? styles.disableGutters : \"\",\n )}\n onTouchStart={eventWithRipple(createRipple, onTouchStart)}\n onClick={eventWithRipple(createRipple, onClick)}\n onBlur={(e) => {\n setIsErrored(false);\n onBlur?.(e);\n }}\n size={htmlSize}\n />\n {endIcon && (\n <span\n {...slotProps.endIcon}\n className={cn(\n styles.iconContainer,\n slotProps.endIcon?.className,\n disableEndIconGutters ? styles.disableGutters : undefined,\n )}\n >\n {endIcon}\n </span>\n )}\n {rippleElements}\n </div>\n {isErrored && (\n <InputErrors\n {...slotProps.error}\n className={cn(slotProps.error?.className, styles.errorText)}\n error={error}\n />\n )}\n </div>\n );\n}\n"],"names":["TextInput","props","startIcon","endIcon","label","error","fullWidth","disableEndIconGutters","disableStartIconGutters","disableInputGutters","size","htmlSize","onTouchStart","onClick","onBlur","slotProps","className","inputClass","inputProps","rippleElements","createRipple","useRipple","ripple","isErrored","setIsErrored","useState","length","id","toCamelCase","useEffect","_jsxs","root","cn","styles","undefined","errored","_jsx","htmlFor","children","inputWrapper","iconContainer","disableGutters","type","input","eventWithRipple","e","InputErrors","errorText"],"mappings":"sWA6CM,SAAUA,EAAUC,GACxB,MAAMC,UACJA,EAASC,QACTA,EAAOC,MACPA,EAAKC,MACLA,EAAKC,UACLA,EAASC,sBACTA,GAAwB,EAAKC,wBAC7BA,GAA0B,EAAKC,oBAC/BA,EAAmBC,KACnBA,EAAO,KAAIC,SACXA,EAAQC,aACRA,EAAYC,QACZA,EAAOC,OACPA,EAAMC,UACNA,EAAY,CAAA,EACZC,UAAWC,KACRC,GACDjB,GACEkB,eAAEA,EAAcC,aAAEA,GAAiBC,EAAUN,EAAUO,SACtDC,EAAWC,GAAgBC,EAASpB,KAAWA,EAAMqB,QACtDC,EAAK1B,EAAM0B,IAAMC,EAAYxB,GAMnC,OAJAyB,EAAU,KACRL,EAAanB,KAAWA,EAAMqB,SAC7B,CAACrB,IAGFyB,YACMf,EAAUgB,KACdf,UAAWgB,EACTjB,EAAUgB,MAAMf,UAChBiB,EAAOF,KACPE,EAAO,QAAQvB,KACfJ,EAAY2B,EAAO3B,eAAY4B,EAC/BX,EAAYU,EAAOE,aAAUD,aAG9B9B,GACCgC,EAAA,QAAA,IACMrB,EAAUX,MACdiC,QAASV,EACTX,UAAWgB,EAAGjB,EAAUX,OAAOY,UAAWiB,EAAO7B,OAAMkC,SAEtDlC,IAGL0B,EAAA,MAAA,IACMf,EAAUwB,aACdvB,UAAWgB,EAAGjB,EAAUwB,cAAcvB,UAAWiB,EAAOM,wBAEvDrC,GACCkC,EAAA,OAAA,IACMrB,EAAUb,UACdc,UAAWgB,EACTC,EAAOO,cACPzB,EAAUb,WAAWc,UACrBR,EAA0ByB,EAAOQ,oBAAiBP,YAGnDhC,IAGLkC,EAAA,QAAA,IACMlB,EACJS,GAAIA,EACJe,KAAK,OACL1B,UAAWgB,EACTf,EACAgB,EAAOU,MACPlC,EAAsBwB,EAAOQ,eAAiB,IAEhD7B,aAAcgC,EAAgBxB,EAAcR,GAC5CC,QAAS+B,EAAgBxB,EAAcP,GACvCC,OAAS+B,IACPrB,GAAa,GACbV,IAAS+B,IAEXnC,KAAMC,IAEPR,GACCiC,EAAA,OAAA,IACMrB,EAAUZ,QACda,UAAWgB,EACTC,EAAOO,cACPzB,EAAUZ,SAASa,UACnBT,EAAwB0B,EAAOQ,oBAAiBP,GACjDI,SAEAnC,IAGJgB,KAEFI,GACCa,EAACU,EAAW,IACN/B,EAAUV,MACdW,UAAWgB,EAAGjB,EAAUV,OAAOW,UAAWiB,EAAOc,WACjD1C,MAAOA,MAKjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as
|
|
1
|
+
import{jsxs as o,Fragment as t,jsx as r}from"react/jsx-runtime";import{useDisclosure as e}from"@studiocubics/hooks";import{Button as i}from"../../Inputs/Button/Button.js";import{Dialog as n}from"../Dialog/Dialog.js";import{cn as s}from"@studiocubics/utils";import l from"./Drawer.module.css.js";const h=t=>o("svg",{width:"24",height:"24",stroke:"currentColor",...t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[r("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),r("path",{d:"M9 3v18"}),r("path",{d:"m16 15-3-3 3-3"})]}),d=t=>o("svg",{width:"24",height:"24",stroke:"currentColor",...t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[r("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),r("path",{d:"M15 3v18"}),r("path",{d:"m8 9 3 3-3 3"})]});function c(c){const{side:m="right",slotProps:p,children:u,className:w,...a}=c,{open:g,handleOpen:f,handleClose:k}=e();return o(t,{children:[r(i,{onClick:f,children:r("left"==m?d:h,{})}),r(n,{open:g,onClose:k,className:s(w,l.drawer),...a,children:u})]})}export{c as Drawer};
|
|
2
2
|
//# sourceMappingURL=Drawer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.js","sources":["../../../src/Layout/Drawer/Drawer.tsx"],"sourcesContent":["import { useDisclosure } from \"@studiocubics/hooks\";\nimport { Button, type ButtonProps } from \"../../Inputs/
|
|
1
|
+
{"version":3,"file":"Drawer.js","sources":["../../../src/Layout/Drawer/Drawer.tsx"],"sourcesContent":["import { useDisclosure } from \"@studiocubics/hooks\";\nimport { Button, type ButtonProps } from \"../../Inputs/Button/Button\";\nimport { Dialog, type DialogProps } from \"../../Layout/Dialog/Dialog\";\nimport type { ComponentProps } from \"react\";\nimport { cn } from \"@studiocubics/utils\";\nimport styles from \"./Drawer.module.css\";\n\nexport interface DrawerProps extends Omit<DialogProps, \"open\" | \"onClose\"> {\n /**\n * @default \"right\"\n */\n side?: \"right\" | \"left\";\n\n slotProps?: {\n button?: ButtonProps;\n };\n}\n\nconst PanelLeft = (props: ComponentProps<\"svg\">) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n stroke=\"currentColor\"\n {...props}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\" />\n <path d=\"M9 3v18\" />\n <path d=\"m16 15-3-3 3-3\" />\n </svg>\n );\n};\nconst PanelRight = (props: ComponentProps<\"svg\">) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n stroke=\"currentColor\"\n {...props}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\" />\n <path d=\"M15 3v18\" />\n <path d=\"m8 9 3 3-3 3\" />\n </svg>\n );\n};\n\n/**\n * Opens a drawer from the side of the screen\n */\nexport function Drawer(props: DrawerProps) {\n const { side = \"right\", slotProps, children, className, ...rest } = props;\n const { open, handleOpen, handleClose } = useDisclosure();\n\n return (\n <>\n <Button onClick={handleOpen}>\n {side == \"left\" ? <PanelRight /> : <PanelLeft />}\n </Button>\n <Dialog\n open={open}\n onClose={handleClose}\n className={cn(className, styles.drawer)}\n {...rest}\n >\n {children}\n </Dialog>\n </>\n );\n}\n"],"names":["PanelLeft","props","_jsxs","width","height","stroke","xmlns","viewBox","fill","children","_jsx","x","y","rx","d","PanelRight","Drawer","side","slotProps","className","rest","open","handleOpen","handleClose","useDisclosure","_Fragment","Button","onClick","Dialog","onClose","cn","styles","drawer"],"mappings":"uSAkBA,MAAMA,EAAaC,GAEfC,EAAA,MAAA,CACEC,MAAM,KACNC,OAAO,KACPC,OAAO,kBACHJ,EACJK,MAAM,6BACNC,QAAQ,YACRC,KAAK,OAAM,eACE,IAAG,iBACD,0BACC,QAAOC,SAAA,CAEvBC,EAAA,OAAA,CAAMP,MAAM,KAAKC,OAAO,KAAKO,EAAE,IAAIC,EAAE,IAAIC,GAAG,MAC5CH,EAAA,OAAA,CAAMI,EAAE,YACRJ,EAAA,OAAA,CAAMI,EAAE,sBAIRC,EAAcd,GAEhBC,EAAA,MAAA,CACEC,MAAM,KACNC,OAAO,KACPC,OAAO,kBACHJ,EACJK,MAAM,6BACNC,QAAQ,YACRC,KAAK,OAAM,eACE,IAAG,iBACD,0BACC,QAAOC,SAAA,CAEvBC,EAAA,OAAA,CAAMP,MAAM,KAAKC,OAAO,KAAKO,EAAE,IAAIC,EAAE,IAAIC,GAAG,MAC5CH,EAAA,OAAA,CAAMI,EAAE,aACRJ,EAAA,OAAA,CAAMI,EAAE,oBAQR,SAAUE,EAAOf,GACrB,MAAMgB,KAAEA,EAAO,QAAOC,UAAEA,EAAST,SAAEA,EAAQU,UAAEA,KAAcC,GAASnB,GAC9DoB,KAAEA,EAAIC,WAAEA,EAAUC,YAAEA,GAAgBC,IAE1C,OACEtB,EAAAuB,EAAA,CAAAhB,SAAA,CACEC,EAACgB,EAAM,CAACC,QAASL,EAAUb,SACPC,EAAT,QAARO,EAAkBF,EAAiBf,EAAP,CAAA,KAE/BU,EAACkB,EAAM,CACLP,KAAMA,EACNQ,QAASN,EACTJ,UAAWW,EAAGX,EAAWY,EAAOC,WAC5BZ,EAAIX,SAEPA,MAIT"}
|
|
@@ -34,6 +34,4 @@ export interface BreadCrumbsProps {
|
|
|
34
34
|
*/
|
|
35
35
|
renderItem?: (props: BreadcrumbsItemProps, key?: string | number) => ReactElement;
|
|
36
36
|
}
|
|
37
|
-
export declare const ChevronRightIcon: import("react/jsx-runtime").JSX.Element;
|
|
38
|
-
export declare const EllipsisIcon: import("react/jsx-runtime").JSX.Element;
|
|
39
37
|
export declare function Breadcrumbs(props: BreadCrumbsProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as r,jsxs as e}from"react/jsx-runtime";import{useState as i,Fragment as t}from"react";import{useBreadcrumbs as o}from"./useBreadcrumbs.js";import{BreadcrumbsItem as n}from"./BreadcrumbsItem.js";import{cn as s}from"@studiocubics/utils";import c from"./Breadcrumbs.module.css.js";function l(e){const{width:i=24,height:t=i,...o}=e;return r("svg",{fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...o,xmlns:"http://www.w3.org/2000/svg",width:i,height:t,viewBox:"0 0 24 24",children:r("path",{d:"m9 18 6-6-6-6"})})}function u(i){const{width:t=24,height:o=t,...n}=i;return e("svg",{fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...n,xmlns:"http://www.w3.org/2000/svg",width:t,height:o,viewBox:"0 0 24 24",children:[r("circle",{cx:"12",cy:"12",r:"1"}),r("circle",{cx:"19",cy:"12",r:"1"}),r("circle",{cx:"5",cy:"12",r:"1"})]})}function m(m){const{onChange:d,boundaryCount:h=1,siblingCount:a=0,children:p,defaultActive:g=0,separator:w=r(l,{}),ellipsis:f=r(u,{}),renderItem:v=(e,i)=>r(n,{...e},i)}=m,[b,k]=i(g),x=o({activeCrumb:b,crumbs:p,boundaryCount:h,siblingCount:a});return r("span",{className:c.root,children:x.map((r,i)=>e(t,{children:[v({className:s(c.item,b===i?c.activeItem:"","ellipsis"==r?c.ellipsis:""),onClick:()=>{return k(r=i),void(d&&d(r));var r},children:"ellipsis"==r?f:r}),i!==x.length-1&&"ellipsis"!==r&&"ellipsis"!=x[i+1]&&w]},i))})}export{m as Breadcrumbs};
|
|
2
2
|
//# sourceMappingURL=Breadcrumbs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breadcrumbs.js","sources":["../../../src/Navigation/Breadcrumbs/Breadcrumbs.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment
|
|
1
|
+
{"version":3,"file":"Breadcrumbs.js","sources":["../../../src/Navigation/Breadcrumbs/Breadcrumbs.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentProps,\n Fragment,\n type ReactElement,\n type ReactNode,\n useState,\n} from \"react\";\nimport { useBreadcrumbs } from \"./useBreadcrumbs\";\nimport { BreadcrumbsItem, type BreadcrumbsItemProps } from \"./BreadcrumbsItem\";\nimport { cn } from \"@studiocubics/utils\";\nimport styles from \"./Breadcrumbs.module.css\";\n\nexport interface BreadCrumbsProps {\n children: ReactElement[];\n /**\n * For controlled Breadcrumbs pass the onChange function\n */\n onChange?: (pageNumber: number) => void;\n /**\n * How many siblings of the active item should be shown\n * @default 1\n */\n siblingCount?: number;\n /**\n * How many of the boundary items should be shown\n * @default 0\n */\n boundaryCount?: number;\n /**\n * Crumb that will be selected by default\n * @default 1\n */\n defaultActive?: number;\n /**\n * Node to use as separator\n */\n separator?: ReactNode;\n /**\n * Node to use as ellipsis\n */\n ellipsis?: ReactNode;\n /**\n * Function that can be used to modify the rendered BreadcrumbsItem component\n */\n renderItem?: (\n props: BreadcrumbsItemProps,\n key?: string | number,\n ) => ReactElement;\n}\n\nfunction ChevronRightIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <path d=\"m9 18 6-6-6-6\" />\n </svg>\n );\n}\nfunction EllipsisIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"1\" />\n <circle cx=\"19\" cy=\"12\" r=\"1\" />\n <circle cx=\"5\" cy=\"12\" r=\"1\" />\n </svg>\n );\n}\nexport function Breadcrumbs(props: BreadCrumbsProps) {\n const {\n onChange,\n boundaryCount = 1,\n siblingCount = 0,\n children,\n defaultActive = 0,\n separator = <ChevronRightIcon />,\n ellipsis = <EllipsisIcon />,\n renderItem = (props, key?) => <BreadcrumbsItem key={key} {...props} />,\n } = props;\n const [activeCrumb, setActiveCrumb] = useState<number>(defaultActive);\n\n const breadcrumbRange = useBreadcrumbs({\n activeCrumb,\n crumbs: children,\n boundaryCount,\n siblingCount,\n });\n\n function handleClick(i: number) {\n setActiveCrumb(i);\n if (onChange) onChange(i);\n }\n\n return (\n <span className={styles.root}>\n {breadcrumbRange.map((item, idx) => (\n <Fragment key={idx}>\n {renderItem({\n className: cn(\n styles.item,\n activeCrumb === idx ? styles.activeItem : \"\",\n item == \"ellipsis\" ? styles.ellipsis : \"\",\n ),\n onClick: () => handleClick(idx),\n children: item == \"ellipsis\" ? ellipsis : item,\n })}\n {idx !== breadcrumbRange.length - 1 &&\n item !== \"ellipsis\" &&\n breadcrumbRange[idx + 1] != \"ellipsis\" &&\n separator}\n </Fragment>\n ))}\n </span>\n );\n}\n"],"names":["ChevronRightIcon","props","width","height","rest","_jsx","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","xmlns","viewBox","d","EllipsisIcon","_jsxs","children","cx","cy","r","Breadcrumbs","onChange","boundaryCount","siblingCount","defaultActive","separator","ellipsis","renderItem","key","BreadcrumbsItem","activeCrumb","setActiveCrumb","useState","breadcrumbRange","useBreadcrumbs","crumbs","className","styles","root","map","item","idx","Fragment","cn","activeItem","onClick","handleClick","i","length"],"mappings":"8SAoDA,SAASA,EAAiBC,GACxB,MAAMC,MAAEA,EAAQ,GAAEC,OAAEA,EAASD,KAAUE,GAASH,EAChD,OACEI,SACEC,KAAK,OACLC,OAAO,eACPC,YAAY,IACZC,cAAc,QACdC,eAAe,WACXN,EACJO,MAAM,6BACNT,MAAOA,EACPC,OAAQA,EACRS,QAAQ,qBAERP,EAAA,OAAA,CAAMQ,EAAE,mBAGd,CACA,SAASC,EAAab,GACpB,MAAMC,MAAEA,EAAQ,GAAEC,OAAEA,EAASD,KAAUE,GAASH,EAChD,OACEc,EAAA,MAAA,CACET,KAAK,OACLC,OAAO,eACPC,YAAY,IACZC,cAAc,QACdC,eAAe,WACXN,EACJO,MAAM,6BACNT,MAAOA,EACPC,OAAQA,EACRS,QAAQ,YAAWI,SAAA,CAEnBX,EAAA,SAAA,CAAQY,GAAG,KAAKC,GAAG,KAAKC,EAAE,MAC1Bd,YAAQY,GAAG,KAAKC,GAAG,KAAKC,EAAE,MAC1Bd,YAAQY,GAAG,IAAIC,GAAG,KAAKC,EAAE,QAG/B,CACM,SAAUC,EAAYnB,GAC1B,MAAMoB,SACJA,EAAQC,cACRA,EAAgB,EAACC,aACjBA,EAAe,EAACP,SAChBA,EAAQQ,cACRA,EAAgB,EAACC,UACjBA,EAAYpB,EAACL,EAAgB,CAAA,GAAG0B,SAChCA,EAAWrB,EAACS,MAAea,WAC3BA,EAAa,CAAC1B,EAAO2B,IAASvB,EAACwB,MAA8B5B,GAAT2B,IAClD3B,GACG6B,EAAaC,GAAkBC,EAAiBR,GAEjDS,EAAkBC,EAAe,CACrCJ,cACAK,OAAQnB,EACRM,gBACAC,iBAQF,OACElB,EAAA,OAAA,CAAM+B,UAAWC,EAAOC,KAAItB,SACzBiB,EAAgBM,IAAI,CAACC,EAAMC,IAC1B1B,EAAC2B,EAAQ,CAAA1B,SAAA,CACNW,EAAW,CACVS,UAAWO,EACTN,EAAOG,KACPV,IAAgBW,EAAMJ,EAAOO,WAAa,GAClC,YAARJ,EAAqBH,EAAOX,SAAW,IAEzCmB,QAAS,KAAMC,OAdvBf,EADmBgB,EAegBN,QAb/BpB,GAAUA,EAAS0B,IAFzB,IAAqBA,GAgBX/B,SAAkB,YAARwB,EAAqBd,EAAWc,IAE3CC,IAAQR,EAAgBe,OAAS,GACvB,aAATR,GAC4B,YAA5BP,EAAgBQ,EAAM,IACtBhB,IAbWgB,KAkBvB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{jsx as t,jsxs as o}from"react/jsx-runtime";import{useState as n}from"react";import i from"./Pagination.module.css.js";import{usePagination as e}from"./usePagination.js";import{PaginationItem as r}from"./PaginationItem.js";import{cn as s}from"@studiocubics/utils";function c(n){const{width:i=24,height:e=i,...r}=n;return o("svg",{fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...r,xmlns:"http://www.w3.org/2000/svg",width:i,height:e,viewBox:"0 0 24 24",children:[t("path",{d:"m12 19-7-7 7-7"}),t("path",{d:"M19 12H5"})]})}function d(n){const{width:i=24,height:e=i,...r}=n;return o("svg",{fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...r,xmlns:"http://www.w3.org/2000/svg",width:i,height:e,viewBox:"0 0 24 24",children:[t("path",{d:"M3 19V5"}),t("path",{d:"m13 6-6 6 6 6"}),t("path",{d:"M7 12h14"})]})}function l(l){const{count:a,page:u,onChange:h,defaultPage:m=1,boundaryCount:p=1,siblingCount:g=1,showFirstButton:w=!0,showLastButton:f=!0,firstLastButtonIcon:k=t(d,{}),prevNextButtonIcon:C=t(c,{}),renderItem:b=(o,n)=>t(r,{...o},n)}=l,[v,x]=n(m),j=u??v,B=e({count:a,page:j,siblingCount:g,boundaryCount:p});function L({disabled:t,onClick:o,icon:n}){return b({className:s(i.item,i.icon,t?i.disabled:""),onClick:t?void 0:o,children:n})}function I(t){t<1||t>a||(x(t),h&&h(t))}return o("ul",{className:i.root,children:[w&&a>1&&L({disabled:1===j,onClick:()=>I(1),icon:k}),a>1&&L({disabled:1===j,onClick:()=>I(j-1),icon:C}),B.map((o,n)=>"ellipses"===o?t("li",{children:"…"},`dots-${n}`):b({className:s(i.item,j===o?i.activeItem:""),onClick:()=>I(o),children:o},o)),a>1&&L({disabled:j===a,onClick:()=>I(j+1),icon:C}),f&&a>1&&L({disabled:j===a,onClick:()=>I(a),icon:k})]})}export{l as Pagination};
|
|
2
2
|
//# sourceMappingURL=Pagination.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.js","sources":["../../../src/Navigation/Pagination/Pagination.tsx"],"sourcesContent":["\"use client\";\nimport {
|
|
1
|
+
{"version":3,"file":"Pagination.js","sources":["../../../src/Navigation/Pagination/Pagination.tsx"],"sourcesContent":["\"use client\";\nimport {\n useState,\n type ComponentProps,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport styles from \"./Pagination.module.css\";\nimport { usePagination } from \"./usePagination\";\nimport { type PaginationItemProps, PaginationItem } from \"./PaginationItem\";\nimport { cn } from \"@studiocubics/utils\";\n\nexport interface PaginationProps {\n /**\n * Total number of pages\n */\n count: number;\n /**\n * For controlled Pagination pass the state\n */\n page?: number;\n /**\n * For controlled Pagination pass the onChange function\n */\n onChange?: (pageNumber: number) => void;\n /**\n * Page that will be selected by default\n * @default 1\n */\n defaultPage?: number;\n /**\n * How many siblings of the active item should be shown\n * @default 1\n */\n siblingCount?: number;\n /**\n * How many of the boundary items should be shown\n * @default 1\n */\n boundaryCount?: number;\n /**\n * Function that can be used to modify the rendered PaginationItem component\n */\n renderItem?: (\n props: PaginationItemProps,\n key?: string | number,\n ) => ReactElement;\n /**\n * Shows the skip to first button\n */\n showFirstButton?: boolean;\n /**\n * Shows the skip to last button\n */\n showLastButton?: boolean;\n /**\n * Icon for first button and the last button icon which will be 180deg\n */\n firstLastButtonIcon?: ReactNode;\n /**\n * Icon for prev button and the next button icon which will be 180deg\n */\n prevNextButtonIcon?: ReactNode;\n}\nfunction ArrowLeftIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <path d=\"m12 19-7-7 7-7\" />\n <path d=\"M19 12H5\" />\n </svg>\n );\n}\nfunction ArrowLeftToLineIcon(props: ComponentProps<\"svg\">) {\n const { width = 24, height = width, ...rest } = props;\n return (\n <svg\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...rest}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n viewBox=\"0 0 24 24\"\n >\n <path d=\"M3 19V5\" />\n <path d=\"m13 6-6 6 6 6\" />\n <path d=\"M7 12h14\" />\n </svg>\n );\n}\nexport function Pagination(props: PaginationProps) {\n const {\n count,\n page: pageProp,\n onChange,\n defaultPage = 1,\n boundaryCount = 1,\n siblingCount = 1,\n showFirstButton = true,\n showLastButton = true,\n firstLastButtonIcon = <ArrowLeftToLineIcon />,\n prevNextButtonIcon = <ArrowLeftIcon />,\n renderItem = (props, key?) => <PaginationItem key={key} {...props} />,\n } = props;\n\n const [page, setPage] = useState(defaultPage);\n const activePage = pageProp ?? page;\n\n const paginationRange = usePagination({\n count,\n page: activePage,\n siblingCount,\n boundaryCount,\n });\n\n function renderIconButton({\n disabled,\n onClick,\n icon,\n }: {\n disabled: boolean;\n onClick: () => void;\n icon: React.ReactNode;\n }) {\n return renderItem({\n className: cn(styles.item, styles.icon, disabled ? styles.disabled : \"\"),\n onClick: !disabled ? onClick : undefined,\n children: icon,\n });\n }\n\n function handleClick(i: number) {\n if (i < 1 || i > count) return;\n setPage(i);\n if (onChange) onChange(i);\n }\n\n return (\n <ul className={styles.root}>\n {showFirstButton &&\n count > 1 &&\n renderIconButton({\n disabled: activePage === 1,\n onClick: () => handleClick(1),\n icon: firstLastButtonIcon,\n })}\n {count > 1 &&\n renderIconButton({\n disabled: activePage === 1,\n onClick: () => handleClick(activePage - 1),\n icon: prevNextButtonIcon,\n })}\n\n {paginationRange.map((item, idx) =>\n item === \"ellipses\" ? (\n <li key={`dots-${idx}`}>…</li>\n ) : (\n renderItem(\n {\n className: cn(\n styles.item,\n activePage === item ? styles.activeItem : \"\",\n ),\n onClick: () => handleClick(item),\n children: item,\n },\n item,\n )\n ),\n )}\n {count > 1 &&\n renderIconButton({\n disabled: activePage === count,\n onClick: () => handleClick(activePage + 1),\n icon: prevNextButtonIcon,\n })}\n\n {showLastButton &&\n count > 1 &&\n renderIconButton({\n disabled: activePage === count,\n onClick: () => handleClick(count),\n icon: firstLastButtonIcon,\n })}\n </ul>\n );\n}\n"],"names":["ArrowLeftIcon","props","width","height","rest","_jsxs","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","xmlns","viewBox","children","_jsx","d","ArrowLeftToLineIcon","Pagination","count","page","pageProp","onChange","defaultPage","boundaryCount","siblingCount","showFirstButton","showLastButton","firstLastButtonIcon","prevNextButtonIcon","renderItem","key","PaginationItem","setPage","useState","activePage","paginationRange","usePagination","renderIconButton","disabled","onClick","icon","className","cn","styles","item","undefined","handleClick","i","root","map","idx","activeItem"],"mappings":"2RAgEA,SAASA,EAAcC,GACrB,MAAMC,MAAEA,EAAQ,GAAEC,OAAEA,EAASD,KAAUE,GAASH,EAChD,OACEI,EAAA,MAAA,CACEC,KAAK,OACLC,OAAO,eACPC,YAAY,IACZC,cAAc,QACdC,eAAe,WACXN,EACJO,MAAM,6BACNT,MAAOA,EACPC,OAAQA,EACRS,QAAQ,YAAWC,SAAA,CAEnBC,UAAMC,EAAE,mBACRD,EAAA,OAAA,CAAMC,EAAE,eAGd,CACA,SAASC,EAAoBf,GAC3B,MAAMC,MAAEA,EAAQ,GAAEC,OAAEA,EAASD,KAAUE,GAASH,EAChD,OACEI,EAAA,MAAA,CACEC,KAAK,OACLC,OAAO,eACPC,YAAY,IACZC,cAAc,QACdC,eAAe,WACXN,EACJO,MAAM,6BACNT,MAAOA,EACPC,OAAQA,EACRS,QAAQ,YAAWC,SAAA,CAEnBC,EAAA,OAAA,CAAMC,EAAE,YACRD,EAAA,OAAA,CAAMC,EAAE,kBACRD,EAAA,OAAA,CAAMC,EAAE,eAGd,CACM,SAAUE,EAAWhB,GACzB,MAAMiB,MACJA,EACAC,KAAMC,EAAQC,SACdA,EAAQC,YACRA,EAAc,EAACC,cACfA,EAAgB,EAACC,aACjBA,EAAe,EAACC,gBAChBA,GAAkB,EAAIC,eACtBA,GAAiB,EAAIC,oBACrBA,EAAsBb,EAACE,EAAmB,CAAA,GAAGY,mBAC7CA,EAAqBd,EAACd,EAAa,CAAA,GAAG6B,WACtCA,EAAa,CAAC5B,EAAO6B,IAAShB,EAACiB,EAAc,IAAe9B,GAAT6B,IACjD7B,GAEGkB,EAAMa,GAAWC,EAASX,GAC3BY,EAAad,GAAYD,EAEzBgB,EAAkBC,EAAc,CACpClB,QACAC,KAAMe,EACNV,eACAD,kBAGF,SAASc,GAAiBC,SACxBA,EAAQC,QACRA,EAAOC,KACPA,IAMA,OAAOX,EAAW,CAChBY,UAAWC,EAAGC,EAAOC,KAAMD,EAAOH,KAAMF,EAAWK,EAAOL,SAAW,IACrEC,QAAUD,OAAqBO,EAAVN,EACrB1B,SAAU2B,GAEd,CAEA,SAASM,EAAYC,GACfA,EAAI,GAAKA,EAAI7B,IACjBc,EAAQe,GACJ1B,GAAUA,EAAS0B,GACzB,CAEA,OACE1C,QAAIoC,UAAWE,EAAOK,eACnBvB,GACCP,EAAQ,GACRmB,EAAiB,CACfC,SAAyB,IAAfJ,EACVK,QAAS,IAAMO,EAAY,GAC3BN,KAAMb,IAETT,EAAQ,GACPmB,EAAiB,CACfC,SAAyB,IAAfJ,EACVK,QAAS,IAAMO,EAAYZ,EAAa,GACxCM,KAAMZ,IAGTO,EAAgBc,IAAI,CAACL,EAAMM,IACjB,aAATN,EACE9B,EAAA,KAAA,CAAAD,SAAA,KAAS,QAAQqC,KAEjBrB,EACE,CACEY,UAAWC,EACTC,EAAOC,KACPV,IAAeU,EAAOD,EAAOQ,WAAa,IAE5CZ,QAAS,IAAMO,EAAYF,GAC3B/B,SAAU+B,GAEZA,IAIL1B,EAAQ,GACPmB,EAAiB,CACfC,SAAUJ,IAAehB,EACzBqB,QAAS,IAAMO,EAAYZ,EAAa,GACxCM,KAAMZ,IAGTF,GACCR,EAAQ,GACRmB,EAAiB,CACfC,SAAUJ,IAAehB,EACzBqB,QAAS,IAAMO,EAAY5B,GAC3BsB,KAAMb,MAIhB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PolymorphicComponentProps, PolymorphicComponentType } from "@studiocubics/types";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ElementType } from "react";
|
|
3
3
|
import { type ButtonProps } from "../../Inputs/Button/Button";
|
|
4
4
|
export interface CopyableTextBaseProps {
|
|
5
5
|
children: string;
|
|
@@ -12,5 +12,4 @@ declare const defaultElement = "div";
|
|
|
12
12
|
type DefaultElement = typeof defaultElement;
|
|
13
13
|
export type CopyableTextProps<C extends ElementType = DefaultElement> = PolymorphicComponentProps<C, CopyableTextBaseProps>;
|
|
14
14
|
export declare const CopyableText: PolymorphicComponentType<CopyableTextBaseProps, DefaultElement>;
|
|
15
|
-
export declare function CopyIcon(props: ComponentProps<"svg">): import("react/jsx-runtime").JSX.Element;
|
|
16
15
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsxs as t,jsx as o}from"react/jsx-runtime";import{cn as r}from"@studiocubics/utils";import{useState as e,useEffect as i}from"react";import n from"./CopyableText.module.css.js";import{useDelayedAction as s}from"@studiocubics/hooks";import{Button as c}from"../../Inputs/Button/Button.js";function l(l){const{as:u,children:p,className:h,disabled:m=!1,slotProps:w={},...f}=l,[k,x]=e(!1),b=s(),g=u||"div",v={...f,className:r(h,n.root)};return i(()=>{k&&b(()=>x(!1),2e3)},[b,k]),t(g,{...v,children:[o("span",{children:p}),o(c,{disabled:m,square:!0,size:"sm",type:"button",...w.button,onClick:async function(t){await navigator.clipboard.writeText(p),x(!0),w.button?.onClick?.(t)},children:o(k?a:d,{width:24,height:24})})]})}l.displayName="CopyableText";const u=l;function d(r){return t("svg",{...r,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.3",strokeLinecap:"round",strokeLinejoin:"round",children:[o("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),o("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]})}function a(t){return o("svg",{...t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.3",strokeLinecap:"round",strokeLinejoin:"round",children:o("path",{d:"M4 12 9 17l11 -11"})})}export{
|
|
1
|
+
"use client";import{jsxs as t,jsx as o}from"react/jsx-runtime";import{cn as r}from"@studiocubics/utils";import{useState as e,useEffect as i}from"react";import n from"./CopyableText.module.css.js";import{useDelayedAction as s}from"@studiocubics/hooks";import{Button as c}from"../../Inputs/Button/Button.js";function l(l){const{as:u,children:p,className:h,disabled:m=!1,slotProps:w={},...f}=l,[k,x]=e(!1),b=s(),g=u||"div",v={...f,className:r(h,n.root)};return i(()=>{k&&b(()=>x(!1),2e3)},[b,k]),t(g,{...v,children:[o("span",{children:p}),o(c,{disabled:m,square:!0,size:"sm",type:"button",...w.button,onClick:async function(t){await navigator.clipboard.writeText(p),x(!0),w.button?.onClick?.(t)},children:o(k?a:d,{width:24,height:24})})]})}l.displayName="CopyableText";const u=l;function d(r){return t("svg",{...r,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.3",strokeLinecap:"round",strokeLinejoin:"round",children:[o("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),o("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]})}function a(t){return o("svg",{...t,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.3",strokeLinecap:"round",strokeLinejoin:"round",children:o("path",{d:"M4 12 9 17l11 -11"})})}export{u as CopyableText};
|
|
2
2
|
//# sourceMappingURL=CopyableText.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyableText.js","sources":["../../../src/Typography/CopyableText/CopyableText.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n PolymorphicComponentProps,\n PolymorphicComponentType,\n} from \"@studiocubics/types\";\nimport { cn } from \"@studiocubics/utils\";\nimport {\n type ComponentProps,\n type MouseEvent,\n useEffect,\n useState,\n type ElementType,\n} from \"react\";\nimport styles from \"./CopyableText.module.css\";\nimport { useDelayedAction } from \"@studiocubics/hooks\";\nimport { Button, type ButtonProps } from \"../../Inputs/Button/Button\";\n\nexport interface CopyableTextBaseProps {\n children: string;\n disabled?: boolean;\n slotProps?: {\n button?: ButtonProps;\n };\n}\n\nconst defaultElement = \"div\";\ntype DefaultElement = typeof defaultElement;\n\nexport type CopyableTextProps<C extends ElementType = DefaultElement> =\n PolymorphicComponentProps<C, CopyableTextBaseProps>;\n\nfunction CopyableTextBase<C extends ElementType = DefaultElement>(\n props: CopyableTextProps<C>,\n) {\n const {\n as,\n children,\n className,\n disabled = false,\n slotProps = {},\n ...rest\n } = props as CopyableTextProps<DefaultElement>;\n\n const [copied, setCopied] = useState(false);\n const delay = useDelayedAction();\n const Component = (as || defaultElement) as ElementType;\n const componentProps = { ...rest, className: cn(className, styles.root) };\n\n async function handleCopy(e: MouseEvent<HTMLButtonElement>) {\n await navigator.clipboard.writeText(children);\n setCopied(true);\n slotProps.button?.onClick?.(e);\n }\n useEffect(() => {\n if (copied) {\n delay(() => setCopied(false), 2000);\n }\n }, [delay, copied]);\n return (\n <Component {...componentProps}>\n <span>{children}</span>\n <Button\n disabled={disabled}\n square\n size=\"sm\"\n type=\"button\"\n {...slotProps.button}\n onClick={handleCopy}\n >\n {copied ? (\n <CheckIcon width={24} height={24} />\n ) : (\n <CopyIcon width={24} height={24} />\n )}\n </Button>\n </Component>\n );\n}\n\nCopyableTextBase.displayName = \"CopyableText\";\n\nexport const CopyableText = CopyableTextBase as PolymorphicComponentType<\n CopyableTextBaseProps,\n DefaultElement\n>;\n\
|
|
1
|
+
{"version":3,"file":"CopyableText.js","sources":["../../../src/Typography/CopyableText/CopyableText.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n PolymorphicComponentProps,\n PolymorphicComponentType,\n} from \"@studiocubics/types\";\nimport { cn } from \"@studiocubics/utils\";\nimport {\n type ComponentProps,\n type MouseEvent,\n useEffect,\n useState,\n type ElementType,\n} from \"react\";\nimport styles from \"./CopyableText.module.css\";\nimport { useDelayedAction } from \"@studiocubics/hooks\";\nimport { Button, type ButtonProps } from \"../../Inputs/Button/Button\";\n\nexport interface CopyableTextBaseProps {\n children: string;\n disabled?: boolean;\n slotProps?: {\n button?: ButtonProps;\n };\n}\n\nconst defaultElement = \"div\";\ntype DefaultElement = typeof defaultElement;\n\nexport type CopyableTextProps<C extends ElementType = DefaultElement> =\n PolymorphicComponentProps<C, CopyableTextBaseProps>;\n\nfunction CopyableTextBase<C extends ElementType = DefaultElement>(\n props: CopyableTextProps<C>,\n) {\n const {\n as,\n children,\n className,\n disabled = false,\n slotProps = {},\n ...rest\n } = props as CopyableTextProps<DefaultElement>;\n\n const [copied, setCopied] = useState(false);\n const delay = useDelayedAction();\n const Component = (as || defaultElement) as ElementType;\n const componentProps = { ...rest, className: cn(className, styles.root) };\n\n async function handleCopy(e: MouseEvent<HTMLButtonElement>) {\n await navigator.clipboard.writeText(children);\n setCopied(true);\n slotProps.button?.onClick?.(e);\n }\n useEffect(() => {\n if (copied) {\n delay(() => setCopied(false), 2000);\n }\n }, [delay, copied]);\n return (\n <Component {...componentProps}>\n <span>{children}</span>\n <Button\n disabled={disabled}\n square\n size=\"sm\"\n type=\"button\"\n {...slotProps.button}\n onClick={handleCopy}\n >\n {copied ? (\n <CheckIcon width={24} height={24} />\n ) : (\n <CopyIcon width={24} height={24} />\n )}\n </Button>\n </Component>\n );\n}\n\nCopyableTextBase.displayName = \"CopyableText\";\n\nexport const CopyableText = CopyableTextBase as PolymorphicComponentType<\n CopyableTextBaseProps,\n DefaultElement\n>;\n\nfunction CopyIcon(props: ComponentProps<\"svg\">) {\n return (\n <svg\n {...props}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.3\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\" />\n <path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\" />\n </svg>\n );\n}\n// TODO convert to animated check icon\nfunction CheckIcon(props: ComponentProps<\"svg\">) {\n return (\n <svg\n {...props}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.3\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M4 12 9 17l11 -11\" />\n </svg>\n );\n}\n"],"names":["CopyableTextBase","props","as","children","className","disabled","slotProps","rest","copied","setCopied","useState","delay","useDelayedAction","Component","componentProps","cn","styles","root","useEffect","_jsxs","_jsx","Button","square","size","type","button","onClick","async","e","navigator","clipboard","writeText","CheckIcon","CopyIcon","width","height","displayName","CopyableText","xmlns","viewBox","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","x","y","rx","ry","d"],"mappings":"kTAgCA,SAASA,EACPC,GAEA,MAAMC,GACJA,EAAEC,SACFA,EAAQC,UACRA,EAASC,SACTA,GAAW,EAAKC,UAChBA,EAAY,CAAA,KACTC,GACDN,GAEGO,EAAQC,GAAaC,GAAS,GAC/BC,EAAQC,IACRC,EAAaX,GApBE,MAqBfY,EAAiB,IAAKP,EAAMH,UAAWW,EAAGX,EAAWY,EAAOC,OAYlE,OALAC,EAAU,KACJV,GACFG,EAAM,IAAMF,GAAU,GAAQ,MAE/B,CAACE,EAAOH,IAETW,EAACN,EAAS,IAAKC,EAAcX,SAAA,CAC3BiB,EAAA,OAAA,CAAAjB,SAAOA,IACPiB,EAACC,EAAM,CACLhB,SAAUA,EACViB,QAAM,EACNC,KAAK,KACLC,KAAK,YACDlB,EAAUmB,OACdC,QAnBNC,eAA0BC,SAClBC,UAAUC,UAAUC,UAAU5B,GACpCM,GAAU,GACVH,EAAUmB,QAAQC,UAAUE,EAC9B,EAeyBzB,SAGjBiB,EADDZ,EACEwB,EAEAC,EAFS,CAACC,MAAO,GAAIC,OAAQ,SAOxC,CAEAn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