UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 2.16 kB
{"version":3,"file":"use-textarea.cjs","names":["useAutosize","mergeRefs"],"sources":["../../../../src/components/textarea/use-textarea.ts"],"sourcesContent":["\"use client\"\n\nimport type { ForwardedRef } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { UseAutosizeProps } from \"./use-autosize\"\nimport { useCallback } from \"react\"\nimport { assignRef, handlerAll, mergeRefs, noop } from \"../../utils\"\nimport { useAutosize } from \"./use-autosize\"\n\nexport interface UseTextareaProps\n extends HTMLProps<\"textarea\">,\n Omit<UseAutosizeProps, \"disabled\" | \"ref\"> {\n /**\n * If `true`, the Textarea height auto-adjusts to text height.\n */\n autosize?: boolean\n /**\n * Ref to a resize function.\n */\n resizeRef?: ForwardedRef<() => void>\n}\n\nexport const useTextarea = ({\n autosize,\n maxRows,\n minRows,\n resizeRef,\n ...rest\n}: UseTextareaProps = {}) => {\n const { ref, onResizeTextarea } = useAutosize({\n disabled: !autosize,\n maxRows,\n minRows,\n })\n\n assignRef(resizeRef, onResizeTextarea)\n\n const getTextareaProps: PropGetter<\"textarea\"> = useCallback(\n ({ style, ...props } = {}) => ({\n ...rest,\n ...props,\n ref: mergeRefs(props.ref, rest.ref, ref),\n style: { resize: autosize ? \"none\" : undefined, ...rest.style, ...style },\n onChange: handlerAll(\n props.onChange,\n rest.onChange,\n autosize ? onResizeTextarea : noop,\n ),\n }),\n [autosize, onResizeTextarea, rest, ref],\n )\n\n return {\n getTextareaProps,\n onResizeTextarea,\n }\n}\n\nexport type UseTextareaReturn = ReturnType<typeof useTextarea>\n"],"mappings":";;;;;;;;;;;AAsBA,MAAa,eAAe,EAC1B,UACA,SACA,SACA,UACA,GAAG,SACiB,EAAE,KAAK;CAC3B,MAAM,EAAE,KAAK,qBAAqBA,iCAAY;EAC5C,UAAU,CAAC;EACX;EACA;EACD,CAAC;AAEF,uBAAU,WAAW,iBAAiB;AAiBtC,QAAO;EACL,0CAfC,EAAE,MAAO,GAAG,UAAU,EAAE,MAAM;GAC7B,GAAG;GACH,GAAG;GACH,KAAKC,sBAAU,MAAM,KAAK,KAAK,KAAK,IAAI;GACxC,OAAO;IAAE,QAAQ,WAAW,SAAS;IAAW,GAAG,KAAK;IAAO,GAAG;IAAO;GACzE,4DACE,MAAM,UACN,KAAK,UACL,WAAW,qDAAmB,KAC/B;GACF,GACD;GAAC;GAAU;GAAkB;GAAM;GAAI,CACxC;EAIC;EACD"}