@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 2.67 kB
Source Map (JSON)
{"version":3,"file":"use-progress.cjs","names":["useI18n"],"sources":["../../../../src/components/progress/use-progress.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLProps } from \"../../core\"\nimport { useCallback } from \"react\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport { dataAttr, valueToPercent } from \"../../utils\"\n\nexport interface UseProgressProps {\n /**\n * The maximum value of the progress.\n *\n * @default 100\n */\n max?: number\n /**\n * The minimum value of the progress.\n *\n * @default 0\n */\n min?: number\n /**\n * The value of the progress. If `null`, the progress will be indeterminate.\n *\n * @default 0\n */\n value?: null | number\n}\n\nexport const useProgress = <Y extends \"div\" | \"svg\" = \"div\">({\n max = 100,\n min = 0,\n value,\n}: UseProgressProps = {}) => {\n const indeterminate = value === null\n const percent = valueToPercent(value ?? 0, min, max)\n const { t } = useI18n(\"progress\")\n\n const getRootProps = useCallback(\n (props?: HTMLProps<Y>) => ({\n \"aria-label\": indeterminate\n ? t(\"Loading...\")\n : t(\"{value} percent\", { value: percent }),\n \"aria-valuemax\": max,\n \"aria-valuemin\": min,\n \"aria-valuenow\": value ?? undefined,\n \"data-indeterminate\": dataAttr(indeterminate),\n role: \"progressbar\",\n ...props,\n }),\n [max, min, percent, value, indeterminate, t],\n )\n\n const getTrackProps = useCallback(\n (props?: HTMLProps<Y extends \"svg\" ? \"circle\" : \"div\">) => ({\n \"data-indeterminate\": dataAttr(indeterminate),\n ...props,\n }),\n [indeterminate],\n )\n\n const getRangeProps = useCallback(\n (props?: HTMLProps<Y extends \"svg\" ? \"circle\" : \"div\">) => ({\n \"data-indeterminate\": dataAttr(indeterminate),\n ...props,\n }),\n [indeterminate],\n )\n\n return {\n percent,\n getRangeProps,\n getRootProps,\n getTrackProps,\n }\n}\n\nexport type UseProgressReturn = ReturnType<typeof useProgress>\n"],"mappings":";;;;;;;;;;AA4BA,MAAa,eAAgD,EAC3D,MAAM,KACN,MAAM,GACN,UACoB,EAAE,KAAK;CAC3B,MAAM,gBAAgB,UAAU;CAChC,MAAM,gEAAyB,SAAS,GAAG,KAAK,IAAI;CACpD,MAAM,EAAE,MAAMA,8BAAQ,WAAW;CAEjC,MAAM,uCACH,WAA0B;EACzB,cAAc,gBACV,EAAE,aAAa,GACf,EAAE,mBAAmB,EAAE,OAAO,SAAS,CAAC;EAC5C,iBAAiB;EACjB,iBAAiB;EACjB,iBAAiB,SAAS;EAC1B,sEAA+B,cAAc;EAC7C,MAAM;EACN,GAAG;EACJ,GACD;EAAC;EAAK;EAAK;EAAS;EAAO;EAAe;EAAE,CAC7C;CAED,MAAM,wCACH,WAA2D;EAC1D,sEAA+B,cAAc;EAC7C,GAAG;EACJ,GACD,CAAC,cAAc,CAChB;AAUD,QAAO;EACL;EACA,uCATC,WAA2D;GAC1D,sEAA+B,cAAc;GAC7C,GAAG;GACJ,GACD,CAAC,cAAc,CAChB;EAKC;EACA;EACD"}