UNPKG

@chakra-ui/progress

Version:

Progress bar component for Chakra UI

1 lines 3.24 kB
{"version":3,"sources":["../src/progress.utils.tsx"],"sourcesContent":["import { keyframes } from \"@chakra-ui/system\"\n\nfunction valueToPercent(value: number, min: number, max: number) {\n return ((value - min) * 100) / (max - min)\n}\n\ntype Keyframe = ReturnType<typeof keyframes>\n\nexport const spin: Keyframe = keyframes({\n \"0%\": {\n strokeDasharray: \"1, 400\",\n strokeDashoffset: \"0\",\n },\n \"50%\": {\n strokeDasharray: \"400, 400\",\n strokeDashoffset: \"-100\",\n },\n \"100%\": {\n strokeDasharray: \"400, 400\",\n strokeDashoffset: \"-260\",\n },\n})\n\nexport const rotate: Keyframe = keyframes({\n \"0%\": {\n transform: \"rotate(0deg)\",\n },\n \"100%\": {\n transform: \"rotate(360deg)\",\n },\n})\n\nexport const progress: Keyframe = keyframes({\n \"0%\": { left: \"-40%\" },\n \"100%\": { left: \"100%\" },\n})\n\nexport const stripe: Keyframe = keyframes({\n from: { backgroundPosition: \"1rem 0\" },\n to: { backgroundPosition: \"0 0\" },\n})\n\nexport interface GetProgressPropsOptions {\n value?: number\n min: number\n max: number\n valueText?: string\n getValueText?(value: number, percent: number): string\n isIndeterminate?: boolean\n role?: React.AriaRole\n}\n\n/**\n * Get the common `aria-*` attributes for both the linear and circular\n * progress components.\n */\nexport function getProgressProps(options: GetProgressPropsOptions) {\n const {\n value = 0,\n min,\n max,\n valueText,\n getValueText,\n isIndeterminate,\n role = \"progressbar\",\n } = options\n\n const percent = valueToPercent(value, min, max)\n\n const getAriaValueText = () => {\n if (value == null) return undefined\n return typeof getValueText === \"function\"\n ? getValueText(value, percent)\n : valueText\n }\n\n return {\n bind: {\n \"data-indeterminate\": isIndeterminate ? \"\" : undefined,\n \"aria-valuemax\": max,\n \"aria-valuemin\": min,\n \"aria-valuenow\": isIndeterminate ? undefined : value,\n \"aria-valuetext\": getAriaValueText(),\n role,\n },\n percent,\n value,\n }\n}\n"],"mappings":";;;AAAA,SAA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