@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 6.41 kB
Source Map (JSON)
{"version":3,"file":"editable.cjs","names":["createSlotComponent","editableStyle","useEditable","useInputBorder","EditableContext","styled","useEditableContext"],"sources":["../../../../src/components/editable/editable.tsx"],"sourcesContent":["\"use client\"\n\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { ReactNodeOrFunction } from \"../../utils\"\nimport type { UseInputBorderProps } from \"../input\"\nimport type { EditableStyle } from \"./editable.style\"\nimport type { UseEditableProps, UseEditableReturn } from \"./use-editable\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { runIfFn } from \"../../utils\"\nimport { useInputBorder } from \"../input\"\nimport { editableStyle } from \"./editable.style\"\nimport {\n EditableContext,\n useEditable,\n useEditableContext,\n} from \"./use-editable\"\n\ninterface EditableElementProps\n extends Pick<\n UseEditableReturn,\n \"editing\" | \"onCancel\" | \"onEdit\" | \"onSubmit\"\n > {}\n\nexport interface EditableRootProps\n extends Omit<\n HTMLStyledProps,\n \"children\" | \"defaultValue\" | \"onChange\" | \"onSubmit\" | \"value\"\n >,\n ThemeProps<EditableStyle>,\n UseInputBorderProps,\n UseEditableProps {\n /**\n * The editable children to use.\n */\n children?: ReactNodeOrFunction<EditableElementProps>\n}\n\nconst {\n PropsContext: EditablePropsContext,\n usePropsContext: useEditablePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<EditableRootProps, EditableStyle>(\n \"editable\",\n editableStyle,\n)\n\nexport { EditablePropsContext, useEditablePropsContext }\n\n/**\n * `Editable` is a component used to obtain inline editable text input.\n *\n * @see https://yamada-ui.com/docs/components/editable\n */\nexport const EditableRoot = withProvider(\n ({ children, errorBorderColor, focusBorderColor, ...props }) => {\n const {\n editing,\n value: _value,\n getRootProps,\n onCancel,\n onEdit,\n onSubmit,\n ...rest\n } = useEditable(props)\n const varProps = useInputBorder({ errorBorderColor, focusBorderColor })\n const cloneChildren = runIfFn(children, {\n editing,\n onCancel,\n onEdit,\n onSubmit,\n })\n\n return (\n <EditableContext value={{ editing, ...rest }}>\n <styled.div {...getRootProps()} {...varProps}>\n {cloneChildren}\n </styled.div>\n </EditableContext>\n )\n },\n)()\n\nexport interface EditablePreviewProps extends HTMLStyledProps<\"span\"> {}\n\nexport const EditablePreview = withContext<\"span\", EditablePreviewProps>(\n \"span\",\n \"preview\",\n)(undefined, (props) => {\n const { getPreviewProps } = useEditableContext()\n\n return { ...getPreviewProps(props) }\n})\n\nexport interface EditableInputProps extends HTMLStyledProps<\"input\"> {}\n\nexport const EditableInput = withContext<\"input\", EditableInputProps>(\n \"input\",\n \"input\",\n)(undefined, (props) => {\n const { getInputProps } = useEditableContext()\n\n return { ...getInputProps(props) }\n})\n\nexport interface EditableTextareaProps extends HTMLStyledProps<\"textarea\"> {}\n\nexport const EditableTextarea = withContext<\"textarea\", EditableTextareaProps>(\n \"textarea\",\n \"textarea\",\n)(undefined, (props) => {\n const { getTextareaProps } = useEditableContext()\n\n return { ...getTextareaProps(props) }\n})\n\nexport interface EditableControlProps extends HTMLStyledProps {}\n\nexport const EditableControl = withContext<\"div\", EditableControlProps>(\n \"div\",\n \"control\",\n)(undefined, (props) => {\n const { getControlProps } = useEditableContext()\n\n return { ...getControlProps(props) }\n})\n\nexport interface EditableEditTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nexport const EditableEditTrigger = withContext<\n \"button\",\n EditableEditTriggerProps\n>(\"button\", { name: \"EditTrigger\", slot: [\"trigger\", \"edit\"] })(\n undefined,\n (props) => {\n const { getEditProps } = useEditableContext()\n\n return { asChild: true, ...getEditProps(props) }\n },\n)\n\nexport interface EditableCancelTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nexport const EditableCancelTrigger = withContext<\n \"button\",\n EditableCancelTriggerProps\n>(\"button\", { name: \"CancelTrigger\", slot: [\"trigger\", \"cancel\"] })(\n undefined,\n (props) => {\n const { getCancelProps } = useEditableContext()\n\n return { asChild: true, ...getCancelProps(props) }\n },\n)\n\nexport interface EditableSubmitTriggerProps extends HTMLStyledProps<\"button\"> {}\n\nexport const EditableSubmitTrigger = withContext<\n \"button\",\n EditableSubmitTriggerProps\n>(\"button\", { name: \"SubmitTrigger\", slot: [\"trigger\", \"submit\"] })(\n undefined,\n (props) => {\n const { getSubmitProps } = useEditableContext()\n\n return { asChild: true, ...getSubmitProps(props) }\n },\n)\n"],"mappings":";;;;;;;;;;;;;;AAqCA,MAAM,EACJ,cAAc,sBACd,iBAAiB,yBACjB,aACA,iBACEA,6CACF,YACAC,qCACD;;;;;;AASD,MAAa,eAAe,cACzB,EAAE,UAAU,kBAAkB,iBAAkB,GAAG,YAAY;CAC9D,MAAM,EACJ,SACA,OAAO,QACP,cACA,UACA,QACA,SACA,GAAG,SACDC,iCAAY,MAAM;CACtB,MAAM,WAAWC,wCAAe;EAAE;EAAkB;EAAkB,CAAC;CACvE,MAAM,+DAAwB,UAAU;EACtC;EACA;EACA;EACA;EACD,CAAC;AAEF,QACE,2CAACC;EAAgB,OAAO;GAAE;GAAS,GAAG;GAAM;YAC1C,2CAACC,uBAAO;GAAI,GAAI,cAAc;GAAE,GAAI;aACjC;IACU;GACG;EAGvB,EAAE;AAIH,MAAa,kBAAkB,YAC7B,QACA,UACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,oBAAoBC,yCAAoB;AAEhD,QAAO,EAAE,GAAG,gBAAgB,MAAM,EAAE;EACpC;AAIF,MAAa,gBAAgB,YAC3B,SACA,QACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,kBAAkBA,yCAAoB;AAE9C,QAAO,EAAE,GAAG,cAAc,MAAM,EAAE;EAClC;AAIF,MAAa,mBAAmB,YAC9B,YACA,WACD,CAAC,SAAY,UAAU;CACtB,MAAM,EAAE,qBAAqBA,yCAAoB;AAEjD,QAAO,EAAE,GAAG,iBAAiB,MAAM,EAAE;EACrC;AAIF,MAAa,kBAAkB,YAC7B,OACA,UACD,CAAC,SAAY,UAAU;CACtB,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