@bug-on/md3-react 2.0.3 → 3.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.
Files changed (308) hide show
  1. package/.turbo/turbo-build.log +33 -0
  2. package/CHANGELOG.md +55 -0
  3. package/dist/index.css.d.ts +2 -0
  4. package/dist/index.d.mts +6127 -0
  5. package/dist/index.d.ts +6127 -71
  6. package/dist/index.js +1653 -614
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +1566 -547
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/material-symbols-cdn.css.d.ts +2 -0
  11. package/dist/material-symbols-self-hosted.css.d.ts +2 -0
  12. package/dist/typography.css.d.ts +2 -0
  13. package/package.json +22 -19
  14. package/scripts/copy-assets.js +82 -0
  15. package/src/assets/fonts/GoogleSansFlex-VariableFont.woff2 +0 -0
  16. package/src/assets/fonts/MaterialSymbolsOutlined-VariableFont_FILL,GRAD,opsz,wght.ttf +0 -0
  17. package/src/assets/fonts/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght.ttf +0 -0
  18. package/src/assets/fonts/MaterialSymbolsSharp-VariableFont_FILL,GRAD,opsz,wght.ttf +0 -0
  19. package/src/assets/loading-indicator.svg +19 -0
  20. package/src/assets/material-symbols-cdn.css +65 -0
  21. package/src/assets/material-symbols-self-hosted.css +90 -0
  22. package/src/css.d.ts +20 -0
  23. package/src/hooks/useClickOutside.ts +37 -0
  24. package/src/hooks/useMediaQuery.ts +28 -0
  25. package/src/hooks/useRipple.ts +88 -0
  26. package/src/index.css +23 -0
  27. package/src/index.ts +349 -0
  28. package/src/lib/material-symbols-preconnect.tsx +82 -0
  29. package/src/lib/theme-utils.ts +180 -0
  30. package/src/lib/utils.ts +6 -0
  31. package/src/test/button.test.tsx +59 -0
  32. package/src/test/icon.test.tsx +91 -0
  33. package/src/test/loading-indicator.test.tsx +128 -0
  34. package/src/test/progress-indicator.test.tsx +306 -0
  35. package/src/test/setup.ts +80 -0
  36. package/src/test/typography.test.tsx +206 -0
  37. package/src/types/index.ts +7 -0
  38. package/src/types/md3.ts +31 -0
  39. package/src/ui/Text.tsx +60 -0
  40. package/src/ui/__snapshots__/divider.test.tsx.snap +63 -0
  41. package/src/ui/app-bar/app-bar-column.tsx +99 -0
  42. package/src/ui/app-bar/app-bar-item-button.tsx +71 -0
  43. package/src/ui/app-bar/app-bar-items.test.tsx +89 -0
  44. package/src/ui/app-bar/app-bar-overflow-indicator.tsx +108 -0
  45. package/src/ui/app-bar/app-bar-row.tsx +104 -0
  46. package/src/ui/app-bar/app-bar.test.tsx +87 -0
  47. package/src/ui/app-bar/app-bar.tokens.ts +223 -0
  48. package/src/ui/app-bar/app-bar.types.ts +441 -0
  49. package/src/ui/app-bar/bottom-app-bar.test.tsx +42 -0
  50. package/src/ui/app-bar/bottom-app-bar.tsx +84 -0
  51. package/src/ui/app-bar/docked-toolbar.test.tsx +34 -0
  52. package/src/ui/app-bar/docked-toolbar.tsx +54 -0
  53. package/src/ui/app-bar/flexible-app-bar.test.tsx +75 -0
  54. package/src/ui/app-bar/hooks/use-app-bar-scroll.ts +110 -0
  55. package/src/ui/app-bar/hooks/use-flexible-app-bar.ts +123 -0
  56. package/{dist/ui/app-bar/index.d.ts → src/ui/app-bar/index.ts} +35 -2
  57. package/src/ui/app-bar/large-flexible-app-bar.tsx +165 -0
  58. package/src/ui/app-bar/medium-flexible-app-bar.tsx +167 -0
  59. package/src/ui/app-bar/search-app-bar.test.tsx +49 -0
  60. package/src/ui/app-bar/search-app-bar.tsx +176 -0
  61. package/src/ui/app-bar/search-view.tsx +227 -0
  62. package/src/ui/app-bar/small-app-bar.test.tsx +48 -0
  63. package/src/ui/app-bar/small-app-bar.tsx +203 -0
  64. package/src/ui/badge.test.tsx +345 -0
  65. package/src/ui/badge.tsx +282 -0
  66. package/src/ui/button-group.test.tsx +71 -0
  67. package/src/ui/button-group.tsx +350 -0
  68. package/src/ui/button.test.tsx +297 -0
  69. package/src/ui/button.tsx +669 -0
  70. package/src/ui/card.test.tsx +187 -0
  71. package/src/ui/card.tsx +259 -0
  72. package/src/ui/checkbox.test.tsx +423 -0
  73. package/src/ui/checkbox.tsx +525 -0
  74. package/src/ui/chip.test.tsx +292 -0
  75. package/src/ui/chip.tsx +548 -0
  76. package/src/ui/code-block.tsx +219 -0
  77. package/src/ui/dialog.test.tsx +300 -0
  78. package/src/ui/dialog.tsx +384 -0
  79. package/src/ui/divider.test.tsx +314 -0
  80. package/src/ui/divider.tsx +412 -0
  81. package/src/ui/drawer.tsx +240 -0
  82. package/src/ui/fab-menu.test.tsx +494 -0
  83. package/src/ui/fab-menu.tsx +739 -0
  84. package/src/ui/fab.test.tsx +232 -0
  85. package/src/ui/fab.tsx +505 -0
  86. package/src/ui/icon-button.test.tsx +515 -0
  87. package/src/ui/icon-button.tsx +525 -0
  88. package/src/ui/icon.test.tsx +197 -0
  89. package/src/ui/icon.tsx +179 -0
  90. package/src/ui/loading-indicator.test.tsx +73 -0
  91. package/src/ui/loading-indicator.tsx +312 -0
  92. package/src/ui/menu/context-menu.tsx +275 -0
  93. package/src/ui/menu/index.ts +77 -0
  94. package/src/ui/menu/menu-animations.ts +102 -0
  95. package/src/ui/menu/menu-context.tsx +99 -0
  96. package/src/ui/menu/menu-divider.tsx +47 -0
  97. package/src/ui/menu/menu-group.tsx +200 -0
  98. package/src/ui/menu/menu-item.tsx +294 -0
  99. package/src/ui/menu/menu-tokens.ts +208 -0
  100. package/src/ui/menu/menu-types.ts +313 -0
  101. package/src/ui/menu/menu.test.tsx +624 -0
  102. package/src/ui/menu/menu.tsx +289 -0
  103. package/src/ui/menu/sub-menu.tsx +223 -0
  104. package/src/ui/menu/vertical-menu.tsx +382 -0
  105. package/src/ui/navigation-rail.test.tsx +404 -0
  106. package/src/ui/navigation-rail.tsx +604 -0
  107. package/src/ui/progress-indicator/circular.tsx +248 -0
  108. package/src/ui/progress-indicator/hooks.ts +51 -0
  109. package/{dist/ui/progress-indicator/index.d.ts → src/ui/progress-indicator/index.tsx} +20 -2
  110. package/src/ui/progress-indicator/linear-flat.tsx +83 -0
  111. package/src/ui/progress-indicator/linear-wavy.tsx +243 -0
  112. package/src/ui/progress-indicator/linear.tsx +143 -0
  113. package/src/ui/progress-indicator/types.ts +158 -0
  114. package/src/ui/progress-indicator/utils.ts +73 -0
  115. package/src/ui/radio-button.test.tsx +407 -0
  116. package/src/ui/radio-button.tsx +551 -0
  117. package/src/ui/ripple.test.tsx +72 -0
  118. package/src/ui/ripple.tsx +234 -0
  119. package/src/ui/scroll-area.test.tsx +58 -0
  120. package/src/ui/scroll-area.tsx +139 -0
  121. package/src/ui/search/animated-placeholder.tsx +145 -0
  122. package/src/ui/search/hooks/use-search-keyboard.test.ts +202 -0
  123. package/src/ui/search/hooks/use-search-keyboard.ts +104 -0
  124. package/src/ui/search/hooks/use-search-view-focus.test.ts +96 -0
  125. package/src/ui/search/hooks/use-search-view-focus.ts +24 -0
  126. package/src/ui/search/index.ts +44 -0
  127. package/src/ui/search/search-bar.tsx +220 -0
  128. package/src/ui/search/search-context.tsx +42 -0
  129. package/src/ui/search/search-view-docked.tsx +194 -0
  130. package/src/ui/search/search-view-fullscreen.tsx +247 -0
  131. package/src/ui/search/search.test.tsx +233 -0
  132. package/src/ui/search/search.tokens.ts +134 -0
  133. package/src/ui/search/search.tsx +131 -0
  134. package/src/ui/search/search.types.ts +154 -0
  135. package/src/ui/search/trailing-action.tsx +49 -0
  136. package/src/ui/shared/constants.ts +122 -0
  137. package/{dist/ui/shared/touch-target.d.ts → src/ui/shared/touch-target.tsx} +13 -1
  138. package/src/ui/slider/hooks/useSliderMath.ts +195 -0
  139. package/{dist/ui/slider/index.d.ts → src/ui/slider/index.ts} +12 -1
  140. package/src/ui/slider/range-slider.tsx +561 -0
  141. package/src/ui/slider/slider-thumb.tsx +379 -0
  142. package/src/ui/slider/slider-track.tsx +912 -0
  143. package/src/ui/slider/slider.tokens.ts +189 -0
  144. package/src/ui/slider/slider.tsx +259 -0
  145. package/src/ui/slider/slider.types.ts +288 -0
  146. package/src/ui/snackbar/index.ts +20 -0
  147. package/src/ui/snackbar/snackbar.test.tsx +338 -0
  148. package/src/ui/snackbar/snackbar.tsx +476 -0
  149. package/{dist/ui/switch/index.d.ts → src/ui/switch/index.ts} +1 -0
  150. package/src/ui/switch/switch.stories.tsx +309 -0
  151. package/src/ui/switch/switch.test.tsx +243 -0
  152. package/src/ui/switch/switch.tokens.ts +89 -0
  153. package/src/ui/switch/switch.tsx +504 -0
  154. package/src/ui/switch/switch.types.ts +62 -0
  155. package/{dist/ui/tabs/index.d.ts → src/ui/tabs/index.ts} +8 -1
  156. package/src/ui/tabs/tab.tsx +407 -0
  157. package/src/ui/tabs/tabs-content.tsx +89 -0
  158. package/src/ui/tabs/tabs-list.tsx +146 -0
  159. package/src/ui/tabs/tabs.test.tsx +290 -0
  160. package/src/ui/tabs/tabs.tokens.ts +121 -0
  161. package/src/ui/tabs/tabs.tsx +229 -0
  162. package/src/ui/tabs/tabs.types.ts +185 -0
  163. package/{dist/ui/text-field/index.d.ts → src/ui/text-field/index.ts} +8 -1
  164. package/src/ui/text-field/subcomponents/active-indicator.tsx +67 -0
  165. package/src/ui/text-field/subcomponents/floating-label.tsx +161 -0
  166. package/src/ui/text-field/subcomponents/leading-icon.tsx +46 -0
  167. package/src/ui/text-field/subcomponents/outline-container.tsx +170 -0
  168. package/src/ui/text-field/subcomponents/prefix-suffix.tsx +59 -0
  169. package/src/ui/text-field/subcomponents/supporting-text.tsx +145 -0
  170. package/src/ui/text-field/subcomponents/trailing-icon.tsx +199 -0
  171. package/src/ui/text-field/text-field.test.tsx +454 -0
  172. package/src/ui/text-field/text-field.tokens.ts +104 -0
  173. package/src/ui/text-field/text-field.tsx +548 -0
  174. package/src/ui/text-field/text-field.types.ts +180 -0
  175. package/src/ui/theme-provider/index.tsx +190 -0
  176. package/src/ui/toc.test.tsx +108 -0
  177. package/src/ui/toc.tsx +172 -0
  178. package/src/ui/tooltip/plain-tooltip.tsx +63 -0
  179. package/src/ui/tooltip/rich-tooltip.tsx +94 -0
  180. package/src/ui/tooltip/tooltip-box.tsx +266 -0
  181. package/src/ui/tooltip/tooltip-caret-shape.tsx +68 -0
  182. package/src/ui/tooltip/tooltip.tokens.ts +26 -0
  183. package/src/ui/tooltip/tooltip.types.ts +70 -0
  184. package/src/ui/tooltip/use-tooltip-position.ts +208 -0
  185. package/src/ui/tooltip/use-tooltip-state.ts +41 -0
  186. package/src/ui/typography/__tests__/typography.test.tsx +170 -0
  187. package/{dist/ui/typography/index.d.ts → src/ui/typography/index.ts} +21 -3
  188. package/src/ui/typography/type-scale-tokens.ts +205 -0
  189. package/src/ui/typography/typography-key-tokens.ts +43 -0
  190. package/src/ui/typography/typography-tokens.ts +360 -0
  191. package/src/ui/typography/typography.css +22 -0
  192. package/src/ui/typography/typography.tsx +559 -0
  193. package/test-render.tsx +4 -0
  194. package/test-shadow.html +26 -0
  195. package/test_output.txt +164 -0
  196. package/test_output_v2.txt +5 -0
  197. package/tsconfig.build.json +10 -0
  198. package/tsconfig.json +18 -0
  199. package/tsup.config.ts +20 -0
  200. package/vitest.config.ts +11 -0
  201. package/dist/hooks/useClickOutside.d.ts +0 -8
  202. package/dist/hooks/useMediaQuery.d.ts +0 -11
  203. package/dist/hooks/useRipple.d.ts +0 -26
  204. package/dist/lib/material-symbols-preconnect.d.ts +0 -42
  205. package/dist/lib/theme-utils.d.ts +0 -63
  206. package/dist/lib/utils.d.ts +0 -2
  207. package/dist/types/index.d.ts +0 -1
  208. package/dist/types/md3.d.ts +0 -14
  209. package/dist/ui/app-bar/app-bar-column.d.ts +0 -28
  210. package/dist/ui/app-bar/app-bar-item-button.d.ts +0 -16
  211. package/dist/ui/app-bar/app-bar-overflow-indicator.d.ts +0 -18
  212. package/dist/ui/app-bar/app-bar-row.d.ts +0 -36
  213. package/dist/ui/app-bar/app-bar.tokens.d.ts +0 -184
  214. package/dist/ui/app-bar/app-bar.types.d.ts +0 -392
  215. package/dist/ui/app-bar/bottom-app-bar.d.ts +0 -31
  216. package/dist/ui/app-bar/docked-toolbar.d.ts +0 -25
  217. package/dist/ui/app-bar/hooks/use-app-bar-scroll.d.ts +0 -42
  218. package/dist/ui/app-bar/hooks/use-flexible-app-bar.d.ts +0 -37
  219. package/dist/ui/app-bar/large-flexible-app-bar.d.ts +0 -26
  220. package/dist/ui/app-bar/medium-flexible-app-bar.d.ts +0 -28
  221. package/dist/ui/app-bar/search-app-bar.d.ts +0 -43
  222. package/dist/ui/app-bar/search-view.d.ts +0 -54
  223. package/dist/ui/app-bar/small-app-bar.d.ts +0 -37
  224. package/dist/ui/badge.d.ts +0 -125
  225. package/dist/ui/button-group.d.ts +0 -59
  226. package/dist/ui/button.d.ts +0 -148
  227. package/dist/ui/card.d.ts +0 -62
  228. package/dist/ui/checkbox.d.ts +0 -82
  229. package/dist/ui/chip.d.ts +0 -110
  230. package/dist/ui/code-block.d.ts +0 -14
  231. package/dist/ui/dialog.d.ts +0 -111
  232. package/dist/ui/divider.d.ts +0 -164
  233. package/dist/ui/drawer.d.ts +0 -39
  234. package/dist/ui/dropdown.d.ts +0 -29
  235. package/dist/ui/fab-menu.d.ts +0 -204
  236. package/dist/ui/fab.d.ts +0 -162
  237. package/dist/ui/icon-button.d.ts +0 -131
  238. package/dist/ui/icon.d.ts +0 -88
  239. package/dist/ui/loading-indicator.d.ts +0 -42
  240. package/dist/ui/navigation-rail.d.ts +0 -29
  241. package/dist/ui/progress-indicator/circular.d.ts +0 -3
  242. package/dist/ui/progress-indicator/hooks.d.ts +0 -3
  243. package/dist/ui/progress-indicator/linear-flat.d.ts +0 -10
  244. package/dist/ui/progress-indicator/linear-wavy.d.ts +0 -18
  245. package/dist/ui/progress-indicator/linear.d.ts +0 -3
  246. package/dist/ui/progress-indicator/types.d.ts +0 -151
  247. package/dist/ui/progress-indicator/utils.d.ts +0 -3
  248. package/dist/ui/radio-button.d.ts +0 -106
  249. package/dist/ui/ripple.d.ts +0 -126
  250. package/dist/ui/scroll-area.d.ts +0 -27
  251. package/dist/ui/search/animated-placeholder.d.ts +0 -54
  252. package/dist/ui/search/hooks/use-search-keyboard.d.ts +0 -32
  253. package/dist/ui/search/hooks/use-search-view-focus.d.ts +0 -6
  254. package/dist/ui/search/index.d.ts +0 -27
  255. package/dist/ui/search/search-bar.d.ts +0 -32
  256. package/dist/ui/search/search-context.d.ts +0 -24
  257. package/dist/ui/search/search-view-docked.d.ts +0 -25
  258. package/dist/ui/search/search-view-fullscreen.d.ts +0 -36
  259. package/dist/ui/search/search.d.ts +0 -50
  260. package/dist/ui/search/search.tokens.d.ts +0 -112
  261. package/dist/ui/search/search.types.d.ts +0 -131
  262. package/dist/ui/search/trailing-action.d.ts +0 -9
  263. package/dist/ui/shared/constants.d.ts +0 -86
  264. package/dist/ui/slider/hooks/useSliderMath.d.ts +0 -101
  265. package/dist/ui/slider/range-slider.d.ts +0 -47
  266. package/dist/ui/slider/slider-thumb.d.ts +0 -33
  267. package/dist/ui/slider/slider-track.d.ts +0 -25
  268. package/dist/ui/slider/slider.d.ts +0 -60
  269. package/dist/ui/slider/slider.tokens.d.ts +0 -151
  270. package/dist/ui/slider/slider.types.d.ts +0 -259
  271. package/dist/ui/snackbar/index.d.ts +0 -6
  272. package/dist/ui/snackbar/snackbar.d.ts +0 -197
  273. package/dist/ui/switch/switch.d.ts +0 -30
  274. package/dist/ui/switch/switch.stories.d.ts +0 -48
  275. package/dist/ui/switch/switch.tokens.d.ts +0 -67
  276. package/dist/ui/switch/switch.types.d.ts +0 -59
  277. package/dist/ui/tabs/tab.d.ts +0 -43
  278. package/dist/ui/tabs/tabs-content.d.ts +0 -36
  279. package/dist/ui/tabs/tabs-list.d.ts +0 -40
  280. package/dist/ui/tabs/tabs.d.ts +0 -60
  281. package/dist/ui/tabs/tabs.tokens.d.ts +0 -94
  282. package/dist/ui/tabs/tabs.types.d.ts +0 -172
  283. package/dist/ui/text-field/subcomponents/active-indicator.d.ts +0 -24
  284. package/dist/ui/text-field/subcomponents/floating-label.d.ts +0 -43
  285. package/dist/ui/text-field/subcomponents/leading-icon.d.ts +0 -23
  286. package/dist/ui/text-field/subcomponents/outline-container.d.ts +0 -42
  287. package/dist/ui/text-field/subcomponents/prefix-suffix.d.ts +0 -24
  288. package/dist/ui/text-field/subcomponents/supporting-text.d.ts +0 -37
  289. package/dist/ui/text-field/subcomponents/trailing-icon.d.ts +0 -41
  290. package/dist/ui/text-field/text-field.d.ts +0 -49
  291. package/dist/ui/text-field/text-field.tokens.d.ts +0 -76
  292. package/dist/ui/text-field/text-field.types.d.ts +0 -126
  293. package/dist/ui/theme-provider/index.d.ts +0 -48
  294. package/dist/ui/toc.d.ts +0 -80
  295. package/dist/ui/tooltip/plain-tooltip.d.ts +0 -2
  296. package/dist/ui/tooltip/rich-tooltip.d.ts +0 -2
  297. package/dist/ui/tooltip/tooltip-box.d.ts +0 -2
  298. package/dist/ui/tooltip/tooltip-caret-shape.d.ts +0 -9
  299. package/dist/ui/tooltip/tooltip.tokens.d.ts +0 -26
  300. package/dist/ui/tooltip/tooltip.types.d.ts +0 -56
  301. package/dist/ui/tooltip/use-tooltip-position.d.ts +0 -8
  302. package/dist/ui/tooltip/use-tooltip-state.d.ts +0 -2
  303. package/dist/ui/typography/type-scale-tokens.d.ts +0 -162
  304. package/dist/ui/typography/typography-key-tokens.d.ts +0 -40
  305. package/dist/ui/typography/typography-tokens.d.ts +0 -220
  306. package/dist/ui/typography/typography.d.ts +0 -265
  307. /package/{dist/hooks/index.d.ts → src/hooks/index.ts} +0 -0
  308. /package/{dist/ui/tooltip/index.d.ts → src/ui/tooltip/index.ts} +0 -0
@@ -0,0 +1,248 @@
1
+ import { domMax, LazyMotion, m } from "motion/react";
2
+ import * as React from "react";
3
+ import { cn } from "../../lib/utils";
4
+ import type { CircularProgressProps } from "./types";
5
+ import { generateWavyCircularPath } from "./utils";
6
+
7
+ export const CircularProgress = React.forwardRef<
8
+ HTMLDivElement,
9
+ CircularProgressProps
10
+ >(
11
+ (
12
+ {
13
+ value,
14
+ size = 48,
15
+ trackHeight = 4,
16
+ shape = "flat",
17
+ amplitude,
18
+ wavelength,
19
+ gapSize = 4,
20
+ crawlerSpeed = 1,
21
+ color,
22
+ trackColor,
23
+ className,
24
+ "aria-label": ariaLabel,
25
+ ...restProps
26
+ },
27
+ ref,
28
+ ) => {
29
+ const isDeterminate = value !== undefined;
30
+ const clampedValue = isDeterminate ? Math.min(100, Math.max(0, value)) : 0;
31
+
32
+ const radius = (size - trackHeight) / 2;
33
+ const center = size / 2;
34
+
35
+ const activeColor = color || "var(--md-sys-color-indicator-active)";
36
+ const bgTrackColor = trackColor || "var(--md-sys-color-indicator-track)";
37
+
38
+ const isWavy = shape === "wavy";
39
+
40
+ const BASELINE_SIZE = 48;
41
+ const scaleFactor = size / BASELINE_SIZE;
42
+ const effectiveAmplitude = React.useMemo(
43
+ () => amplitude ?? 1.6 * scaleFactor,
44
+ [amplitude, scaleFactor],
45
+ );
46
+ const effectiveWavelength = React.useMemo(
47
+ () => wavelength ?? 15 * scaleFactor,
48
+ [wavelength, scaleFactor],
49
+ );
50
+
51
+ const wavyActivePath = React.useMemo(
52
+ () =>
53
+ isWavy
54
+ ? generateWavyCircularPath(
55
+ center,
56
+ radius,
57
+ effectiveAmplitude,
58
+ effectiveWavelength,
59
+ )
60
+ : null,
61
+ [isWavy, center, radius, effectiveAmplitude, effectiveWavelength],
62
+ );
63
+
64
+ const circumference = React.useMemo(() => 2 * Math.PI * radius, [radius]);
65
+ const gapForTrack = React.useMemo(
66
+ () => (gapSize + trackHeight) / circumference,
67
+ [gapSize, trackHeight, circumference],
68
+ );
69
+ const activeAngularFraction = isDeterminate ? clampedValue / 100 : 0;
70
+
71
+ const trackOffset = isDeterminate ? activeAngularFraction + gapForTrack : 0;
72
+ const trackLength = isDeterminate
73
+ ? Math.max(0.001, 1 - activeAngularFraction - 2 * gapForTrack)
74
+ : 1;
75
+
76
+ const ActiveCircleElem = m.circle;
77
+ const ActivePathElem = m.path;
78
+
79
+ return (
80
+ <div
81
+ ref={ref}
82
+ role="progressbar"
83
+ aria-label={ariaLabel}
84
+ aria-valuenow={isDeterminate ? clampedValue : undefined}
85
+ aria-valuemin={0}
86
+ aria-valuemax={100}
87
+ className={cn(
88
+ "relative inline-flex items-center justify-center shrink-0",
89
+ className,
90
+ )}
91
+ style={{ width: size, height: size }}
92
+ {...restProps}
93
+ >
94
+ <LazyMotion features={domMax} strict>
95
+ <svg
96
+ width={size}
97
+ height={size}
98
+ viewBox={`0 0 ${size} ${size}`}
99
+ aria-hidden="true"
100
+ style={{ transform: "rotate(-90deg)", overflow: "visible" }}
101
+ >
102
+ {isDeterminate ? (
103
+ <m.circle
104
+ cx={center}
105
+ cy={center}
106
+ r={radius}
107
+ fill="none"
108
+ stroke={bgTrackColor}
109
+ strokeWidth={trackHeight}
110
+ initial={{ pathLength: trackLength, pathOffset: trackOffset }}
111
+ animate={{ pathLength: trackLength, pathOffset: trackOffset }}
112
+ transition={{ duration: 0.4, ease: [0.2, 0, 0, 1] }}
113
+ strokeLinecap="round"
114
+ />
115
+ ) : null}
116
+
117
+ {isDeterminate &&
118
+ (isWavy ? (
119
+ <ActivePathElem
120
+ d={wavyActivePath ?? ""}
121
+ fill="none"
122
+ stroke={activeColor}
123
+ strokeWidth={trackHeight}
124
+ strokeLinecap="round"
125
+ initial={{ pathLength: 0 }}
126
+ animate={{ pathLength: clampedValue / 100 }}
127
+ transition={{
128
+ duration: 0.4,
129
+ ease: [0.2, 0, 0, 1],
130
+ }}
131
+ />
132
+ ) : (
133
+ <ActiveCircleElem
134
+ cx={center}
135
+ cy={center}
136
+ r={radius}
137
+ fill="none"
138
+ stroke={activeColor}
139
+ strokeWidth={trackHeight}
140
+ strokeLinecap="round"
141
+ initial={{ pathLength: 0 }}
142
+ animate={{ pathLength: clampedValue / 100 }}
143
+ transition={{
144
+ duration: 0.4,
145
+ ease: [0.2, 0, 0, 1],
146
+ }}
147
+ />
148
+ ))}
149
+ </svg>
150
+
151
+ {!isDeterminate && (
152
+ <m.svg
153
+ width={size}
154
+ height={size}
155
+ viewBox={`0 0 ${size} ${size}`}
156
+ aria-hidden="true"
157
+ style={{
158
+ position: "absolute",
159
+ inset: 0,
160
+ overflow: "visible",
161
+ rotate: "-90deg",
162
+ transformOrigin: "center",
163
+ }}
164
+ animate={{ rotate: ["-90deg", "270deg"] }}
165
+ transition={{
166
+ rotate: {
167
+ duration: 2 / Math.max(0.1, crawlerSpeed),
168
+ repeat: Number.POSITIVE_INFINITY,
169
+ ease: "linear",
170
+ },
171
+ }}
172
+ >
173
+ <m.circle
174
+ cx={center}
175
+ cy={center}
176
+ r={radius}
177
+ fill="none"
178
+ stroke={bgTrackColor}
179
+ strokeWidth={trackHeight}
180
+ strokeLinecap="round"
181
+ style={{ originX: "50%", originY: "50%" }}
182
+ animate={{
183
+ pathLength: [
184
+ Math.max(0.001, 1 - 0.1 - 2 * gapForTrack),
185
+ Math.max(0.001, 1 - 0.75 - 2 * gapForTrack),
186
+ Math.max(0.001, 1 - 0.1 - 2 * gapForTrack),
187
+ ],
188
+ rotate: [
189
+ `${(0.1 + gapForTrack) * 360}deg`,
190
+ `${(1.0 + gapForTrack) * 360}deg`,
191
+ `${(1.1 + gapForTrack) * 360}deg`,
192
+ ],
193
+ }}
194
+ transition={{
195
+ duration: 2 / Math.max(0.1, crawlerSpeed),
196
+ repeat: Number.POSITIVE_INFINITY,
197
+ ease: [0.4, 0, 0.2, 1],
198
+ }}
199
+ />
200
+
201
+ {isWavy ? (
202
+ <ActivePathElem
203
+ d={wavyActivePath ?? ""}
204
+ fill="none"
205
+ stroke={activeColor}
206
+ strokeWidth={trackHeight}
207
+ strokeLinecap="round"
208
+ style={{ originX: "50%", originY: "50%" }}
209
+ animate={{
210
+ pathLength: [0.1, 0.75, 0.1],
211
+ rotate: ["0deg", "90deg", "360deg"],
212
+ }}
213
+ transition={{
214
+ duration: 2 / Math.max(0.1, crawlerSpeed),
215
+ repeat: Number.POSITIVE_INFINITY,
216
+ ease: [0.4, 0, 0.2, 1],
217
+ }}
218
+ />
219
+ ) : (
220
+ <ActiveCircleElem
221
+ cx={center}
222
+ cy={center}
223
+ r={radius}
224
+ fill="none"
225
+ stroke={activeColor}
226
+ strokeWidth={trackHeight}
227
+ strokeLinecap="round"
228
+ style={{ originX: "50%", originY: "50%" }}
229
+ animate={{
230
+ pathLength: [0.1, 0.75, 0.1],
231
+ rotate: ["0deg", "90deg", "360deg"],
232
+ }}
233
+ transition={{
234
+ duration: 2 / Math.max(0.1, crawlerSpeed),
235
+ repeat: Number.POSITIVE_INFINITY,
236
+ ease: [0.4, 0, 0.2, 1],
237
+ }}
238
+ />
239
+ )}
240
+ </m.svg>
241
+ )}
242
+ </LazyMotion>
243
+ </div>
244
+ );
245
+ },
246
+ );
247
+
248
+ CircularProgress.displayName = "CircularProgress";
@@ -0,0 +1,51 @@
1
+ import * as React from "react";
2
+
3
+ export function useContainerWidth() {
4
+ const [width, setWidth] = React.useState(0);
5
+ const observerRef = React.useRef<ResizeObserver | null>(null);
6
+
7
+ const ref = React.useCallback((node: HTMLDivElement | null) => {
8
+ if (observerRef.current) {
9
+ observerRef.current.disconnect();
10
+ observerRef.current = null;
11
+ }
12
+
13
+ if (node) {
14
+ const obs = new ResizeObserver((entries) => {
15
+ const contentRect = entries[0].contentRect;
16
+ setWidth(contentRect.width);
17
+ });
18
+ obs.observe(node);
19
+ observerRef.current = obs;
20
+ }
21
+ }, []);
22
+
23
+ // Cleanup on unmount
24
+ React.useEffect(() => {
25
+ return () => {
26
+ if (observerRef.current) {
27
+ observerRef.current.disconnect();
28
+ }
29
+ };
30
+ }, []);
31
+
32
+ return [ref, width] as const;
33
+ }
34
+
35
+ export function useMergedRef<T>(
36
+ ...refs: (React.Ref<T> | undefined | null)[]
37
+ ): React.RefCallback<T> {
38
+ return React.useCallback(
39
+ (node: T | null) => {
40
+ for (const ref of refs) {
41
+ if (typeof ref === "function") {
42
+ ref(node);
43
+ } else if (ref && typeof ref === "object") {
44
+ (ref as React.MutableRefObject<T | null>).current = node;
45
+ }
46
+ }
47
+ },
48
+ // eslint-disable-next-line react-hooks/exhaustive-deps
49
+ [refs],
50
+ );
51
+ }
@@ -1,5 +1,8 @@
1
1
  import * as React from "react";
2
+ import { CircularProgress } from "./circular";
3
+ import { LinearProgress } from "./linear";
2
4
  import type { ProgressIndicatorProps } from "./types";
5
+
3
6
  /**
4
7
  * Thanh tiến trình (Progress Indicator) theo nguyên tắc Material Design 3 Expressive.
5
8
  * Hỗ trợ linh hoạt 2 loại hình hiển thị: Linear (Đường thẳng) và Circular (Hình tròn),
@@ -17,5 +20,20 @@ import type { ProgressIndicatorProps } from "./types";
17
20
  * <ProgressIndicator variant="circular" value={45} size={48} aria-label="Syncing..." />
18
21
  * ```
19
22
  */
20
- export declare const ProgressIndicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
21
- export type { CircularProgressProps, LinearProgressProps, ProgressIndicatorProps, } from "./types";
23
+ export const ProgressIndicator = React.forwardRef<
24
+ HTMLDivElement,
25
+ ProgressIndicatorProps
26
+ >((props, ref) => {
27
+ if (props.variant === "circular") {
28
+ return <CircularProgress ref={ref} {...props} />;
29
+ }
30
+ return <LinearProgress ref={ref} {...props} />;
31
+ });
32
+
33
+ ProgressIndicator.displayName = "ProgressIndicator";
34
+
35
+ export type {
36
+ CircularProgressProps,
37
+ LinearProgressProps,
38
+ ProgressIndicatorProps,
39
+ } from "./types";
@@ -0,0 +1,83 @@
1
+ import { m } from "motion/react";
2
+ import * as React from "react";
3
+
4
+ export const FlatLinearTrack = React.memo<{
5
+ trackHeight: number;
6
+ activeColor: string;
7
+ trackColor: string;
8
+ value?: number;
9
+ isRtl: boolean;
10
+ gapSize: number;
11
+ crawlerSpeed: number;
12
+ }>(function FlatLinearTrack({
13
+ trackHeight,
14
+ activeColor,
15
+ trackColor,
16
+ value,
17
+ isRtl,
18
+ gapSize,
19
+ crawlerSpeed,
20
+ }) {
21
+ const isDeterminate = value !== undefined;
22
+ const radius = trackHeight / 2;
23
+ const minActiveWidth = trackHeight;
24
+
25
+ return (
26
+ <div
27
+ className="relative w-full overflow-hidden"
28
+ style={{ height: trackHeight, borderRadius: radius }}
29
+ >
30
+ {isDeterminate ? (
31
+ <>
32
+ <m.div
33
+ className="absolute inset-y-0"
34
+ style={{
35
+ backgroundColor: trackColor,
36
+ borderRadius: radius,
37
+ width: "100%",
38
+ }}
39
+ initial={{
40
+ [isRtl ? "right" : "left"]:
41
+ `calc(max(${minActiveWidth}px, 0%) + ${gapSize}px)`,
42
+ }}
43
+ animate={{
44
+ [isRtl ? "right" : "left"]:
45
+ `calc(max(${minActiveWidth}px, ${value}%) + ${gapSize}px)`,
46
+ }}
47
+ transition={{ duration: 0.4, ease: [0.2, 0, 0, 1] }}
48
+ />
49
+ <m.div
50
+ className="absolute inset-y-0"
51
+ style={{
52
+ backgroundColor: activeColor,
53
+ borderRadius: radius,
54
+ minWidth: minActiveWidth,
55
+ ...(isRtl ? { right: 0 } : { left: 0 }),
56
+ }}
57
+ initial={{ width: `${minActiveWidth}px` }}
58
+ animate={{ width: `${value}%` }}
59
+ transition={{ duration: 0.4, ease: [0.2, 0, 0, 1] }}
60
+ />
61
+ </>
62
+ ) : (
63
+ <>
64
+ <div
65
+ className="absolute inset-0"
66
+ style={{ backgroundColor: trackColor, borderRadius: radius }}
67
+ />
68
+ <m.div
69
+ className="absolute inset-y-0"
70
+ style={{ backgroundColor: activeColor, borderRadius: radius }}
71
+ initial={{ left: "-40%", width: "40%" }}
72
+ animate={{ left: ["-40%", "100%"], width: ["40%", "20%", "40%"] }}
73
+ transition={{
74
+ duration: 2 / Math.max(0.1, crawlerSpeed),
75
+ repeat: Number.POSITIVE_INFINITY,
76
+ ease: "easeInOut",
77
+ }}
78
+ />
79
+ </>
80
+ )}
81
+ </div>
82
+ );
83
+ });
@@ -0,0 +1,243 @@
1
+ import { animate, useAnimationFrame, useMotionValue } from "motion/react";
2
+ import * as React from "react";
3
+ import { useContainerWidth } from "./hooks";
4
+ import { easeInOutCubic, getSinePath } from "./utils";
5
+
6
+ export const WavyLinearTrack = React.memo<{
7
+ trackHeight: number;
8
+ svgHeight: number;
9
+ amplitude: number;
10
+ wavelength: number;
11
+ indeterminateWavelength: number;
12
+ activeColor: string;
13
+ trackColor: string;
14
+ value?: number;
15
+ isRtl: boolean;
16
+ gapSize: number;
17
+ waveSpeed: number;
18
+ crawlerSpeed: number;
19
+ determinateAnimation: "md3" | "continuous";
20
+ indeterminateAnimation: "md3" | "continuous";
21
+ trackShape: "flat" | "wavy";
22
+ }>(function WavyLinearTrack({
23
+ trackHeight,
24
+ svgHeight,
25
+ amplitude,
26
+ wavelength,
27
+ indeterminateWavelength,
28
+ activeColor,
29
+ trackColor,
30
+ value,
31
+ isRtl,
32
+ gapSize,
33
+ waveSpeed,
34
+ crawlerSpeed,
35
+ determinateAnimation,
36
+ indeterminateAnimation,
37
+ trackShape,
38
+ }) {
39
+ const isDeterminate = typeof value === "number";
40
+ const clampedValue = isDeterminate ? Math.max(0, Math.min(100, value)) : 100;
41
+ const titleId = React.useId();
42
+
43
+ const [containerRef, width] = useContainerWidth();
44
+
45
+ const activePathRef = React.useRef<SVGPathElement>(null);
46
+ const trackPathRef = React.useRef<SVGPathElement>(null);
47
+
48
+ const amplitudeMV = useMotionValue(amplitude);
49
+ const fractionMV = useMotionValue(isDeterminate ? clampedValue / 100 : 1);
50
+
51
+ React.useEffect(() => {
52
+ if (isDeterminate) {
53
+ const fraction = clampedValue / 100;
54
+
55
+ // Xử lý Flattening Logic dựa trên prop determinateAnimation
56
+ let targetAmp = amplitude;
57
+ if (determinateAnimation === "md3") {
58
+ targetAmp = fraction <= 0.1 || fraction >= 0.95 ? 0 : amplitude;
59
+ }
60
+
61
+ animate(amplitudeMV, targetAmp, {
62
+ type: "spring",
63
+ bounce: 0,
64
+ duration: 0.5,
65
+ });
66
+ animate(fractionMV, fraction, { duration: 0.4, ease: [0.2, 0, 0, 1] });
67
+ }
68
+ }, [
69
+ clampedValue,
70
+ isDeterminate,
71
+ amplitude,
72
+ amplitudeMV,
73
+ fractionMV,
74
+ determinateAnimation,
75
+ ]);
76
+
77
+ const activeWavelength = Math.max(
78
+ 1,
79
+ isDeterminate ? wavelength : indeterminateWavelength,
80
+ );
81
+ const trackAmp = trackShape === "wavy" ? amplitude : 0;
82
+
83
+ useAnimationFrame((time) => {
84
+ if (width === 0) return;
85
+
86
+ const currentAmp = amplitudeMV.get();
87
+ const phase = (time / 1000) * waveSpeed * activeWavelength;
88
+ const capWidth = trackHeight / 2;
89
+
90
+ let activePathD = "";
91
+ let trackD = "";
92
+ const totalGap = gapSize + trackHeight;
93
+
94
+ // 1. CHẾ ĐỘ CÓ XÁC ĐỊNH (DETERMINATE)
95
+ if (isDeterminate) {
96
+ const fraction = fractionMV.get();
97
+ const barHead = fraction * width;
98
+
99
+ const adjHead = Math.max(capWidth, Math.min(width - capWidth, barHead));
100
+ const adjTail = capWidth;
101
+
102
+ if (fraction > 0 && adjHead - adjTail > 0.1) {
103
+ activePathD = getSinePath(
104
+ adjTail,
105
+ adjHead,
106
+ phase,
107
+ activeWavelength,
108
+ currentAmp,
109
+ );
110
+ } else if (fraction === 0) {
111
+ activePathD = `M ${capWidth} 0 L ${capWidth + 0.01} 0`;
112
+ }
113
+
114
+ const trackStart = adjHead + totalGap;
115
+ if (trackStart < width - capWidth) {
116
+ trackD = getSinePath(
117
+ trackStart,
118
+ width - capWidth,
119
+ phase,
120
+ activeWavelength,
121
+ trackAmp,
122
+ );
123
+ }
124
+ }
125
+ // 2. CHẾ ĐỘ KHÔNG XÁC ĐỊNH (INDETERMINATE)
126
+ else {
127
+ const safeCrawlerSpeed = Math.max(0.1, crawlerSpeed);
128
+ const activeLines: { tail: number; head: number }[] = [];
129
+
130
+ if (indeterminateAnimation === "continuous") {
131
+ const cycle = 2000 / safeCrawlerSpeed;
132
+ const fraction = (time % cycle) / cycle;
133
+ activeLines.push({
134
+ tail: easeInOutCubic(Math.max(0, fraction * 1.5 - 0.5)),
135
+ head: easeInOutCubic(Math.min(1, fraction * 1.5)),
136
+ });
137
+ } else {
138
+ const cycle = 1750 / safeCrawlerSpeed;
139
+ const t = (time % cycle) * safeCrawlerSpeed;
140
+
141
+ const l1H = easeInOutCubic(Math.max(0, Math.min(1, t / 1000)));
142
+ const l1T = easeInOutCubic(Math.max(0, Math.min(1, (t - 250) / 1000)));
143
+ const l2H = easeInOutCubic(Math.max(0, Math.min(1, (t - 650) / 850)));
144
+ const l2T = easeInOutCubic(Math.max(0, Math.min(1, (t - 900) / 850)));
145
+
146
+ activeLines.push({ tail: l1T, head: l1H });
147
+ activeLines.push({ tail: l2T, head: l2H });
148
+ }
149
+
150
+ const segments = activeLines
151
+ .map((line) => {
152
+ const barTail = line.tail * width;
153
+ const barHead = line.head * width;
154
+ const adjTail = Math.max(
155
+ capWidth,
156
+ Math.min(width - capWidth, barTail),
157
+ );
158
+ const adjHead = Math.max(
159
+ capWidth,
160
+ Math.min(width - capWidth, barHead),
161
+ );
162
+ return { adjTail, adjHead };
163
+ })
164
+ .filter((seg) => seg.adjHead - seg.adjTail > 0.1);
165
+
166
+ activePathD = segments
167
+ .map((seg) =>
168
+ getSinePath(
169
+ seg.adjTail,
170
+ seg.adjHead,
171
+ phase,
172
+ activeWavelength,
173
+ currentAmp,
174
+ ),
175
+ )
176
+ .join(" ");
177
+
178
+ let currentTrackX = capWidth;
179
+ for (const seg of segments) {
180
+ const trackEnd = seg.adjTail - totalGap;
181
+ if (trackEnd > currentTrackX) {
182
+ trackD += `${getSinePath(currentTrackX, trackEnd, phase, activeWavelength, trackAmp)} `;
183
+ }
184
+ currentTrackX = Math.max(currentTrackX, seg.adjHead + totalGap);
185
+ }
186
+ if (currentTrackX < width - capWidth) {
187
+ trackD += getSinePath(
188
+ currentTrackX,
189
+ width - capWidth,
190
+ phase,
191
+ activeWavelength,
192
+ trackAmp,
193
+ );
194
+ }
195
+ }
196
+
197
+ if (activePathRef.current)
198
+ activePathRef.current.setAttribute("d", activePathD);
199
+ if (trackPathRef.current)
200
+ trackPathRef.current.setAttribute("d", trackD.trim());
201
+ });
202
+
203
+ return (
204
+ <div
205
+ ref={containerRef}
206
+ className="relative w-full overflow-hidden"
207
+ style={{ height: svgHeight }}
208
+ >
209
+ {width > 0 && (
210
+ <svg
211
+ className="absolute inset-0 w-full h-full"
212
+ style={{
213
+ overflow: "visible",
214
+ transform: isRtl ? "scaleX(-1)" : undefined,
215
+ }}
216
+ aria-labelledby={titleId}
217
+ >
218
+ <title id={titleId}>
219
+ {isDeterminate
220
+ ? `Progress: ${clampedValue}%`
221
+ : "Indeterminate loading progress"}
222
+ </title>
223
+ <g transform={`translate(0, ${svgHeight / 2})`}>
224
+ <path
225
+ ref={trackPathRef}
226
+ fill="none"
227
+ stroke={trackColor}
228
+ strokeWidth={trackHeight}
229
+ strokeLinecap="round"
230
+ />
231
+ <path
232
+ ref={activePathRef}
233
+ fill="none"
234
+ stroke={activeColor}
235
+ strokeWidth={trackHeight}
236
+ strokeLinecap="round"
237
+ />
238
+ </g>
239
+ </svg>
240
+ )}
241
+ </div>
242
+ );
243
+ });