@kanso-labs/kanso-ui 0.35.0 → 0.36.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.
- package/README.md +88 -9
- package/dist/button/hooks.js +81 -0
- package/dist/button/hooks.js.map +1 -0
- package/dist/button/index.d.ts +11 -0
- package/dist/button/index.js +260 -0
- package/dist/button/index.js.map +1 -0
- package/dist/button/styles.js +23 -0
- package/dist/button/styles.js.map +1 -0
- package/dist/calendar/index.js +473 -7
- package/dist/calendar/index.js.map +1 -1
- package/dist/calendar/styles.js +132 -4
- package/dist/calendar/styles.js.map +1 -1
- package/dist/chip/index.js +29 -2
- package/dist/chip/index.js.map +1 -1
- package/dist/chip/styles.js +30 -4
- package/dist/chip/styles.js.map +1 -1
- package/dist/collection/index.js +12 -9
- package/dist/collection/index.js.map +1 -1
- package/dist/color-scheme.d.ts +29 -0
- package/dist/color-scheme.js +32 -0
- package/dist/color-scheme.js.map +1 -0
- package/dist/components/avatar/index.js +35 -22
- package/dist/components/avatar/index.js.map +1 -1
- package/dist/components/badge/index.d.ts +37 -0
- package/dist/components/badge/index.js +97 -0
- package/dist/components/badge/index.js.map +1 -0
- package/dist/components/breadcrumbs/index.d.ts +1 -1
- package/dist/components/breadcrumbs/index.js +1 -1
- package/dist/components/breadcrumbs/index.js.map +1 -1
- package/dist/components/button/index.d.ts +58 -14
- package/dist/components/button/index.js +418 -148
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/calendar/index.d.ts +9 -1
- package/dist/components/calendar/index.js +71 -44
- package/dist/components/calendar/index.js.map +1 -1
- package/dist/components/card/index.d.ts +1 -1
- package/dist/components/card/index.js +4 -4
- package/dist/components/card/index.js.map +1 -1
- package/dist/components/checkbox-group/index.js +1 -0
- package/dist/components/checkbox-group/index.js.map +1 -1
- package/dist/components/chip/index.js +2 -8
- package/dist/components/chip/index.js.map +1 -1
- package/dist/components/chip-group/index.d.ts +3 -3
- package/dist/components/chip-group/index.js +8 -9
- package/dist/components/chip-group/index.js.map +1 -1
- package/dist/components/color-field/index.js +25 -23
- package/dist/components/color-field/index.js.map +1 -1
- package/dist/components/color-picker/index.js +42 -31
- package/dist/components/color-picker/index.js.map +1 -1
- package/dist/components/color-swatch-picker/index.d.ts +1 -1
- package/dist/components/color-swatch-picker/index.js +17 -13
- package/dist/components/color-swatch-picker/index.js.map +1 -1
- package/dist/components/combo-box/index.js +63 -58
- package/dist/components/combo-box/index.js.map +1 -1
- package/dist/components/copy-field/index.d.ts +7 -6
- package/dist/components/copy-field/index.js +92 -90
- package/dist/components/copy-field/index.js.map +1 -1
- package/dist/components/currency/index.d.ts +8 -7
- package/dist/components/currency/index.js +43 -65
- package/dist/components/currency/index.js.map +1 -1
- package/dist/components/date-field/index.js +24 -22
- package/dist/components/date-field/index.js.map +1 -1
- package/dist/components/date-picker/index.d.ts +10 -2
- package/dist/components/date-picker/index.js +76 -69
- package/dist/components/date-picker/index.js.map +1 -1
- package/dist/components/date-range-picker/index.d.ts +10 -2
- package/dist/components/date-range-picker/index.js +93 -86
- package/dist/components/date-range-picker/index.js.map +1 -1
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/index.js +2 -2
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/disclosure/index.d.ts +1 -1
- package/dist/components/disclosure/index.js +6 -6
- package/dist/components/disclosure/index.js.map +1 -1
- package/dist/components/fab/index.d.ts +72 -0
- package/dist/components/fab/index.js +89 -0
- package/dist/components/fab/index.js.map +1 -0
- package/dist/components/fab-menu/index.d.ts +90 -0
- package/dist/components/fab-menu/index.js +297 -0
- package/dist/components/fab-menu/index.js.map +1 -0
- package/dist/components/feed/index.d.ts +2 -1
- package/dist/components/feed/index.js +1 -1
- package/dist/components/feed/index.js.map +1 -1
- package/dist/components/icon-button/index.d.ts +11 -8
- package/dist/components/icon-button/index.js +209 -177
- package/dist/components/icon-button/index.js.map +1 -1
- package/dist/components/index.d.ts +26 -20
- package/dist/components/list/index.d.ts +15 -13
- package/dist/components/list/index.js +62 -63
- package/dist/components/list/index.js.map +1 -1
- package/dist/components/list-box/index.d.ts +3 -2
- package/dist/components/list-box/index.js +8 -8
- package/dist/components/list-box/index.js.map +1 -1
- package/dist/components/list-item/index.js +1 -1
- package/dist/components/list-item/index.js.map +1 -1
- package/dist/components/menu/index.d.ts +3 -2
- package/dist/components/menu/index.js +2 -2
- package/dist/components/menu/index.js.map +1 -1
- package/dist/components/navigation-bar/index.d.ts +50 -0
- package/dist/components/navigation-bar/index.js +129 -0
- package/dist/components/navigation-bar/index.js.map +1 -0
- package/dist/components/navigation-rail/index.d.ts +59 -0
- package/dist/components/navigation-rail/index.js +166 -0
- package/dist/components/navigation-rail/index.js.map +1 -0
- package/dist/components/navigation-tree/index.d.ts +1 -5
- package/dist/components/navigation-tree/index.js +3 -3
- package/dist/components/navigation-tree/index.js.map +1 -1
- package/dist/components/number-field/index.d.ts +6 -4
- package/dist/components/number-field/index.js +84 -84
- package/dist/components/number-field/index.js.map +1 -1
- package/dist/components/popover/index.d.ts +1 -1
- package/dist/components/popover/index.js +1 -1
- package/dist/components/popover/index.js.map +1 -1
- package/dist/components/radio-group/index.js +11 -10
- package/dist/components/radio-group/index.js.map +1 -1
- package/dist/components/range-calendar/index.d.ts +7 -1
- package/dist/components/range-calendar/index.js +71 -44
- package/dist/components/range-calendar/index.js.map +1 -1
- package/dist/components/search-field/index.d.ts +2 -1
- package/dist/components/search-field/index.js +24 -25
- package/dist/components/search-field/index.js.map +1 -1
- package/dist/components/segmented-button/index.d.ts +1 -1
- package/dist/components/segmented-button/index.js +2 -2
- package/dist/components/segmented-button/index.js.map +1 -1
- package/dist/components/select/index.js +1 -0
- package/dist/components/select/index.js.map +1 -1
- package/dist/components/sheet/index.d.ts +1 -1
- package/dist/components/sheet/index.js +2 -2
- package/dist/components/sheet/index.js.map +1 -1
- package/dist/components/slider/index.js +1 -1
- package/dist/components/slider/index.js.map +1 -1
- package/dist/components/snackbar/index.d.ts +2 -2
- package/dist/components/snackbar/index.js +28 -13
- package/dist/components/snackbar/index.js.map +1 -1
- package/dist/components/table/index.d.ts +11 -9
- package/dist/components/table/index.js +68 -29
- package/dist/components/table/index.js.map +1 -1
- package/dist/components/tabs/index.d.ts +1 -1
- package/dist/components/tabs/index.js +79 -23
- package/dist/components/tabs/index.js.map +1 -1
- package/dist/components/tag/index.d.ts +1 -1
- package/dist/components/tag/index.js.map +1 -1
- package/dist/components/text-area/index.d.ts +7 -5
- package/dist/components/text-area/index.js +28 -26
- package/dist/components/text-area/index.js.map +1 -1
- package/dist/components/text-field/index.d.ts +7 -5
- package/dist/components/text-field/index.js +28 -26
- package/dist/components/text-field/index.js.map +1 -1
- package/dist/components/time-field/index.js +24 -22
- package/dist/components/time-field/index.js.map +1 -1
- package/dist/components/tree/index.d.ts +7 -9
- package/dist/components/tree/index.js +11 -12
- package/dist/components/tree/index.js.map +1 -1
- package/dist/drag/styles.js +4 -1
- package/dist/drag/styles.js.map +1 -1
- package/dist/fab/styles.js +161 -0
- package/dist/fab/styles.js.map +1 -0
- package/dist/field/index.js +260 -214
- package/dist/field/index.js.map +1 -1
- package/dist/field/styles.js +10 -2
- package/dist/field/styles.js.map +1 -1
- package/dist/glyphs/index.js +19 -1
- package/dist/glyphs/index.js.map +1 -1
- package/dist/hooks/useRipple.js +199 -162
- package/dist/hooks/useRipple.js.map +1 -1
- package/dist/i18n/index.js +42 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/messages.js +353 -0
- package/dist/i18n/messages.js.map +1 -0
- package/dist/index.d.ts +27 -20
- package/dist/index.js +22 -16
- package/dist/navigation/context.js +7 -0
- package/dist/navigation/context.js.map +1 -0
- package/dist/navigation/index.d.ts +28 -0
- package/dist/navigation/index.js +96 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/navigation/styles.js +312 -0
- package/dist/navigation/styles.js.map +1 -0
- package/dist/react-aria.d.ts +2 -2
- package/dist/react-aria.js +2 -2
- package/dist/render/useRender.js +0 -1
- package/dist/render/useRender.js.map +1 -1
- package/dist/row/styles.js +18 -11
- package/dist/row/styles.js.map +1 -1
- package/dist/styles/focus.js.map +1 -1
- package/dist/styles/icon-button.js +9 -1
- package/dist/styles/icon-button.js.map +1 -1
- package/dist/styles/overlay.js +1 -0
- package/dist/styles/overlay.js.map +1 -1
- package/dist/styles/picker.js +1 -1
- package/dist/styles/picker.js.map +1 -1
- package/dist/styles.css +870 -360
- package/dist/tokens/design.tokens.stylex.js +18 -1
- package/dist/tokens/design.tokens.stylex.js.map +1 -1
- package/dist/tokens.css +166 -53
- package/package.json +8 -4
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
|
-
|
|
237
|
-
|
|
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,6 +301,7 @@ 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` |
|
|
275
305
|
| `IconButton` | 20px, 24px, 24px, 32px and 40px across `xs` to `xxl` |
|
|
276
306
|
| A field's `leadingIcon` and `trailingIcon` | 24px |
|
|
277
307
|
| `SegmentedButton.Segment`'s `icon` | 18px |
|
|
@@ -287,8 +317,8 @@ those a size of its own:
|
|
|
287
317
|
|
|
288
318
|
An SVG with a `viewBox` and no size at all has no size to shrink from, so what
|
|
289
319
|
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
|
|
291
|
-
nothing. Sizing it is what avoids both.
|
|
320
|
+
fills the button edge to edge; in a field's icon slot or a `Button`'s it
|
|
321
|
+
collapses and draws nothing. Sizing it is what avoids both.
|
|
292
322
|
|
|
293
323
|
### Server components
|
|
294
324
|
|
|
@@ -311,9 +341,29 @@ Four things follow from where that boundary falls.
|
|
|
311
341
|
`onPress` and a `render` callback belong in a client component of your own.
|
|
312
342
|
Neither does a class instance, so a `CalendarDate` for a date component is
|
|
313
343
|
built on the client side too.
|
|
314
|
-
- **A sub-part is
|
|
315
|
-
|
|
316
|
-
|
|
344
|
+
- **A sub-part is rendered by its own name**, as in `DialogTitle` or `MenuItem`.
|
|
345
|
+
A server component cannot reach into a client module through a property, so
|
|
346
|
+
`<Dialog.Title>` works only from a client component, while every part is also
|
|
347
|
+
exported as its component's name followed by the part's: `SheetContent`,
|
|
348
|
+
`TableRow`, `NavigationTreeItem`. `List.Item` is `ListRow`, since the
|
|
349
|
+
standalone `ListItem` already has that name:
|
|
350
|
+
|
|
351
|
+
```tsx
|
|
352
|
+
// app/settings/page.tsx
|
|
353
|
+
import { Button, Sheet, SheetContent, SheetTitle } from '@kanso-labs/kanso-ui'
|
|
354
|
+
|
|
355
|
+
export default function Page() {
|
|
356
|
+
return (
|
|
357
|
+
<Sheet>
|
|
358
|
+
<Button>Open</Button>
|
|
359
|
+
<SheetContent>
|
|
360
|
+
<SheetTitle>Headline</SheetTitle>
|
|
361
|
+
</SheetContent>
|
|
362
|
+
</Sheet>
|
|
363
|
+
)
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
317
367
|
- **The React Aria utilities the package re-exports are client-only** —
|
|
318
368
|
`I18nProvider`, `useListData`, `parseColor` and the rest. `collectionSizes` is
|
|
319
369
|
a plain value and works on either side.
|
|
@@ -357,6 +407,35 @@ default value — useful for discovering names, not required at runtime
|
|
|
357
407
|
import '@kanso-labs/kanso-ui/tokens.css'
|
|
358
408
|
```
|
|
359
409
|
|
|
410
|
+
### Pinning light or dark
|
|
411
|
+
|
|
412
|
+
The colours follow the reader's OS through `prefers-color-scheme` unless the app
|
|
413
|
+
says otherwise. An app with a theme switch of its own pins a scheme with
|
|
414
|
+
`colorScheme`, two class names: put `colorScheme.light` or `colorScheme.dark` on
|
|
415
|
+
the `<html>` element, and remove both to follow the OS again. The `<html>`
|
|
416
|
+
element is the place for it, since overlays are portalled to the body and still
|
|
417
|
+
sit inside it.
|
|
418
|
+
|
|
419
|
+
Its shape is the one next-themes takes for class names, so a provider is all it
|
|
420
|
+
needs:
|
|
421
|
+
|
|
422
|
+
```tsx
|
|
423
|
+
import { ThemeProvider } from 'next-themes'
|
|
424
|
+
import { colorScheme } from '@kanso-labs/kanso-ui'
|
|
425
|
+
|
|
426
|
+
function Providers({ children }: { children: React.ReactNode }) {
|
|
427
|
+
return (
|
|
428
|
+
<ThemeProvider attribute="class" value={colorScheme}>
|
|
429
|
+
{children}
|
|
430
|
+
</ThemeProvider>
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
A `--kui-color-*` override on `:root` still applies under a pinned scheme. To
|
|
436
|
+
give one scheme a value of its own, key the override on an attribute your switch
|
|
437
|
+
sets beside the class, since the class names are generated.
|
|
438
|
+
|
|
360
439
|
### For StyleX consumers
|
|
361
440
|
|
|
362
441
|
If your app also uses StyleX, theme with
|
|
@@ -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,260 @@
|
|
|
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 { useMessages } from "../i18n/index.js";
|
|
6
|
+
import { useButtonBase } from "./hooks.js";
|
|
7
|
+
import { buttonBaseStyles } from "./styles.js";
|
|
8
|
+
import { c } from "react/compiler-runtime";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { Button, Link, ToggleButton } from "react-aria-components";
|
|
11
|
+
//#region src/button/index.tsx
|
|
12
|
+
/**
|
|
13
|
+
* A button drawn with the classes a component hands it: React Aria's
|
|
14
|
+
* `Button`, or its `Link` given `href`. See the header.
|
|
15
|
+
*/
|
|
16
|
+
function ButtonBase(t0) {
|
|
17
|
+
const $ = c(43);
|
|
18
|
+
let children;
|
|
19
|
+
let classes;
|
|
20
|
+
let href;
|
|
21
|
+
let input;
|
|
22
|
+
let pendingLabel;
|
|
23
|
+
let rel;
|
|
24
|
+
let render;
|
|
25
|
+
let t1;
|
|
26
|
+
let target;
|
|
27
|
+
if ($[0] !== t0) {
|
|
28
|
+
({children, classes, href, isPending: t1, pendingLabel, rel, render, target, ...input} = t0);
|
|
29
|
+
$[0] = t0;
|
|
30
|
+
$[1] = children;
|
|
31
|
+
$[2] = classes;
|
|
32
|
+
$[3] = href;
|
|
33
|
+
$[4] = input;
|
|
34
|
+
$[5] = pendingLabel;
|
|
35
|
+
$[6] = rel;
|
|
36
|
+
$[7] = render;
|
|
37
|
+
$[8] = t1;
|
|
38
|
+
$[9] = target;
|
|
39
|
+
} else {
|
|
40
|
+
children = $[1];
|
|
41
|
+
classes = $[2];
|
|
42
|
+
href = $[3];
|
|
43
|
+
input = $[4];
|
|
44
|
+
pendingLabel = $[5];
|
|
45
|
+
rel = $[6];
|
|
46
|
+
render = $[7];
|
|
47
|
+
t1 = $[8];
|
|
48
|
+
target = $[9];
|
|
49
|
+
}
|
|
50
|
+
const isPending = t1 === void 0 ? false : t1;
|
|
51
|
+
const messages = useMessages();
|
|
52
|
+
const { disabled, element, props, ref, ripple } = useButtonBase(input, isPending);
|
|
53
|
+
let t2;
|
|
54
|
+
if ($[10] !== classes || $[11] !== props) {
|
|
55
|
+
t2 = mergeStatefulStyles(classes, props);
|
|
56
|
+
$[10] = classes;
|
|
57
|
+
$[11] = props;
|
|
58
|
+
$[12] = t2;
|
|
59
|
+
} else t2 = $[12];
|
|
60
|
+
const styleProps = t2;
|
|
61
|
+
if (href !== void 0) {
|
|
62
|
+
let t3;
|
|
63
|
+
if ($[13] !== element) {
|
|
64
|
+
t3 = linkRenderer(element);
|
|
65
|
+
$[13] = element;
|
|
66
|
+
$[14] = t3;
|
|
67
|
+
} else t3 = $[14];
|
|
68
|
+
let t4;
|
|
69
|
+
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) {
|
|
70
|
+
t4 = /* @__PURE__ */ jsxs(Link, {
|
|
71
|
+
href,
|
|
72
|
+
isDisabled: disabled,
|
|
73
|
+
ref,
|
|
74
|
+
rel,
|
|
75
|
+
render: t3,
|
|
76
|
+
target,
|
|
77
|
+
...ripple.handlers,
|
|
78
|
+
...props,
|
|
79
|
+
...styleProps,
|
|
80
|
+
children: [children, ripple.surface]
|
|
81
|
+
});
|
|
82
|
+
$[15] = children;
|
|
83
|
+
$[16] = disabled;
|
|
84
|
+
$[17] = href;
|
|
85
|
+
$[18] = props;
|
|
86
|
+
$[19] = ref;
|
|
87
|
+
$[20] = rel;
|
|
88
|
+
$[21] = ripple.handlers;
|
|
89
|
+
$[22] = ripple.surface;
|
|
90
|
+
$[23] = styleProps;
|
|
91
|
+
$[24] = t3;
|
|
92
|
+
$[25] = target;
|
|
93
|
+
$[26] = t4;
|
|
94
|
+
} else t4 = $[26];
|
|
95
|
+
return t4;
|
|
96
|
+
}
|
|
97
|
+
let t3;
|
|
98
|
+
if ($[27] !== element || $[28] !== render) {
|
|
99
|
+
t3 = buttonRenderer(element, render);
|
|
100
|
+
$[27] = element;
|
|
101
|
+
$[28] = render;
|
|
102
|
+
$[29] = t3;
|
|
103
|
+
} else t3 = $[29];
|
|
104
|
+
const t4 = ripple.handlers;
|
|
105
|
+
const t5 = pendingLabel ?? messages.loading;
|
|
106
|
+
let t6;
|
|
107
|
+
if ($[30] !== children || $[31] !== ripple.surface || $[32] !== t5) {
|
|
108
|
+
t6 = buttonContent(children, t5, ripple.surface);
|
|
109
|
+
$[30] = children;
|
|
110
|
+
$[31] = ripple.surface;
|
|
111
|
+
$[32] = t5;
|
|
112
|
+
$[33] = t6;
|
|
113
|
+
} else t6 = $[33];
|
|
114
|
+
let t7;
|
|
115
|
+
if ($[34] !== disabled || $[35] !== isPending || $[36] !== props || $[37] !== ref || $[38] !== ripple.handlers || $[39] !== styleProps || $[40] !== t3 || $[41] !== t6) {
|
|
116
|
+
t7 = /* @__PURE__ */ jsx(Button, {
|
|
117
|
+
isDisabled: disabled,
|
|
118
|
+
isPending,
|
|
119
|
+
ref,
|
|
120
|
+
render: t3,
|
|
121
|
+
...t4,
|
|
122
|
+
...props,
|
|
123
|
+
...styleProps,
|
|
124
|
+
children: t6
|
|
125
|
+
});
|
|
126
|
+
$[34] = disabled;
|
|
127
|
+
$[35] = isPending;
|
|
128
|
+
$[36] = props;
|
|
129
|
+
$[37] = ref;
|
|
130
|
+
$[38] = ripple.handlers;
|
|
131
|
+
$[39] = styleProps;
|
|
132
|
+
$[40] = t3;
|
|
133
|
+
$[41] = t6;
|
|
134
|
+
$[42] = t7;
|
|
135
|
+
} else t7 = $[42];
|
|
136
|
+
return t7;
|
|
137
|
+
}
|
|
138
|
+
function buttonContent(children, pendingLabel, surface) {
|
|
139
|
+
return (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
140
|
+
/* @__PURE__ */ jsx("span", {
|
|
141
|
+
...props(buttonBaseStyles.label, state.isPending && buttonBaseStyles.labelPending),
|
|
142
|
+
children
|
|
143
|
+
}),
|
|
144
|
+
state.isPending ? /* @__PURE__ */ jsx("span", {
|
|
145
|
+
...props(buttonBaseStyles.pending),
|
|
146
|
+
children: /* @__PURE__ */ jsx(ProgressIndicator, {
|
|
147
|
+
"aria-label": pendingLabel,
|
|
148
|
+
isIndeterminate: true,
|
|
149
|
+
size: "1em",
|
|
150
|
+
tone: "inherit",
|
|
151
|
+
variant: "circular"
|
|
152
|
+
})
|
|
153
|
+
}) : null,
|
|
154
|
+
surface
|
|
155
|
+
] });
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A toggle drawn with the classes a component hands it: React Aria's
|
|
159
|
+
* `ToggleButton`, which reports its state through `aria-pressed`. It is never
|
|
160
|
+
* a link and never pending — React Aria's toggle takes neither, and neither
|
|
161
|
+
* means anything for a control whose whole job is to report which of two
|
|
162
|
+
* states it is in — so `isPending` reaches it only to keep the ripple off,
|
|
163
|
+
* as it does for the plain button.
|
|
164
|
+
*/
|
|
165
|
+
function ToggleButtonBase(t0) {
|
|
166
|
+
const $ = c(29);
|
|
167
|
+
let children;
|
|
168
|
+
let classes;
|
|
169
|
+
let defaultSelected;
|
|
170
|
+
let input;
|
|
171
|
+
let isSelected;
|
|
172
|
+
let onChange;
|
|
173
|
+
let render;
|
|
174
|
+
let t1;
|
|
175
|
+
if ($[0] !== t0) {
|
|
176
|
+
({children, classes, defaultSelected, isPending: t1, isSelected, onChange, render, ...input} = t0);
|
|
177
|
+
$[0] = t0;
|
|
178
|
+
$[1] = children;
|
|
179
|
+
$[2] = classes;
|
|
180
|
+
$[3] = defaultSelected;
|
|
181
|
+
$[4] = input;
|
|
182
|
+
$[5] = isSelected;
|
|
183
|
+
$[6] = onChange;
|
|
184
|
+
$[7] = render;
|
|
185
|
+
$[8] = t1;
|
|
186
|
+
} else {
|
|
187
|
+
children = $[1];
|
|
188
|
+
classes = $[2];
|
|
189
|
+
defaultSelected = $[3];
|
|
190
|
+
input = $[4];
|
|
191
|
+
isSelected = $[5];
|
|
192
|
+
onChange = $[6];
|
|
193
|
+
render = $[7];
|
|
194
|
+
t1 = $[8];
|
|
195
|
+
}
|
|
196
|
+
const { disabled, element, props, ref, ripple } = useButtonBase(input, t1 === void 0 ? false : t1);
|
|
197
|
+
let t2;
|
|
198
|
+
if ($[9] !== element || $[10] !== render) {
|
|
199
|
+
t2 = toggleButtonRenderer(element, toggleRender(render));
|
|
200
|
+
$[9] = element;
|
|
201
|
+
$[10] = render;
|
|
202
|
+
$[11] = t2;
|
|
203
|
+
} else t2 = $[11];
|
|
204
|
+
const t3 = ripple.handlers;
|
|
205
|
+
let t4;
|
|
206
|
+
if ($[12] !== classes || $[13] !== props) {
|
|
207
|
+
t4 = mergeStatefulStyles(classes, props);
|
|
208
|
+
$[12] = classes;
|
|
209
|
+
$[13] = props;
|
|
210
|
+
$[14] = t4;
|
|
211
|
+
} else t4 = $[14];
|
|
212
|
+
let t5;
|
|
213
|
+
if ($[15] !== children || $[16] !== ripple.surface) {
|
|
214
|
+
t5 = toggleContent(children, ripple.surface);
|
|
215
|
+
$[15] = children;
|
|
216
|
+
$[16] = ripple.surface;
|
|
217
|
+
$[17] = t5;
|
|
218
|
+
} else t5 = $[17];
|
|
219
|
+
let t6;
|
|
220
|
+
if ($[18] !== defaultSelected || $[19] !== disabled || $[20] !== isSelected || $[21] !== onChange || $[22] !== props || $[23] !== ref || $[24] !== ripple.handlers || $[25] !== t2 || $[26] !== t4 || $[27] !== t5) {
|
|
221
|
+
t6 = /* @__PURE__ */ jsx(ToggleButton, {
|
|
222
|
+
defaultSelected,
|
|
223
|
+
isDisabled: disabled,
|
|
224
|
+
isSelected,
|
|
225
|
+
onChange,
|
|
226
|
+
ref,
|
|
227
|
+
render: t2,
|
|
228
|
+
...t3,
|
|
229
|
+
...props,
|
|
230
|
+
...t4,
|
|
231
|
+
children: t5
|
|
232
|
+
});
|
|
233
|
+
$[18] = defaultSelected;
|
|
234
|
+
$[19] = disabled;
|
|
235
|
+
$[20] = isSelected;
|
|
236
|
+
$[21] = onChange;
|
|
237
|
+
$[22] = props;
|
|
238
|
+
$[23] = ref;
|
|
239
|
+
$[24] = ripple.handlers;
|
|
240
|
+
$[25] = t2;
|
|
241
|
+
$[26] = t4;
|
|
242
|
+
$[27] = t5;
|
|
243
|
+
$[28] = t6;
|
|
244
|
+
} else t6 = $[28];
|
|
245
|
+
return t6;
|
|
246
|
+
}
|
|
247
|
+
function toggleContent(children, surface) {
|
|
248
|
+
return () => /* @__PURE__ */ jsxs(Fragment, { children: [children, surface] });
|
|
249
|
+
}
|
|
250
|
+
function toggleRender(render) {
|
|
251
|
+
if (render === void 0) return;
|
|
252
|
+
return (props, state) => render(props, {
|
|
253
|
+
...state,
|
|
254
|
+
isPending: false
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
export { ButtonBase, ToggleButtonBase };
|
|
259
|
+
|
|
260
|
+
//# 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","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","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 { 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 const {\n disabled,\n element,\n props,\n ref,\n ripple\n } = useButtonBase(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":";;;;;;;;;;;;;;;AA8EA,SAAAmD,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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Af,EAAA,QAAAkB,IAAA;EADrCE,KAAA,oBAACa,cAAD;GAAkCrC;GAA6BY,YAAAA;GAAsBf;GAAsBI;GAAea;GAAa,QAAAE;GAAmD,GAAME;GAAe,GAAMpC;GAAK,GAAMqC;GAClOG,UAAAA;EADkB,CAAA;EAEHlB,EAAA,MAAAJ;EAAAI,EAAA,MAAAQ;EAAAR,EAAA,MAAAP;EAAAO,EAAA,MAAAH;EAAAG,EAAA,MAAAtB;EAAAsB,EAAA,MAAAU;EAAAV,EAAA,MAAAW,OAAAK;EAAAhB,EAAA,MAAAY;EAAAZ,EAAA,MAAAe;EAAAf,EAAA,MAAAkB;EAAAlB,EAAA,MAAAoB;CAAA,OAAAA,KAAApB,EAAA;CAAA,OAFboB;AAEa;AAKtB,SAASQ,cAAcvD,UAAqB4C,SAAoB;CAC9D,aAAa,qBAAA,UAAA,EAAA,UAAA,CACR5C,UACA4C,OACH,EAAA,CAAA;AACJ;AAOA,SAASU,aAAaxB,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"}
|