@magiclabs/ui-components 1.21.2 → 1.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/inputs/text-input.js +1 -1
- package/dist/cjs/components/inputs/text-input.js.map +1 -1
- package/dist/es/components/inputs/text-input.js +1 -1
- package/dist/es/components/inputs/text-input.js.map +1 -1
- package/dist/types/components/inputs/text-input.d.ts +2 -0
- package/dist/types/components/inputs/text-input.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),a=require("react"),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),a=require("react"),n=require("react-aria"),R=require("../primitives/button.js");require("../primitives/checkbox.js"),require("../primitives/dropdown-selector.js"),require("../primitives/popover.js"),require("../primitives/radio.js"),require("../primitives/segmented-control.js"),require("../primitives/switch.js");var x=require("../primitives/text.js"),z=require("../../recipes/text-input.js"),N=require("@styled/css"),m=require("@styled/jsx"),f=require("@styled/tokens"),o=require("create-slots");const E=o.createSlot(({children:s,...l})=>e.jsx(m.Flex,{alignItems:"center",justifyContent:"center",children:a.Children.map(s,r=>{var t;return a.cloneElement(r,{...l,color:(t=r.props.color)!==null&&t!==void 0?t:f.token("colors.neutral.primary")})})})),w=o.createSlot(({children:s,...l})=>e.jsx(m.Flex,{alignItems:"center",justifyContent:"center",children:a.Children.map(s,r=>{var t;return a.isValidElement(r)?a.cloneElement(r,{...l,color:(t=r.props.color)!==null&&t!==void 0?t:f.token("colors.brand.base")}):null})})),D=o.createSlot(R.default),H=o.createSlot(x.default),A=o.createSlot(x.default),V=a.forwardRef((s,l)=>{const{label:r,disabled:t,size:c="md",alignText:g="left",attr:j,description:u,autoFocus:q,className:b="",errorMessage:h,required:d}=s,v=c==="sm"?16:20,M=a.useRef(null),y=l||M,{labelProps:O,inputProps:W,descriptionProps:G,errorMessageProps:J,isInvalid:F,validationErrors:C}=n.useTextField({...s,isDisabled:t??!1,isInvalid:!!h},y),{focusProps:K}=n.useFocusRing({autoFocus:q??!1}),{hoverProps:L}=n.useHover({isDisabled:t??!1});return o.createHost(s.children,p=>{const I=p.get(E),P=p.get(w),T=p.getProps(D),S=p.getProps(H),k=p.getProps(A),i=z.textInput({size:c,alignText:g,disabled:t,isError:F});return e.jsxs(m.VStack,{className:N.cx(i.container,b),children:[r&&e.jsxs("label",{className:i.label,...O,children:[r," ",d&&e.jsx("span",{className:N.css({color:"negative.darker"}),children:"*"})]}),e.jsxs(m.HStack,{className:i.inputContainer,children:[I&&{...I,props:{...I.props,className:i.typeIcon,width:v,height:v}},S&&e.jsx(x.default,{...S,styles:{color:f.token("colors.text.tertiary")}}),e.jsx("input",{ref:y,className:i.input,...n.mergeProps(W,K,L),...j}),k&&e.jsx(x.default,{...k,styles:{color:f.token("colors.text.tertiary")}}),P&&{...P,props:{...P.props,className:i.actionIcon,width:v,height:v}},T&&e.jsx(m.Flex,{alignItems:"center",justifyContent:"center",className:i.actionButton,children:e.jsx(R.default,{...T,variant:"text",size:c})})]}),u&&e.jsx("div",{className:i.description,...G,children:u}),F&&e.jsx(x.default,{variant:"error",...J,size:"sm",styles:{fontWeight:"400"},children:C.length>0?C.join(" "):h})]})})}),B=a.forwardRef((s,l)=>{const{disabled:r,autoFocus:t,className:c="",attr:g}=s,j=a.useRef(null),u=l||j,{inputProps:q}=n.useTextField({...s,isDisabled:r??!1},u),{focusProps:b}=n.useFocusRing({autoFocus:t??!1}),{hoverProps:h}=n.useHover({isDisabled:r??!1}),d=z.textInput({char:!0,disabled:r});return e.jsx("div",{className:N.cx(d.container,d.inputContainer,c),children:e.jsx("input",{ref:u,className:d.input,...n.mergeProps(q,b,h),size:1,...g})})}),Q=Object.assign(V,{TypeIcon:E,ActionIcon:w,ActionButton:D,Char:B,Prefix:H,Suffix:A});V.displayName="TextInput",B.displayName="TextInputChar",exports.TextInput=Q;
|
|
2
2
|
//# sourceMappingURL=text-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-input.js","sources":["../../../../src/components/inputs/text-input.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n HTMLAttributes,\n InputHTMLAttributes,\n isValidElement,\n ReactNode,\n RefObject,\n useRef,\n} from 'react';\nimport type { AriaTextFieldProps } from 'react-aria';\nimport { mergeProps, useFocusRing, useHover, useTextField } from 'react-aria';\n\nimport { Button, Text } from '@components/primitives';\nimport { textInput } from '@recipes/text-input';\nimport { cx } from '@styled/css';\nimport { Flex, HStack, VStack } from '@styled/jsx';\nimport { token } from '@styled/tokens';\n\nimport { createHost, createSlot } from 'create-slots';\n\nexport type TextInputProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n errorMessage?: string;\n children?: ReactNode;\n size?: 'sm' | 'md' | 'lg';\n alignText?: 'left' | 'center' | 'right';\n};\n\nexport type CharProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport type ActionIconProps = HTMLAttributes<HTMLElement> & {\n onClick: () => void;\n};\n\nconst TypeIcon = createSlot(({ children, ...props }) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.neutral.primary') });\n })}\n </Flex>\n );\n});\n\nconst ActionIcon = createSlot(({ children, ...props }: ActionIconProps) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n if (isValidElement<ActionIconProps>(child)) {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.brand.base') });\n }\n return null;\n })}\n </Flex>\n );\n});\n\nconst ActionButton = createSlot(Button);\nconst Prefix = createSlot(Text);\nconst Suffix = createSlot(Text);\n\nconst Component = forwardRef<HTMLInputElement, TextInputProps>((props, forwardedRef) => {\n const {\n label,\n disabled,\n size = 'md',\n alignText = 'left',\n attr,\n description,\n autoFocus,\n className = '',\n errorMessage,\n } = props;\n const iconSize = size === 'sm' ? 16 : 20;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { labelProps, inputProps, descriptionProps, errorMessageProps, isInvalid, validationErrors } = useTextField(\n { ...props, isDisabled: disabled ?? false, isInvalid: !!errorMessage },\n ref as RefObject<HTMLInputElement>,\n );\n\n const { focusProps } = useFocusRing({\n autoFocus: autoFocus ?? false,\n });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n return createHost(props.children, slots => {\n const typeIcon = slots.get(TypeIcon);\n const actionIcon = slots.get(ActionIcon);\n const actionButtonProps = slots.getProps(ActionButton);\n const prefixProps = slots.getProps(Prefix);\n const suffixProps = slots.getProps(Suffix);\n\n const classes = textInput({\n size,\n alignText,\n disabled,\n isError: isInvalid,\n });\n\n return (\n <VStack className={cx(classes.container, className)}>\n {label && (\n <label className={classes.label} {...labelProps}>\n {label}\n </label>\n )}\n <HStack className={classes.inputContainer}>\n {typeIcon && {\n ...typeIcon,\n props: { ...typeIcon.props, className: classes.typeIcon, width: iconSize, height: iconSize },\n }}\n {prefixProps && <Text {...prefixProps} styles={{ color: token('colors.text.tertiary') }} />}\n <input ref={ref} className={classes.input} {...mergeProps(inputProps, focusProps, hoverProps)} {...attr} />\n {suffixProps && <Text {...suffixProps} styles={{ color: token('colors.text.tertiary') }} />}\n {actionIcon && {\n ...actionIcon,\n props: { ...actionIcon.props, className: classes.actionIcon, width: iconSize, height: iconSize },\n }}\n {actionButtonProps && (\n <Flex alignItems=\"center\" justifyContent=\"center\" className={classes.actionButton}>\n <Button {...actionButtonProps} variant=\"text\" size={size} />\n </Flex>\n )}\n </HStack>\n {description && (\n <div className={classes.description} {...descriptionProps}>\n {description}\n </div>\n )}\n {isInvalid && (\n <Text variant=\"error\" {...errorMessageProps} size={'sm'} styles={{ fontWeight: '400' }}>\n {validationErrors.length > 0 ? validationErrors.join(' ') : errorMessage}\n </Text>\n )}\n </VStack>\n );\n });\n});\n\nconst Char = forwardRef<HTMLInputElement, CharProps>((props, forwardedRef) => {\n const { disabled, autoFocus, className = '', attr } = props;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { inputProps } = useTextField({ ...props, isDisabled: disabled ?? false }, ref as RefObject<HTMLInputElement>);\n\n const { focusProps } = useFocusRing({ autoFocus: autoFocus ?? false });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n const classes = textInput({ char: true, disabled });\n\n return (\n <div className={cx(classes.container, classes.inputContainer, className)}>\n <input\n ref={ref}\n className={classes.input}\n {...mergeProps(inputProps, focusProps, hoverProps)}\n size={1}\n {...attr}\n />\n </div>\n );\n});\n\nexport const TextInput = Object.assign(Component, {\n TypeIcon,\n ActionIcon,\n ActionButton,\n Char,\n Prefix,\n Suffix,\n});\n\nComponent.displayName = 'TextInput';\nChar.displayName = 'TextInputChar';\n"],"names":["TypeIcon","createSlot","children","props","_jsx","Flex","Children","child","cloneElement","_a","token","ActionIcon","isValidElement","ActionButton","Button","Prefix","Text","Suffix","Component","forwardRef","forwardedRef","label","disabled","size","alignText","attr","description","autoFocus","className","errorMessage","iconSize","internalRef","useRef","ref","labelProps","inputProps","descriptionProps","errorMessageProps","isInvalid","validationErrors","useTextField","focusProps","useFocusRing","hoverProps","useHover","createHost","slots","typeIcon","actionIcon","actionButtonProps","prefixProps","suffixProps","classes","textInput","_jsxs","VStack","cx","HStack","mergeProps","Char","TextInput"],"mappings":"kiBA0CA,MAAMA,EAAWC,EAAAA,WAAW,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAO,IAE/CC,MAACC,EAAI,KAAA,CAAC,WAAW,SAAS,eAAe,SACtC,SAAAC,EAAS,SAAA,IAAIJ,EAAUK,GAAQ,OAC9B,OAAOC,EAAAA,aAAaD,EAAO,CAAE,GAAGJ,EAAO,OAAOM,EAAAF,EAAM,MAAM,SAAS,MAAAE,IA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AAO,OAAO1C,EAAW,CAChD,SAAAlB,EACA,WAAAW,EACA,aAAAE,EACA,KAAA8C,EACA,OAAA5C,EACA,OAAAE,CACD,CAAA,EAEDC,EAAU,YAAc,YACxByC,EAAK,YAAc"}
|
|
1
|
+
{"version":3,"file":"text-input.js","sources":["../../../../src/components/inputs/text-input.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n HTMLAttributes,\n InputHTMLAttributes,\n isValidElement,\n ReactNode,\n RefObject,\n useRef,\n} from 'react';\nimport type { AriaTextFieldProps } from 'react-aria';\nimport { mergeProps, useFocusRing, useHover, useTextField } from 'react-aria';\n\nimport { Button, Text } from '@components/primitives';\nimport { textInput } from '@recipes/text-input';\nimport { css, cx } from '@styled/css';\nimport { Flex, HStack, VStack } from '@styled/jsx';\nimport { token } from '@styled/tokens';\n\nimport { createHost, createSlot } from 'create-slots';\n\nexport type TextInputProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n errorMessage?: string;\n children?: ReactNode;\n size?: 'sm' | 'md' | 'lg';\n alignText?: 'left' | 'center' | 'right';\n required?: boolean;\n};\n\nexport type CharProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport type ActionIconProps = HTMLAttributes<HTMLElement> & {\n onClick: () => void;\n};\n\nconst TypeIcon = createSlot(({ children, ...props }) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.neutral.primary') });\n })}\n </Flex>\n );\n});\n\nconst ActionIcon = createSlot(({ children, ...props }: ActionIconProps) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n if (isValidElement<ActionIconProps>(child)) {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.brand.base') });\n }\n return null;\n })}\n </Flex>\n );\n});\n\nconst ActionButton = createSlot(Button);\nconst Prefix = createSlot(Text);\nconst Suffix = createSlot(Text);\n\nconst Component = forwardRef<HTMLInputElement, TextInputProps>((props, forwardedRef) => {\n const {\n label,\n disabled,\n size = 'md',\n alignText = 'left',\n attr,\n description,\n autoFocus,\n className = '',\n errorMessage,\n required,\n } = props;\n const iconSize = size === 'sm' ? 16 : 20;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { labelProps, inputProps, descriptionProps, errorMessageProps, isInvalid, validationErrors } = useTextField(\n { ...props, isDisabled: disabled ?? false, isInvalid: !!errorMessage },\n ref as RefObject<HTMLInputElement>,\n );\n\n const { focusProps } = useFocusRing({\n autoFocus: autoFocus ?? false,\n });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n return createHost(props.children, slots => {\n const typeIcon = slots.get(TypeIcon);\n const actionIcon = slots.get(ActionIcon);\n const actionButtonProps = slots.getProps(ActionButton);\n const prefixProps = slots.getProps(Prefix);\n const suffixProps = slots.getProps(Suffix);\n\n const classes = textInput({\n size,\n alignText,\n disabled,\n isError: isInvalid,\n });\n\n return (\n <VStack className={cx(classes.container, className)}>\n {label && (\n <label className={classes.label} {...labelProps}>\n {label} {required && <span className={css({ color: 'negative.darker' })}>*</span>}\n </label>\n )}\n <HStack className={classes.inputContainer}>\n {typeIcon && {\n ...typeIcon,\n props: { ...typeIcon.props, className: classes.typeIcon, width: iconSize, height: iconSize },\n }}\n {prefixProps && <Text {...prefixProps} styles={{ color: token('colors.text.tertiary') }} />}\n <input ref={ref} className={classes.input} {...mergeProps(inputProps, focusProps, hoverProps)} {...attr} />\n {suffixProps && <Text {...suffixProps} styles={{ color: token('colors.text.tertiary') }} />}\n {actionIcon && {\n ...actionIcon,\n props: { ...actionIcon.props, className: classes.actionIcon, width: iconSize, height: iconSize },\n }}\n {actionButtonProps && (\n <Flex alignItems=\"center\" justifyContent=\"center\" className={classes.actionButton}>\n <Button {...actionButtonProps} variant=\"text\" size={size} />\n </Flex>\n )}\n </HStack>\n {description && (\n <div className={classes.description} {...descriptionProps}>\n {description}\n </div>\n )}\n {isInvalid && (\n <Text variant=\"error\" {...errorMessageProps} size={'sm'} styles={{ fontWeight: '400' }}>\n {validationErrors.length > 0 ? validationErrors.join(' ') : errorMessage}\n </Text>\n )}\n </VStack>\n );\n });\n});\n\nconst Char = forwardRef<HTMLInputElement, CharProps>((props, forwardedRef) => {\n const { disabled, autoFocus, className = '', attr } = props;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { inputProps } = useTextField({ ...props, isDisabled: disabled ?? false }, ref as RefObject<HTMLInputElement>);\n\n const { focusProps } = useFocusRing({ autoFocus: autoFocus ?? false });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n const classes = textInput({ char: true, disabled });\n\n return (\n <div className={cx(classes.container, classes.inputContainer, className)}>\n <input\n ref={ref}\n className={classes.input}\n {...mergeProps(inputProps, focusProps, hoverProps)}\n size={1}\n {...attr}\n />\n </div>\n );\n});\n\nexport const TextInput = Object.assign(Component, {\n TypeIcon,\n ActionIcon,\n ActionButton,\n Char,\n Prefix,\n Suffix,\n});\n\nComponent.displayName = 'TextInput';\nChar.displayName = 'TextInputChar';\n"],"names":["TypeIcon","createSlot","children","props","_jsx","Flex","Children","child","cloneElement","_a","token","ActionIcon","isValidElement","ActionButton","Button","Prefix","Text","Suffix","Component","forwardRef","forwardedRef","label","disabled","size","alignText","attr","description","autoFocus","className","errorMessage","required","iconSize","internalRef","useRef","ref","labelProps","inputProps","descriptionProps","errorMessageProps","isInvalid","validationErrors","useTextField","focusProps","useFocusRing","hoverProps","useHover","createHost","slots","typeIcon","actionIcon","actionButtonProps","prefixProps","suffixProps","classes","textInput","_jsxs","VStack","cx","css","HStack","mergeProps","Char","TextInput"],"mappings":"kiBA2CA,MAAMA,EAAWC,EAAAA,WAAW,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAO,IAE/CC,EA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,EAAUC,YAAU,CAAE,KAAM,GAAM,SAAAhC,CAAU,CAAA,EAElD,OACElB,EAAAA,WAAK,UAAWqD,EAAGJ,GAAAA,EAAQ,UAAWA,EAAQ,eAAgBzB,CAAS,WACrExB,EAAAA,IACE,QAAA,CAAA,IAAK8B,EACL,UAAWmB,EAAQ,MAAK,GACpBO,EAAAA,WAAWxB,EAAYM,EAAYE,CAAU,EACjD,KAAM,KACFnB,CAAI,CAAA,CAEN,CAAA,CAEV,CAAC,EAEYqC,EAAY,OAAO,OAAO5C,EAAW,CAChD,SAAAlB,EACA,WAAAW,EACA,aAAAE,EACA,KAAAgD,EACA,OAAA9C,EACA,OAAAE,CACD,CAAA,EAEDC,EAAU,YAAc,YACxB2C,EAAK,YAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t,jsxs as
|
|
1
|
+
import{jsx as t,jsxs as P}from"react/jsx-runtime";import{Children as k,cloneElement as D,isValidElement as ee,forwardRef as E,useRef as S}from"react";import{useTextField as w,useFocusRing as H,useHover as R,mergeProps as V}from"react-aria";import $ from"../primitives/button.js";import"../primitives/checkbox.js";import"../primitives/dropdown-selector.js";import"../primitives/popover.js";import"../primitives/radio.js";import"../primitives/segmented-control.js";import"../primitives/switch.js";import p from"../primitives/text.js";import{textInput as q}from"../../recipes/text-input.js";import{cx as A,css as re}from"@styled/css";import{Flex as I,VStack as te,HStack as se}from"@styled/jsx";import{token as h}from"@styled/tokens";import{createSlot as m,createHost as oe}from"create-slots";const B=m(({children:s,...i})=>t(I,{alignItems:"center",justifyContent:"center",children:k.map(s,e=>{var r;return D(e,{...i,color:(r=e.props.color)!==null&&r!==void 0?r:h("colors.neutral.primary")})})})),G=m(({children:s,...i})=>t(I,{alignItems:"center",justifyContent:"center",children:k.map(s,e=>{var r;return ee(e)?D(e,{...i,color:(r=e.props.color)!==null&&r!==void 0?r:h("colors.brand.base")}):null})})),M=m($),O=m(p),W=m(p),J=E((s,i)=>{const{label:e,disabled:r,size:n="md",alignText:f="left",attr:g,description:a,autoFocus:x,className:v="",errorMessage:d,required:l}=s,u=n==="sm"?16:20,L=S(null),y=i||L,{labelProps:Q,inputProps:U,descriptionProps:X,errorMessageProps:Y,isInvalid:j,validationErrors:C}=w({...s,isDisabled:r??!1,isInvalid:!!d},y),{focusProps:Z}=H({autoFocus:x??!1}),{hoverProps:_}=R({isDisabled:r??!1});return oe(s.children,c=>{const b=c.get(B),N=c.get(G),F=c.getProps(M),T=c.getProps(O),z=c.getProps(W),o=q({size:n,alignText:f,disabled:r,isError:j});return P(te,{className:A(o.container,v),children:[e&&P("label",{className:o.label,...Q,children:[e," ",l&&t("span",{className:re({color:"negative.darker"}),children:"*"})]}),P(se,{className:o.inputContainer,children:[b&&{...b,props:{...b.props,className:o.typeIcon,width:u,height:u}},T&&t(p,{...T,styles:{color:h("colors.text.tertiary")}}),t("input",{ref:y,className:o.input,...V(U,Z,_),...g}),z&&t(p,{...z,styles:{color:h("colors.text.tertiary")}}),N&&{...N,props:{...N.props,className:o.actionIcon,width:u,height:u}},F&&t(I,{alignItems:"center",justifyContent:"center",className:o.actionButton,children:t($,{...F,variant:"text",size:n})})]}),a&&t("div",{className:o.description,...X,children:a}),j&&t(p,{variant:"error",...Y,size:"sm",styles:{fontWeight:"400"},children:C.length>0?C.join(" "):d})]})})}),K=E((s,i)=>{const{disabled:e,autoFocus:r,className:n="",attr:f}=s,g=S(null),a=i||g,{inputProps:x}=w({...s,isDisabled:e??!1},a),{focusProps:v}=H({autoFocus:r??!1}),{hoverProps:d}=R({isDisabled:e??!1}),l=q({char:!0,disabled:e});return t("div",{className:A(l.container,l.inputContainer,n),children:t("input",{ref:a,className:l.input,...V(x,v,d),size:1,...f})})}),ie=Object.assign(J,{TypeIcon:B,ActionIcon:G,ActionButton:M,Char:K,Prefix:O,Suffix:W});J.displayName="TextInput",K.displayName="TextInputChar";export{ie as TextInput};
|
|
2
2
|
//# sourceMappingURL=text-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-input.js","sources":["../../../../src/components/inputs/text-input.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n HTMLAttributes,\n InputHTMLAttributes,\n isValidElement,\n ReactNode,\n RefObject,\n useRef,\n} from 'react';\nimport type { AriaTextFieldProps } from 'react-aria';\nimport { mergeProps, useFocusRing, useHover, useTextField } from 'react-aria';\n\nimport { Button, Text } from '@components/primitives';\nimport { textInput } from '@recipes/text-input';\nimport { cx } from '@styled/css';\nimport { Flex, HStack, VStack } from '@styled/jsx';\nimport { token } from '@styled/tokens';\n\nimport { createHost, createSlot } from 'create-slots';\n\nexport type TextInputProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n errorMessage?: string;\n children?: ReactNode;\n size?: 'sm' | 'md' | 'lg';\n alignText?: 'left' | 'center' | 'right';\n};\n\nexport type CharProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport type ActionIconProps = HTMLAttributes<HTMLElement> & {\n onClick: () => void;\n};\n\nconst TypeIcon = createSlot(({ children, ...props }) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.neutral.primary') });\n })}\n </Flex>\n );\n});\n\nconst ActionIcon = createSlot(({ children, ...props }: ActionIconProps) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n if (isValidElement<ActionIconProps>(child)) {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.brand.base') });\n }\n return null;\n })}\n </Flex>\n );\n});\n\nconst ActionButton = createSlot(Button);\nconst Prefix = createSlot(Text);\nconst Suffix = createSlot(Text);\n\nconst Component = forwardRef<HTMLInputElement, TextInputProps>((props, forwardedRef) => {\n const {\n label,\n disabled,\n size = 'md',\n alignText = 'left',\n attr,\n description,\n autoFocus,\n className = '',\n errorMessage,\n } = props;\n const iconSize = size === 'sm' ? 16 : 20;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { labelProps, inputProps, descriptionProps, errorMessageProps, isInvalid, validationErrors } = useTextField(\n { ...props, isDisabled: disabled ?? false, isInvalid: !!errorMessage },\n ref as RefObject<HTMLInputElement>,\n );\n\n const { focusProps } = useFocusRing({\n autoFocus: autoFocus ?? false,\n });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n return createHost(props.children, slots => {\n const typeIcon = slots.get(TypeIcon);\n const actionIcon = slots.get(ActionIcon);\n const actionButtonProps = slots.getProps(ActionButton);\n const prefixProps = slots.getProps(Prefix);\n const suffixProps = slots.getProps(Suffix);\n\n const classes = textInput({\n size,\n alignText,\n disabled,\n isError: isInvalid,\n });\n\n return (\n <VStack className={cx(classes.container, className)}>\n {label && (\n <label className={classes.label} {...labelProps}>\n {label}\n </label>\n )}\n <HStack className={classes.inputContainer}>\n {typeIcon && {\n ...typeIcon,\n props: { ...typeIcon.props, className: classes.typeIcon, width: iconSize, height: iconSize },\n }}\n {prefixProps && <Text {...prefixProps} styles={{ color: token('colors.text.tertiary') }} />}\n <input ref={ref} className={classes.input} {...mergeProps(inputProps, focusProps, hoverProps)} {...attr} />\n {suffixProps && <Text {...suffixProps} styles={{ color: token('colors.text.tertiary') }} />}\n {actionIcon && {\n ...actionIcon,\n props: { ...actionIcon.props, className: classes.actionIcon, width: iconSize, height: iconSize },\n }}\n {actionButtonProps && (\n <Flex alignItems=\"center\" justifyContent=\"center\" className={classes.actionButton}>\n <Button {...actionButtonProps} variant=\"text\" size={size} />\n </Flex>\n )}\n </HStack>\n {description && (\n <div className={classes.description} {...descriptionProps}>\n {description}\n </div>\n )}\n {isInvalid && (\n <Text variant=\"error\" {...errorMessageProps} size={'sm'} styles={{ fontWeight: '400' }}>\n {validationErrors.length > 0 ? validationErrors.join(' ') : errorMessage}\n </Text>\n )}\n </VStack>\n );\n });\n});\n\nconst Char = forwardRef<HTMLInputElement, CharProps>((props, forwardedRef) => {\n const { disabled, autoFocus, className = '', attr } = props;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { inputProps } = useTextField({ ...props, isDisabled: disabled ?? false }, ref as RefObject<HTMLInputElement>);\n\n const { focusProps } = useFocusRing({ autoFocus: autoFocus ?? false });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n const classes = textInput({ char: true, disabled });\n\n return (\n <div className={cx(classes.container, classes.inputContainer, className)}>\n <input\n ref={ref}\n className={classes.input}\n {...mergeProps(inputProps, focusProps, hoverProps)}\n size={1}\n {...attr}\n />\n </div>\n );\n});\n\nexport const TextInput = Object.assign(Component, {\n TypeIcon,\n ActionIcon,\n ActionButton,\n Char,\n Prefix,\n Suffix,\n});\n\nComponent.displayName = 'TextInput';\nChar.displayName = 'TextInputChar';\n"],"names":["TypeIcon","createSlot","children","props","_jsx","Flex","Children","child","cloneElement","_a","token","ActionIcon","isValidElement","ActionButton","Button","Prefix","Text","Suffix","Component","forwardRef","forwardedRef","label","disabled","size","alignText","attr","description","autoFocus","className","errorMessage","iconSize","internalRef","useRef","ref","labelProps","inputProps","descriptionProps","errorMessageProps","isInvalid","validationErrors","useTextField","focusProps","useFocusRing","hoverProps","useHover","createHost","slots","typeIcon","actionIcon","actionButtonProps","prefixProps","suffixProps","classes","textInput","_jsxs","VStack","cx","HStack","mergeProps","Char","TextInput"],"mappings":"2wBA0CA,MAAMA,EAAWC,EAAW,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAO,IAE/CC,EAACC,EAAI,CAAC,WAAW,SAAS,eAAe,SACtC,SAAAC,EAAS,IAAIJ,EAAUK,GAAQ,OAC9B,OAAOC,EAAaD,EAAO,CAAE,GAAGJ,EAAO,OAAOM,EAAAF,EAAM,MAAM,SAAS,MAAAE,IAAA,OAAAA,EAAAC,EAAM,wBAAwB,CAAG,CAAA,CACt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,KAAM,OAAQ,CAAE,WAAY,OAC5E,SAAAE,EAAiB,OAAS,EAAIA,EAAiB,KAAK,GAAG,EAAIV,CACvD,CAAA,CACR,CACM,CAAA,CAEb,CAAC,CACH,CAAC,EAEK8B,EAAOxC,EAAwC,CAAChB,EAAOiB,IAAgB,CAC3E,KAAM,CAAE,SAAAE,EAAU,UAAAK,EAAW,UAAAC,EAAY,GAAI,KAAAH,CAAM,EAAGtB,EAEhD4B,EAAcC,EAAO,IAAI,EAEzBC,EAAMb,GAAgBW,EAEtB,CAAE,WAAAI,CAAY,EAAGK,EAAa,CAAE,GAAGrC,EAAO,WAAYmB,GAAY,EAAO,EAAEW,CAAkC,EAE7G,CAAE,WAAAQ,CAAU,EAAKC,EAAa,CAAE,UAAWf,GAAa,EAAK,CAAE,EAC/D,CAAE,WAAAgB,CAAU,EAAKC,EAAS,CAAE,WAAYtB,GAAY,EAAK,CAAE,EAE3D8B,EAAUC,EAAU,CAAE,KAAM,GAAM,SAAA/B,CAAU,CAAA,EAElD,OACElB,SAAK,UAAWoD,EAAGJ,EAAQ,UAAWA,EAAQ,eAAgBxB,CAAS,WACrExB,EACE,QAAA,CAAA,IAAK6B,EACL,UAAWmB,EAAQ,MAAK,GACpBM,EAAWvB,EAAYM,EAAYE,CAAU,EACjD,KAAM,KACFlB,CAAI,CAAA,CAEN,CAAA,CAEV,CAAC,EAEYmC,GAAY,OAAO,OAAO1C,EAAW,CAChD,SAAAlB,EACA,WAAAW,EACA,aAAAE,EACA,KAAA8C,EACA,OAAA5C,EACA,OAAAE,CACD,CAAA,EAEDC,EAAU,YAAc,YACxByC,EAAK,YAAc"}
|
|
1
|
+
{"version":3,"file":"text-input.js","sources":["../../../../src/components/inputs/text-input.tsx"],"sourcesContent":["import {\n Children,\n cloneElement,\n forwardRef,\n HTMLAttributes,\n InputHTMLAttributes,\n isValidElement,\n ReactNode,\n RefObject,\n useRef,\n} from 'react';\nimport type { AriaTextFieldProps } from 'react-aria';\nimport { mergeProps, useFocusRing, useHover, useTextField } from 'react-aria';\n\nimport { Button, Text } from '@components/primitives';\nimport { textInput } from '@recipes/text-input';\nimport { css, cx } from '@styled/css';\nimport { Flex, HStack, VStack } from '@styled/jsx';\nimport { token } from '@styled/tokens';\n\nimport { createHost, createSlot } from 'create-slots';\n\nexport type TextInputProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n errorMessage?: string;\n children?: ReactNode;\n size?: 'sm' | 'md' | 'lg';\n alignText?: 'left' | 'center' | 'right';\n required?: boolean;\n};\n\nexport type CharProps = AriaTextFieldProps & {\n className?: string;\n disabled?: boolean;\n attr?: InputHTMLAttributes<HTMLInputElement>;\n};\n\nexport type ActionIconProps = HTMLAttributes<HTMLElement> & {\n onClick: () => void;\n};\n\nconst TypeIcon = createSlot(({ children, ...props }) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.neutral.primary') });\n })}\n </Flex>\n );\n});\n\nconst ActionIcon = createSlot(({ children, ...props }: ActionIconProps) => {\n return (\n <Flex alignItems=\"center\" justifyContent=\"center\">\n {Children.map(children, child => {\n if (isValidElement<ActionIconProps>(child)) {\n return cloneElement(child, { ...props, color: child.props.color ?? token('colors.brand.base') });\n }\n return null;\n })}\n </Flex>\n );\n});\n\nconst ActionButton = createSlot(Button);\nconst Prefix = createSlot(Text);\nconst Suffix = createSlot(Text);\n\nconst Component = forwardRef<HTMLInputElement, TextInputProps>((props, forwardedRef) => {\n const {\n label,\n disabled,\n size = 'md',\n alignText = 'left',\n attr,\n description,\n autoFocus,\n className = '',\n errorMessage,\n required,\n } = props;\n const iconSize = size === 'sm' ? 16 : 20;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { labelProps, inputProps, descriptionProps, errorMessageProps, isInvalid, validationErrors } = useTextField(\n { ...props, isDisabled: disabled ?? false, isInvalid: !!errorMessage },\n ref as RefObject<HTMLInputElement>,\n );\n\n const { focusProps } = useFocusRing({\n autoFocus: autoFocus ?? false,\n });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n return createHost(props.children, slots => {\n const typeIcon = slots.get(TypeIcon);\n const actionIcon = slots.get(ActionIcon);\n const actionButtonProps = slots.getProps(ActionButton);\n const prefixProps = slots.getProps(Prefix);\n const suffixProps = slots.getProps(Suffix);\n\n const classes = textInput({\n size,\n alignText,\n disabled,\n isError: isInvalid,\n });\n\n return (\n <VStack className={cx(classes.container, className)}>\n {label && (\n <label className={classes.label} {...labelProps}>\n {label} {required && <span className={css({ color: 'negative.darker' })}>*</span>}\n </label>\n )}\n <HStack className={classes.inputContainer}>\n {typeIcon && {\n ...typeIcon,\n props: { ...typeIcon.props, className: classes.typeIcon, width: iconSize, height: iconSize },\n }}\n {prefixProps && <Text {...prefixProps} styles={{ color: token('colors.text.tertiary') }} />}\n <input ref={ref} className={classes.input} {...mergeProps(inputProps, focusProps, hoverProps)} {...attr} />\n {suffixProps && <Text {...suffixProps} styles={{ color: token('colors.text.tertiary') }} />}\n {actionIcon && {\n ...actionIcon,\n props: { ...actionIcon.props, className: classes.actionIcon, width: iconSize, height: iconSize },\n }}\n {actionButtonProps && (\n <Flex alignItems=\"center\" justifyContent=\"center\" className={classes.actionButton}>\n <Button {...actionButtonProps} variant=\"text\" size={size} />\n </Flex>\n )}\n </HStack>\n {description && (\n <div className={classes.description} {...descriptionProps}>\n {description}\n </div>\n )}\n {isInvalid && (\n <Text variant=\"error\" {...errorMessageProps} size={'sm'} styles={{ fontWeight: '400' }}>\n {validationErrors.length > 0 ? validationErrors.join(' ') : errorMessage}\n </Text>\n )}\n </VStack>\n );\n });\n});\n\nconst Char = forwardRef<HTMLInputElement, CharProps>((props, forwardedRef) => {\n const { disabled, autoFocus, className = '', attr } = props;\n\n const internalRef = useRef(null);\n // forwardedRef is null until after first render\n const ref = forwardedRef || internalRef;\n\n const { inputProps } = useTextField({ ...props, isDisabled: disabled ?? false }, ref as RefObject<HTMLInputElement>);\n\n const { focusProps } = useFocusRing({ autoFocus: autoFocus ?? false });\n const { hoverProps } = useHover({ isDisabled: disabled ?? false });\n\n const classes = textInput({ char: true, disabled });\n\n return (\n <div className={cx(classes.container, classes.inputContainer, className)}>\n <input\n ref={ref}\n className={classes.input}\n {...mergeProps(inputProps, focusProps, hoverProps)}\n size={1}\n {...attr}\n />\n </div>\n );\n});\n\nexport const TextInput = Object.assign(Component, {\n TypeIcon,\n ActionIcon,\n ActionButton,\n Char,\n Prefix,\n Suffix,\n});\n\nComponent.displayName = 'TextInput';\nChar.displayName = 'TextInputChar';\n"],"names":["TypeIcon","createSlot","children","props","_jsx","Flex","Children","child","cloneElement","_a","token","ActionIcon","isValidElement","ActionButton","Button","Prefix","Text","Suffix","Component","forwardRef","forwardedRef","label","disabled","size","alignText","attr","description","autoFocus","className","errorMessage","required","iconSize","internalRef","useRef","ref","labelProps","inputProps","descriptionProps","errorMessageProps","isInvalid","validationErrors","useTextField","focusProps","useFocusRing","hoverProps","useHover","createHost","slots","typeIcon","actionIcon","actionButtonProps","prefixProps","suffixProps","classes","textInput","_jsxs","VStack","cx","css","HStack","mergeProps","Char","TextInput"],"mappings":"sxBA2CA,MAAMA,EAAWC,EAAW,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAO,IAE/CC,EAACC,EAAI,CAAC,WAAW,SAAS,eAAe,SACtC,SAAAC,EAAS,IAAIJ,EAAUK,GAAQ,OAC9B,OAAOC,EAAaD,EAAO,CAAE,GAAGJ,EAAO,OAAOM,EAAAF,EAAM,MAAM,SAAS,MAAAE,IAAA,OAAAA,EAAAC,EAAM,wBAAwB,CAAG,CAAA,CACtG,CAAC,CACI,CAAA,CAEV,EAEKC,EAAaV,EAAW,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAwB,IAElEC,EAACC,EAAI,CAAC,WAAW,SAAS,eAAe,SACtC,SAAAC,EAAS,IAAIJ,EAA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WAAY,OAC5E,SAAAE,EAAiB,OAAS,EAAIA,EAAiB,KAAK,GAAG,EAAIX,CACvD,CAAA,CACR,CACM,CAAA,CAEb,CAAC,CACH,CAAC,EAEKgC,EAAO1C,EAAwC,CAAChB,EAAOiB,IAAgB,CAC3E,KAAM,CAAE,SAAAE,EAAU,UAAAK,EAAW,UAAAC,EAAY,GAAI,KAAAH,CAAM,EAAGtB,EAEhD6B,EAAcC,EAAO,IAAI,EAEzBC,EAAMd,GAAgBY,EAEtB,CAAE,WAAAI,CAAY,EAAGK,EAAa,CAAE,GAAGtC,EAAO,WAAYmB,GAAY,EAAO,EAAEY,CAAkC,EAE7G,CAAE,WAAAQ,CAAU,EAAKC,EAAa,CAAE,UAAWhB,GAAa,EAAK,CAAE,EAC/D,CAAE,WAAAiB,CAAU,EAAKC,EAAS,CAAE,WAAYvB,GAAY,EAAK,CAAE,EAE3D+B,EAAUC,EAAU,CAAE,KAAM,GAAM,SAAAhC,CAAU,CAAA,EAElD,OACElB,SAAK,UAAWqD,EAAGJ,EAAQ,UAAWA,EAAQ,eAAgBzB,CAAS,WACrExB,EACE,QAAA,CAAA,IAAK8B,EACL,UAAWmB,EAAQ,MAAK,GACpBO,EAAWxB,EAAYM,EAAYE,CAAU,EACjD,KAAM,KACFnB,CAAI,CAAA,CAEN,CAAA,CAEV,CAAC,EAEYqC,GAAY,OAAO,OAAO5C,EAAW,CAChD,SAAAlB,EACA,WAAAW,EACA,aAAAE,EACA,KAAAgD,EACA,OAAA9C,EACA,OAAAE,CACD,CAAA,EAEDC,EAAU,YAAc,YACxB2C,EAAK,YAAc"}
|
|
@@ -8,6 +8,7 @@ export type TextInputProps = AriaTextFieldProps & {
|
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
size?: 'sm' | 'md' | 'lg';
|
|
10
10
|
alignText?: 'left' | 'center' | 'right';
|
|
11
|
+
required?: boolean;
|
|
11
12
|
};
|
|
12
13
|
export type CharProps = AriaTextFieldProps & {
|
|
13
14
|
className?: string;
|
|
@@ -25,6 +26,7 @@ export declare const TextInput: import("react").ForwardRefExoticComponent<AriaTe
|
|
|
25
26
|
children?: ReactNode;
|
|
26
27
|
size?: "sm" | "md" | "lg" | undefined;
|
|
27
28
|
alignText?: "left" | "center" | "right" | undefined;
|
|
29
|
+
required?: boolean | undefined;
|
|
28
30
|
} & import("react").RefAttributes<HTMLInputElement>> & {
|
|
29
31
|
TypeIcon: ({ children, ...props }: any) => import("react/jsx-runtime").JSX.Element;
|
|
30
32
|
ActionIcon: ({ children, ...props }: ActionIconProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-input.d.ts","sourceRoot":"","sources":["../../../../src/components/inputs/text-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,cAAc,EACd,mBAAmB,EAEnB,SAAS,EAGV,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAWrD,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"text-input.d.ts","sourceRoot":"","sources":["../../../../src/components/inputs/text-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,cAAc,EACd,mBAAmB,EAEnB,SAAS,EAGV,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAWrD,MAAM,MAAM,cAAc,GAA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