@kanso-labs/kanso-ui 0.40.5 → 0.40.6
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/dist/button/hooks.js +37 -1
- package/dist/button/hooks.js.map +1 -1
- package/dist/button/index.d.ts +57 -1
- package/dist/button/index.js +153 -96
- package/dist/button/index.js.map +1 -1
- package/dist/button/toggle.js +17 -0
- package/dist/button/toggle.js.map +1 -0
- package/dist/calendar/index.js +69 -58
- package/dist/calendar/index.js.map +1 -1
- package/dist/calendar/styles.js +29 -6
- package/dist/calendar/styles.js.map +1 -1
- package/dist/chip/index.js +3 -4
- package/dist/chip/index.js.map +1 -1
- package/dist/chip/styles.js +2 -6
- package/dist/chip/styles.js.map +1 -1
- package/dist/collection/empty.js +7 -0
- package/dist/collection/empty.js.map +1 -0
- package/dist/collection/index.js +125 -2
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/styles.js +14 -0
- package/dist/collection/styles.js.map +1 -1
- package/dist/components/app-bar/index.d.ts +26 -23
- package/dist/components/app-bar/index.js +89 -72
- package/dist/components/app-bar/index.js.map +1 -1
- package/dist/components/autocomplete/index.d.ts +6 -4
- package/dist/components/autocomplete/index.js +23 -14
- package/dist/components/autocomplete/index.js.map +1 -1
- package/dist/components/button/index.d.ts +15 -35
- package/dist/components/button/index.js +102 -74
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/calendar/index.d.ts +9 -3
- package/dist/components/calendar/index.js +51 -42
- package/dist/components/calendar/index.js.map +1 -1
- package/dist/components/card/index.js +43 -27
- package/dist/components/card/index.js.map +1 -1
- package/dist/components/carousel/index.js +1 -1
- package/dist/components/checkbox/index.d.ts +9 -0
- package/dist/components/checkbox/index.js +47 -35
- package/dist/components/checkbox/index.js.map +1 -1
- package/dist/components/checkbox-group/index.js +1 -1
- package/dist/components/chip/index.d.ts +9 -4
- package/dist/components/chip/index.js.map +1 -1
- package/dist/components/chip-group/index.js +51 -37
- package/dist/components/chip-group/index.js.map +1 -1
- package/dist/components/copy-field/index.d.ts +28 -6
- package/dist/components/copy-field/index.js +140 -54
- package/dist/components/copy-field/index.js.map +1 -1
- package/dist/components/currency/index.d.ts +6 -2
- package/dist/components/currency/index.js +74 -46
- package/dist/components/currency/index.js.map +1 -1
- package/dist/components/disclosure/index.js +1 -1
- package/dist/components/icon-button/index.d.ts +6 -31
- package/dist/components/icon-button/index.js +64 -52
- package/dist/components/icon-button/index.js.map +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/list/index.js +2 -2
- package/dist/components/list-box/index.d.ts +14 -2
- package/dist/components/list-box/index.js +16 -8
- package/dist/components/list-box/index.js.map +1 -1
- package/dist/components/list-item/index.js +1 -1
- package/dist/components/menu/index.d.ts +14 -1
- package/dist/components/menu/index.js +32 -17
- package/dist/components/menu/index.js.map +1 -1
- package/dist/components/navigation-tree/index.js +2 -2
- package/dist/components/radio-group/index.d.ts +4 -0
- package/dist/components/radio-group/index.js +2 -2
- package/dist/components/radio-group/index.js.map +1 -1
- package/dist/components/range-calendar/index.d.ts +9 -3
- package/dist/components/range-calendar/index.js +51 -42
- package/dist/components/range-calendar/index.js.map +1 -1
- package/dist/components/search-view/index.js +1 -1
- package/dist/components/segmented-button/index.d.ts +5 -4
- package/dist/components/segmented-button/index.js +3 -3
- package/dist/components/segmented-button/index.js.map +1 -1
- package/dist/components/split-button/index.d.ts +1 -1
- package/dist/components/split-button/index.js.map +1 -1
- package/dist/components/switch/index.d.ts +9 -2
- package/dist/components/switch/index.js +2 -2
- package/dist/components/switch/index.js.map +1 -1
- package/dist/components/table/index.js +3 -3
- package/dist/components/time-picker/index.js +1 -1
- package/dist/components/tree/index.js +2 -2
- package/dist/control/index.js +55 -17
- package/dist/control/index.js.map +1 -1
- package/dist/field/index.js +59 -51
- package/dist/field/index.js.map +1 -1
- package/dist/hooks/useAppBarScroll.d.ts +52 -0
- package/dist/hooks/useAppBarScroll.js +75 -0
- package/dist/hooks/useAppBarScroll.js.map +1 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/messages.js +68 -0
- package/dist/i18n/messages.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/render/name.d.ts +22 -0
- package/dist/styles.css +83 -24
- package/package.json +2 -2
package/dist/button/hooks.js
CHANGED
|
@@ -2,6 +2,7 @@ import { refCallback } from "../render/ref.js";
|
|
|
2
2
|
import { ariaAttributesOf } from "../render/aria.js";
|
|
3
3
|
import { useRipple } from "../hooks/useRipple.js";
|
|
4
4
|
import { c } from "react/compiler-runtime";
|
|
5
|
+
import { useState } from "react";
|
|
5
6
|
import { ButtonContext, useSlottedContext } from "react-aria-components";
|
|
6
7
|
//#region src/button/hooks.ts
|
|
7
8
|
/**
|
|
@@ -75,7 +76,42 @@ function useButtonBase(input, isPending) {
|
|
|
75
76
|
} else t5 = $[18];
|
|
76
77
|
return t5;
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A toggle's state, for a button that is a toggle on its own rather than in
|
|
81
|
+
* a selecting group: the call site's `isSelected` where it holds the state,
|
|
82
|
+
* otherwise the button's own, starting from `defaultSelected`. `toggle` is
|
|
83
|
+
* what a press calls, and reports the new state through `onChange` either
|
|
84
|
+
* way. Called whether or not the button is a toggle, so that becoming one
|
|
85
|
+
* changes no hook order.
|
|
86
|
+
*/
|
|
87
|
+
function useSelection(t0) {
|
|
88
|
+
const $ = c(6);
|
|
89
|
+
const { defaultSelected, isSelected, onChange } = t0;
|
|
90
|
+
const [own, setOwn] = useState(defaultSelected ?? false);
|
|
91
|
+
const selected = isSelected ?? own;
|
|
92
|
+
let t1;
|
|
93
|
+
if ($[0] !== onChange || $[1] !== selected) {
|
|
94
|
+
t1 = () => {
|
|
95
|
+
setOwn(!selected);
|
|
96
|
+
onChange?.(!selected);
|
|
97
|
+
};
|
|
98
|
+
$[0] = onChange;
|
|
99
|
+
$[1] = selected;
|
|
100
|
+
$[2] = t1;
|
|
101
|
+
} else t1 = $[2];
|
|
102
|
+
let t2;
|
|
103
|
+
if ($[3] !== selected || $[4] !== t1) {
|
|
104
|
+
t2 = {
|
|
105
|
+
selected,
|
|
106
|
+
toggle: t1
|
|
107
|
+
};
|
|
108
|
+
$[3] = selected;
|
|
109
|
+
$[4] = t1;
|
|
110
|
+
$[5] = t2;
|
|
111
|
+
} else t2 = $[5];
|
|
112
|
+
return t2;
|
|
113
|
+
}
|
|
78
114
|
//#endregion
|
|
79
|
-
export { useButtonBase };
|
|
115
|
+
export { useButtonBase, useSelection };
|
|
80
116
|
|
|
81
117
|
//# sourceMappingURL=hooks.js.map
|
package/dist/button/hooks.js.map
CHANGED
|
@@ -1 +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":"
|
|
1
|
+
{"version":3,"file":"hooks.js","names":["Ref","FocusableElement","useState","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","useSelection","defaultSelected","isSelected","onChange","own","setOwn","selected","toggle","_c"],"sources":["../../src/button/hooks.ts"],"sourcesContent":["import type { Ref } from 'react'\nimport type { FocusableElement } from 'react-aria-components'\n\nimport { useState } from 'react'\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\n/**\n * A toggle's state, for a button that is a toggle on its own rather than in\n * a selecting group: the call site's `isSelected` where it holds the state,\n * otherwise the button's own, starting from `defaultSelected`. `toggle` is\n * what a press calls, and reports the new state through `onChange` either\n * way. Called whether or not the button is a toggle, so that becoming one\n * changes no hook order.\n */\nfunction useSelection({\n defaultSelected,\n isSelected,\n onChange,\n}: {\n defaultSelected?: boolean | undefined\n isSelected?: boolean | undefined\n onChange?: ((isSelected: boolean) => void) | undefined\n}) {\n const [own, setOwn] = useState(defaultSelected ?? false)\n const selected = isSelected ?? own\n\n return {\n selected,\n toggle: () => {\n setOwn(!selected)\n onChange?.(!selected)\n },\n }\n}\n\nexport { useButtonBase, useSelection }\n"],"mappings":";;;;;;;;;;;;;;;;AA2CA,SAAAe,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;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B;EAAA/B,EAAA,KAAAiB;CAAA,OAAAA,KAAAjB,EAAA;CAAA,IAAAmB;CAAA,IAAAnB,EAAA,OAAA+B,YAAA/B,EAAA,OAAAiB,IAAA;EALIE,KAAA;GAAAY;GAAAC,QAEGf;EAIV;EAACjB,EAAA,KAAA+B;EAAA/B,EAAA,KAAAiB;EAAAjB,EAAA,KAAAmB;CAAA,OAAAA,KAAAnB,EAAA;CAAA,OANMmB;AAMN"}
|
package/dist/button/index.d.ts
CHANGED
|
@@ -2,10 +2,66 @@ import { DOMAttributes, ReactNode, RefAttributes } from "react";
|
|
|
2
2
|
import { ButtonProps, ButtonRenderProps, ClassNameOrFunction, StyleOrFunction } from "react-aria-components";
|
|
3
3
|
//#region src/button/index.d.ts
|
|
4
4
|
type ButtonDOMProps = Omit<ButtonProps, 'children' | 'className' | 'style' | GlobalEventKey> & Pick<DOMAttributes<HTMLElement>, GlobalEventKey>;
|
|
5
|
+
/**
|
|
6
|
+
* The three forms a button takes, of which a call site writes exactly one:
|
|
7
|
+
* a plain button, a link, or a toggle. Each names the props of the other two
|
|
8
|
+
* as `never`, so a combination the rendered form would ignore — a toggle
|
|
9
|
+
* given `href`, a link given `isPending` — is a compile error rather than a
|
|
10
|
+
* prop that silently does nothing.
|
|
11
|
+
*/
|
|
12
|
+
type ButtonForm = ButtonLinkForm | ButtonPressForm | ButtonToggleForm;
|
|
13
|
+
type ButtonLinkForm = {
|
|
14
|
+
defaultSelected?: never;
|
|
15
|
+
/**
|
|
16
|
+
* Where the button leads. Given one, the button is rendered as a link —
|
|
17
|
+
* an `<a>`, announced as the link it is — with the same styles and ripple.
|
|
18
|
+
* A link is never a toggle and never pending, and `render`, `type` and the
|
|
19
|
+
* form props apply to the other two forms only.
|
|
20
|
+
*/
|
|
21
|
+
href: string;
|
|
22
|
+
isPending?: never;
|
|
23
|
+
isSelected?: never;
|
|
24
|
+
onChange?: never;
|
|
25
|
+
pendingLabel?: never;
|
|
26
|
+
/** The link's `rel`. */
|
|
27
|
+
rel?: string;
|
|
28
|
+
/** The link's `target`. */
|
|
29
|
+
target?: string;
|
|
30
|
+
};
|
|
31
|
+
type ButtonPressForm = {
|
|
32
|
+
defaultSelected?: never;
|
|
33
|
+
href?: never;
|
|
34
|
+
isSelected?: never;
|
|
35
|
+
onChange?: never;
|
|
36
|
+
rel?: never;
|
|
37
|
+
target?: never;
|
|
38
|
+
};
|
|
5
39
|
type ButtonState = Pick<ButtonRenderProps, 'isDisabled' | 'isFocused' | 'isFocusVisible' | 'isHovered' | 'isPressed'> & {
|
|
6
40
|
isSelected?: boolean;
|
|
7
41
|
};
|
|
42
|
+
type ButtonToggleForm = {
|
|
43
|
+
/**
|
|
44
|
+
* Whether a toggle starts selected, when it keeps its own state. Passing
|
|
45
|
+
* this, `isSelected` or `onChange` is what makes the button a toggle.
|
|
46
|
+
*/
|
|
47
|
+
defaultSelected?: boolean;
|
|
48
|
+
href?: never;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a toggle is selected, when the call site holds the state. Pass
|
|
51
|
+
* it with `onChange`; passing this, `defaultSelected` or `onChange` is what
|
|
52
|
+
* makes the button a toggle. A value still loading may be `undefined` for a
|
|
53
|
+
* while: the button stays the same element when it arrives.
|
|
54
|
+
*/
|
|
55
|
+
isSelected?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Called with the new state when a toggle is pressed. Passing this,
|
|
58
|
+
* `isSelected` or `defaultSelected` is what makes the button a toggle.
|
|
59
|
+
*/
|
|
60
|
+
onChange?: (isSelected: boolean) => void;
|
|
61
|
+
rel?: never;
|
|
62
|
+
target?: never;
|
|
63
|
+
};
|
|
8
64
|
type GlobalEventKey = Exclude<keyof DOMAttributes<HTMLElement> & keyof ButtonProps, 'onBlur' | 'onClick' | 'onFocus'>;
|
|
9
65
|
//#endregion
|
|
10
|
-
export type { ButtonDOMProps, ButtonState };
|
|
66
|
+
export type { ButtonDOMProps, ButtonForm, ButtonLinkForm, ButtonPressForm, ButtonState, ButtonToggleForm };
|
|
11
67
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/button/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { props } from "../node_modules/@stylexjs/stylex/lib/es/stylex.js";
|
|
2
2
|
import { mergeStatefulStyles } from "../styles/merge.js";
|
|
3
|
-
import { buttonRenderer, linkRenderer, toggleButtonRenderer } from "../render/aria.js";
|
|
4
3
|
import ProgressIndicator from "../components/progress-indicator/index.js";
|
|
5
|
-
import { useToggleGroupDisabled } from "../hooks/useToggleGroupDisabled.js";
|
|
6
4
|
import { useMessages } from "../i18n/index.js";
|
|
5
|
+
import { buttonRenderer, linkRenderer, toggleButtonRenderer } from "../render/aria.js";
|
|
6
|
+
import { useToggleGroupDisabled } from "../hooks/useToggleGroupDisabled.js";
|
|
7
7
|
import { useButtonBase } from "./hooks.js";
|
|
8
8
|
import { buttonBaseStyles } from "./styles.js";
|
|
9
9
|
import { c } from "react/compiler-runtime";
|
|
@@ -15,126 +15,174 @@ import { Button, Link, ToggleButton } from "react-aria-components";
|
|
|
15
15
|
* `Button`, or its `Link` given `href`. See the header.
|
|
16
16
|
*/
|
|
17
17
|
function ButtonBase(t0) {
|
|
18
|
-
const $ = c(
|
|
18
|
+
const $ = c(52);
|
|
19
19
|
let children;
|
|
20
20
|
let classes;
|
|
21
21
|
let href;
|
|
22
22
|
let input;
|
|
23
|
+
let isSelected;
|
|
23
24
|
let pendingLabel;
|
|
24
25
|
let rel;
|
|
25
26
|
let render;
|
|
26
27
|
let t1;
|
|
27
28
|
let target;
|
|
28
29
|
if ($[0] !== t0) {
|
|
29
|
-
({children, classes, href, isPending: t1, pendingLabel, rel, render, target, ...input} = t0);
|
|
30
|
+
({children, classes, href, isPending: t1, isSelected, pendingLabel, rel, render, target, ...input} = t0);
|
|
30
31
|
$[0] = t0;
|
|
31
32
|
$[1] = children;
|
|
32
33
|
$[2] = classes;
|
|
33
34
|
$[3] = href;
|
|
34
35
|
$[4] = input;
|
|
35
|
-
$[5] =
|
|
36
|
-
$[6] =
|
|
37
|
-
$[7] =
|
|
38
|
-
$[8] =
|
|
39
|
-
$[9] =
|
|
36
|
+
$[5] = isSelected;
|
|
37
|
+
$[6] = pendingLabel;
|
|
38
|
+
$[7] = rel;
|
|
39
|
+
$[8] = render;
|
|
40
|
+
$[9] = t1;
|
|
41
|
+
$[10] = target;
|
|
40
42
|
} else {
|
|
41
43
|
children = $[1];
|
|
42
44
|
classes = $[2];
|
|
43
45
|
href = $[3];
|
|
44
46
|
input = $[4];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
isSelected = $[5];
|
|
48
|
+
pendingLabel = $[6];
|
|
49
|
+
rel = $[7];
|
|
50
|
+
render = $[8];
|
|
51
|
+
t1 = $[9];
|
|
52
|
+
target = $[10];
|
|
50
53
|
}
|
|
51
54
|
const isPending = t1 === void 0 ? false : t1;
|
|
52
55
|
const messages = useMessages();
|
|
53
|
-
const
|
|
56
|
+
const base = useButtonBase(input, isPending);
|
|
57
|
+
const { disabled, props, ref, ripple } = base;
|
|
54
58
|
let t2;
|
|
55
|
-
if ($[
|
|
59
|
+
if ($[11] !== classes || $[12] !== props) {
|
|
56
60
|
t2 = mergeStatefulStyles(classes, props);
|
|
57
|
-
$[
|
|
58
|
-
$[
|
|
59
|
-
$[
|
|
60
|
-
} else t2 = $[
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
|
61
|
+
$[11] = classes;
|
|
62
|
+
$[12] = props;
|
|
63
|
+
$[13] = t2;
|
|
64
|
+
} else t2 = $[13];
|
|
65
|
+
const merged = t2;
|
|
66
|
+
let T0;
|
|
67
|
+
let styleProps;
|
|
98
68
|
let t3;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
$[27] = element;
|
|
102
|
-
$[28] = render;
|
|
103
|
-
$[29] = t3;
|
|
104
|
-
} else t3 = $[29];
|
|
105
|
-
const t4 = ripple.handlers;
|
|
106
|
-
const t5 = pendingLabel ?? messages.loading;
|
|
69
|
+
let t4;
|
|
70
|
+
let t5;
|
|
107
71
|
let t6;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
72
|
+
let t7;
|
|
73
|
+
if ($[14] !== base.element || $[15] !== children || $[16] !== disabled || $[17] !== href || $[18] !== isPending || $[19] !== isSelected || $[20] !== merged || $[21] !== props || $[22] !== ref || $[23] !== rel || $[24] !== render || $[25] !== ripple.handlers || $[26] !== ripple.surface || $[27] !== target) {
|
|
74
|
+
t7 = Symbol.for("react.early_return_sentinel");
|
|
75
|
+
bb0: {
|
|
76
|
+
const element = isSelected === void 0 ? base.element : {
|
|
77
|
+
...base.element,
|
|
78
|
+
aria: {
|
|
79
|
+
...base.element.aria,
|
|
80
|
+
"aria-pressed": isSelected
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
let t8;
|
|
84
|
+
if ($[35] !== isSelected || $[36] !== merged) {
|
|
85
|
+
t8 = isSelected === void 0 ? merged : {
|
|
86
|
+
className: (state) => merged.className({
|
|
87
|
+
...state,
|
|
88
|
+
isSelected
|
|
89
|
+
}),
|
|
90
|
+
style: (state_0) => merged.style({
|
|
91
|
+
...state_0,
|
|
92
|
+
isSelected
|
|
93
|
+
})
|
|
94
|
+
};
|
|
95
|
+
$[35] = isSelected;
|
|
96
|
+
$[36] = merged;
|
|
97
|
+
$[37] = t8;
|
|
98
|
+
} else t8 = $[37];
|
|
99
|
+
styleProps = t8;
|
|
100
|
+
if (href !== void 0) {
|
|
101
|
+
t7 = /* @__PURE__ */ jsxs(Link, {
|
|
102
|
+
href,
|
|
103
|
+
isDisabled: disabled,
|
|
104
|
+
ref,
|
|
105
|
+
rel,
|
|
106
|
+
render: linkRenderer(element),
|
|
107
|
+
target,
|
|
108
|
+
...ripple.handlers,
|
|
109
|
+
...props,
|
|
110
|
+
...styleProps,
|
|
111
|
+
children: [children, ripple.surface]
|
|
112
|
+
});
|
|
113
|
+
break bb0;
|
|
114
|
+
}
|
|
115
|
+
T0 = Button;
|
|
116
|
+
t3 = disabled;
|
|
117
|
+
t4 = isPending;
|
|
118
|
+
t5 = ref;
|
|
119
|
+
t6 = buttonRenderer(element, selectedRender(render, isSelected));
|
|
120
|
+
}
|
|
121
|
+
$[14] = base.element;
|
|
122
|
+
$[15] = children;
|
|
123
|
+
$[16] = disabled;
|
|
124
|
+
$[17] = href;
|
|
125
|
+
$[18] = isPending;
|
|
126
|
+
$[19] = isSelected;
|
|
127
|
+
$[20] = merged;
|
|
128
|
+
$[21] = props;
|
|
129
|
+
$[22] = ref;
|
|
130
|
+
$[23] = rel;
|
|
131
|
+
$[24] = render;
|
|
132
|
+
$[25] = ripple.handlers;
|
|
133
|
+
$[26] = ripple.surface;
|
|
134
|
+
$[27] = target;
|
|
135
|
+
$[28] = T0;
|
|
136
|
+
$[29] = styleProps;
|
|
137
|
+
$[30] = t3;
|
|
138
|
+
$[31] = t4;
|
|
112
139
|
$[32] = t5;
|
|
113
140
|
$[33] = t6;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
141
|
+
$[34] = t7;
|
|
142
|
+
} else {
|
|
143
|
+
T0 = $[28];
|
|
144
|
+
styleProps = $[29];
|
|
145
|
+
t3 = $[30];
|
|
146
|
+
t4 = $[31];
|
|
147
|
+
t5 = $[32];
|
|
148
|
+
t6 = $[33];
|
|
149
|
+
t7 = $[34];
|
|
150
|
+
}
|
|
151
|
+
if (t7 !== Symbol.for("react.early_return_sentinel")) return t7;
|
|
152
|
+
const t8 = ripple.handlers;
|
|
153
|
+
const t9 = pendingLabel ?? messages.loading;
|
|
154
|
+
let t10;
|
|
155
|
+
if ($[38] !== children || $[39] !== ripple.surface || $[40] !== t9) {
|
|
156
|
+
t10 = buttonContent(children, t9, ripple.surface);
|
|
157
|
+
$[38] = children;
|
|
158
|
+
$[39] = ripple.surface;
|
|
159
|
+
$[40] = t9;
|
|
160
|
+
$[41] = t10;
|
|
161
|
+
} else t10 = $[41];
|
|
162
|
+
let t11;
|
|
163
|
+
if ($[42] !== T0 || $[43] !== props || $[44] !== ripple.handlers || $[45] !== styleProps || $[46] !== t10 || $[47] !== t3 || $[48] !== t4 || $[49] !== t5 || $[50] !== t6) {
|
|
164
|
+
t11 = /* @__PURE__ */ jsx(T0, {
|
|
165
|
+
isDisabled: t3,
|
|
166
|
+
isPending: t4,
|
|
167
|
+
ref: t5,
|
|
168
|
+
render: t6,
|
|
169
|
+
...t8,
|
|
123
170
|
...props,
|
|
124
171
|
...styleProps,
|
|
125
|
-
children:
|
|
172
|
+
children: t10
|
|
126
173
|
});
|
|
127
|
-
$[
|
|
128
|
-
$[
|
|
129
|
-
$[
|
|
130
|
-
$[
|
|
131
|
-
$[
|
|
132
|
-
$[
|
|
133
|
-
$[
|
|
134
|
-
$[
|
|
135
|
-
$[
|
|
136
|
-
|
|
137
|
-
|
|
174
|
+
$[42] = T0;
|
|
175
|
+
$[43] = props;
|
|
176
|
+
$[44] = ripple.handlers;
|
|
177
|
+
$[45] = styleProps;
|
|
178
|
+
$[46] = t10;
|
|
179
|
+
$[47] = t3;
|
|
180
|
+
$[48] = t4;
|
|
181
|
+
$[49] = t5;
|
|
182
|
+
$[50] = t6;
|
|
183
|
+
$[51] = t11;
|
|
184
|
+
} else t11 = $[51];
|
|
185
|
+
return t11;
|
|
138
186
|
}
|
|
139
187
|
function buttonContent(children, pendingLabel, surface) {
|
|
140
188
|
return (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -155,13 +203,22 @@ function buttonContent(children, pendingLabel, surface) {
|
|
|
155
203
|
surface
|
|
156
204
|
] });
|
|
157
205
|
}
|
|
206
|
+
function selectedRender(render, isSelected) {
|
|
207
|
+
if (render === void 0 || isSelected === void 0) return render;
|
|
208
|
+
return (props, state) => {
|
|
209
|
+
return render(props, {
|
|
210
|
+
...state,
|
|
211
|
+
isSelected
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
}
|
|
158
215
|
/**
|
|
159
|
-
* A toggle drawn with the classes a component hands
|
|
160
|
-
* `ToggleButton`, which
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
216
|
+
* A toggle in a selecting group, drawn with the classes a component hands
|
|
217
|
+
* it: React Aria's `ToggleButton`, which is what takes part in the group's
|
|
218
|
+
* selection and reports its state through `aria-pressed`. A toggle on its
|
|
219
|
+
* own is ButtonBase given `isSelected` instead — see there. React Aria's
|
|
220
|
+
* toggle takes no pending state, so `isPending` reaches it only to keep the
|
|
221
|
+
* ripple off.
|
|
165
222
|
*/
|
|
166
223
|
function ToggleButtonBase(t0) {
|
|
167
224
|
const $ = c(32);
|
package/dist/button/index.js.map
CHANGED
|
@@ -1 +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} diameter=\"1em\" isIndeterminate 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,EAAA,KAAAf;CAAA,OAAA;EAAAZ,WAAA2B,EAAA;EAAA1B,UAAA0B,EAAA;EAAAnB,OAAAmB,EAAA;EAAAE,QAAAF,EAAA;EAAAlB,eAAAkB,EAAA;EAAAjB,MAAAiB,EAAA;EAAAG,SAAAH,EAAA;EAAAI,KAAAJ,EAAA;EAAAf,SAAAe,EAAA;CAAA;CANhB,MAAAK,YAAAD,OAAAE,KAAAA,IAAA,QAAAF;CAOA,MAAAG,WAAiB1C,YAAY;CAC7B,MAAA,EAAA2C,UAAAC,SAAA/B,OAAAgC,KAAAC,WAMIzC,cAAcgC,OAAOG,SAAS;CAAE,IAAAO;CAAA,IAAAZ,EAAA,QAAA1B,WAAA0B,EAAA,QAAAtB,OAAA;EACjBkC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AA,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"}
|
|
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","isSelected","pendingLabel","rel","style","target","ButtonDOMProps","HTMLAnchorElement","HTMLButtonElement","Omit","GlobalEventKey","Pick","HTMLElement","ButtonForm","ButtonLinkForm","ButtonPressForm","ButtonToggleForm","defaultSelected","isPending","onChange","Exclude","ToggleButtonBaseProps","ButtonBase","t0","$","_c","input","render","t1","undefined","messages","base","disabled","ref","ripple","t2","merged","T0","styleProps","t3","t4","t5","t6","t7","element","handlers","surface","Symbol","for","bb0","aria","t8","state_0","selectedRender","t9","loading","t10","buttonContent","t11","label","labelPending","pending","selected","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` inside a selecting group, 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 /**\n * A toggle's state, for a button that reports one through `aria-pressed`.\n * Left undefined, the button reports none. Handed to every function of the\n * render state, so the classes can draw it.\n */\n isSelected?: boolean;\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/**\n * The three forms a button takes, of which a call site writes exactly one:\n * a plain button, a link, or a toggle. Each names the props of the other two\n * as `never`, so a combination the rendered form would ignore — a toggle\n * given `href`, a link given `isPending` — is a compile error rather than a\n * prop that silently does nothing.\n */\ntype ButtonForm = ButtonLinkForm | ButtonPressForm | ButtonToggleForm;\ntype ButtonLinkForm = {\n defaultSelected?: never;\n /**\n * Where the button leads. Given one, the button is rendered as a link —\n * an `<a>`, announced as the link it is — with the same styles and ripple.\n * A link is never a toggle and never pending, and `render`, `type` and the\n * form props apply to the other two forms only.\n */\n href: string;\n isPending?: never;\n isSelected?: never;\n onChange?: never;\n pendingLabel?: never;\n /** The link's `rel`. */\n rel?: string;\n /** The link's `target`. */\n target?: string;\n};\ntype ButtonPressForm = {\n defaultSelected?: never;\n href?: never;\n isSelected?: never;\n onChange?: never;\n rel?: never;\n target?: never;\n};\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 ButtonToggleForm = {\n /**\n * Whether a toggle starts selected, when it keeps its own state. Passing\n * this, `isSelected` or `onChange` is what makes the button a toggle.\n */\n defaultSelected?: boolean;\n href?: never;\n /**\n * Whether a toggle is selected, when the call site holds the state. Pass\n * it with `onChange`; passing this, `defaultSelected` or `onChange` is what\n * makes the button a toggle. A value still loading may be `undefined` for a\n * while: the button stays the same element when it arrives.\n */\n isSelected?: boolean;\n /**\n * Called with the new state when a toggle is pressed. Passing this,\n * `isSelected` or `defaultSelected` is what makes the button a toggle.\n */\n onChange?: (isSelected: boolean) => void;\n rel?: never;\n target?: never;\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 isSelected,\n pendingLabel,\n rel,\n render,\n target,\n ...input\n}: ButtonBaseProps) {\n const messages = useMessages();\n const base = useButtonBase(input, isPending);\n const {\n disabled,\n props,\n ref,\n ripple\n } = base;\n const merged = mergeStatefulStyles(classes, props);\n\n // A toggle is still React Aria's `Button`, which knows nothing of a\n // selected state, so the state goes onto the element as `aria-pressed` and\n // into every function of the render state from here. Being the same\n // component as the plain button is what keeps a button the same element\n // when it becomes a toggle — `isSelected` arriving once its data loads.\n const element = isSelected === undefined ? base.element : {\n ...base.element,\n aria: {\n ...base.element.aria,\n 'aria-pressed': isSelected\n }\n };\n const styleProps = isSelected === undefined ? merged : {\n className: (state: Parameters<typeof merged.className>[0]) => merged.className({\n ...state,\n isSelected\n }),\n style: (state: Parameters<typeof merged.style>[0]) => merged.style({\n ...state,\n isSelected\n })\n };\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, selectedRender(render, isSelected))} {...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} diameter=\"1em\" isIndeterminate tone=\"inherit\" variant=\"circular\" />\n </span> : null}\n {surface}\n </>;\n}\n\n// A toggle drawn through ButtonBase hands a call site's `render` the state of\n// React Aria's plain button, which has no `isSelected`; this fills it in.\nfunction selectedRender(render: RACButtonProps['render'], isSelected: boolean | undefined): RACButtonProps['render'] {\n if (render === undefined || isSelected === undefined) {\n return render;\n }\n // Through a binding rather than as a literal at the call: React Aria types\n // the state as its plain button's, and a call site's `render` is written\n // against ButtonState, which is that plus `isSelected`.\n return (props, state) => {\n const selected = {\n ...state,\n isSelected\n };\n return render(props, selected);\n };\n}\n\n/**\n * A toggle in a selecting group, drawn with the classes a component hands\n * it: React Aria's `ToggleButton`, which is what takes part in the group's\n * selection and reports its state through `aria-pressed`. A toggle on its\n * own is ButtonBase given `isSelected` instead — see there. React Aria's\n * toggle takes no pending state, so `isPending` reaches it only to keep the\n * ripple off.\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, ButtonForm, ButtonLinkForm, ButtonPressForm, ButtonState, ButtonToggleForm };\nexport { ButtonBase, ToggleButtonBase };"],"mappings":";;;;;;;;;;;;;;;;AA8IA,SAAAyD,WAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAjC;CA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c5E,UAAqBsD,SAAoB;CAC9D,aAAa,qBAAA,UAAA,EAAA,UAAA,CACRtD,UACAsD,OACH,EAAA,CAAA;AACJ;AAOA,SAASqB,aAAaxC,QAAkE;CACtF,IAAIA,WAAWE,KAAAA,GACb;CAEF,QAAQhC,OAAOH,UAAUiC,OAAO9B,OAAO;EACrC,GAAGH;EACHwB,WAAW;CACb,CAAC;AACH"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/button/toggle.ts
|
|
2
|
+
/**
|
|
3
|
+
* A toggle's press: the call site's own `onPress` first, then the change of
|
|
4
|
+
* state, which is the order React Aria's own toggle reports them in. Built by
|
|
5
|
+
* a call rather than written inline at the prop, which is what react-perf's
|
|
6
|
+
* no-new-function-as-prop is after.
|
|
7
|
+
*/
|
|
8
|
+
function pressThen(onPress, then) {
|
|
9
|
+
return (...event) => {
|
|
10
|
+
onPress?.(...event);
|
|
11
|
+
then();
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { pressThen };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=toggle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggle.js","names":["ButtonDOMProps","PressHandler","NonNullable","pressThen","onPress","then","event","Parameters"],"sources":["../../src/button/toggle.ts"],"sourcesContent":["import type { ButtonDOMProps } from '.'\n\ntype PressHandler = NonNullable<ButtonDOMProps['onPress']>\n\n/**\n * A toggle's press: the call site's own `onPress` first, then the change of\n * state, which is the order React Aria's own toggle reports them in. Built by\n * a call rather than written inline at the prop, which is what react-perf's\n * no-new-function-as-prop is after.\n */\nfunction pressThen(onPress: PressHandler | undefined, then: () => void) {\n return (...event: Parameters<PressHandler>) => {\n onPress?.(...event)\n then()\n }\n}\n\nexport { pressThen }\n"],"mappings":";;;;;;;AAUA,SAASG,UAAUC,SAAmCC,MAAkB;CACtE,QAAQ,GAAGC,UAAoC;EAC7CF,UAAU,GAAGE,KAAK;EAClBD,KAAK;CACP;AACF"}
|