@spark-ui/components 14.1.2 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FormFieldRequiredIndicator-CHfcoT2y.js +2 -0
- package/dist/FormFieldRequiredIndicator-CHfcoT2y.js.map +1 -0
- package/dist/FormFieldRequiredIndicator-DTnCGiX2.mjs +13 -0
- package/dist/FormFieldRequiredIndicator-DTnCGiX2.mjs.map +1 -0
- package/dist/form-field/index.js +1 -1
- package/dist/form-field/index.js.map +1 -1
- package/dist/form-field/index.mjs +76 -81
- package/dist/form-field/index.mjs.map +1 -1
- package/dist/slider/Slider.d.ts +8 -13
- package/dist/slider/SliderContext.d.ts +7 -1
- package/dist/slider/SliderControl.d.ts +7 -0
- package/dist/slider/SliderIndicator.d.ts +7 -0
- package/dist/slider/SliderLabel.d.ts +13 -0
- package/dist/slider/SliderMaxValue.d.ts +6 -0
- package/dist/slider/SliderMinValue.d.ts +6 -0
- package/dist/slider/SliderThumb.d.ts +4 -11
- package/dist/slider/SliderThumbContext.d.ts +5 -0
- package/dist/slider/SliderTrack.d.ts +4 -11
- package/dist/slider/SliderTrack.styles.d.ts +1 -4
- package/dist/slider/SliderValue.d.ts +10 -0
- package/dist/slider/index.d.mts +13 -1
- package/dist/slider/index.d.ts +13 -1
- package/dist/slider/index.js +1 -1
- package/dist/slider/index.js.map +1 -1
- package/dist/slider/index.mjs +290 -127
- package/dist/slider/index.mjs.map +1 -1
- package/dist/slider/useSliderValueBoundaries.d.ts +12 -0
- package/dist/toast/index.js +1 -1
- package/dist/toast/index.js.map +1 -1
- package/dist/toast/index.mjs +154 -129
- package/dist/toast/index.mjs.map +1 -1
- package/dist/toast/types.d.ts +4 -1
- package/package.json +4 -4
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),a=require("class-variance-authority"),c=require("./label/index.js"),e=({className:r,ref:i,...s})=>t.jsx(c.Label.RequiredIndicator,{ref:i,className:a.cx("ml-sm",r),...s});e.displayName="FormField.RequiredIndicator";exports.FormFieldRequiredIndicator=e;
|
|
2
|
+
//# sourceMappingURL=FormFieldRequiredIndicator-CHfcoT2y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldRequiredIndicator-CHfcoT2y.js","sources":["../src/form-field/FormFieldRequiredIndicator.tsx"],"sourcesContent":["import { cx } from 'class-variance-authority'\nimport { Ref } from 'react'\n\nimport { Label, LabelRequiredIndicatorProps } from '../label'\n\nexport type FormFieldRequiredIndicatorProps = LabelRequiredIndicatorProps & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldRequiredIndicator = ({\n className,\n ref,\n ...props\n}: FormFieldRequiredIndicatorProps) => {\n return <Label.RequiredIndicator ref={ref} className={cx('ml-sm', className)} {...props} />\n}\n\nFormFieldRequiredIndicator.displayName = 'FormField.RequiredIndicator'\n"],"names":["FormFieldRequiredIndicator","className","ref","props","jsx","Label","cx"],"mappings":"sHASaA,EAA6B,CAAC,CACzC,UAAAC,EACA,IAAAC,EACA,GAAGC,CACL,IACSC,MAACC,EAAAA,MAAM,kBAAN,CAAwB,IAAAH,EAAU,UAAWI,EAAAA,GAAG,QAASL,CAAS,EAAI,GAAGE,CAAA,CAAO,EAG1FH,EAA2B,YAAc"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { cx as m } from "class-variance-authority";
|
|
3
|
+
import { Label as a } from "./label/index.mjs";
|
|
4
|
+
const d = ({
|
|
5
|
+
className: r,
|
|
6
|
+
ref: e,
|
|
7
|
+
...o
|
|
8
|
+
}) => /* @__PURE__ */ i(a.RequiredIndicator, { ref: e, className: m("ml-sm", r), ...o });
|
|
9
|
+
d.displayName = "FormField.RequiredIndicator";
|
|
10
|
+
export {
|
|
11
|
+
d as F
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=FormFieldRequiredIndicator-DTnCGiX2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldRequiredIndicator-DTnCGiX2.mjs","sources":["../src/form-field/FormFieldRequiredIndicator.tsx"],"sourcesContent":["import { cx } from 'class-variance-authority'\nimport { Ref } from 'react'\n\nimport { Label, LabelRequiredIndicatorProps } from '../label'\n\nexport type FormFieldRequiredIndicatorProps = LabelRequiredIndicatorProps & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldRequiredIndicator = ({\n className,\n ref,\n ...props\n}: FormFieldRequiredIndicatorProps) => {\n return <Label.RequiredIndicator ref={ref} className={cx('ml-sm', className)} {...props} />\n}\n\nFormFieldRequiredIndicator.displayName = 'FormField.RequiredIndicator'\n"],"names":["FormFieldRequiredIndicator","className","ref","props","jsx","Label","cx"],"mappings":";;;AASO,MAAMA,IAA6B,CAAC;AAAA,EACzC,WAAAC;AAAA,EACA,KAAAC;AAAA,EACA,GAAGC;AACL,MACS,gBAAAC,EAACC,EAAM,mBAAN,EAAwB,KAAAH,GAAU,WAAWI,EAAG,SAASL,CAAS,GAAI,GAAGE,EAAA,CAAO;AAG1FH,EAA2B,cAAc;"}
|
package/dist/form-field/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),u=require("class-variance-authority"),n=require("react"),$=require("../Slot-DQ8z2zsy.js"),z=require("@spark-ui/icons/AlertOutline"),V=require("@spark-ui/icons/Check"),w=require("@spark-ui/icons/WarningOutline"),I=require("../Icon-CF0W0LKr.js"),W=require("../label/index.js"),M=require("../FormFieldRequiredIndicator-CHfcoT2y.js"),N=n.createContext(null),j=":form-field",y=()=>{const s=n.useContext(N);if(!s)throw Error("useFormField must be used within a FormField provider");return s},E=({id:s,name:e,disabled:t=!1,readOnly:l=!1,state:o,isRequired:i,children:d})=>{const a=`${j}-label-${n.useId()}`,[c,m]=n.useState([]),F=c.length>0?c.join(" "):void 0,g=n.useCallback(x=>{m(h=>[...h,x])},[]),A=n.useCallback(x=>{m(h=>h.filter(T=>T!==x))},[]),L=n.useMemo(()=>({id:s,labelId:a,name:e,disabled:t,readOnly:l,state:o,isRequired:i,isInvalid:o==="error",description:F,onMessageIdAdd:g,onMessageIdRemove:A}),[s,a,e,t,l,F,o,i,g,A]);return r.jsx(N.Provider,{value:L,children:d})};E.displayName="FormFieldProvider";const O=({className:s,disabled:e=!1,readOnly:t=!1,name:l,state:o,isRequired:i=!1,asChild:d=!1,ref:a,...c})=>{const m=`${j}-${n.useId()}`,F=d?$.Slot:"div";return r.jsx(E,{id:m,name:l,isRequired:i,disabled:e,readOnly:t,state:o,children:r.jsx(F,{ref:a,"data-spark-component":"form-field",className:u.cx(s,"gap-sm flex flex-col"),...c})})};O.displayName="FormField";const f=({id:s,className:e,ref:t,...l})=>{const{onMessageIdAdd:o,onMessageIdRemove:i}=y(),d=`${j}-message-${n.useId()}`,a=s||d;return n.useEffect(()=>(o(a),()=>{i(a)}),[a,o,i]),r.jsx("span",{ref:t,id:a,"data-spark-component":"form-field-message",className:u.cx(e,"text-caption"),...l})};f.displayName="FormField.Message";const p=({className:s,state:e,children:t,ref:l,...o})=>y().state!==e?null:r.jsxs(f,{ref:l,"data-spark-component":"form-field-state-message",className:u.cx("gap-sm flex items-center",e==="error"?"text-error":"text-on-surface/dim-1",s),...o,children:[e==="alert"&&r.jsx(I.Icon,{size:"sm",children:r.jsx(w.WarningOutline,{})}),e==="error"&&r.jsx(I.Icon,{size:"sm",intent:"error",children:r.jsx(z.AlertOutline,{})}),e==="success"&&r.jsx(I.Icon,{size:"sm",children:r.jsx(V.Check,{})}),t]});p.displayName="FormField.StateMessage";const C=({ref:s,...e})=>r.jsx(p,{ref:s,"data-spark-component":"form-field-alert-message",state:"alert",...e});C.displayName="FormField.AlertMessage";const b=({className:s,value:e="",maxLength:t,description:l,liveAnnouncement:o,ref:i,...d})=>{const[a,c]=n.useState(e);return n.useEffect(()=>{const m=setTimeout(()=>{c(e)},1e3);return()=>clearTimeout(m)},[e]),r.jsxs("span",{className:"ml-auto self-start",children:[l&&r.jsx(f,{className:"default:sr-only",children:l}),r.jsx("span",{ref:i,"aria-hidden":!0,"data-spark-component":"form-field-characters-count",className:u.cx(s,"text-caption","text-neutral"),...d,children:`${e.length}/${t}`}),o&&r.jsx("span",{className:"sr-only","aria-live":"polite",children:o({remainingChars:t-a.length})})]})};b.displayName="FormField.CharactersCount";const P=()=>{const{id:s,name:e,description:t,disabled:l,readOnly:o,state:i,labelId:d,isInvalid:a,isRequired:c}=n.useContext(N)||{};return{id:s,name:e,description:t,disabled:l,readOnly:o,state:i,labelId:d,isInvalid:a,isRequired:c}},q=({children:s})=>{const e=P();return r.jsx(r.Fragment,{children:s(e)})};q.displayName="FormField.Control";const S=({ref:s,...e})=>r.jsx(p,{ref:s,"data-spark-component":"form-field-error-message",state:"error",...e});S.displayName="FormField.ErrorMessage";const v=({className:s,ref:e,...t})=>r.jsx(f,{ref:e,"data-spark-component":"form-field-helper-message",className:u.cx("text-on-surface/dim-1",s),...t});v.displayName="FormField.HelperMessage";const k=({htmlFor:s,className:e,children:t,requiredIndicator:l=r.jsx(M.FormFieldRequiredIndicator,{}),asChild:o,ref:i,...d})=>{const a=y(),{disabled:c,labelId:m,isRequired:F}=a,g=o?void 0:s||a.id;return r.jsx(W.Label,{ref:i,id:m,"data-spark-component":"form-field-label",htmlFor:g,className:u.cx(e,c?"text-on-surface/dim-3 pointer-events-none":void 0),asChild:o,...d,children:r.jsxs(r.Fragment,{children:[r.jsx($.Slottable,{children:t}),F&&l]})})};k.displayName="FormField.Label";const R=({ref:s,...e})=>r.jsx(p,{ref:s,"data-spark-component":"form-field-success-message",state:"success",...e});R.displayName="FormField.SuccessMessage";const H=Object.assign(O,{Label:k,Control:q,StateMessage:p,SuccessMessage:R,AlertMessage:C,ErrorMessage:S,HelperMessage:v,RequiredIndicator:M.FormFieldRequiredIndicator,CharactersCount:b});H.displayName="FormField";k.displayName="FormField.Label";q.displayName="FormField.Control";p.displayName="FormField.StateMessage";R.displayName="FormField.SuccessMessage";C.displayName="FormField.AlertMessage";S.displayName="FormField.ErrorMessage";v.displayName="FormField.HelperMessage";M.FormFieldRequiredIndicator.displayName="FormField.RequiredIndicator";b.displayName="FormField.CharactersCount";exports.FormField=H;exports.useFormFieldControl=P;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/form-field/FormFieldContext.tsx","../../src/form-field/FormFieldProvider.tsx","../../src/form-field/FormField.tsx","../../src/form-field/FormFieldMessage.tsx","../../src/form-field/FormFieldStateMessage.tsx","../../src/form-field/FormFieldAlertMessage.tsx","../../src/form-field/FormFieldCharactersCount.tsx","../../src/form-field/FormFieldControl.tsx","../../src/form-field/FormFieldErrorMessage.tsx","../../src/form-field/FormFieldHelperMessage.tsx","../../src/form-field/FormFieldRequiredIndicator.tsx","../../src/form-field/FormFieldLabel.tsx","../../src/form-field/FormFieldSuccessMessage.tsx","../../src/form-field/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nexport interface FormFieldContextState {\n /**\n * Generated id for the input component.\n */\n id: string\n /**\n * Generated id for the label component.\n */\n labelId?: string\n /**\n * The name of the input. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * A set of ids separated by a space used to describe the input component given by a set of messages.\n */\n description?: string\n /**\n * Disables the field and its associated input\n */\n disabled?: boolean\n /**\n * Marks the field and its associated input as read only\n */\n readOnly?: boolean\n /**\n * The validation state of the input.\n */\n state?: 'error' | 'success' | 'alert'\n /**\n * If true, the form field will be invalid.\n */\n isInvalid?: boolean\n /**\n * If true, the form field will be required.\n */\n isRequired?: boolean\n /**\n * Callback used to store a descriptive message.\n */\n onMessageIdAdd: (id: string) => void\n /**\n * Callback used to remove a descriptive message.\n */\n onMessageIdRemove: (id: string) => void\n}\n\nexport const FormFieldContext = createContext<FormFieldContextState | null>(null)\n\nexport const ID_PREFIX = ':form-field'\n\nexport const useFormField = () => {\n const context = useContext(FormFieldContext)\n\n if (!context) {\n throw Error('useFormField must be used within a FormField provider')\n }\n\n return context\n}\n","import { ReactNode, useCallback, useId, useMemo, useState } from 'react'\n\nimport { FormFieldContext, FormFieldContextState, ID_PREFIX } from './FormFieldContext'\n\nexport interface FormFieldProviderProps\n extends Pick<\n FormFieldContextState,\n 'id' | 'name' | 'disabled' | 'readOnly' | 'state' | 'isRequired'\n > {\n children: ReactNode\n}\n\nexport const FormFieldProvider = ({\n id,\n name,\n disabled = false,\n readOnly = false,\n state,\n isRequired,\n children,\n}: FormFieldProviderProps) => {\n const labelId = `${ID_PREFIX}-label-${useId()}`\n const [messageIds, setMessageIds] = useState<string[]>([])\n const description = messageIds.length > 0 ? messageIds.join(' ') : undefined\n\n const handleMessageIdAdd = useCallback((msgId: string) => {\n setMessageIds(ids => [...ids, msgId])\n }, [])\n\n const handleMessageIdRemove = useCallback((msgId: string) => {\n setMessageIds(ids => ids.filter(current => current !== msgId))\n }, [])\n\n const value = useMemo(() => {\n const isInvalid = state === 'error'\n\n return {\n id,\n labelId,\n name,\n disabled,\n readOnly,\n state,\n isRequired,\n isInvalid,\n description,\n onMessageIdAdd: handleMessageIdAdd,\n onMessageIdRemove: handleMessageIdRemove,\n }\n }, [\n id,\n labelId,\n name,\n disabled,\n readOnly,\n description,\n state,\n isRequired,\n handleMessageIdAdd,\n handleMessageIdRemove,\n ])\n\n return <FormFieldContext.Provider value={value}>{children}</FormFieldContext.Provider>\n}\n\nFormFieldProvider.displayName = 'FormFieldProvider'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, Ref, useId } from 'react'\n\nimport { Slot } from '../slot'\nimport { FormFieldContextState, ID_PREFIX } from './FormFieldContext'\nimport { FormFieldProvider } from './FormFieldProvider'\n\nexport interface FormFieldProps\n extends ComponentPropsWithoutRef<'div'>,\n Pick<FormFieldContextState, 'name' | 'state' | 'isRequired'> {\n /**\n * Change the component to the HTML tag or custom component of the only child. This will merge the original component props with the props of the supplied element/component and change the underlying DOM node.\n */\n asChild?: boolean\n /**\n * When `true`, prevents the user from interacting.\n */\n disabled?: boolean\n /**\n * Sets the component as interactive or not.\n */\n readOnly?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const FormField = ({\n className,\n disabled = false,\n readOnly = false,\n name,\n state,\n isRequired = false,\n asChild = false,\n ref,\n ...others\n}: FormFieldProps) => {\n const id = `${ID_PREFIX}-${useId()}`\n const Component = asChild ? Slot : 'div'\n\n return (\n <FormFieldProvider\n id={id}\n name={name}\n isRequired={isRequired}\n disabled={disabled}\n readOnly={readOnly}\n state={state}\n >\n <Component\n ref={ref}\n data-spark-component=\"form-field\"\n className={cx(className, 'gap-sm flex flex-col')}\n {...others}\n />\n </FormFieldProvider>\n )\n}\n\nFormField.displayName = 'FormField'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, Ref, useEffect, useId } from 'react'\n\nimport { ID_PREFIX, useFormField } from './FormFieldContext'\n\nexport type FormFieldMessageProps = ComponentPropsWithoutRef<'span'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldMessage = ({\n id: idProp,\n className,\n ref,\n ...others\n}: FormFieldMessageProps) => {\n const { onMessageIdAdd, onMessageIdRemove } = useFormField()\n const currentId = `${ID_PREFIX}-message-${useId()}`\n const id = idProp || currentId\n\n useEffect(() => {\n onMessageIdAdd(id)\n\n return () => {\n onMessageIdRemove(id)\n }\n }, [id, onMessageIdAdd, onMessageIdRemove])\n\n return (\n <span\n ref={ref}\n id={id}\n data-spark-component=\"form-field-message\"\n className={cx(className, 'text-caption')}\n {...others}\n />\n )\n}\n\nFormFieldMessage.displayName = 'FormField.Message'\n","import { AlertOutline } from '@spark-ui/icons/AlertOutline'\nimport { Check } from '@spark-ui/icons/Check'\nimport { WarningOutline } from '@spark-ui/icons/WarningOutline'\nimport { cx } from 'class-variance-authority'\nimport { Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { useFormField } from './FormFieldContext'\nimport { FormFieldMessage, FormFieldMessageProps } from './FormFieldMessage'\n\nexport interface FormFieldStateMessageProps extends FormFieldMessageProps {\n state: 'error' | 'alert' | 'success'\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldStateMessage = ({\n className,\n state,\n children,\n ref,\n ...others\n}: FormFieldStateMessageProps) => {\n const field = useFormField()\n\n if (field.state !== state) {\n return null\n }\n\n return (\n <FormFieldMessage\n ref={ref}\n data-spark-component=\"form-field-state-message\"\n className={cx(\n 'gap-sm flex items-center',\n state === 'error' ? 'text-error' : 'text-on-surface/dim-1',\n className\n )}\n {...others}\n >\n {state === 'alert' && (\n <Icon size=\"sm\">\n <WarningOutline />\n </Icon>\n )}\n {state === 'error' && (\n <Icon size=\"sm\" intent=\"error\">\n <AlertOutline />\n </Icon>\n )}\n {state === 'success' && (\n <Icon size=\"sm\">\n <Check />\n </Icon>\n )}\n\n {children}\n </FormFieldMessage>\n )\n}\n\nFormFieldStateMessage.displayName = 'FormField.StateMessage'\n","import { Ref } from 'react'\n\nimport { FormFieldStateMessage, FormFieldStateMessageProps } from './FormFieldStateMessage'\n\nexport type FormFieldAlertMessageProps = Omit<FormFieldStateMessageProps, 'state'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldAlertMessage = ({ ref, ...props }: FormFieldAlertMessageProps) => {\n return (\n <FormFieldStateMessage\n ref={ref}\n data-spark-component=\"form-field-alert-message\"\n state=\"alert\"\n {...props}\n />\n )\n}\n\nFormFieldAlertMessage.displayName = 'FormField.AlertMessage'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, Ref, useEffect, useState } from 'react'\n\nimport { FormFieldMessage } from './FormFieldMessage'\n\nexport type FormFieldCharactersCountProps = ComponentPropsWithoutRef<'span'> & {\n /**\n * This description is for the screen reader, read when the input is focused.\n */\n description?: string\n /**\n * The live announcement is for the screen read after a delay once the input value changes.\n */\n liveAnnouncement?: ({ remainingChars }: { remainingChars: number }) => string\n /**\n * Current value for the input this component belongs to.\n */\n value?: string\n /**\n * Maximum numeric value to be displayed.\n */\n maxLength: number\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldCharactersCount = ({\n className,\n value = '',\n maxLength,\n description,\n liveAnnouncement,\n ref,\n ...others\n}: FormFieldCharactersCountProps) => {\n const [throttledValue, setThrottledValue] = useState(value)\n\n /**\n * The value is throttled to avoid spamming the aria-live region (and consequently the screen reader).\n */\n useEffect(() => {\n const timeoutId = setTimeout(() => {\n setThrottledValue(value)\n }, 1000)\n\n return () => clearTimeout(timeoutId)\n }, [value])\n\n return (\n <span className=\"ml-auto self-start\">\n {description && (\n <FormFieldMessage className=\"default:sr-only\">{description}</FormFieldMessage>\n )}\n <span\n ref={ref}\n aria-hidden\n data-spark-component=\"form-field-characters-count\"\n className={cx(className, 'text-caption', 'text-neutral')}\n {...others}\n >\n {`${value.length}/${maxLength}`}\n </span>\n\n {liveAnnouncement && (\n <span className=\"sr-only\" aria-live=\"polite\">\n {liveAnnouncement({ remainingChars: maxLength - throttledValue.length })}\n </span>\n )}\n </span>\n )\n}\n\nFormFieldCharactersCount.displayName = 'FormField.CharactersCount'\n","import { ReactNode, useContext } from 'react'\n\nimport { FormFieldContext, FormFieldContextState } from './FormFieldContext'\n\ntype State = Partial<\n Pick<\n FormFieldContextState,\n | 'id'\n | 'name'\n | 'description'\n | 'labelId'\n | 'disabled'\n | 'readOnly'\n | 'state'\n | 'isInvalid'\n | 'isRequired'\n >\n>\n\nexport interface FormFieldControlProps {\n children: (state: State) => ReactNode\n}\n\nexport const useFormFieldControl = () => {\n const { id, name, description, disabled, readOnly, state, labelId, isInvalid, isRequired } =\n useContext(FormFieldContext) || {}\n\n return {\n id,\n name,\n description,\n disabled,\n readOnly,\n state,\n labelId,\n isInvalid,\n isRequired,\n } as State\n}\n\nexport const FormFieldControl = ({ children }: FormFieldControlProps) => {\n const props = useFormFieldControl()\n\n return <>{children(props)}</>\n}\n\nFormFieldControl.displayName = 'FormField.Control'\n","import { Ref } from 'react'\n\nimport { FormFieldStateMessage, FormFieldStateMessageProps } from './FormFieldStateMessage'\n\nexport type FormFieldErrorMessageProps = Omit<FormFieldStateMessageProps, 'state'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldErrorMessage = ({ ref, ...props }: FormFieldErrorMessageProps) => {\n return (\n <FormFieldStateMessage\n ref={ref}\n data-spark-component=\"form-field-error-message\"\n state=\"error\"\n {...props}\n />\n )\n}\n\nFormFieldErrorMessage.displayName = 'FormField.ErrorMessage'\n","import { cx } from 'class-variance-authority'\nimport { Ref } from 'react'\n\nimport { FormFieldMessage, FormFieldMessageProps } from './FormFieldMessage'\n\nexport type FormFieldHelperMessageProps = FormFieldMessageProps & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldHelperMessage = ({\n className,\n ref,\n ...others\n}: FormFieldHelperMessageProps) => {\n return (\n <FormFieldMessage\n ref={ref}\n data-spark-component=\"form-field-helper-message\"\n className={cx('text-on-surface/dim-1', className)}\n {...others}\n />\n )\n}\n\nFormFieldHelperMessage.displayName = 'FormField.HelperMessage'\n","import { cx } from 'class-variance-authority'\nimport { Ref } from 'react'\n\nimport { Label, LabelRequiredIndicatorProps } from '../label'\n\nexport type FormFieldRequiredIndicatorProps = LabelRequiredIndicatorProps & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldRequiredIndicator = ({\n className,\n ref,\n ...props\n}: FormFieldRequiredIndicatorProps) => {\n return <Label.RequiredIndicator ref={ref} className={cx('ml-sm', className)} {...props} />\n}\n\nFormFieldRequiredIndicator.displayName = 'FormField.RequiredIndicator'\n","import { cx } from 'class-variance-authority'\nimport { ReactNode, Ref } from 'react'\n\nimport { Label, LabelProps } from '../label'\nimport { Slottable } from '../slot'\nimport { useFormField } from './FormFieldContext'\nimport { FormFieldRequiredIndicator } from './FormFieldRequiredIndicator'\n\nexport interface FormFieldLabelProps extends LabelProps {\n /**\n * Element shown when the input is required inside the label.\n */\n requiredIndicator?: ReactNode\n ref?: Ref<HTMLLabelElement>\n}\n\nexport const FormFieldLabel = ({\n htmlFor: htmlForProp,\n className,\n children,\n requiredIndicator = <FormFieldRequiredIndicator />,\n asChild,\n ref,\n ...others\n}: FormFieldLabelProps) => {\n const control = useFormField()\n\n const { disabled, labelId, isRequired } = control\n const htmlFor = asChild ? undefined : htmlForProp || control.id\n\n return (\n <Label\n ref={ref}\n id={labelId}\n data-spark-component=\"form-field-label\"\n htmlFor={htmlFor}\n className={cx(className, disabled ? 'text-on-surface/dim-3 pointer-events-none' : undefined)}\n asChild={asChild}\n {...others}\n >\n <>\n <Slottable>{children}</Slottable>\n {isRequired && requiredIndicator}\n </>\n </Label>\n )\n}\n\nFormFieldLabel.displayName = 'FormField.Label'\n","import { Ref } from 'react'\n\nimport { FormFieldStateMessage, FormFieldStateMessageProps } from './FormFieldStateMessage'\n\nexport type FormFieldSuccessMessageProps = Omit<FormFieldStateMessageProps, 'state'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldSuccessMessage = ({ ref, ...props }: FormFieldSuccessMessageProps) => {\n return (\n <FormFieldStateMessage\n ref={ref}\n data-spark-component=\"form-field-success-message\"\n state=\"success\"\n {...props}\n />\n )\n}\n\nFormFieldSuccessMessage.displayName = 'FormField.SuccessMessage'\n","import { FormField as Root } from './FormField'\nimport { FormFieldAlertMessage } from './FormFieldAlertMessage'\nimport { FormFieldCharactersCount } from './FormFieldCharactersCount'\nimport { FormFieldControl } from './FormFieldControl'\nimport { FormFieldErrorMessage } from './FormFieldErrorMessage'\nimport { FormFieldHelperMessage } from './FormFieldHelperMessage'\nimport { FormFieldLabel } from './FormFieldLabel'\nimport { FormFieldRequiredIndicator } from './FormFieldRequiredIndicator'\nimport { FormFieldStateMessage } from './FormFieldStateMessage'\nimport { FormFieldSuccessMessage } from './FormFieldSuccessMessage'\n\nexport const FormField: typeof Root & {\n Label: typeof FormFieldLabel\n Control: typeof FormFieldControl\n StateMessage: typeof FormFieldStateMessage\n SuccessMessage: typeof FormFieldSuccessMessage\n AlertMessage: typeof FormFieldAlertMessage\n ErrorMessage: typeof FormFieldErrorMessage\n HelperMessage: typeof FormFieldHelperMessage\n RequiredIndicator: typeof FormFieldRequiredIndicator\n CharactersCount: typeof FormFieldCharactersCount\n} = Object.assign(Root, {\n Label: FormFieldLabel,\n Control: FormFieldControl,\n StateMessage: FormFieldStateMessage,\n SuccessMessage: FormFieldSuccessMessage,\n AlertMessage: FormFieldAlertMessage,\n ErrorMessage: FormFieldErrorMessage,\n HelperMessage: FormFieldHelperMessage,\n RequiredIndicator: FormFieldRequiredIndicator,\n CharactersCount: FormFieldCharactersCount,\n})\n\nFormField.displayName = 'FormField'\nFormFieldLabel.displayName = 'FormField.Label'\nFormFieldControl.displayName = 'FormField.Control'\nFormFieldStateMessage.displayName = 'FormField.StateMessage'\nFormFieldSuccessMessage.displayName = 'FormField.SuccessMessage'\nFormFieldAlertMessage.displayName = 'FormField.AlertMessage'\nFormFieldErrorMessage.displayName = 'FormField.ErrorMessage'\nFormFieldHelperMessage.displayName = 'FormField.HelperMessage'\nFormFieldRequiredIndicator.displayName = 'FormField.RequiredIndicator'\nFormFieldCharactersCount.displayName = 'FormField.CharactersCount'\n\nexport { type FormFieldProps } from './FormField'\nexport { type FormFieldStateMessageProps } from './FormFieldStateMessage'\nexport { type FormFieldControl, useFormFieldControl } from './FormFieldControl'\nexport { type FormFieldHelperMessageProps } from './FormFieldHelperMessage'\nexport { type FormFieldSuccessMessageProps } from './FormFieldSuccessMessage'\nexport { type FormFieldAlertMessageProps } from './FormFieldAlertMessage'\nexport { type FormFieldErrorMessageProps } from './FormFieldErrorMessage'\nexport { type FormFieldLabelProps } from './FormFieldLabel'\nexport { type FormFieldRequiredIndicatorProps } from './FormFieldRequiredIndicator'\nexport { type FormFieldCharactersCountProps } from './FormFieldCharactersCount'\n"],"names":["FormFieldContext","createContext","ID_PREFIX","useFormField","context","useContext","FormFieldProvider","id","name","disabled","readOnly","state","isRequired","children","labelId","useId","messageIds","setMessageIds","useState","description","handleMessageIdAdd","useCallback","msgId","ids","handleMessageIdRemove","current","value","useMemo","jsx","FormField","className","asChild","ref","others","Component","Slot","cx","FormFieldMessage","idProp","onMessageIdAdd","onMessageIdRemove","currentId","useEffect","FormFieldStateMessage","jsxs","Icon","WarningOutline","AlertOutline","Check","FormFieldAlertMessage","props","FormFieldCharactersCount","maxLength","liveAnnouncement","throttledValue","setThrottledValue","timeoutId","useFormFieldControl","isInvalid","FormFieldControl","Fragment","FormFieldErrorMessage","FormFieldHelperMessage","FormFieldRequiredIndicator","Label","FormFieldLabel","htmlForProp","requiredIndicator","control","htmlFor","Slottable","FormFieldSuccessMessage","Root"],"mappings":"wYAiDaA,EAAmBC,EAAAA,cAA4C,IAAI,EAEnEC,EAAY,cAEZC,EAAe,IAAM,CAChC,MAAMC,EAAUC,EAAAA,WAAWL,CAAgB,EAE3C,GAAI,CAACI,EACH,MAAM,MAAM,uDAAuD,EAGrE,OAAOA,CACT,ECjDaE,EAAoB,CAAC,CAChC,GAAAC,EACA,KAAAC,EACA,SAAAC,EAAW,GACX,SAAAC,EAAW,GACX,MAAAC,EACA,WAAAC,EACA,SAAAC,CACF,IAA8B,CAC5B,MAAMC,EAAU,GAAGZ,CAAS,UAAUa,EAAAA,OAAO,GACvC,CAACC,EAAYC,CAAa,EAAIC,EAAAA,SAAmB,CAAA,CAAE,EACnDC,EAAcH,EAAW,OAAS,EAAIA,EAAW,KAAK,GAAG,EAAI,OAE7DI,EAAqBC,cAAaC,GAAkB,CACxDL,EAAcM,GAAO,CAAC,GAAGA,EAAKD,CAAK,CAAC,CACtC,EAAG,CAAA,CAAE,EAECE,EAAwBH,cAAaC,GAAkB,CAC3DL,KAAqBM,EAAI,OAAOE,GAAWA,IAAYH,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MAAMM,EAA0B,CAAC,CAAE,IAAAvC,EAAK,GAAGkB,KAE9CtB,EAAAA,IAACe,EAAA,CACC,IAAAX,EACA,uBAAqB,6BACrB,MAAM,UACL,GAAGkB,CAAA,CAAA,EAKVqB,EAAwB,YAAc,2BCR/B,MAAM1C,EAUT,OAAO,OAAO2C,EAAM,CACtB,MAAOP,EACP,QAASN,EACT,aAAchB,EACd,eAAgB4B,EAChB,aAActB,EACd,aAAcY,EACd,cAAeC,EACf,kBAAmBC,EACnB,gBAAiBZ,CACnB,CAAC,EAEDtB,EAAU,YAAc,YACxBoC,EAAe,YAAc,kBAC7BN,EAAiB,YAAc,oBAC/BhB,EAAsB,YAAc,yBACpC4B,EAAwB,YAAc,2BACtCtB,EAAsB,YAAc,yBACpCY,EAAsB,YAAc,yBACpCC,EAAuB,YAAc,0BACrCC,EAA2B,YAAc,8BACzCZ,EAAyB,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/form-field/FormFieldContext.tsx","../../src/form-field/FormFieldProvider.tsx","../../src/form-field/FormField.tsx","../../src/form-field/FormFieldMessage.tsx","../../src/form-field/FormFieldStateMessage.tsx","../../src/form-field/FormFieldAlertMessage.tsx","../../src/form-field/FormFieldCharactersCount.tsx","../../src/form-field/FormFieldControl.tsx","../../src/form-field/FormFieldErrorMessage.tsx","../../src/form-field/FormFieldHelperMessage.tsx","../../src/form-field/FormFieldLabel.tsx","../../src/form-field/FormFieldSuccessMessage.tsx","../../src/form-field/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nexport interface FormFieldContextState {\n /**\n * Generated id for the input component.\n */\n id: string\n /**\n * Generated id for the label component.\n */\n labelId?: string\n /**\n * The name of the input. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * A set of ids separated by a space used to describe the input component given by a set of messages.\n */\n description?: string\n /**\n * Disables the field and its associated input\n */\n disabled?: boolean\n /**\n * Marks the field and its associated input as read only\n */\n readOnly?: boolean\n /**\n * The validation state of the input.\n */\n state?: 'error' | 'success' | 'alert'\n /**\n * If true, the form field will be invalid.\n */\n isInvalid?: boolean\n /**\n * If true, the form field will be required.\n */\n isRequired?: boolean\n /**\n * Callback used to store a descriptive message.\n */\n onMessageIdAdd: (id: string) => void\n /**\n * Callback used to remove a descriptive message.\n */\n onMessageIdRemove: (id: string) => void\n}\n\nexport const FormFieldContext = createContext<FormFieldContextState | null>(null)\n\nexport const ID_PREFIX = ':form-field'\n\nexport const useFormField = () => {\n const context = useContext(FormFieldContext)\n\n if (!context) {\n throw Error('useFormField must be used within a FormField provider')\n }\n\n return context\n}\n","import { ReactNode, useCallback, useId, useMemo, useState } from 'react'\n\nimport { FormFieldContext, FormFieldContextState, ID_PREFIX } from './FormFieldContext'\n\nexport interface FormFieldProviderProps\n extends Pick<\n FormFieldContextState,\n 'id' | 'name' | 'disabled' | 'readOnly' | 'state' | 'isRequired'\n > {\n children: ReactNode\n}\n\nexport const FormFieldProvider = ({\n id,\n name,\n disabled = false,\n readOnly = false,\n state,\n isRequired,\n children,\n}: FormFieldProviderProps) => {\n const labelId = `${ID_PREFIX}-label-${useId()}`\n const [messageIds, setMessageIds] = useState<string[]>([])\n const description = messageIds.length > 0 ? messageIds.join(' ') : undefined\n\n const handleMessageIdAdd = useCallback((msgId: string) => {\n setMessageIds(ids => [...ids, msgId])\n }, [])\n\n const handleMessageIdRemove = useCallback((msgId: string) => {\n setMessageIds(ids => ids.filter(current => current !== msgId))\n }, [])\n\n const value = useMemo(() => {\n const isInvalid = state === 'error'\n\n return {\n id,\n labelId,\n name,\n disabled,\n readOnly,\n state,\n isRequired,\n isInvalid,\n description,\n onMessageIdAdd: handleMessageIdAdd,\n onMessageIdRemove: handleMessageIdRemove,\n }\n }, [\n id,\n labelId,\n name,\n disabled,\n readOnly,\n description,\n state,\n isRequired,\n handleMessageIdAdd,\n handleMessageIdRemove,\n ])\n\n return <FormFieldContext.Provider value={value}>{children}</FormFieldContext.Provider>\n}\n\nFormFieldProvider.displayName = 'FormFieldProvider'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, Ref, useId } from 'react'\n\nimport { Slot } from '../slot'\nimport { FormFieldContextState, ID_PREFIX } from './FormFieldContext'\nimport { FormFieldProvider } from './FormFieldProvider'\n\nexport interface FormFieldProps\n extends ComponentPropsWithoutRef<'div'>,\n Pick<FormFieldContextState, 'name' | 'state' | 'isRequired'> {\n /**\n * Change the component to the HTML tag or custom component of the only child. This will merge the original component props with the props of the supplied element/component and change the underlying DOM node.\n */\n asChild?: boolean\n /**\n * When `true`, prevents the user from interacting.\n */\n disabled?: boolean\n /**\n * Sets the component as interactive or not.\n */\n readOnly?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const FormField = ({\n className,\n disabled = false,\n readOnly = false,\n name,\n state,\n isRequired = false,\n asChild = false,\n ref,\n ...others\n}: FormFieldProps) => {\n const id = `${ID_PREFIX}-${useId()}`\n const Component = asChild ? Slot : 'div'\n\n return (\n <FormFieldProvider\n id={id}\n name={name}\n isRequired={isRequired}\n disabled={disabled}\n readOnly={readOnly}\n state={state}\n >\n <Component\n ref={ref}\n data-spark-component=\"form-field\"\n className={cx(className, 'gap-sm flex flex-col')}\n {...others}\n />\n </FormFieldProvider>\n )\n}\n\nFormField.displayName = 'FormField'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, Ref, useEffect, useId } from 'react'\n\nimport { ID_PREFIX, useFormField } from './FormFieldContext'\n\nexport type FormFieldMessageProps = ComponentPropsWithoutRef<'span'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldMessage = ({\n id: idProp,\n className,\n ref,\n ...others\n}: FormFieldMessageProps) => {\n const { onMessageIdAdd, onMessageIdRemove } = useFormField()\n const currentId = `${ID_PREFIX}-message-${useId()}`\n const id = idProp || currentId\n\n useEffect(() => {\n onMessageIdAdd(id)\n\n return () => {\n onMessageIdRemove(id)\n }\n }, [id, onMessageIdAdd, onMessageIdRemove])\n\n return (\n <span\n ref={ref}\n id={id}\n data-spark-component=\"form-field-message\"\n className={cx(className, 'text-caption')}\n {...others}\n />\n )\n}\n\nFormFieldMessage.displayName = 'FormField.Message'\n","import { AlertOutline } from '@spark-ui/icons/AlertOutline'\nimport { Check } from '@spark-ui/icons/Check'\nimport { WarningOutline } from '@spark-ui/icons/WarningOutline'\nimport { cx } from 'class-variance-authority'\nimport { Ref } from 'react'\n\nimport { Icon } from '../icon'\nimport { useFormField } from './FormFieldContext'\nimport { FormFieldMessage, FormFieldMessageProps } from './FormFieldMessage'\n\nexport interface FormFieldStateMessageProps extends FormFieldMessageProps {\n state: 'error' | 'alert' | 'success'\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldStateMessage = ({\n className,\n state,\n children,\n ref,\n ...others\n}: FormFieldStateMessageProps) => {\n const field = useFormField()\n\n if (field.state !== state) {\n return null\n }\n\n return (\n <FormFieldMessage\n ref={ref}\n data-spark-component=\"form-field-state-message\"\n className={cx(\n 'gap-sm flex items-center',\n state === 'error' ? 'text-error' : 'text-on-surface/dim-1',\n className\n )}\n {...others}\n >\n {state === 'alert' && (\n <Icon size=\"sm\">\n <WarningOutline />\n </Icon>\n )}\n {state === 'error' && (\n <Icon size=\"sm\" intent=\"error\">\n <AlertOutline />\n </Icon>\n )}\n {state === 'success' && (\n <Icon size=\"sm\">\n <Check />\n </Icon>\n )}\n\n {children}\n </FormFieldMessage>\n )\n}\n\nFormFieldStateMessage.displayName = 'FormField.StateMessage'\n","import { Ref } from 'react'\n\nimport { FormFieldStateMessage, FormFieldStateMessageProps } from './FormFieldStateMessage'\n\nexport type FormFieldAlertMessageProps = Omit<FormFieldStateMessageProps, 'state'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldAlertMessage = ({ ref, ...props }: FormFieldAlertMessageProps) => {\n return (\n <FormFieldStateMessage\n ref={ref}\n data-spark-component=\"form-field-alert-message\"\n state=\"alert\"\n {...props}\n />\n )\n}\n\nFormFieldAlertMessage.displayName = 'FormField.AlertMessage'\n","import { cx } from 'class-variance-authority'\nimport { ComponentPropsWithoutRef, Ref, useEffect, useState } from 'react'\n\nimport { FormFieldMessage } from './FormFieldMessage'\n\nexport type FormFieldCharactersCountProps = ComponentPropsWithoutRef<'span'> & {\n /**\n * This description is for the screen reader, read when the input is focused.\n */\n description?: string\n /**\n * The live announcement is for the screen read after a delay once the input value changes.\n */\n liveAnnouncement?: ({ remainingChars }: { remainingChars: number }) => string\n /**\n * Current value for the input this component belongs to.\n */\n value?: string\n /**\n * Maximum numeric value to be displayed.\n */\n maxLength: number\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldCharactersCount = ({\n className,\n value = '',\n maxLength,\n description,\n liveAnnouncement,\n ref,\n ...others\n}: FormFieldCharactersCountProps) => {\n const [throttledValue, setThrottledValue] = useState(value)\n\n /**\n * The value is throttled to avoid spamming the aria-live region (and consequently the screen reader).\n */\n useEffect(() => {\n const timeoutId = setTimeout(() => {\n setThrottledValue(value)\n }, 1000)\n\n return () => clearTimeout(timeoutId)\n }, [value])\n\n return (\n <span className=\"ml-auto self-start\">\n {description && (\n <FormFieldMessage className=\"default:sr-only\">{description}</FormFieldMessage>\n )}\n <span\n ref={ref}\n aria-hidden\n data-spark-component=\"form-field-characters-count\"\n className={cx(className, 'text-caption', 'text-neutral')}\n {...others}\n >\n {`${value.length}/${maxLength}`}\n </span>\n\n {liveAnnouncement && (\n <span className=\"sr-only\" aria-live=\"polite\">\n {liveAnnouncement({ remainingChars: maxLength - throttledValue.length })}\n </span>\n )}\n </span>\n )\n}\n\nFormFieldCharactersCount.displayName = 'FormField.CharactersCount'\n","import { ReactNode, useContext } from 'react'\n\nimport { FormFieldContext, FormFieldContextState } from './FormFieldContext'\n\ntype State = Partial<\n Pick<\n FormFieldContextState,\n | 'id'\n | 'name'\n | 'description'\n | 'labelId'\n | 'disabled'\n | 'readOnly'\n | 'state'\n | 'isInvalid'\n | 'isRequired'\n >\n>\n\nexport interface FormFieldControlProps {\n children: (state: State) => ReactNode\n}\n\nexport const useFormFieldControl = () => {\n const { id, name, description, disabled, readOnly, state, labelId, isInvalid, isRequired } =\n useContext(FormFieldContext) || {}\n\n return {\n id,\n name,\n description,\n disabled,\n readOnly,\n state,\n labelId,\n isInvalid,\n isRequired,\n } as State\n}\n\nexport const FormFieldControl = ({ children }: FormFieldControlProps) => {\n const props = useFormFieldControl()\n\n return <>{children(props)}</>\n}\n\nFormFieldControl.displayName = 'FormField.Control'\n","import { Ref } from 'react'\n\nimport { FormFieldStateMessage, FormFieldStateMessageProps } from './FormFieldStateMessage'\n\nexport type FormFieldErrorMessageProps = Omit<FormFieldStateMessageProps, 'state'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldErrorMessage = ({ ref, ...props }: FormFieldErrorMessageProps) => {\n return (\n <FormFieldStateMessage\n ref={ref}\n data-spark-component=\"form-field-error-message\"\n state=\"error\"\n {...props}\n />\n )\n}\n\nFormFieldErrorMessage.displayName = 'FormField.ErrorMessage'\n","import { cx } from 'class-variance-authority'\nimport { Ref } from 'react'\n\nimport { FormFieldMessage, FormFieldMessageProps } from './FormFieldMessage'\n\nexport type FormFieldHelperMessageProps = FormFieldMessageProps & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldHelperMessage = ({\n className,\n ref,\n ...others\n}: FormFieldHelperMessageProps) => {\n return (\n <FormFieldMessage\n ref={ref}\n data-spark-component=\"form-field-helper-message\"\n className={cx('text-on-surface/dim-1', className)}\n {...others}\n />\n )\n}\n\nFormFieldHelperMessage.displayName = 'FormField.HelperMessage'\n","import { cx } from 'class-variance-authority'\nimport { ReactNode, Ref } from 'react'\n\nimport { Label, LabelProps } from '../label'\nimport { Slottable } from '../slot'\nimport { useFormField } from './FormFieldContext'\nimport { FormFieldRequiredIndicator } from './FormFieldRequiredIndicator'\n\nexport interface FormFieldLabelProps extends LabelProps {\n /**\n * Element shown when the input is required inside the label.\n */\n requiredIndicator?: ReactNode\n ref?: Ref<HTMLLabelElement>\n}\n\nexport const FormFieldLabel = ({\n htmlFor: htmlForProp,\n className,\n children,\n requiredIndicator = <FormFieldRequiredIndicator />,\n asChild,\n ref,\n ...others\n}: FormFieldLabelProps) => {\n const control = useFormField()\n\n const { disabled, labelId, isRequired } = control\n const htmlFor = asChild ? undefined : htmlForProp || control.id\n\n return (\n <Label\n ref={ref}\n id={labelId}\n data-spark-component=\"form-field-label\"\n htmlFor={htmlFor}\n className={cx(className, disabled ? 'text-on-surface/dim-3 pointer-events-none' : undefined)}\n asChild={asChild}\n {...others}\n >\n <>\n <Slottable>{children}</Slottable>\n {isRequired && requiredIndicator}\n </>\n </Label>\n )\n}\n\nFormFieldLabel.displayName = 'FormField.Label'\n","import { Ref } from 'react'\n\nimport { FormFieldStateMessage, FormFieldStateMessageProps } from './FormFieldStateMessage'\n\nexport type FormFieldSuccessMessageProps = Omit<FormFieldStateMessageProps, 'state'> & {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const FormFieldSuccessMessage = ({ ref, ...props }: FormFieldSuccessMessageProps) => {\n return (\n <FormFieldStateMessage\n ref={ref}\n data-spark-component=\"form-field-success-message\"\n state=\"success\"\n {...props}\n />\n )\n}\n\nFormFieldSuccessMessage.displayName = 'FormField.SuccessMessage'\n","import { FormField as Root } from './FormField'\nimport { FormFieldAlertMessage } from './FormFieldAlertMessage'\nimport { FormFieldCharactersCount } from './FormFieldCharactersCount'\nimport { FormFieldControl } from './FormFieldControl'\nimport { FormFieldErrorMessage } from './FormFieldErrorMessage'\nimport { FormFieldHelperMessage } from './FormFieldHelperMessage'\nimport { FormFieldLabel } from './FormFieldLabel'\nimport { FormFieldRequiredIndicator } from './FormFieldRequiredIndicator'\nimport { FormFieldStateMessage } from './FormFieldStateMessage'\nimport { FormFieldSuccessMessage } from './FormFieldSuccessMessage'\n\nexport const FormField: typeof Root & {\n Label: typeof FormFieldLabel\n Control: typeof FormFieldControl\n StateMessage: typeof FormFieldStateMessage\n SuccessMessage: typeof FormFieldSuccessMessage\n AlertMessage: typeof FormFieldAlertMessage\n ErrorMessage: typeof FormFieldErrorMessage\n HelperMessage: typeof FormFieldHelperMessage\n RequiredIndicator: typeof FormFieldRequiredIndicator\n CharactersCount: typeof FormFieldCharactersCount\n} = Object.assign(Root, {\n Label: FormFieldLabel,\n Control: FormFieldControl,\n StateMessage: FormFieldStateMessage,\n SuccessMessage: FormFieldSuccessMessage,\n AlertMessage: FormFieldAlertMessage,\n ErrorMessage: FormFieldErrorMessage,\n HelperMessage: FormFieldHelperMessage,\n RequiredIndicator: FormFieldRequiredIndicator,\n CharactersCount: FormFieldCharactersCount,\n})\n\nFormField.displayName = 'FormField'\nFormFieldLabel.displayName = 'FormField.Label'\nFormFieldControl.displayName = 'FormField.Control'\nFormFieldStateMessage.displayName = 'FormField.StateMessage'\nFormFieldSuccessMessage.displayName = 'FormField.SuccessMessage'\nFormFieldAlertMessage.displayName = 'FormField.AlertMessage'\nFormFieldErrorMessage.displayName = 'FormField.ErrorMessage'\nFormFieldHelperMessage.displayName = 'FormField.HelperMessage'\nFormFieldRequiredIndicator.displayName = 'FormField.RequiredIndicator'\nFormFieldCharactersCount.displayName = 'FormField.CharactersCount'\n\nexport { type FormFieldProps } from './FormField'\nexport { type FormFieldStateMessageProps } from './FormFieldStateMessage'\nexport { type FormFieldControl, useFormFieldControl } from './FormFieldControl'\nexport { type FormFieldHelperMessageProps } from './FormFieldHelperMessage'\nexport { type FormFieldSuccessMessageProps } from './FormFieldSuccessMessage'\nexport { type FormFieldAlertMessageProps } from './FormFieldAlertMessage'\nexport { type FormFieldErrorMessageProps } from './FormFieldErrorMessage'\nexport { type FormFieldLabelProps } from './FormFieldLabel'\nexport { type FormFieldRequiredIndicatorProps } from './FormFieldRequiredIndicator'\nexport { type FormFieldCharactersCountProps } from './FormFieldCharactersCount'\n"],"names":["FormFieldContext","createContext","ID_PREFIX","useFormField","context","useContext","FormFieldProvider","id","name","disabled","readOnly","state","isRequired","children","labelId","useId","messageIds","setMessageIds","useState","description","handleMessageIdAdd","useCallback","msgId","ids","handleMessageIdRemove","current","value","useMemo","jsx","FormField","className","asChild","ref","others","Component","Slot","cx","FormFieldMessage","idProp","onMessageIdAdd","onMessageIdRemove","currentId","useEffect","FormFieldStateMessage","jsxs","Icon","WarningOutline","AlertOutline","Check","FormFieldAlertMessage","props","FormFieldCharactersCount","maxLength","liveAnnouncement","throttledValue","setThrottledValue","timeoutId","useFormFieldControl","isInvalid","FormFieldControl","Fragment","FormFieldErrorMessage","FormFieldHelperMessage","FormFieldLabel","htmlForProp","requiredIndicator","FormFieldRequiredIndicator","control","htmlFor","Label","Slottable","FormFieldSuccessMessage","Root"],"mappings":"+bAiDaA,EAAmBC,EAAAA,cAA4C,IAAI,EAEnEC,EAAY,cAEZC,EAAe,IAAM,CAChC,MAAMC,EAAUC,EAAAA,WAAWL,CAAgB,EAE3C,GAAI,CAACI,EACH,MAAM,MAAM,uDAAuD,EAGrE,OAAOA,CACT,ECjDaE,EAAoB,CAAC,CAChC,GAAAC,EACA,KAAAC,EACA,SAAAC,EAAW,GACX,SAAAC,EAAW,GACX,MAAAC,EACA,WAAAC,EACA,SAAAC,CACF,IAA8B,CAC5B,MAAMC,EAAU,GAAGZ,CAAS,UAAUa,EAAAA,OAAO,GACvC,CAACC,EAAYC,CAAa,EAAIC,EAAAA,SAAmB,CAAA,CAAE,EACnDC,EAAcH,EAAW,OAAS,EAAIA,EAAW,KAAK,GAAG,EAAI,OAE7DI,EAAqBC,cAAaC,GAAkB,CACxDL,EAAcM,GAAO,CAAC,GAAGA,EAAKD,CAAK,CAAC,CACtC,EAAG,CAAA,CAAE,EAECE,EAAwBH,cAAaC,GAAkB,CAC3DL,KAAqBM,EAAI,OAAOE,GAAWA,IAAYH,CAAK,CAAC,CAC/D,EAAG,CAAA,CAAE,EAECI,EAAQC,EAAAA,QAAQ,KAGb,CACL,GAAApB,EACA,QAAAO,EACA,KAAAN,EACA,SAAAC,EACA,SAAAC,EACA,MAAAC,EACA,WAAAC,EAC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AU,YAAc,YACxBkC,EAAe,YAAc,kBAC7BJ,EAAiB,YAAc,oBAC/BhB,EAAsB,YAAc,yBACpC4B,EAAwB,YAAc,2BACtCtB,EAAsB,YAAc,yBACpCY,EAAsB,YAAc,yBACpCC,EAAuB,YAAc,0BACrCI,EAAAA,2BAA2B,YAAc,8BACzCf,EAAyB,YAAc"}
|
|
@@ -1,80 +1,81 @@
|
|
|
1
|
-
import { jsx as r, jsxs as
|
|
1
|
+
import { jsx as r, jsxs as N, Fragment as H } from "react/jsx-runtime";
|
|
2
2
|
import { cx as c } from "class-variance-authority";
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { a as
|
|
5
|
-
import { AlertOutline as
|
|
6
|
-
import { Check as
|
|
7
|
-
import { WarningOutline as
|
|
3
|
+
import { createContext as D, useContext as L, useId as I, useState as P, useCallback as q, useMemo as W, useEffect as z } from "react";
|
|
4
|
+
import { a as X, S as _ } from "../Slot-D2Bbf8Gw.mjs";
|
|
5
|
+
import { AlertOutline as B } from "@spark-ui/icons/AlertOutline";
|
|
6
|
+
import { Check as G } from "@spark-ui/icons/Check";
|
|
7
|
+
import { WarningOutline as J } from "@spark-ui/icons/WarningOutline";
|
|
8
8
|
import { I as M } from "../Icon-Ck-dhfLd.mjs";
|
|
9
|
-
import { Label as
|
|
10
|
-
|
|
9
|
+
import { Label as K } from "../label/index.mjs";
|
|
10
|
+
import { F as y } from "../FormFieldRequiredIndicator-DTnCGiX2.mjs";
|
|
11
|
+
const C = D(null), x = ":form-field", b = () => {
|
|
11
12
|
const s = L(C);
|
|
12
13
|
if (!s)
|
|
13
14
|
throw Error("useFormField must be used within a FormField provider");
|
|
14
15
|
return s;
|
|
15
|
-
},
|
|
16
|
+
}, O = ({
|
|
16
17
|
id: s,
|
|
17
18
|
name: e,
|
|
18
|
-
disabled:
|
|
19
|
+
disabled: a = !1,
|
|
19
20
|
readOnly: l = !1,
|
|
20
|
-
state:
|
|
21
|
+
state: o,
|
|
21
22
|
isRequired: i,
|
|
22
23
|
children: d
|
|
23
24
|
}) => {
|
|
24
|
-
const t = `${x}-label-${
|
|
25
|
+
const t = `${x}-label-${I()}`, [n, m] = P([]), p = n.length > 0 ? n.join(" ") : void 0, u = q((f) => {
|
|
25
26
|
m((h) => [...h, f]);
|
|
26
|
-
}, []),
|
|
27
|
-
m((h) => h.filter((
|
|
28
|
-
}, []),
|
|
27
|
+
}, []), j = q((f) => {
|
|
28
|
+
m((h) => h.filter((V) => V !== f));
|
|
29
|
+
}, []), w = W(() => ({
|
|
29
30
|
id: s,
|
|
30
31
|
labelId: t,
|
|
31
32
|
name: e,
|
|
32
|
-
disabled:
|
|
33
|
+
disabled: a,
|
|
33
34
|
readOnly: l,
|
|
34
|
-
state:
|
|
35
|
+
state: o,
|
|
35
36
|
isRequired: i,
|
|
36
|
-
isInvalid:
|
|
37
|
+
isInvalid: o === "error",
|
|
37
38
|
description: p,
|
|
38
39
|
onMessageIdAdd: u,
|
|
39
|
-
onMessageIdRemove:
|
|
40
|
+
onMessageIdRemove: j
|
|
40
41
|
}), [
|
|
41
42
|
s,
|
|
42
43
|
t,
|
|
43
44
|
e,
|
|
44
|
-
|
|
45
|
+
a,
|
|
45
46
|
l,
|
|
46
47
|
p,
|
|
47
|
-
|
|
48
|
+
o,
|
|
48
49
|
i,
|
|
49
50
|
u,
|
|
50
|
-
|
|
51
|
+
j
|
|
51
52
|
]);
|
|
52
|
-
return /* @__PURE__ */ r(C.Provider, { value:
|
|
53
|
+
return /* @__PURE__ */ r(C.Provider, { value: w, children: d });
|
|
53
54
|
};
|
|
54
|
-
|
|
55
|
-
const
|
|
55
|
+
O.displayName = "FormFieldProvider";
|
|
56
|
+
const T = ({
|
|
56
57
|
className: s,
|
|
57
58
|
disabled: e = !1,
|
|
58
|
-
readOnly:
|
|
59
|
+
readOnly: a = !1,
|
|
59
60
|
name: l,
|
|
60
|
-
state:
|
|
61
|
+
state: o,
|
|
61
62
|
isRequired: i = !1,
|
|
62
63
|
asChild: d = !1,
|
|
63
64
|
ref: t,
|
|
64
65
|
...n
|
|
65
66
|
}) => {
|
|
66
|
-
const m = `${x}-${
|
|
67
|
+
const m = `${x}-${I()}`;
|
|
67
68
|
return /* @__PURE__ */ r(
|
|
68
|
-
|
|
69
|
+
O,
|
|
69
70
|
{
|
|
70
71
|
id: m,
|
|
71
72
|
name: l,
|
|
72
73
|
isRequired: i,
|
|
73
74
|
disabled: e,
|
|
74
|
-
readOnly:
|
|
75
|
-
state:
|
|
75
|
+
readOnly: a,
|
|
76
|
+
state: o,
|
|
76
77
|
children: /* @__PURE__ */ r(
|
|
77
|
-
d ?
|
|
78
|
+
d ? X : "div",
|
|
78
79
|
{
|
|
79
80
|
ref: t,
|
|
80
81
|
"data-spark-component": "form-field",
|
|
@@ -85,20 +86,20 @@ const w = ({
|
|
|
85
86
|
}
|
|
86
87
|
);
|
|
87
88
|
};
|
|
88
|
-
|
|
89
|
+
T.displayName = "FormField";
|
|
89
90
|
const g = ({
|
|
90
91
|
id: s,
|
|
91
92
|
className: e,
|
|
92
|
-
ref:
|
|
93
|
+
ref: a,
|
|
93
94
|
...l
|
|
94
95
|
}) => {
|
|
95
|
-
const { onMessageIdAdd:
|
|
96
|
-
return z(() => (
|
|
96
|
+
const { onMessageIdAdd: o, onMessageIdRemove: i } = b(), d = `${x}-message-${I()}`, t = s || d;
|
|
97
|
+
return z(() => (o(t), () => {
|
|
97
98
|
i(t);
|
|
98
|
-
}), [t,
|
|
99
|
+
}), [t, o, i]), /* @__PURE__ */ r(
|
|
99
100
|
"span",
|
|
100
101
|
{
|
|
101
|
-
ref:
|
|
102
|
+
ref: a,
|
|
102
103
|
id: t,
|
|
103
104
|
"data-spark-component": "form-field-message",
|
|
104
105
|
className: c(e, "text-caption"),
|
|
@@ -110,10 +111,10 @@ g.displayName = "FormField.Message";
|
|
|
110
111
|
const F = ({
|
|
111
112
|
className: s,
|
|
112
113
|
state: e,
|
|
113
|
-
children:
|
|
114
|
+
children: a,
|
|
114
115
|
ref: l,
|
|
115
|
-
...
|
|
116
|
-
}) => b().state !== e ? null : /* @__PURE__ */
|
|
116
|
+
...o
|
|
117
|
+
}) => b().state !== e ? null : /* @__PURE__ */ N(
|
|
117
118
|
g,
|
|
118
119
|
{
|
|
119
120
|
ref: l,
|
|
@@ -123,12 +124,12 @@ const F = ({
|
|
|
123
124
|
e === "error" ? "text-error" : "text-on-surface/dim-1",
|
|
124
125
|
s
|
|
125
126
|
),
|
|
126
|
-
...
|
|
127
|
+
...o,
|
|
127
128
|
children: [
|
|
128
|
-
e === "alert" && /* @__PURE__ */ r(M, { size: "sm", children: /* @__PURE__ */ r(
|
|
129
|
-
e === "error" && /* @__PURE__ */ r(M, { size: "sm", intent: "error", children: /* @__PURE__ */ r(
|
|
130
|
-
e === "success" && /* @__PURE__ */ r(M, { size: "sm", children: /* @__PURE__ */ r(
|
|
131
|
-
|
|
129
|
+
e === "alert" && /* @__PURE__ */ r(M, { size: "sm", children: /* @__PURE__ */ r(J, {}) }),
|
|
130
|
+
e === "error" && /* @__PURE__ */ r(M, { size: "sm", intent: "error", children: /* @__PURE__ */ r(B, {}) }),
|
|
131
|
+
e === "success" && /* @__PURE__ */ r(M, { size: "sm", children: /* @__PURE__ */ r(G, {}) }),
|
|
132
|
+
a
|
|
132
133
|
]
|
|
133
134
|
}
|
|
134
135
|
);
|
|
@@ -146,9 +147,9 @@ v.displayName = "FormField.AlertMessage";
|
|
|
146
147
|
const S = ({
|
|
147
148
|
className: s,
|
|
148
149
|
value: e = "",
|
|
149
|
-
maxLength:
|
|
150
|
+
maxLength: a,
|
|
150
151
|
description: l,
|
|
151
|
-
liveAnnouncement:
|
|
152
|
+
liveAnnouncement: o,
|
|
152
153
|
ref: i,
|
|
153
154
|
...d
|
|
154
155
|
}) => {
|
|
@@ -158,7 +159,7 @@ const S = ({
|
|
|
158
159
|
n(e);
|
|
159
160
|
}, 1e3);
|
|
160
161
|
return () => clearTimeout(m);
|
|
161
|
-
}, [e]), /* @__PURE__ */
|
|
162
|
+
}, [e]), /* @__PURE__ */ N("span", { className: "ml-auto self-start", children: [
|
|
162
163
|
l && /* @__PURE__ */ r(g, { className: "default:sr-only", children: l }),
|
|
163
164
|
/* @__PURE__ */ r(
|
|
164
165
|
"span",
|
|
@@ -168,21 +169,21 @@ const S = ({
|
|
|
168
169
|
"data-spark-component": "form-field-characters-count",
|
|
169
170
|
className: c(s, "text-caption", "text-neutral"),
|
|
170
171
|
...d,
|
|
171
|
-
children: `${e.length}/${
|
|
172
|
+
children: `${e.length}/${a}`
|
|
172
173
|
}
|
|
173
174
|
),
|
|
174
|
-
|
|
175
|
+
o && /* @__PURE__ */ r("span", { className: "sr-only", "aria-live": "polite", children: o({ remainingChars: a - t.length }) })
|
|
175
176
|
] });
|
|
176
177
|
};
|
|
177
178
|
S.displayName = "FormField.CharactersCount";
|
|
178
179
|
const Q = () => {
|
|
179
|
-
const { id: s, name: e, description:
|
|
180
|
+
const { id: s, name: e, description: a, disabled: l, readOnly: o, state: i, labelId: d, isInvalid: t, isRequired: n } = L(C) || {};
|
|
180
181
|
return {
|
|
181
182
|
id: s,
|
|
182
183
|
name: e,
|
|
183
|
-
description:
|
|
184
|
+
description: a,
|
|
184
185
|
disabled: l,
|
|
185
|
-
readOnly:
|
|
186
|
+
readOnly: o,
|
|
186
187
|
state: i,
|
|
187
188
|
labelId: d,
|
|
188
189
|
isInvalid: t,
|
|
@@ -193,7 +194,7 @@ const Q = () => {
|
|
|
193
194
|
return /* @__PURE__ */ r(H, { children: s(e) });
|
|
194
195
|
};
|
|
195
196
|
k.displayName = "FormField.Control";
|
|
196
|
-
const
|
|
197
|
+
const $ = ({ ref: s, ...e }) => /* @__PURE__ */ r(
|
|
197
198
|
F,
|
|
198
199
|
{
|
|
199
200
|
ref: s,
|
|
@@ -202,49 +203,43 @@ const R = ({ ref: s, ...e }) => /* @__PURE__ */ r(
|
|
|
202
203
|
...e
|
|
203
204
|
}
|
|
204
205
|
);
|
|
205
|
-
|
|
206
|
-
const
|
|
206
|
+
$.displayName = "FormField.ErrorMessage";
|
|
207
|
+
const R = ({
|
|
207
208
|
className: s,
|
|
208
209
|
ref: e,
|
|
209
|
-
...
|
|
210
|
+
...a
|
|
210
211
|
}) => /* @__PURE__ */ r(
|
|
211
212
|
g,
|
|
212
213
|
{
|
|
213
214
|
ref: e,
|
|
214
215
|
"data-spark-component": "form-field-helper-message",
|
|
215
216
|
className: c("text-on-surface/dim-1", s),
|
|
216
|
-
...
|
|
217
|
+
...a
|
|
217
218
|
}
|
|
218
219
|
);
|
|
219
|
-
|
|
220
|
-
const N = ({
|
|
221
|
-
className: s,
|
|
222
|
-
ref: e,
|
|
223
|
-
...o
|
|
224
|
-
}) => /* @__PURE__ */ r(O.RequiredIndicator, { ref: e, className: c("ml-sm", s), ...o });
|
|
225
|
-
N.displayName = "FormField.RequiredIndicator";
|
|
220
|
+
R.displayName = "FormField.HelperMessage";
|
|
226
221
|
const A = ({
|
|
227
222
|
htmlFor: s,
|
|
228
223
|
className: e,
|
|
229
|
-
children:
|
|
230
|
-
requiredIndicator: l = /* @__PURE__ */ r(
|
|
231
|
-
asChild:
|
|
224
|
+
children: a,
|
|
225
|
+
requiredIndicator: l = /* @__PURE__ */ r(y, {}),
|
|
226
|
+
asChild: o,
|
|
232
227
|
ref: i,
|
|
233
228
|
...d
|
|
234
229
|
}) => {
|
|
235
|
-
const t = b(), { disabled: n, labelId: m, isRequired: p } = t, u =
|
|
230
|
+
const t = b(), { disabled: n, labelId: m, isRequired: p } = t, u = o ? void 0 : s || t.id;
|
|
236
231
|
return /* @__PURE__ */ r(
|
|
237
|
-
|
|
232
|
+
K,
|
|
238
233
|
{
|
|
239
234
|
ref: i,
|
|
240
235
|
id: m,
|
|
241
236
|
"data-spark-component": "form-field-label",
|
|
242
237
|
htmlFor: u,
|
|
243
238
|
className: c(e, n ? "text-on-surface/dim-3 pointer-events-none" : void 0),
|
|
244
|
-
asChild:
|
|
239
|
+
asChild: o,
|
|
245
240
|
...d,
|
|
246
|
-
children: /* @__PURE__ */
|
|
247
|
-
/* @__PURE__ */ r(
|
|
241
|
+
children: /* @__PURE__ */ N(H, { children: [
|
|
242
|
+
/* @__PURE__ */ r(_, { children: a }),
|
|
248
243
|
p && l
|
|
249
244
|
] })
|
|
250
245
|
}
|
|
@@ -261,15 +256,15 @@ const E = ({ ref: s, ...e }) => /* @__PURE__ */ r(
|
|
|
261
256
|
}
|
|
262
257
|
);
|
|
263
258
|
E.displayName = "FormField.SuccessMessage";
|
|
264
|
-
const U = Object.assign(
|
|
259
|
+
const U = Object.assign(T, {
|
|
265
260
|
Label: A,
|
|
266
261
|
Control: k,
|
|
267
262
|
StateMessage: F,
|
|
268
263
|
SuccessMessage: E,
|
|
269
264
|
AlertMessage: v,
|
|
270
|
-
ErrorMessage:
|
|
271
|
-
HelperMessage:
|
|
272
|
-
RequiredIndicator:
|
|
265
|
+
ErrorMessage: $,
|
|
266
|
+
HelperMessage: R,
|
|
267
|
+
RequiredIndicator: y,
|
|
273
268
|
CharactersCount: S
|
|
274
269
|
});
|
|
275
270
|
U.displayName = "FormField";
|
|
@@ -278,9 +273,9 @@ k.displayName = "FormField.Control";
|
|
|
278
273
|
F.displayName = "FormField.StateMessage";
|
|
279
274
|
E.displayName = "FormField.SuccessMessage";
|
|
280
275
|
v.displayName = "FormField.AlertMessage";
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
276
|
+
$.displayName = "FormField.ErrorMessage";
|
|
277
|
+
R.displayName = "FormField.HelperMessage";
|
|
278
|
+
y.displayName = "FormField.RequiredIndicator";
|
|
284
279
|
S.displayName = "FormField.CharactersCount";
|
|
285
280
|
export {
|
|
286
281
|
U as FormField,
|