@kanso-labs/kanso-ui 0.35.0 → 0.37.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 (220) hide show
  1. package/README.md +90 -9
  2. package/dist/button/context.js +7 -0
  3. package/dist/button/context.js.map +1 -0
  4. package/dist/button/group.js +25 -0
  5. package/dist/button/group.js.map +1 -0
  6. package/dist/button/hooks.js +81 -0
  7. package/dist/button/hooks.js.map +1 -0
  8. package/dist/button/index.d.ts +11 -0
  9. package/dist/button/index.js +273 -0
  10. package/dist/button/index.js.map +1 -0
  11. package/dist/button/styles.js +23 -0
  12. package/dist/button/styles.js.map +1 -0
  13. package/dist/calendar/index.js +473 -7
  14. package/dist/calendar/index.js.map +1 -1
  15. package/dist/calendar/styles.js +132 -4
  16. package/dist/calendar/styles.js.map +1 -1
  17. package/dist/chip/index.js +74 -9
  18. package/dist/chip/index.js.map +1 -1
  19. package/dist/chip/styles.js +78 -4
  20. package/dist/chip/styles.js.map +1 -1
  21. package/dist/collection/index.js +12 -9
  22. package/dist/collection/index.js.map +1 -1
  23. package/dist/collection/styles.js +21 -2
  24. package/dist/collection/styles.js.map +1 -1
  25. package/dist/color-scheme.d.ts +29 -0
  26. package/dist/color-scheme.js +32 -0
  27. package/dist/color-scheme.js.map +1 -0
  28. package/dist/components/avatar/index.js +35 -22
  29. package/dist/components/avatar/index.js.map +1 -1
  30. package/dist/components/badge/index.d.ts +40 -0
  31. package/dist/components/badge/index.js +102 -0
  32. package/dist/components/badge/index.js.map +1 -0
  33. package/dist/components/breadcrumbs/index.d.ts +1 -1
  34. package/dist/components/breadcrumbs/index.js +1 -1
  35. package/dist/components/breadcrumbs/index.js.map +1 -1
  36. package/dist/components/button/index.d.ts +58 -14
  37. package/dist/components/button/index.js +400 -147
  38. package/dist/components/button/index.js.map +1 -1
  39. package/dist/components/button-group/index.d.ts +54 -0
  40. package/dist/components/button-group/index.js +272 -0
  41. package/dist/components/button-group/index.js.map +1 -0
  42. package/dist/components/calendar/index.d.ts +9 -1
  43. package/dist/components/calendar/index.js +71 -44
  44. package/dist/components/calendar/index.js.map +1 -1
  45. package/dist/components/card/index.d.ts +1 -1
  46. package/dist/components/card/index.js +4 -4
  47. package/dist/components/card/index.js.map +1 -1
  48. package/dist/components/checkbox/index.js +15 -1
  49. package/dist/components/checkbox/index.js.map +1 -1
  50. package/dist/components/checkbox-group/index.js +1 -0
  51. package/dist/components/checkbox-group/index.js.map +1 -1
  52. package/dist/components/chip/index.d.ts +55 -8
  53. package/dist/components/chip/index.js +174 -63
  54. package/dist/components/chip/index.js.map +1 -1
  55. package/dist/components/chip-group/index.d.ts +16 -7
  56. package/dist/components/chip-group/index.js +58 -35
  57. package/dist/components/chip-group/index.js.map +1 -1
  58. package/dist/components/color-field/index.js +25 -23
  59. package/dist/components/color-field/index.js.map +1 -1
  60. package/dist/components/color-picker/index.js +42 -31
  61. package/dist/components/color-picker/index.js.map +1 -1
  62. package/dist/components/color-swatch-picker/index.d.ts +1 -1
  63. package/dist/components/color-swatch-picker/index.js +17 -13
  64. package/dist/components/color-swatch-picker/index.js.map +1 -1
  65. package/dist/components/combo-box/index.d.ts +5 -3
  66. package/dist/components/combo-box/index.js +63 -58
  67. package/dist/components/combo-box/index.js.map +1 -1
  68. package/dist/components/copy-field/index.d.ts +7 -6
  69. package/dist/components/copy-field/index.js +92 -90
  70. package/dist/components/copy-field/index.js.map +1 -1
  71. package/dist/components/currency/index.d.ts +8 -7
  72. package/dist/components/currency/index.js +43 -65
  73. package/dist/components/currency/index.js.map +1 -1
  74. package/dist/components/date-field/index.js +24 -22
  75. package/dist/components/date-field/index.js.map +1 -1
  76. package/dist/components/date-picker/index.d.ts +10 -2
  77. package/dist/components/date-picker/index.js +76 -69
  78. package/dist/components/date-picker/index.js.map +1 -1
  79. package/dist/components/date-range-picker/index.d.ts +10 -2
  80. package/dist/components/date-range-picker/index.js +93 -86
  81. package/dist/components/date-range-picker/index.js.map +1 -1
  82. package/dist/components/dialog/index.d.ts +1 -1
  83. package/dist/components/dialog/index.js +2 -2
  84. package/dist/components/dialog/index.js.map +1 -1
  85. package/dist/components/disclosure/index.d.ts +1 -1
  86. package/dist/components/disclosure/index.js +6 -6
  87. package/dist/components/disclosure/index.js.map +1 -1
  88. package/dist/components/fab/index.d.ts +72 -0
  89. package/dist/components/fab/index.js +89 -0
  90. package/dist/components/fab/index.js.map +1 -0
  91. package/dist/components/fab-menu/index.d.ts +90 -0
  92. package/dist/components/fab-menu/index.js +297 -0
  93. package/dist/components/fab-menu/index.js.map +1 -0
  94. package/dist/components/feed/index.d.ts +2 -1
  95. package/dist/components/feed/index.js +1 -1
  96. package/dist/components/feed/index.js.map +1 -1
  97. package/dist/components/icon-button/index.d.ts +11 -8
  98. package/dist/components/icon-button/index.js +244 -181
  99. package/dist/components/icon-button/index.js.map +1 -1
  100. package/dist/components/index.d.ts +30 -21
  101. package/dist/components/list/index.d.ts +15 -13
  102. package/dist/components/list/index.js +60 -61
  103. package/dist/components/list/index.js.map +1 -1
  104. package/dist/components/list-box/index.d.ts +3 -2
  105. package/dist/components/list-box/index.js +16 -16
  106. package/dist/components/list-box/index.js.map +1 -1
  107. package/dist/components/list-item/index.js +1 -1
  108. package/dist/components/list-item/index.js.map +1 -1
  109. package/dist/components/menu/index.d.ts +3 -2
  110. package/dist/components/menu/index.js +2 -2
  111. package/dist/components/menu/index.js.map +1 -1
  112. package/dist/components/navigation-bar/index.d.ts +50 -0
  113. package/dist/components/navigation-bar/index.js +129 -0
  114. package/dist/components/navigation-bar/index.js.map +1 -0
  115. package/dist/components/navigation-rail/index.d.ts +59 -0
  116. package/dist/components/navigation-rail/index.js +166 -0
  117. package/dist/components/navigation-rail/index.js.map +1 -0
  118. package/dist/components/navigation-tree/index.d.ts +1 -5
  119. package/dist/components/navigation-tree/index.js +3 -3
  120. package/dist/components/navigation-tree/index.js.map +1 -1
  121. package/dist/components/number-field/index.d.ts +6 -4
  122. package/dist/components/number-field/index.js +84 -84
  123. package/dist/components/number-field/index.js.map +1 -1
  124. package/dist/components/popover/index.d.ts +1 -1
  125. package/dist/components/popover/index.js +1 -1
  126. package/dist/components/popover/index.js.map +1 -1
  127. package/dist/components/radio-group/index.js +22 -11
  128. package/dist/components/radio-group/index.js.map +1 -1
  129. package/dist/components/range-calendar/index.d.ts +7 -1
  130. package/dist/components/range-calendar/index.js +71 -44
  131. package/dist/components/range-calendar/index.js.map +1 -1
  132. package/dist/components/search-field/index.d.ts +2 -1
  133. package/dist/components/search-field/index.js +24 -25
  134. package/dist/components/search-field/index.js.map +1 -1
  135. package/dist/components/search-view/index.d.ts +79 -0
  136. package/dist/components/search-view/index.js +255 -0
  137. package/dist/components/search-view/index.js.map +1 -0
  138. package/dist/components/segmented-button/index.d.ts +2 -2
  139. package/dist/components/segmented-button/index.js +60 -31
  140. package/dist/components/segmented-button/index.js.map +1 -1
  141. package/dist/components/select/index.js +1 -0
  142. package/dist/components/select/index.js.map +1 -1
  143. package/dist/components/sheet/index.d.ts +1 -1
  144. package/dist/components/sheet/index.js +2 -2
  145. package/dist/components/sheet/index.js.map +1 -1
  146. package/dist/components/slider/index.js +1 -1
  147. package/dist/components/slider/index.js.map +1 -1
  148. package/dist/components/snackbar/index.d.ts +2 -2
  149. package/dist/components/snackbar/index.js +28 -13
  150. package/dist/components/snackbar/index.js.map +1 -1
  151. package/dist/components/split-button/index.d.ts +83 -0
  152. package/dist/components/split-button/index.js +341 -0
  153. package/dist/components/split-button/index.js.map +1 -0
  154. package/dist/components/switch/index.js +11 -1
  155. package/dist/components/switch/index.js.map +1 -1
  156. package/dist/components/table/index.d.ts +11 -9
  157. package/dist/components/table/index.js +87 -31
  158. package/dist/components/table/index.js.map +1 -1
  159. package/dist/components/tabs/index.d.ts +35 -4
  160. package/dist/components/tabs/index.js +403 -93
  161. package/dist/components/tabs/index.js.map +1 -1
  162. package/dist/components/tag/index.d.ts +1 -1
  163. package/dist/components/tag/index.js.map +1 -1
  164. package/dist/components/text-area/index.d.ts +7 -5
  165. package/dist/components/text-area/index.js +28 -26
  166. package/dist/components/text-area/index.js.map +1 -1
  167. package/dist/components/text-field/index.d.ts +7 -5
  168. package/dist/components/text-field/index.js +28 -26
  169. package/dist/components/text-field/index.js.map +1 -1
  170. package/dist/components/time-field/index.js +24 -22
  171. package/dist/components/time-field/index.js.map +1 -1
  172. package/dist/components/tree/index.d.ts +7 -9
  173. package/dist/components/tree/index.js +15 -16
  174. package/dist/components/tree/index.js.map +1 -1
  175. package/dist/drag/index.js.map +1 -1
  176. package/dist/drag/styles.js +4 -1
  177. package/dist/drag/styles.js.map +1 -1
  178. package/dist/fab/styles.js +161 -0
  179. package/dist/fab/styles.js.map +1 -0
  180. package/dist/field/index.js +260 -214
  181. package/dist/field/index.js.map +1 -1
  182. package/dist/field/styles.js +10 -2
  183. package/dist/field/styles.js.map +1 -1
  184. package/dist/glyphs/index.js +55 -1
  185. package/dist/glyphs/index.js.map +1 -1
  186. package/dist/hooks/useRipple.js +199 -162
  187. package/dist/hooks/useRipple.js.map +1 -1
  188. package/dist/hooks/useToggleGroupDisabled.js +24 -0
  189. package/dist/hooks/useToggleGroupDisabled.js.map +1 -0
  190. package/dist/i18n/index.js +43 -0
  191. package/dist/i18n/index.js.map +1 -0
  192. package/dist/i18n/messages.js +387 -0
  193. package/dist/i18n/messages.js.map +1 -0
  194. package/dist/index.d.ts +31 -21
  195. package/dist/index.js +25 -16
  196. package/dist/navigation/context.js +7 -0
  197. package/dist/navigation/context.js.map +1 -0
  198. package/dist/navigation/index.d.ts +28 -0
  199. package/dist/navigation/index.js +96 -0
  200. package/dist/navigation/index.js.map +1 -0
  201. package/dist/navigation/styles.js +312 -0
  202. package/dist/navigation/styles.js.map +1 -0
  203. package/dist/react-aria.d.ts +2 -2
  204. package/dist/react-aria.js +2 -2
  205. package/dist/render/useRender.js +0 -1
  206. package/dist/render/useRender.js.map +1 -1
  207. package/dist/row/styles.js +33 -11
  208. package/dist/row/styles.js.map +1 -1
  209. package/dist/styles/focus.js.map +1 -1
  210. package/dist/styles/icon-button.js +9 -1
  211. package/dist/styles/icon-button.js.map +1 -1
  212. package/dist/styles/overlay.js +1 -0
  213. package/dist/styles/overlay.js.map +1 -1
  214. package/dist/styles/picker.js +1 -1
  215. package/dist/styles/picker.js.map +1 -1
  216. package/dist/styles.css +1104 -336
  217. package/dist/tokens/design.tokens.stylex.js +42 -1
  218. package/dist/tokens/design.tokens.stylex.js.map +1 -1
  219. package/dist/tokens.css +166 -53
  220. package/package.json +9 -5
package/README.md CHANGED
@@ -128,6 +128,37 @@ import {
128
128
  is a subpath rather than part of the main entry so an app with no date component
129
129
  pays nothing for it.
130
130
 
131
+ ### Localisation
132
+
133
+ Wrap the app in `I18nProvider`, which this package re-exports, and every word
134
+ the components write follows its locale. React Aria names most of the controls
135
+ they draw, in some thirty languages: an overlay's dismiss button, a field's
136
+ clear button and steppers, a snackbar's close, a chip's remove, a row's
137
+ selection box, a column's resize handle, a picker's trigger and a colour
138
+ picker's strips.
139
+
140
+ Five strings have no word in React Aria, so this package carries them in the
141
+ same locales React Aria ships:
142
+
143
+ - the ring a pending `Button` or `IconButton` shows,
144
+ - a collection's loading-more row,
145
+ - `CopyField`'s button and what it announces once it has copied,
146
+ - and a field's character limit.
147
+
148
+ These translations are the package's own, and a wrong one is worth an issue.
149
+ Every string sits behind a prop for the call site's own words: `pendingLabel`, a
150
+ `LoadMore`'s `label`, `copyLabel`, `copiedLabel` and `characterLimitLabel`. The
151
+ names React Aria gives sit behind `clearLabel`, `closeLabel` and the rest.
152
+
153
+ Numbers follow the provider too: `Currency` writes its amount, and a field its
154
+ character count, in the locale's digits and grouping.
155
+
156
+ A bundler includes every language unless told which ones the app supports. React
157
+ Aria's
158
+ [`@react-aria/optimize-locales-plugin`](https://www.npmjs.com/package/@react-aria/optimize-locales-plugin)
159
+ is how an app says so for React Aria's own tables. This package's table is one
160
+ small module, included whole.
161
+
131
162
  ### Layout
132
163
 
133
164
  `Container` centres content at a measure, and `Stack` puts one gap from the
@@ -233,10 +264,8 @@ content given `slot="close"`:
233
264
  ```
234
265
 
235
266
  An open overlay carries a visually hidden dismiss button for screen readers,
236
- whose label React Aria ships in some thirty languages. A bundler includes all of
237
- them unless told which the app supports; React Aria's
238
- [`@react-aria/optimize-locales-plugin`](https://www.npmjs.com/package/@react-aria/optimize-locales-plugin)
239
- is how an app says so.
267
+ named in the reader's language like every other control here; see
268
+ [Localisation](#localisation).
240
269
 
241
270
  ### Icons
242
271
 
@@ -272,9 +301,12 @@ the icon inherits it:
272
301
 
273
302
  | Slot | Size an `em` icon takes |
274
303
  | ------------------------------------------ | ---------------------------------------------------- |
304
+ | `Button`'s `icon` | 20px, 20px, 24px, 32px and 40px across `xs` to `xxl` |
305
+ | `Chip`'s and `ChipGroup.Chip`'s `icon` | 18px |
275
306
  | `IconButton` | 20px, 24px, 24px, 32px and 40px across `xs` to `xxl` |
276
307
  | A field's `leadingIcon` and `trailingIcon` | 24px |
277
308
  | `SegmentedButton.Segment`'s `icon` | 18px |
309
+ | `Tabs.Tab`'s `icon` | 24px |
278
310
 
279
311
  **The `leading` and `trailing` slots on a row are different.** A list item, a
280
312
  menu item, a tree item and an app bar set no icon size, so an icon there takes
@@ -287,8 +319,8 @@ those a size of its own:
287
319
 
288
320
  An SVG with a `viewBox` and no size at all has no size to shrink from, so what
289
321
  it does next belongs to the slot rather than to the icon. In an `IconButton` it
290
- fills the button edge to edge; in a field's icon slot it collapses and draws
291
- nothing. Sizing it is what avoids both.
322
+ fills the button edge to edge; in a field's icon slot or a `Button`'s it
323
+ collapses and draws nothing. Sizing it is what avoids both.
292
324
 
293
325
  ### Server components
294
326
 
@@ -311,9 +343,29 @@ Four things follow from where that boundary falls.
311
343
  `onPress` and a `render` callback belong in a client component of your own.
312
344
  Neither does a class instance, so a `CalendarDate` for a date component is
313
345
  built on the client side too.
314
- - **A sub-part is reached through its component**, as in `Dialog.Title` or
315
- `Menu.Item`, and a server component cannot reach into a client module that
316
- way. Compose those in a client component and render that.
346
+ - **A sub-part is rendered by its own name**, as in `DialogTitle` or `MenuItem`.
347
+ A server component cannot reach into a client module through a property, so
348
+ `<Dialog.Title>` works only from a client component, while every part is also
349
+ exported as its component's name followed by the part's: `SheetContent`,
350
+ `TableRow`, `NavigationTreeItem`. `List.Item` is `ListRow`, since the
351
+ standalone `ListItem` already has that name:
352
+
353
+ ```tsx
354
+ // app/settings/page.tsx
355
+ import { Button, Sheet, SheetContent, SheetTitle } from '@kanso-labs/kanso-ui'
356
+
357
+ export default function Page() {
358
+ return (
359
+ <Sheet>
360
+ <Button>Open</Button>
361
+ <SheetContent>
362
+ <SheetTitle>Headline</SheetTitle>
363
+ </SheetContent>
364
+ </Sheet>
365
+ )
366
+ }
367
+ ```
368
+
317
369
  - **The React Aria utilities the package re-exports are client-only** —
318
370
  `I18nProvider`, `useListData`, `parseColor` and the rest. `collectionSizes` is
319
371
  a plain value and works on either side.
@@ -357,6 +409,35 @@ default value — useful for discovering names, not required at runtime
357
409
  import '@kanso-labs/kanso-ui/tokens.css'
358
410
  ```
359
411
 
412
+ ### Pinning light or dark
413
+
414
+ The colours follow the reader's OS through `prefers-color-scheme` unless the app
415
+ says otherwise. An app with a theme switch of its own pins a scheme with
416
+ `colorScheme`, two class names: put `colorScheme.light` or `colorScheme.dark` on
417
+ the `<html>` element, and remove both to follow the OS again. The `<html>`
418
+ element is the place for it, since overlays are portalled to the body and still
419
+ sit inside it.
420
+
421
+ Its shape is the one next-themes takes for class names, so a provider is all it
422
+ needs:
423
+
424
+ ```tsx
425
+ import { ThemeProvider } from 'next-themes'
426
+ import { colorScheme } from '@kanso-labs/kanso-ui'
427
+
428
+ function Providers({ children }: { children: React.ReactNode }) {
429
+ return (
430
+ <ThemeProvider attribute="class" value={colorScheme}>
431
+ {children}
432
+ </ThemeProvider>
433
+ )
434
+ }
435
+ ```
436
+
437
+ A `--kui-color-*` override on `:root` still applies under a pinned scheme. To
438
+ give one scheme a value of its own, key the override on an attribute your switch
439
+ sets beside the class, since the class names are generated.
440
+
360
441
  ### For StyleX consumers
361
442
 
362
443
  If your app also uses StyleX, theme with
@@ -0,0 +1,7 @@
1
+ import { createContext } from "react";
2
+ //#region src/button/context.ts
3
+ const ButtonGroupItemContext = createContext(null);
4
+ //#endregion
5
+ export { ButtonGroupItemContext };
6
+
7
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","names":["stylex","createContext","ButtonState","ButtonGroupItem","onPressEnd","onPressStart","width","shift","size","GroupSize","styles","state","StyleXStyles","ButtonGroupItemContext"],"sources":["../../src/button/context.ts"],"sourcesContent":["import type * as stylex from '@stylexjs/stylex';\nimport { createContext } from 'react';\nimport type { ButtonState } from '.';\n\n// What a group hands each Button or IconButton in it: ButtonGroup's two\n// variants and SplitButton's two halves. Apart from ./index.tsx so that file\n// exports components alone, which is what keeps fast refresh working for it.\n\ntype ButtonGroupItem = {\n /** Called as a press on the button ends, so the group lets go of it. */\n onPressEnd?: () => void;\n /**\n * Called as a press on the button starts, with its width, so a standard\n * group can widen it and narrow its neighbours.\n */\n onPressStart?: (width: number) => void;\n /**\n * How far the button's width moves while it or a neighbour is pressed, in\n * pixels: the pressed button's gain, or a neighbour's loss as a negative.\n * Zero at rest.\n */\n shift: number;\n /** The group's size, which a button takes unless it names its own. */\n size: GroupSize | undefined;\n /**\n * Styles the group lays over the button's own, from its render state: a\n * connected group's inner corners, a split button's paddings. Applied\n * after the button's own shape and before its disabled styles.\n */\n styles?: (state: ButtonState) => stylex.StyleXStyles[];\n};\n\n/** The five sizes Button and IconButton share. */\ntype GroupSize = 'lg' | 'md' | 'xl' | 'xs' | 'xxl';\nconst ButtonGroupItemContext = createContext<ButtonGroupItem | null>(null);\nexport type { ButtonGroupItem, GroupSize };\nexport { ButtonGroupItemContext };"],"mappings":";;AAkCA,MAAMa,yBAAyBZ,cAAsC,IAAI"}
@@ -0,0 +1,25 @@
1
+ //#region src/button/group.ts
2
+ /**
3
+ * The press handlers a button inside a group that tracks presses takes: its
4
+ * own, with the group told first. Empty anywhere else, which leaves the
5
+ * call site's own handlers on the button untouched.
6
+ */
7
+ function groupPressHandlers(group, onPressStart, onPressEnd) {
8
+ const start = group?.onPressStart;
9
+ if (start === void 0) return {};
10
+ const end = group?.onPressEnd;
11
+ return {
12
+ onPressEnd: (event) => {
13
+ end?.();
14
+ onPressEnd?.(event);
15
+ },
16
+ onPressStart: (event) => {
17
+ start(event.target.getBoundingClientRect().width);
18
+ onPressStart?.(event);
19
+ }
20
+ };
21
+ }
22
+ //#endregion
23
+ export { groupPressHandlers };
24
+
25
+ //# sourceMappingURL=group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.js","names":["PressEvent","ButtonGroupItem","groupPressHandlers","group","onPressStart","event","onPressEnd","start","undefined","end","target","getBoundingClientRect","width"],"sources":["../../src/button/group.ts"],"sourcesContent":["import type { PressEvent } from 'react-aria-components'\n\nimport type { ButtonGroupItem } from './context'\n\n// What a button in a standard ButtonGroup does about its own presses: tell\n// the group when one starts, with its width, and when it ends, so the group\n// can widen it and narrow its neighbours. Apart from ./index.tsx so that file\n// exports components alone, which is what keeps fast refresh working for it.\n\n/**\n * The press handlers a button inside a group that tracks presses takes: its\n * own, with the group told first. Empty anywhere else, which leaves the\n * call site's own handlers on the button untouched.\n */\nfunction groupPressHandlers(\n group: ButtonGroupItem | null,\n onPressStart: ((event: PressEvent) => void) | undefined,\n onPressEnd: ((event: PressEvent) => void) | undefined,\n) {\n const start = group?.onPressStart\n if (start === undefined) {\n return {}\n }\n const end = group?.onPressEnd\n\n return {\n onPressEnd: (event: PressEvent) => {\n end?.()\n onPressEnd?.(event)\n },\n onPressStart: (event: PressEvent) => {\n start(event.target.getBoundingClientRect().width)\n onPressStart?.(event)\n },\n }\n}\n\nexport { groupPressHandlers }\n"],"mappings":";;;;;;AAcA,SAASE,mBACPC,OACAC,cACAE,YACA;CACA,MAAMC,QAAQJ,OAAOC;CACrB,IAAIG,UAAUC,KAAAA,GACZ,OAAO,CAAC;CAEV,MAAMC,MAAMN,OAAOG;CAEnB,OAAO;EACLA,aAAaD,UAAsB;GACjCI,MAAM;GACNH,aAAaD,KAAK;EACpB;EACAD,eAAeC,UAAsB;GACnCE,MAAMF,MAAMK,OAAOC,sBAAsB,CAAC,CAACC,KAAK;GAChDR,eAAeC,KAAK;EACtB;CACF;AACF"}
@@ -0,0 +1,81 @@
1
+ import { ariaAttributesOf } from "../render/aria.js";
2
+ import { useRipple } from "../hooks/useRipple.js";
3
+ import { refCallback } from "../render/ref.js";
4
+ import { c } from "react/compiler-runtime";
5
+ import { ButtonContext, useSlottedContext } from "react-aria-components";
6
+ //#region src/button/hooks.ts
7
+ /**
8
+ * What a button does past React Aria, whichever of its elements it renders:
9
+ * the disabled state a parent's context sets, the ripple, and the `aria-*`
10
+ * props and keyboard handlers React Aria would drop or wrap. Hands back the
11
+ * props it did not take, for the element.
12
+ *
13
+ * Shared by ButtonBase and by IconButton's toggle, which is React Aria's
14
+ * `ToggleButton` rather than either element ButtonBase renders.
15
+ */
16
+ function useButtonBase(input, isPending) {
17
+ const $ = c(19);
18
+ const { disableRipple: t0, isDisabled, onClick, onContextMenu, onKeyDown, onKeyUp, onPointerCancel, onPointerDown, onPointerLeave, onPointerUp, ref, ...props } = input;
19
+ const disableRipple = t0 === void 0 ? false : t0;
20
+ const context = useSlottedContext(ButtonContext, input.slot);
21
+ const disabled = isDisabled ?? context?.isDisabled ?? false;
22
+ let t1;
23
+ if ($[0] !== onClick || $[1] !== onContextMenu || $[2] !== onPointerCancel || $[3] !== onPointerDown || $[4] !== onPointerLeave || $[5] !== onPointerUp) {
24
+ t1 = {
25
+ onClick,
26
+ onContextMenu,
27
+ onPointerCancel,
28
+ onPointerDown,
29
+ onPointerLeave,
30
+ onPointerUp
31
+ };
32
+ $[0] = onClick;
33
+ $[1] = onContextMenu;
34
+ $[2] = onPointerCancel;
35
+ $[3] = onPointerDown;
36
+ $[4] = onPointerLeave;
37
+ $[5] = onPointerUp;
38
+ $[6] = t1;
39
+ } else t1 = $[6];
40
+ const ripple = useRipple(!disableRipple && !disabled && !isPending, t1);
41
+ const t2 = ariaAttributesOf(props);
42
+ let t3;
43
+ if ($[7] !== onKeyDown || $[8] !== onKeyUp || $[9] !== t2) {
44
+ t3 = {
45
+ aria: t2,
46
+ onKeyDown,
47
+ onKeyUp
48
+ };
49
+ $[7] = onKeyDown;
50
+ $[8] = onKeyUp;
51
+ $[9] = t2;
52
+ $[10] = t3;
53
+ } else t3 = $[10];
54
+ let t4;
55
+ if ($[11] !== ref) {
56
+ t4 = refCallback(ref);
57
+ $[11] = ref;
58
+ $[12] = t4;
59
+ } else t4 = $[12];
60
+ let t5;
61
+ if ($[13] !== disabled || $[14] !== props || $[15] !== ripple || $[16] !== t3 || $[17] !== t4) {
62
+ t5 = {
63
+ disabled,
64
+ element: t3,
65
+ props,
66
+ ref: t4,
67
+ ripple
68
+ };
69
+ $[13] = disabled;
70
+ $[14] = props;
71
+ $[15] = ripple;
72
+ $[16] = t3;
73
+ $[17] = t4;
74
+ $[18] = t5;
75
+ } else t5 = $[18];
76
+ return t5;
77
+ }
78
+ //#endregion
79
+ export { useButtonBase };
80
+
81
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","names":["Ref","FocusableElement","ButtonContext","useSlottedContext","ButtonDOMProps","useRipple","ariaAttributesOf","refCallback","ButtonBaseInput","Pick","disableRipple","ref","HTMLAnchorElement","HTMLButtonElement","useButtonBase","input","isPending","$","_c","t0","isDisabled","onClick","onContextMenu","onKeyDown","onKeyUp","onPointerCancel","onPointerDown","onPointerLeave","onPointerUp","props","undefined","context","slot","disabled","t1","ripple","t2","t3","aria","t4","t5","element","_c"],"sources":["../../src/button/hooks.ts"],"sourcesContent":["import type { Ref } from 'react'\nimport type { FocusableElement } from 'react-aria-components'\n\nimport { ButtonContext, useSlottedContext } from 'react-aria-components'\n\nimport type { ButtonDOMProps } from '.'\n\nimport { useRipple } from '../hooks/useRipple'\nimport { ariaAttributesOf } from '../render/aria'\nimport { refCallback } from '../render/ref'\n\n// The hook half of `src/button`, apart from ./index.tsx so that file exports\n// components alone — which is what keeps fast refresh working for it, the\n// same arrangement `src/drag` uses.\n\n/** What {@link useButtonBase} takes off a button's props for itself. */\ntype ButtonBaseInput = Pick<\n ButtonDOMProps,\n | 'isDisabled'\n | 'onClick'\n | 'onContextMenu'\n | 'onKeyDown'\n | 'onKeyUp'\n | 'onPointerCancel'\n | 'onPointerDown'\n | 'onPointerLeave'\n | 'onPointerUp'\n | 'slot'\n> & {\n disableRipple?: boolean\n ref?: Ref<HTMLAnchorElement | HTMLButtonElement>\n}\n\n/**\n * What a button does past React Aria, whichever of its elements it renders:\n * the disabled state a parent's context sets, the ripple, and the `aria-*`\n * props and keyboard handlers React Aria would drop or wrap. Hands back the\n * props it did not take, for the element.\n *\n * Shared by ButtonBase and by IconButton's toggle, which is React Aria's\n * `ToggleButton` rather than either element ButtonBase renders.\n */\nfunction useButtonBase<Props extends ButtonBaseInput>(\n input: Props,\n isPending: boolean,\n) {\n const {\n disableRipple = false,\n isDisabled,\n onClick,\n onContextMenu,\n onKeyDown,\n onKeyUp,\n onPointerCancel,\n onPointerDown,\n onPointerLeave,\n onPointerUp,\n ref,\n ...props\n } = input\n\n // A parent's context may disable the button — React Aria's own fields\n // disable the buttons they hold with them, a number field's stepper at the\n // end of its range and a search field's clear button with the field — and\n // React Aria takes a prop over its context, so a default of `false` here\n // would keep the button enabled whatever the parent said. The call site's\n // own prop still wins where it is given; the context is read for the\n // ripple, which has to know before the render state does.\n const context = useSlottedContext(ButtonContext, input.slot)\n const disabled = isDisabled ?? context?.isDisabled ?? false\n\n // The rest of the props (className/style, etc.) are handed back rather\n // than given to the ripple: `className` and `style` there may be functions\n // of render state, which the ripple's own handler-only merge doesn't need\n // to know about. It is also why ButtonBase merges the styles through\n // mergeStatefulStyles rather than the plain mergeStyles. The ripple is off\n // while disabled: React Aria still forwards pointer events to a disabled\n // element, and a press that changes nothing should not look like one.\n //\n // Off while pending for the same reason, and for a second one. React Aria\n // nulls out the handlers it derived itself while pending — the click among\n // them — but not the separate copy of the global pointer events that\n // carries ours, so a press still reached the ripple and started it while\n // the click that would have ended it never arrived. The ripple stayed at\n // its pressed opacity until some later press completed a cycle of its own.\n const ripple = useRipple<FocusableElement>(\n !disableRipple && !disabled && !isPending,\n {\n onClick,\n onContextMenu,\n onPointerCancel,\n onPointerDown,\n onPointerLeave,\n onPointerUp,\n },\n )\n\n return {\n disabled,\n element: { aria: ariaAttributesOf(props), onKeyDown, onKeyUp },\n props,\n // The element is a button, a link or IconButton's toggle, so the ref is\n // typed as a link or a button and handed to each as the callback all\n // three accept — see src/render/ref.ts.\n ref: refCallback(ref),\n ripple,\n }\n}\n\nexport { useButtonBase }\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,SAAAc,cAAAC,OAAAC,WAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAIE,MAAA,EAAAR,eAAAS,IAAAC,YAAAC,SAAAC,eAAAC,WAAAC,SAAAC,iBAAAC,eAAAC,gBAAAC,aAAAjB,KAAA,GAAAkB,UAaId;CAZF,MAAAL,gBAAAS,OAAAW,KAAAA,IAAA,QAAAX;CAqBF,MAAAY,UAAgB5B,kBAAkBD,eAAea,MAAKiB,IAAK;CAC3D,MAAAC,WAAiBb,cAAcW,SAAOX,cAArB;CAA0C,IAAAc;CAAA,IAAAjB,EAAA,OAAAI,WAAAJ,EAAA,OAAAK,iBAAAL,EAAA,OAAAQ,mBAAAR,EAAA,OAAAS,iBAAAT,EAAA,OAAAU,kBAAAV,EAAA,OAAAW,aAAA;EAkBzDM,KAAA;GAAAb;GAAAC;GAAAG;GAAAC;GAAAC;GAAAC;EAOA;EAACX,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;EAAAL,EAAA,KAAAQ;EAAAR,EAAA,KAAAS;EAAAT,EAAA,KAAAU;EAAAV,EAAA,KAAAW;EAAAX,EAAA,KAAAiB;CAAA,OAAAA,KAAAjB,EAAA;CATH,MAAAkB,SAAe9B,UACb,CAACK,iBAAD,CAAmBuB,YAAnB,CAAgCjB,WAChCkB,EAQF;CAImB,MAAAE,KAAA9B,iBAAiBuB,KAAK;CAAC,IAAAQ;CAAA,IAAApB,EAAA,OAAAM,aAAAN,EAAA,OAAAO,WAAAP,EAAA,OAAAmB,IAAA;EAA/BC,KAAA;GAAAC,MAAQF;GAAuBb;GAAAC;EAAqB;EAACP,EAAA,KAAAM;EAAAN,EAAA,KAAAO;EAAAP,EAAA,KAAAmB;EAAAnB,EAAA,MAAAoB;CAAA,OAAAA,KAAApB,EAAA;CAAA,IAAAsB;CAAA,IAAAtB,EAAA,QAAAN,KAAA;EAKzD4B,KAAAhC,YAAYI,GAAG;EAACM,EAAA,MAAAN;EAAAM,EAAA,MAAAsB;CAAA,OAAAA,KAAAtB,EAAA;CAAA,IAAAuB;CAAA,IAAAvB,EAAA,QAAAgB,YAAAhB,EAAA,QAAAY,SAAAZ,EAAA,QAAAkB,UAAAlB,EAAA,QAAAoB,MAAApB,EAAA,QAAAsB,IAAA;EAPhBC,KAAA;GAAAP;GAAAQ,SAEIJ;GAAqDR;GAAAlB,KAKzD4B;GAAgBJ;EAEvB;EAAClB,EAAA,MAAAgB;EAAAhB,EAAA,MAAAY;EAAAZ,EAAA,MAAAkB;EAAAlB,EAAA,MAAAoB;EAAApB,EAAA,MAAAsB;EAAAtB,EAAA,MAAAuB;CAAA,OAAAA,KAAAvB,EAAA;CAAA,OATMuB;AASN"}
@@ -0,0 +1,11 @@
1
+ import { DOMAttributes, ReactNode, RefAttributes } from "react";
2
+ import { ButtonProps, ButtonRenderProps, ClassNameOrFunction, StyleOrFunction } from "react-aria-components";
3
+ //#region src/button/index.d.ts
4
+ type ButtonDOMProps = Omit<ButtonProps, 'children' | 'className' | 'style' | GlobalEventKey> & Pick<DOMAttributes<HTMLElement>, GlobalEventKey>;
5
+ type ButtonState = Pick<ButtonRenderProps, 'isDisabled' | 'isFocused' | 'isFocusVisible' | 'isHovered' | 'isPressed'> & {
6
+ isSelected?: boolean;
7
+ };
8
+ type GlobalEventKey = Exclude<keyof DOMAttributes<HTMLElement> & keyof ButtonProps, 'onBlur' | 'onClick' | 'onFocus'>;
9
+ //#endregion
10
+ export type { ButtonDOMProps, ButtonState };
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,273 @@
1
+ import { props } from "../node_modules/@stylexjs/stylex/lib/es/stylex.js";
2
+ import { mergeStatefulStyles } from "../styles/merge.js";
3
+ import { buttonRenderer, linkRenderer, toggleButtonRenderer } from "../render/aria.js";
4
+ import ProgressIndicator from "../components/progress-indicator/index.js";
5
+ import { useToggleGroupDisabled } from "../hooks/useToggleGroupDisabled.js";
6
+ import { useMessages } from "../i18n/index.js";
7
+ import { useButtonBase } from "./hooks.js";
8
+ import { buttonBaseStyles } from "./styles.js";
9
+ import { c } from "react/compiler-runtime";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
+ import { Button, Link, ToggleButton } from "react-aria-components";
12
+ //#region src/button/index.tsx
13
+ /**
14
+ * A button drawn with the classes a component hands it: React Aria's
15
+ * `Button`, or its `Link` given `href`. See the header.
16
+ */
17
+ function ButtonBase(t0) {
18
+ const $ = c(43);
19
+ let children;
20
+ let classes;
21
+ let href;
22
+ let input;
23
+ let pendingLabel;
24
+ let rel;
25
+ let render;
26
+ let t1;
27
+ let target;
28
+ if ($[0] !== t0) {
29
+ ({children, classes, href, isPending: t1, pendingLabel, rel, render, target, ...input} = t0);
30
+ $[0] = t0;
31
+ $[1] = children;
32
+ $[2] = classes;
33
+ $[3] = href;
34
+ $[4] = input;
35
+ $[5] = pendingLabel;
36
+ $[6] = rel;
37
+ $[7] = render;
38
+ $[8] = t1;
39
+ $[9] = target;
40
+ } else {
41
+ children = $[1];
42
+ classes = $[2];
43
+ href = $[3];
44
+ input = $[4];
45
+ pendingLabel = $[5];
46
+ rel = $[6];
47
+ render = $[7];
48
+ t1 = $[8];
49
+ target = $[9];
50
+ }
51
+ const isPending = t1 === void 0 ? false : t1;
52
+ const messages = useMessages();
53
+ const { disabled, element, props, ref, ripple } = useButtonBase(input, isPending);
54
+ let t2;
55
+ if ($[10] !== classes || $[11] !== props) {
56
+ t2 = mergeStatefulStyles(classes, props);
57
+ $[10] = classes;
58
+ $[11] = props;
59
+ $[12] = t2;
60
+ } else t2 = $[12];
61
+ const styleProps = t2;
62
+ if (href !== void 0) {
63
+ let t3;
64
+ if ($[13] !== element) {
65
+ t3 = linkRenderer(element);
66
+ $[13] = element;
67
+ $[14] = t3;
68
+ } else t3 = $[14];
69
+ let t4;
70
+ if ($[15] !== children || $[16] !== disabled || $[17] !== href || $[18] !== props || $[19] !== ref || $[20] !== rel || $[21] !== ripple.handlers || $[22] !== ripple.surface || $[23] !== styleProps || $[24] !== t3 || $[25] !== target) {
71
+ t4 = /* @__PURE__ */ jsxs(Link, {
72
+ href,
73
+ isDisabled: disabled,
74
+ ref,
75
+ rel,
76
+ render: t3,
77
+ target,
78
+ ...ripple.handlers,
79
+ ...props,
80
+ ...styleProps,
81
+ children: [children, ripple.surface]
82
+ });
83
+ $[15] = children;
84
+ $[16] = disabled;
85
+ $[17] = href;
86
+ $[18] = props;
87
+ $[19] = ref;
88
+ $[20] = rel;
89
+ $[21] = ripple.handlers;
90
+ $[22] = ripple.surface;
91
+ $[23] = styleProps;
92
+ $[24] = t3;
93
+ $[25] = target;
94
+ $[26] = t4;
95
+ } else t4 = $[26];
96
+ return t4;
97
+ }
98
+ let t3;
99
+ if ($[27] !== element || $[28] !== render) {
100
+ t3 = buttonRenderer(element, render);
101
+ $[27] = element;
102
+ $[28] = render;
103
+ $[29] = t3;
104
+ } else t3 = $[29];
105
+ const t4 = ripple.handlers;
106
+ const t5 = pendingLabel ?? messages.loading;
107
+ let t6;
108
+ if ($[30] !== children || $[31] !== ripple.surface || $[32] !== t5) {
109
+ t6 = buttonContent(children, t5, ripple.surface);
110
+ $[30] = children;
111
+ $[31] = ripple.surface;
112
+ $[32] = t5;
113
+ $[33] = t6;
114
+ } else t6 = $[33];
115
+ let t7;
116
+ if ($[34] !== disabled || $[35] !== isPending || $[36] !== props || $[37] !== ref || $[38] !== ripple.handlers || $[39] !== styleProps || $[40] !== t3 || $[41] !== t6) {
117
+ t7 = /* @__PURE__ */ jsx(Button, {
118
+ isDisabled: disabled,
119
+ isPending,
120
+ ref,
121
+ render: t3,
122
+ ...t4,
123
+ ...props,
124
+ ...styleProps,
125
+ children: t6
126
+ });
127
+ $[34] = disabled;
128
+ $[35] = isPending;
129
+ $[36] = props;
130
+ $[37] = ref;
131
+ $[38] = ripple.handlers;
132
+ $[39] = styleProps;
133
+ $[40] = t3;
134
+ $[41] = t6;
135
+ $[42] = t7;
136
+ } else t7 = $[42];
137
+ return t7;
138
+ }
139
+ function buttonContent(children, pendingLabel, surface) {
140
+ return (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
141
+ /* @__PURE__ */ jsx("span", {
142
+ ...props(buttonBaseStyles.label, state.isPending && buttonBaseStyles.labelPending),
143
+ children
144
+ }),
145
+ state.isPending ? /* @__PURE__ */ jsx("span", {
146
+ ...props(buttonBaseStyles.pending),
147
+ children: /* @__PURE__ */ jsx(ProgressIndicator, {
148
+ "aria-label": pendingLabel,
149
+ isIndeterminate: true,
150
+ size: "1em",
151
+ tone: "inherit",
152
+ variant: "circular"
153
+ })
154
+ }) : null,
155
+ surface
156
+ ] });
157
+ }
158
+ /**
159
+ * A toggle drawn with the classes a component hands it: React Aria's
160
+ * `ToggleButton`, which reports its state through `aria-pressed`. It is never
161
+ * a link and never pending — React Aria's toggle takes neither, and neither
162
+ * means anything for a control whose whole job is to report which of two
163
+ * states it is in — so `isPending` reaches it only to keep the ripple off,
164
+ * as it does for the plain button.
165
+ */
166
+ function ToggleButtonBase(t0) {
167
+ const $ = c(32);
168
+ let children;
169
+ let classes;
170
+ let defaultSelected;
171
+ let input;
172
+ let isSelected;
173
+ let onChange;
174
+ let render;
175
+ let t1;
176
+ if ($[0] !== t0) {
177
+ ({children, classes, defaultSelected, isPending: t1, isSelected, onChange, render, ...input} = t0);
178
+ $[0] = t0;
179
+ $[1] = children;
180
+ $[2] = classes;
181
+ $[3] = defaultSelected;
182
+ $[4] = input;
183
+ $[5] = isSelected;
184
+ $[6] = onChange;
185
+ $[7] = render;
186
+ $[8] = t1;
187
+ } else {
188
+ children = $[1];
189
+ classes = $[2];
190
+ defaultSelected = $[3];
191
+ input = $[4];
192
+ isSelected = $[5];
193
+ onChange = $[6];
194
+ render = $[7];
195
+ t1 = $[8];
196
+ }
197
+ const isPending = t1 === void 0 ? false : t1;
198
+ const disabledByGroup = useToggleGroupDisabled(input.id);
199
+ let t2;
200
+ if ($[9] !== disabledByGroup || $[10] !== input) {
201
+ t2 = disabledByGroup ? {
202
+ ...input,
203
+ isDisabled: true
204
+ } : input;
205
+ $[9] = disabledByGroup;
206
+ $[10] = input;
207
+ $[11] = t2;
208
+ } else t2 = $[11];
209
+ const { disabled, element, props, ref, ripple } = useButtonBase(t2, isPending);
210
+ let t3;
211
+ if ($[12] !== element || $[13] !== render) {
212
+ t3 = toggleButtonRenderer(element, toggleRender(render));
213
+ $[12] = element;
214
+ $[13] = render;
215
+ $[14] = t3;
216
+ } else t3 = $[14];
217
+ const t4 = ripple.handlers;
218
+ let t5;
219
+ if ($[15] !== classes || $[16] !== props) {
220
+ t5 = mergeStatefulStyles(classes, props);
221
+ $[15] = classes;
222
+ $[16] = props;
223
+ $[17] = t5;
224
+ } else t5 = $[17];
225
+ let t6;
226
+ if ($[18] !== children || $[19] !== ripple.surface) {
227
+ t6 = toggleContent(children, ripple.surface);
228
+ $[18] = children;
229
+ $[19] = ripple.surface;
230
+ $[20] = t6;
231
+ } else t6 = $[20];
232
+ let t7;
233
+ if ($[21] !== defaultSelected || $[22] !== disabled || $[23] !== isSelected || $[24] !== onChange || $[25] !== props || $[26] !== ref || $[27] !== ripple.handlers || $[28] !== t3 || $[29] !== t5 || $[30] !== t6) {
234
+ t7 = /* @__PURE__ */ jsx(ToggleButton, {
235
+ defaultSelected,
236
+ isDisabled: disabled,
237
+ isSelected,
238
+ onChange,
239
+ ref,
240
+ render: t3,
241
+ ...t4,
242
+ ...props,
243
+ ...t5,
244
+ children: t6
245
+ });
246
+ $[21] = defaultSelected;
247
+ $[22] = disabled;
248
+ $[23] = isSelected;
249
+ $[24] = onChange;
250
+ $[25] = props;
251
+ $[26] = ref;
252
+ $[27] = ripple.handlers;
253
+ $[28] = t3;
254
+ $[29] = t5;
255
+ $[30] = t6;
256
+ $[31] = t7;
257
+ } else t7 = $[31];
258
+ return t7;
259
+ }
260
+ function toggleContent(children, surface) {
261
+ return () => /* @__PURE__ */ jsxs(Fragment, { children: [children, surface] });
262
+ }
263
+ function toggleRender(render) {
264
+ if (render === void 0) return;
265
+ return (props, state) => render(props, {
266
+ ...state,
267
+ isPending: false
268
+ });
269
+ }
270
+ //#endregion
271
+ export { ButtonBase, ToggleButtonBase };
272
+
273
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["DOMAttributes","ReactNode","RefAttributes","ButtonRenderProps","ClassNameOrFunction","ButtonProps","RACButtonProps","ToggleButtonProps","RACToggleButtonProps","StyleOrFunction","stylex","Button","RACButton","Link","RACLink","ToggleButton","RACToggleButton","ProgressIndicator","useToggleGroupDisabled","useMessages","buttonRenderer","linkRenderer","toggleButtonRenderer","mergeStatefulStyles","useButtonBase","buttonBaseStyles","ButtonBaseProps","children","classes","state","ButtonState","ReturnType","props","className","disableRipple","href","pendingLabel","rel","style","target","ButtonDOMProps","HTMLAnchorElement","HTMLButtonElement","Omit","GlobalEventKey","Pick","HTMLElement","isSelected","Exclude","ToggleButtonBaseProps","defaultSelected","onChange","ButtonBase","t0","$","_c","input","render","t1","isPending","undefined","messages","disabled","element","ref","ripple","t2","styleProps","t3","t4","handlers","surface","t5","loading","t6","buttonContent","t7","label","labelPending","pending","ToggleButtonBase","disabledByGroup","id","isDisabled","toggleRender","toggleContent","_c","RACLink","RACButton","stylex.props","RACToggleButton"],"sources":["../../src/button/index.tsx"],"sourcesContent":["import type { DOMAttributes, ReactNode, RefAttributes } from 'react';\nimport type { ButtonRenderProps, ClassNameOrFunction, ButtonProps as RACButtonProps, ToggleButtonProps as RACToggleButtonProps, StyleOrFunction } from 'react-aria-components';\nimport * as stylex from '@stylexjs/stylex';\nimport { Button as RACButton, Link as RACLink, ToggleButton as RACToggleButton } from 'react-aria-components';\nimport ProgressIndicator from '../components/progress-indicator';\nimport { useToggleGroupDisabled } from '../hooks/useToggleGroupDisabled';\nimport { useMessages } from '../i18n';\nimport { buttonRenderer, linkRenderer, toggleButtonRenderer } from '../render/aria';\nimport { mergeStatefulStyles } from '../styles/merge';\nimport { useButtonBase } from './hooks';\nimport { buttonBaseStyles } from './styles';\n\n// The press-button core Button and IconButton both render through. A button\n// is React Aria's `Button`, its `Link` once given `href`, or its\n// `ToggleButton` once it reports a state, and around each this adds what\n// React Aria leaves out: the ripple, the disabled state a parent's context\n// sets, the `aria-*` props and keyboard handlers it would drop or wrap, and\n// the ring drawn over the label while the button is pending. Each component\n// brings its own classes, as a function of the render state, and the call\n// site's `className` and `style` are merged over them.\n//\n// One module rather than a copy in each, since the copies had already drifted\n// once: IconButton read `ButtonContext` for a parent's disabled state and\n// Button did not. Not a component of the library's own and not exported from\n// the package; see `src/row` for the same arrangement around a list's row.\n\ntype ButtonBaseProps = {\n children?: ReactNode;\n /**\n * The component's own classes, from the render state. The call site's\n * `className` and `style` are merged over them.\n */\n classes: (state: ButtonState) => ReturnType<typeof stylex.props>;\n className?: ClassNameOrFunction<ButtonState>;\n disableRipple?: boolean;\n href?: string;\n pendingLabel?: string;\n rel?: string;\n style?: StyleOrFunction<ButtonState>;\n target?: string;\n} & ButtonDOMProps & RefAttributes<HTMLAnchorElement | HTMLButtonElement>;\n\n// The props a button hands React Aria. React Aria types the global DOM events\n// — pointer, mouse, touch, wheel and the rest — against the element each\n// component renders, and a handler written for a <button> does not type-check\n// against an <a>. The keys are retyped against HTMLElement here so one set of\n// props serves both forms; the events React Aria defines itself (press,\n// focus, keyboard) keep its types, since it hands those its own event objects.\ntype ButtonDOMProps = Omit<RACButtonProps, 'children' | 'className' | 'style' | GlobalEventKey> & Pick<DOMAttributes<HTMLElement>, GlobalEventKey>;\n\n// The render state React Aria's three elements share. A className or style\n// function written against it serves the button, the link and the toggle\n// alike; `isPending` belongs to the button alone, and `isCurrent` to the\n// link, so neither is here. What the button draws while pending is decided\n// in `buttonContent`, which sees React Aria's own state rather than this one.\n//\n// `isSelected` is optional because only the toggle has one: React Aria hands\n// the button and the link a state without it and the toggle a state with\n// it, and a parameter type this wide accepts either.\ntype ButtonState = Pick<ButtonRenderProps, 'isDisabled' | 'isFocused' | 'isFocusVisible' | 'isHovered' | 'isPressed'> & {\n isSelected?: boolean;\n};\ntype GlobalEventKey = Exclude<keyof DOMAttributes<HTMLElement> & keyof RACButtonProps, 'onBlur' | 'onClick' | 'onFocus'>;\ntype ToggleButtonBaseProps = {\n children?: ReactNode;\n /** As for ButtonBase, handed `isSelected` as well. */\n classes: (state: ButtonState) => ReturnType<typeof stylex.props>;\n className?: ClassNameOrFunction<ButtonState>;\n defaultSelected?: boolean;\n disableRipple?: boolean;\n isSelected?: boolean;\n onChange?: (isSelected: boolean) => void;\n style?: StyleOrFunction<ButtonState>;\n} & ButtonDOMProps & RefAttributes<HTMLAnchorElement | HTMLButtonElement>;\n\n/**\n * A button drawn with the classes a component hands it: React Aria's\n * `Button`, or its `Link` given `href`. See the header.\n */\nfunction ButtonBase({\n children,\n classes,\n href,\n isPending = false,\n pendingLabel,\n rel,\n render,\n target,\n ...input\n}: ButtonBaseProps) {\n const messages = useMessages();\n const {\n disabled,\n element,\n props,\n ref,\n ripple\n } = useButtonBase(input, isPending);\n const styleProps = mergeStatefulStyles(classes, props);\n if (href !== undefined) {\n return <RACLink href={href} isDisabled={disabled} ref={ref} rel={rel} render={linkRenderer(element)} target={target} {...ripple.handlers} {...props} {...styleProps}>\n {children}\n {ripple.surface}\n </RACLink>;\n }\n return <RACButton isDisabled={disabled} isPending={isPending} ref={ref} render={buttonRenderer(element, render)} {...ripple.handlers} {...props} {...styleProps}>\n {buttonContent(children, pendingLabel ?? messages.loading, ripple.surface)}\n </RACButton>;\n}\n\n// What the button draws: its label, hidden while the button is pending, with\n// the ring over it. The ring takes the button's own content colour rather\n// than the progress page's primary, which on a filled button is the fill\n// itself and so invisible. The label stays in the flow so the button keeps its\n// width, which is what stops a form jumping the moment it is submitted.\n// React Aria wants the progress bar in the accessibility tree as soon as the\n// button goes pending, so it is rendered from the render state rather than\n// after a delay.\n//\n// Built by a call rather than written inline at the prop, which is what\n// react-perf's no-new-function-as-prop is after; the React Compiler\n// memoises the result on its inputs.\nfunction buttonContent(children: ReactNode, pendingLabel: string, surface: ReactNode) {\n return (state: ButtonRenderProps) => <>\n <span {...stylex.props(buttonBaseStyles.label, state.isPending && buttonBaseStyles.labelPending)}>\n {children}\n </span>\n {state.isPending ? <span {...stylex.props(buttonBaseStyles.pending)}>\n <ProgressIndicator aria-label={pendingLabel} isIndeterminate size=\"1em\" tone=\"inherit\" variant=\"circular\" />\n </span> : null}\n {surface}\n </>;\n}\n\n/**\n * A toggle drawn with the classes a component hands it: React Aria's\n * `ToggleButton`, which reports its state through `aria-pressed`. It is never\n * a link and never pending — React Aria's toggle takes neither, and neither\n * means anything for a control whose whole job is to report which of two\n * states it is in — so `isPending` reaches it only to keep the ripple off,\n * as it does for the plain button.\n */\nfunction ToggleButtonBase({\n children,\n classes,\n defaultSelected,\n isPending = false,\n isSelected,\n onChange,\n render,\n ...input\n}: ToggleButtonBaseProps) {\n // A selecting ButtonGroup disables its toggles through React Aria's group\n // state, which no prop here carries, so the ripple would stay on in a\n // disabled group and answer a press with an animation. Handed on as the\n // toggle's own `isDisabled`, which is what React Aria makes of it anyway.\n const disabledByGroup = useToggleGroupDisabled(input.id);\n const {\n disabled,\n element,\n props,\n ref,\n ripple\n } = useButtonBase(disabledByGroup ? {\n ...input,\n isDisabled: true\n } : input, isPending);\n return <RACToggleButton defaultSelected={defaultSelected} isDisabled={disabled} isSelected={isSelected} onChange={onChange} ref={ref} render={toggleButtonRenderer(element, toggleRender(render))} {...ripple.handlers} {...props} {...mergeStatefulStyles(classes, props)}>\n {toggleContent(children, ripple.surface)}\n </RACToggleButton>;\n}\n\n// What a toggle draws: its label and the ripple. No pending ring — see\n// ToggleButtonBase. Built by a call for the reason `buttonContent` is.\nfunction toggleContent(children: ReactNode, surface: ReactNode) {\n return () => <>\n {children}\n {surface}\n </>;\n}\n\n// A call site's `render` is written for React Aria's button, whose render\n// state says whether it is pending; a toggle's says nothing of it, and a\n// toggle never is. So the toggle hands that function its own state with\n// `isPending` filled in, which is what lets one `render` prop serve a button\n// whichever element it turns out to be.\nfunction toggleRender(render: RACButtonProps['render']): RACToggleButtonProps['render'] {\n if (render === undefined) {\n return undefined;\n }\n return (props, state) => render(props, {\n ...state,\n isPending: false\n });\n}\nexport type { ButtonDOMProps, ButtonState };\nexport { ButtonBase, ToggleButtonBase };"],"mappings":";;;;;;;;;;;;;;;;AA+EA,SAAAoD,WAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAA5B;CAAA,IAAAC;CAAA,IAAAO;CAAA,IAAAqB;CAAA,IAAApB;CAAA,IAAAC;CAAA,IAAAoB;CAAA,IAAAC;CAAA,IAAAnB;CAAA,IAAAe,EAAA,OAAAD,IAAA;EAAoB,CAAA,CAAA1B,UAAAC,SAAAO,MAAAwB,WAAAD,IAAAtB,cAAAC,KAAAoB,QAAAlB,QAAA,GAAAiB,SAAAH;EAUFC,EAAA,KAAAD;EAAAC,EAAA,KAAA3B;EAAA2B,EAAA,KAAA1B;EAAA0B,EAAA,KAAAnB;EAAAmB,EAAA,KAAAE;EAAAF,EAAA,KAAAlB;EAAAkB,EAAA,KAAAjB;EAAAiB,EAAA,KAAAG;EAAAH,EAAA,KAAAI;EAAAJ,E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AAJ,mBAAAI,EAAA,QAAAQ,YAAAR,EAAA,QAAAP,cAAAO,EAAA,QAAAH,YAAAG,EAAA,QAAAtB,SAAAsB,EAAA,QAAAU,OAAAV,EAAA,QAAAW,OAAAK,YAAAhB,EAAA,QAAAc,MAAAd,EAAA,QAAAkB,MAAAlB,EAAA,QAAAoB,IAAA;EADrCE,KAAA,oBAACc,cAAD;GAAkCxC;GAA6BY,YAAAA;GAAsBf;GAAsBI;GAAea;GAAa,QAAAI;GAAmD,GAAMC;GAAe,GAAMrC;GAAK,GAAMwC;GAClOE,UAAAA;EADkB,CAAA;EAEHpB,EAAA,MAAAJ;EAAAI,EAAA,MAAAQ;EAAAR,EAAA,MAAAP;EAAAO,EAAA,MAAAH;EAAAG,EAAA,MAAAtB;EAAAsB,EAAA,MAAAU;EAAAV,EAAA,MAAAW,OAAAK;EAAAhB,EAAA,MAAAc;EAAAd,EAAA,MAAAkB;EAAAlB,EAAA,MAAAoB;EAAApB,EAAA,MAAAsB;CAAA,OAAAA,KAAAtB,EAAA;CAAA,OAFbsB;AAEa;AAKtB,SAASS,cAAc1D,UAAqB4C,SAAoB;CAC9D,aAAa,qBAAA,UAAA,EAAA,UAAA,CACR5C,UACA4C,OACH,EAAA,CAAA;AACJ;AAOA,SAASa,aAAa3B,QAAkE;CACtF,IAAIA,WAAWG,KAAAA,GACb;CAEF,QAAQ5B,OAAOH,UAAU4B,OAAOzB,OAAO;EACrC,GAAGH;EACH8B,WAAW;CACb,CAAC;AACH"}
@@ -0,0 +1,23 @@
1
+ //#region src/button/styles.ts
2
+ const buttonBaseStyles = {
3
+ label: {
4
+ k1xSpc: "xjp7ctv",
5
+ $$css: true
6
+ },
7
+ labelPending: {
8
+ k33iCy: "xlshs6z",
9
+ $$css: true
10
+ },
11
+ pending: {
12
+ kGNEyG: "x6s0dn4",
13
+ k1xSpc: "x78zum5",
14
+ kpwlN0: "x10a8y8t",
15
+ kjj79g: "xl56j7k",
16
+ kVAEAm: "x10l6tqk",
17
+ $$css: true
18
+ }
19
+ };
20
+ //#endregion
21
+ export { buttonBaseStyles };
22
+
23
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","names":["stylex","buttonBaseStyles","label","k1xSpc","$$css","labelPending","k33iCy","pending","kGNEyG","kpwlN0","kjj79g","kVAEAm"],"sources":["../../src/button/styles.ts"],"sourcesContent":["import * as stylex from '@stylexjs/stylex';\n\n// What ButtonBase draws inside every button, whatever the component's own\n// container: the label, held in place while the button is pending, and the\n// ring over it. Apart from ./index.tsx so that file exports components alone,\n// which is what keeps fast refresh working for it.\nconst buttonBaseStyles = {\n label: {\n k1xSpc: \"xjp7ctv\",\n $$css: true\n },\n labelPending: {\n k33iCy: \"xlshs6z\",\n $$css: true\n },\n pending: {\n kGNEyG: \"x6s0dn4\",\n k1xSpc: \"x78zum5\",\n kpwlN0: \"x10a8y8t\",\n kjj79g: \"xl56j7k\",\n kVAEAm: \"x10l6tqk\",\n $$css: true\n }\n};\nexport { buttonBaseStyles };"],"mappings":";AAMA,MAAMC,mBAAmB;CACvBC,OAAO;EACLC,QAAQ;EACRC,OAAO;CACT;CACAC,cAAc;EACZC,QAAQ;EACRF,OAAO;CACT;CACAG,SAAS;EACPC,QAAQ;EACRL,QAAQ;EACRM,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRP,OAAO;CACT;AACF"}