@react-aria/button 3.0.0-nightly-641446f65-240905

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 ADDED
@@ -0,0 +1,3 @@
1
+ # @react-aria/button
2
+
3
+ This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
@@ -0,0 +1,19 @@
1
+ import {useButton as $701a24aa0da5b062$export$ea18c227d4417cc3} from "./useButton.mjs";
2
+ import {useToggleButton as $55f54f7887471b58$export$51e84d46ca0bc451} from "./useToggleButton.mjs";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+
17
+
18
+ export {$701a24aa0da5b062$export$ea18c227d4417cc3 as useButton, $55f54f7887471b58$export$51e84d46ca0bc451 as useToggleButton};
19
+ //# sourceMappingURL=module.js.map
package/dist/main.js ADDED
@@ -0,0 +1,25 @@
1
+ var $988353faa005faf8$exports = require("./useButton.main.js");
2
+ var $c49208f7d2aac50b$exports = require("./useToggleButton.main.js");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "useButton", () => $988353faa005faf8$exports.useButton);
10
+ $parcel$export(module.exports, "useToggleButton", () => $c49208f7d2aac50b$exports.useToggleButton);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+
25
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/button/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useButton} from './useButton';\nexport {useToggleButton} from './useToggleButton';\nexport type {AriaButtonOptions, ButtonAria} from './useButton';\nexport type {AriaButtonProps, AriaToggleButtonProps} from '@react-types/button';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js ADDED
@@ -0,0 +1,19 @@
1
+ import {useButton as $701a24aa0da5b062$export$ea18c227d4417cc3} from "./useButton.module.js";
2
+ import {useToggleButton as $55f54f7887471b58$export$51e84d46ca0bc451} from "./useToggleButton.module.js";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+
17
+
18
+ export {$701a24aa0da5b062$export$ea18c227d4417cc3 as useButton, $55f54f7887471b58$export$51e84d46ca0bc451 as useToggleButton};
19
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/button/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useButton} from './useButton';\nexport {useToggleButton} from './useToggleButton';\nexport type {AriaButtonOptions, ButtonAria} from './useButton';\nexport type {AriaButtonProps, AriaToggleButtonProps} from '@react-types/button';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,29 @@
1
+ import { AnchorHTMLAttributes, ButtonHTMLAttributes, ElementType, HTMLAttributes, InputHTMLAttributes, RefObject } from "react";
2
+ import { AriaButtonProps, AriaToggleButtonProps } from "@react-types/button";
3
+ import { DOMAttributes } from "@react-types/shared";
4
+ import { ToggleState } from "@react-stately/toggle";
5
+ export interface AriaButtonOptions<E extends ElementType> extends Omit<AriaButtonProps<E>, 'children'> {
6
+ }
7
+ export interface ButtonAria<T> {
8
+ /** Props for the button element. */
9
+ buttonProps: T;
10
+ /** Whether the button is currently pressed. */
11
+ isPressed: boolean;
12
+ }
13
+ export function useButton(props: AriaButtonOptions<'button'>, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;
14
+ export function useButton(props: AriaButtonOptions<'a'>, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;
15
+ export function useButton(props: AriaButtonOptions<'div'>, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;
16
+ export function useButton(props: AriaButtonOptions<'input'>, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;
17
+ export function useButton(props: AriaButtonOptions<'span'>, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;
18
+ export function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;
19
+ interface AriaToggleButtonOptions<E extends ElementType> extends Omit<AriaToggleButtonProps<E>, 'children'> {
20
+ }
21
+ export function useToggleButton(props: AriaToggleButtonOptions<'button'>, state: ToggleState, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;
22
+ export function useToggleButton(props: AriaToggleButtonOptions<'a'>, state: ToggleState, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;
23
+ export function useToggleButton(props: AriaToggleButtonOptions<'div'>, state: ToggleState, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;
24
+ export function useToggleButton(props: AriaToggleButtonOptions<'input'>, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;
25
+ export function useToggleButton(props: AriaToggleButtonOptions<'span'>, state: ToggleState, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;
26
+ export function useToggleButton(props: AriaToggleButtonOptions<ElementType>, state: ToggleState, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;
27
+ export type { AriaButtonProps, AriaToggleButtonProps } from '@react-types/button';
28
+
29
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AA0BA,mCAAmC,CAAC,SAAS,WAAW,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,UAAU,CAAC;CAAG;AAEzG,4BAA4B,CAAC;IAC3B,oCAAoC;IACpC,WAAW,EAAE,CAAC,CAAC;IACf,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAA;CACnB;AAGD,0BAA0B,KAAK,EAAE,kBAAkB,QAAQ,CAAC,EAAE,GAAG,EAAE,UAAU,iBAAiB,GAAG,IAAI,CAAC,GAAG,WAAW,qBAAqB,iBAAiB,CAAC,CAAC,CAAC;AAC7J,0BAA0B,KAAK,EAAE,kBAAkB,GAAG,CAAC,EAAE,GAAG,EAAE,UAAU,iBAAiB,GAAG,IAAI,CAAC,GAAG,WAAW,qBAAqB,iBAAiB,CAAC,CAAC,CAAC;AACxJ,0BAA0B,KAAK,EAAE,kBAAkB,KAAK,CAAC,EAAE,GAAG,EAAE,UAAU,cAAc,GAAG,IAAI,CAAC,GAAG,WAAW,eAAe,cAAc,CAAC,CAAC,CAAC;AAC9I,0BAA0B,KAAK,EAAE,kBAAkB,OAAO,CAAC,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,WAAW,oBAAoB,gBAAgB,CAAC,CAAC,CAAC;AACzJ,0BAA0B,KAAK,EAAE,kBAAkB,MAAM,CAAC,EAAE,GAAG,EAAE,UAAU,eAAe,GAAG,IAAI,CAAC,GAAG,WAAW,eAAe,eAAe,CAAC,CAAC,CAAC;AACjJ,0BAA0B,KAAK,EAAE,kBAAkB,WAAW,CAAC,EAAE,GAAG,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,GAAG,WAAW,aAAa,CAAC,CAAC;ACf5H,kCAAyC,CAAC,SAAS,WAAW,CAAE,SAAQ,IAAI,CAAC,sBAAsB,CAAC,CAAC,EAAE,UAAU,CAAC;CAAG;AAGrH,gCAAgC,KAAK,EAAE,wBAAwB,QAAQ,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,iBAAiB,GAAG,IAAI,CAAC,GAAG,WAAW,qBAAqB,iBAAiB,CAAC,CAAC,CAAC;AAC7L,gCAAgC,KAAK,EAAE,wBAAwB,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,iBAAiB,GAAG,IAAI,CAAC,GAAG,WAAW,qBAAqB,iBAAiB,CAAC,CAAC,CAAC;AACxL,gCAAgC,KAAK,EAAE,wBAAwB,KAAK,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,cAAc,GAAG,IAAI,CAAC,GAAG,WAAW,eAAe,cAAc,CAAC,CAAC,CAAC;AAC9K,gCAAgC,KAAK,EAAE,wBAAwB,OAAO,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,WAAW,oBAAoB,gBAAgB,CAAC,CAAC,CAAC;AACzL,gCAAgC,KAAK,EAAE,wBAAwB,MAAM,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,eAAe,GAAG,IAAI,CAAC,GAAG,WAAW,eAAe,eAAe,CAAC,CAAC,CAAC;AACjL,gCAAgC,KAAK,EAAE,wBAAwB,WAAW,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,GAAG,WAAW,aAAa,CAAC,CAAC;ACpB5J,YAAY,EAAC,eAAe,EAAE,qBAAqB,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/button/src/packages/@react-aria/button/src/useButton.ts","packages/@react-aria/button/src/packages/@react-aria/button/src/useToggleButton.ts","packages/@react-aria/button/src/packages/@react-aria/button/src/index.ts","packages/@react-aria/button/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useButton} from './useButton';\nexport {useToggleButton} from './useToggleButton';\nexport type {AriaButtonOptions, ButtonAria} from './useButton';\nexport type {AriaButtonProps, AriaToggleButtonProps} from '@react-types/button';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,76 @@
1
+ var $lIlxZ$reactariautils = require("@react-aria/utils");
2
+ var $lIlxZ$reactariafocus = require("@react-aria/focus");
3
+ var $lIlxZ$reactariainteractions = require("@react-aria/interactions");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useButton", () => $988353faa005faf8$export$ea18c227d4417cc3);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $988353faa005faf8$export$ea18c227d4417cc3(props, ref) {
25
+ let { elementType: elementType = 'button', isDisabled: isDisabled, onPress: onPress, onPressStart: onPressStart, onPressEnd: onPressEnd, onPressUp: onPressUp, onPressChange: onPressChange, preventFocusOnPress: preventFocusOnPress, allowFocusWhenDisabled: // @ts-ignore - undocumented
26
+ allowFocusWhenDisabled, // @ts-ignore
27
+ onClick: deprecatedOnClick, href: href, target: target, rel: rel, type: type = 'button' } = props;
28
+ let additionalProps;
29
+ if (elementType === 'button') additionalProps = {
30
+ type: type,
31
+ disabled: isDisabled
32
+ };
33
+ else additionalProps = {
34
+ role: 'button',
35
+ tabIndex: isDisabled ? undefined : 0,
36
+ href: elementType === 'a' && isDisabled ? undefined : href,
37
+ target: elementType === 'a' ? target : undefined,
38
+ type: elementType === 'input' ? type : undefined,
39
+ disabled: elementType === 'input' ? isDisabled : undefined,
40
+ 'aria-disabled': !isDisabled || elementType === 'input' ? undefined : isDisabled,
41
+ rel: elementType === 'a' ? rel : undefined
42
+ };
43
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $lIlxZ$reactariainteractions.usePress)({
44
+ onPressStart: onPressStart,
45
+ onPressEnd: onPressEnd,
46
+ onPressChange: onPressChange,
47
+ onPress: onPress,
48
+ onPressUp: onPressUp,
49
+ isDisabled: isDisabled,
50
+ preventFocusOnPress: preventFocusOnPress,
51
+ ref: ref
52
+ });
53
+ let { focusableProps: focusableProps } = (0, $lIlxZ$reactariafocus.useFocusable)(props, ref);
54
+ if (allowFocusWhenDisabled) focusableProps.tabIndex = isDisabled ? -1 : focusableProps.tabIndex;
55
+ let buttonProps = (0, $lIlxZ$reactariautils.mergeProps)(focusableProps, pressProps, (0, $lIlxZ$reactariautils.filterDOMProps)(props, {
56
+ labelable: true
57
+ }));
58
+ return {
59
+ isPressed: isPressed,
60
+ buttonProps: (0, $lIlxZ$reactariautils.mergeProps)(additionalProps, buttonProps, {
61
+ 'aria-haspopup': props['aria-haspopup'],
62
+ 'aria-expanded': props['aria-expanded'],
63
+ 'aria-controls': props['aria-controls'],
64
+ 'aria-pressed': props['aria-pressed'],
65
+ onClick: (e)=>{
66
+ if (deprecatedOnClick) {
67
+ deprecatedOnClick(e);
68
+ console.warn('onClick is deprecated, please use onPress');
69
+ }
70
+ }
71
+ })
72
+ };
73
+ }
74
+
75
+
76
+ //# sourceMappingURL=useButton.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAsCM,SAAS,0CAAU,KAAqC,EAAE,GAAmB;IAClF,IAAI,eACF,cAAc,sBACd,UAAU,WACV,OAAO,gBACP,YAAY,cACZ,UAAU,aACV,SAAS,iBACT,aAAa,uBACb,mBAAmB,0BACnB,4BAA4B;IAC5B,sBAAsB,EACtB,aAAa;IACb,SAAS,iBAAiB,QAC1B,IAAI,UACJ,MAAM,OACN,GAAG,QACH,OAAO,UACR,GAAG;IACJ,IAAI;IACJ,IAAI,gBAAgB,UAClB,kBAAkB;cAChB;QACA,UAAU;IACZ;SAEA,kBAAkB;QAChB,MAAM;QACN,UAAU,aAAa,YAAY;QACnC,MAAM,gBAAgB,OAAO,aAAa,YAAY;QACtD,QAAQ,gBAAgB,MAAM,SAAS;QACvC,MAAM,gBAAgB,UAAU,OAAO;QACvC,UAAU,gBAAgB,UAAU,aAAa;QACjD,iBAAiB,CAAC,cAAc,gBAAgB,UAAU,YAAY;QACtE,KAAK,gBAAgB,MAAM,MAAM;IACnC;IAGF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;sBACrC;oBACA;uBACA;iBACA;mBACA;oBACA;6BACA;aACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,wBACF,eAAe,QAAQ,GAAG,aAAa,KAAK,eAAe,QAAQ;IAErE,IAAI,cAAc,CAAA,GAAA,gCAAS,EAAE,gBAAgB,YAAY,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAE/F,OAAO;mBACL;QACA,aAAa,CAAA,GAAA,gCAAS,EAAE,iBAAiB,aAAa;YACpD,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,gBAAgB,KAAK,CAAC,eAAe;YACrC,SAAS,CAAC;gBACR,IAAI,mBAAmB;oBACrB,kBAAkB;oBAClB,QAAQ,IAAI,CAAC;gBACf;YACF;QACF;IACF;AACF","sources":["packages/@react-aria/button/src/useButton.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n AnchorHTMLAttributes,\n ButtonHTMLAttributes,\n ElementType,\n HTMLAttributes,\n InputHTMLAttributes,\n RefObject\n} from 'react';\nimport {AriaButtonProps} from '@react-types/button';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface AriaButtonOptions<E extends ElementType> extends Omit<AriaButtonProps<E>, 'children'> {}\n\nexport interface ButtonAria<T> {\n /** Props for the button element. */\n buttonProps: T,\n /** Whether the button is currently pressed. */\n isPressed: boolean\n}\n\n// Order with overrides is important: 'button' should be default\nexport function useButton(props: AriaButtonOptions<'button'>, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;\nexport function useButton(props: AriaButtonOptions<'a'>, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;\nexport function useButton(props: AriaButtonOptions<'div'>, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;\nexport function useButton(props: AriaButtonOptions<'input'>, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;\nexport function useButton(props: AriaButtonOptions<'span'>, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;\nexport function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;\n/**\n * Provides the behavior and accessibility implementation for a button component. Handles mouse, keyboard, and touch interactions,\n * focus behavior, and ARIA props for both native button elements and custom element types.\n * @param props - Props to be applied to the button.\n * @param ref - A ref to a DOM element for the button.\n */\nexport function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<any>): ButtonAria<HTMLAttributes<any>> {\n let {\n elementType = 'button',\n isDisabled,\n onPress,\n onPressStart,\n onPressEnd,\n onPressUp,\n onPressChange,\n preventFocusOnPress,\n // @ts-ignore - undocumented\n allowFocusWhenDisabled,\n // @ts-ignore\n onClick: deprecatedOnClick,\n href,\n target,\n rel,\n type = 'button'\n } = props;\n let additionalProps;\n if (elementType === 'button') {\n additionalProps = {\n type,\n disabled: isDisabled\n };\n } else {\n additionalProps = {\n role: 'button',\n tabIndex: isDisabled ? undefined : 0,\n href: elementType === 'a' && isDisabled ? undefined : href,\n target: elementType === 'a' ? target : undefined,\n type: elementType === 'input' ? type : undefined,\n disabled: elementType === 'input' ? isDisabled : undefined,\n 'aria-disabled': !isDisabled || elementType === 'input' ? undefined : isDisabled,\n rel: elementType === 'a' ? rel : undefined\n };\n }\n\n let {pressProps, isPressed} = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n onPressUp,\n isDisabled,\n preventFocusOnPress,\n ref\n });\n\n let {focusableProps} = useFocusable(props, ref);\n if (allowFocusWhenDisabled) {\n focusableProps.tabIndex = isDisabled ? -1 : focusableProps.tabIndex;\n }\n let buttonProps = mergeProps(focusableProps, pressProps, filterDOMProps(props, {labelable: true}));\n\n return {\n isPressed, // Used to indicate press state for visual\n buttonProps: mergeProps(additionalProps, buttonProps, {\n 'aria-haspopup': props['aria-haspopup'],\n 'aria-expanded': props['aria-expanded'],\n 'aria-controls': props['aria-controls'],\n 'aria-pressed': props['aria-pressed'],\n onClick: (e) => {\n if (deprecatedOnClick) {\n deprecatedOnClick(e);\n console.warn('onClick is deprecated, please use onPress');\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useButton.main.js.map"}
@@ -0,0 +1,71 @@
1
+ import {mergeProps as $bwqiF$mergeProps, filterDOMProps as $bwqiF$filterDOMProps} from "@react-aria/utils";
2
+ import {useFocusable as $bwqiF$useFocusable} from "@react-aria/focus";
3
+ import {usePress as $bwqiF$usePress} from "@react-aria/interactions";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $701a24aa0da5b062$export$ea18c227d4417cc3(props, ref) {
19
+ let { elementType: elementType = 'button', isDisabled: isDisabled, onPress: onPress, onPressStart: onPressStart, onPressEnd: onPressEnd, onPressUp: onPressUp, onPressChange: onPressChange, preventFocusOnPress: preventFocusOnPress, allowFocusWhenDisabled: // @ts-ignore - undocumented
20
+ allowFocusWhenDisabled, // @ts-ignore
21
+ onClick: deprecatedOnClick, href: href, target: target, rel: rel, type: type = 'button' } = props;
22
+ let additionalProps;
23
+ if (elementType === 'button') additionalProps = {
24
+ type: type,
25
+ disabled: isDisabled
26
+ };
27
+ else additionalProps = {
28
+ role: 'button',
29
+ tabIndex: isDisabled ? undefined : 0,
30
+ href: elementType === 'a' && isDisabled ? undefined : href,
31
+ target: elementType === 'a' ? target : undefined,
32
+ type: elementType === 'input' ? type : undefined,
33
+ disabled: elementType === 'input' ? isDisabled : undefined,
34
+ 'aria-disabled': !isDisabled || elementType === 'input' ? undefined : isDisabled,
35
+ rel: elementType === 'a' ? rel : undefined
36
+ };
37
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $bwqiF$usePress)({
38
+ onPressStart: onPressStart,
39
+ onPressEnd: onPressEnd,
40
+ onPressChange: onPressChange,
41
+ onPress: onPress,
42
+ onPressUp: onPressUp,
43
+ isDisabled: isDisabled,
44
+ preventFocusOnPress: preventFocusOnPress,
45
+ ref: ref
46
+ });
47
+ let { focusableProps: focusableProps } = (0, $bwqiF$useFocusable)(props, ref);
48
+ if (allowFocusWhenDisabled) focusableProps.tabIndex = isDisabled ? -1 : focusableProps.tabIndex;
49
+ let buttonProps = (0, $bwqiF$mergeProps)(focusableProps, pressProps, (0, $bwqiF$filterDOMProps)(props, {
50
+ labelable: true
51
+ }));
52
+ return {
53
+ isPressed: isPressed,
54
+ buttonProps: (0, $bwqiF$mergeProps)(additionalProps, buttonProps, {
55
+ 'aria-haspopup': props['aria-haspopup'],
56
+ 'aria-expanded': props['aria-expanded'],
57
+ 'aria-controls': props['aria-controls'],
58
+ 'aria-pressed': props['aria-pressed'],
59
+ onClick: (e)=>{
60
+ if (deprecatedOnClick) {
61
+ deprecatedOnClick(e);
62
+ console.warn('onClick is deprecated, please use onPress');
63
+ }
64
+ }
65
+ })
66
+ };
67
+ }
68
+
69
+
70
+ export {$701a24aa0da5b062$export$ea18c227d4417cc3 as useButton};
71
+ //# sourceMappingURL=useButton.module.js.map
@@ -0,0 +1,71 @@
1
+ import {mergeProps as $bwqiF$mergeProps, filterDOMProps as $bwqiF$filterDOMProps} from "@react-aria/utils";
2
+ import {useFocusable as $bwqiF$useFocusable} from "@react-aria/focus";
3
+ import {usePress as $bwqiF$usePress} from "@react-aria/interactions";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $701a24aa0da5b062$export$ea18c227d4417cc3(props, ref) {
19
+ let { elementType: elementType = 'button', isDisabled: isDisabled, onPress: onPress, onPressStart: onPressStart, onPressEnd: onPressEnd, onPressUp: onPressUp, onPressChange: onPressChange, preventFocusOnPress: preventFocusOnPress, allowFocusWhenDisabled: // @ts-ignore - undocumented
20
+ allowFocusWhenDisabled, // @ts-ignore
21
+ onClick: deprecatedOnClick, href: href, target: target, rel: rel, type: type = 'button' } = props;
22
+ let additionalProps;
23
+ if (elementType === 'button') additionalProps = {
24
+ type: type,
25
+ disabled: isDisabled
26
+ };
27
+ else additionalProps = {
28
+ role: 'button',
29
+ tabIndex: isDisabled ? undefined : 0,
30
+ href: elementType === 'a' && isDisabled ? undefined : href,
31
+ target: elementType === 'a' ? target : undefined,
32
+ type: elementType === 'input' ? type : undefined,
33
+ disabled: elementType === 'input' ? isDisabled : undefined,
34
+ 'aria-disabled': !isDisabled || elementType === 'input' ? undefined : isDisabled,
35
+ rel: elementType === 'a' ? rel : undefined
36
+ };
37
+ let { pressProps: pressProps, isPressed: isPressed } = (0, $bwqiF$usePress)({
38
+ onPressStart: onPressStart,
39
+ onPressEnd: onPressEnd,
40
+ onPressChange: onPressChange,
41
+ onPress: onPress,
42
+ onPressUp: onPressUp,
43
+ isDisabled: isDisabled,
44
+ preventFocusOnPress: preventFocusOnPress,
45
+ ref: ref
46
+ });
47
+ let { focusableProps: focusableProps } = (0, $bwqiF$useFocusable)(props, ref);
48
+ if (allowFocusWhenDisabled) focusableProps.tabIndex = isDisabled ? -1 : focusableProps.tabIndex;
49
+ let buttonProps = (0, $bwqiF$mergeProps)(focusableProps, pressProps, (0, $bwqiF$filterDOMProps)(props, {
50
+ labelable: true
51
+ }));
52
+ return {
53
+ isPressed: isPressed,
54
+ buttonProps: (0, $bwqiF$mergeProps)(additionalProps, buttonProps, {
55
+ 'aria-haspopup': props['aria-haspopup'],
56
+ 'aria-expanded': props['aria-expanded'],
57
+ 'aria-controls': props['aria-controls'],
58
+ 'aria-pressed': props['aria-pressed'],
59
+ onClick: (e)=>{
60
+ if (deprecatedOnClick) {
61
+ deprecatedOnClick(e);
62
+ console.warn('onClick is deprecated, please use onPress');
63
+ }
64
+ }
65
+ })
66
+ };
67
+ }
68
+
69
+
70
+ export {$701a24aa0da5b062$export$ea18c227d4417cc3 as useButton};
71
+ //# sourceMappingURL=useButton.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAsCM,SAAS,0CAAU,KAAqC,EAAE,GAAmB;IAClF,IAAI,eACF,cAAc,sBACd,UAAU,WACV,OAAO,gBACP,YAAY,cACZ,UAAU,aACV,SAAS,iBACT,aAAa,uBACb,mBAAmB,0BACnB,4BAA4B;IAC5B,sBAAsB,EACtB,aAAa;IACb,SAAS,iBAAiB,QAC1B,IAAI,UACJ,MAAM,OACN,GAAG,QACH,OAAO,UACR,GAAG;IACJ,IAAI;IACJ,IAAI,gBAAgB,UAClB,kBAAkB;cAChB;QACA,UAAU;IACZ;SAEA,kBAAkB;QAChB,MAAM;QACN,UAAU,aAAa,YAAY;QACnC,MAAM,gBAAgB,OAAO,aAAa,YAAY;QACtD,QAAQ,gBAAgB,MAAM,SAAS;QACvC,MAAM,gBAAgB,UAAU,OAAO;QACvC,UAAU,gBAAgB,UAAU,aAAa;QACjD,iBAAiB,CAAC,cAAc,gBAAgB,UAAU,YAAY;QACtE,KAAK,gBAAgB,MAAM,MAAM;IACnC;IAGF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;sBACrC;oBACA;uBACA;iBACA;mBACA;oBACA;6BACA;aACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,wBACF,eAAe,QAAQ,GAAG,aAAa,KAAK,eAAe,QAAQ;IAErE,IAAI,cAAc,CAAA,GAAA,iBAAS,EAAE,gBAAgB,YAAY,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAE/F,OAAO;mBACL;QACA,aAAa,CAAA,GAAA,iBAAS,EAAE,iBAAiB,aAAa;YACpD,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,gBAAgB,KAAK,CAAC,eAAe;YACrC,SAAS,CAAC;gBACR,IAAI,mBAAmB;oBACrB,kBAAkB;oBAClB,QAAQ,IAAI,CAAC;gBACf;YACF;QACF;IACF;AACF","sources":["packages/@react-aria/button/src/useButton.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n AnchorHTMLAttributes,\n ButtonHTMLAttributes,\n ElementType,\n HTMLAttributes,\n InputHTMLAttributes,\n RefObject\n} from 'react';\nimport {AriaButtonProps} from '@react-types/button';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useFocusable} from '@react-aria/focus';\nimport {usePress} from '@react-aria/interactions';\n\nexport interface AriaButtonOptions<E extends ElementType> extends Omit<AriaButtonProps<E>, 'children'> {}\n\nexport interface ButtonAria<T> {\n /** Props for the button element. */\n buttonProps: T,\n /** Whether the button is currently pressed. */\n isPressed: boolean\n}\n\n// Order with overrides is important: 'button' should be default\nexport function useButton(props: AriaButtonOptions<'button'>, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;\nexport function useButton(props: AriaButtonOptions<'a'>, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;\nexport function useButton(props: AriaButtonOptions<'div'>, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;\nexport function useButton(props: AriaButtonOptions<'input'>, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;\nexport function useButton(props: AriaButtonOptions<'span'>, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;\nexport function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;\n/**\n * Provides the behavior and accessibility implementation for a button component. Handles mouse, keyboard, and touch interactions,\n * focus behavior, and ARIA props for both native button elements and custom element types.\n * @param props - Props to be applied to the button.\n * @param ref - A ref to a DOM element for the button.\n */\nexport function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<any>): ButtonAria<HTMLAttributes<any>> {\n let {\n elementType = 'button',\n isDisabled,\n onPress,\n onPressStart,\n onPressEnd,\n onPressUp,\n onPressChange,\n preventFocusOnPress,\n // @ts-ignore - undocumented\n allowFocusWhenDisabled,\n // @ts-ignore\n onClick: deprecatedOnClick,\n href,\n target,\n rel,\n type = 'button'\n } = props;\n let additionalProps;\n if (elementType === 'button') {\n additionalProps = {\n type,\n disabled: isDisabled\n };\n } else {\n additionalProps = {\n role: 'button',\n tabIndex: isDisabled ? undefined : 0,\n href: elementType === 'a' && isDisabled ? undefined : href,\n target: elementType === 'a' ? target : undefined,\n type: elementType === 'input' ? type : undefined,\n disabled: elementType === 'input' ? isDisabled : undefined,\n 'aria-disabled': !isDisabled || elementType === 'input' ? undefined : isDisabled,\n rel: elementType === 'a' ? rel : undefined\n };\n }\n\n let {pressProps, isPressed} = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n onPressUp,\n isDisabled,\n preventFocusOnPress,\n ref\n });\n\n let {focusableProps} = useFocusable(props, ref);\n if (allowFocusWhenDisabled) {\n focusableProps.tabIndex = isDisabled ? -1 : focusableProps.tabIndex;\n }\n let buttonProps = mergeProps(focusableProps, pressProps, filterDOMProps(props, {labelable: true}));\n\n return {\n isPressed, // Used to indicate press state for visual\n buttonProps: mergeProps(additionalProps, buttonProps, {\n 'aria-haspopup': props['aria-haspopup'],\n 'aria-expanded': props['aria-expanded'],\n 'aria-controls': props['aria-controls'],\n 'aria-pressed': props['aria-pressed'],\n onClick: (e) => {\n if (deprecatedOnClick) {\n deprecatedOnClick(e);\n console.warn('onClick is deprecated, please use onPress');\n }\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useButton.module.js.map"}
@@ -0,0 +1,37 @@
1
+ var $988353faa005faf8$exports = require("./useButton.main.js");
2
+ var $4M9F2$reactariautils = require("@react-aria/utils");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "useToggleButton", () => $c49208f7d2aac50b$export$51e84d46ca0bc451);
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ function $c49208f7d2aac50b$export$51e84d46ca0bc451(props, state, ref) {
23
+ const { isSelected: isSelected } = state;
24
+ const { isPressed: isPressed, buttonProps: buttonProps } = (0, $988353faa005faf8$exports.useButton)({
25
+ ...props,
26
+ onPress: (0, $4M9F2$reactariautils.chain)(state.toggle, props.onPress)
27
+ }, ref);
28
+ return {
29
+ isPressed: isPressed,
30
+ buttonProps: (0, $4M9F2$reactariautils.mergeProps)(buttonProps, {
31
+ 'aria-pressed': isSelected
32
+ })
33
+ };
34
+ }
35
+
36
+
37
+ //# sourceMappingURL=useToggleButton.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA6BM,SAAS,0CAAgB,KAA2C,EAAE,KAAkB,EAAE,GAAmB;IAClH,MAAM,cAAC,UAAU,EAAC,GAAG;IACrB,MAAM,aAAC,SAAS,eAAE,WAAW,EAAC,GAAG,CAAA,GAAA,mCAAQ,EAAE;QACzC,GAAG,KAAK;QACR,SAAS,CAAA,GAAA,2BAAI,EAAE,MAAM,MAAM,EAAE,MAAM,OAAO;IAC5C,GAAG;IAEH,OAAO;mBACL;QACA,aAAa,CAAA,GAAA,gCAAS,EAAE,aAAa;YACnC,gBAAgB;QAClB;IACF;AACF","sources":["packages/@react-aria/button/src/useToggleButton.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n AnchorHTMLAttributes,\n ButtonHTMLAttributes,\n ElementType,\n HTMLAttributes,\n InputHTMLAttributes,\n RefObject\n} from 'react';\nimport {AriaToggleButtonProps} from '@react-types/button';\nimport {ButtonAria, useButton} from './useButton';\nimport {chain, mergeProps} from '@react-aria/utils';\nimport {DOMAttributes} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\n\nexport interface AriaToggleButtonOptions<E extends ElementType> extends Omit<AriaToggleButtonProps<E>, 'children'> {}\n\n// Order with overrides is important: 'button' should be default\nexport function useToggleButton(props: AriaToggleButtonOptions<'button'>, state: ToggleState, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'a'>, state: ToggleState, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'div'>, state: ToggleState, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'input'>, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'span'>, state: ToggleState, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<ElementType>, state: ToggleState, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;\n/**\n * Provides the behavior and accessibility implementation for a toggle button component.\n * ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.\n */\nexport function useToggleButton(props: AriaToggleButtonOptions<ElementType>, state: ToggleState, ref: RefObject<any>): ButtonAria<HTMLAttributes<any>> {\n const {isSelected} = state;\n const {isPressed, buttonProps} = useButton({\n ...props,\n onPress: chain(state.toggle, props.onPress)\n }, ref);\n\n return {\n isPressed,\n buttonProps: mergeProps(buttonProps, {\n 'aria-pressed': isSelected\n })\n };\n}\n"],"names":[],"version":3,"file":"useToggleButton.main.js.map"}
@@ -0,0 +1,32 @@
1
+ import {useButton as $701a24aa0da5b062$export$ea18c227d4417cc3} from "./useButton.mjs";
2
+ import {chain as $h7Tql$chain, mergeProps as $h7Tql$mergeProps} from "@react-aria/utils";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ function $55f54f7887471b58$export$51e84d46ca0bc451(props, state, ref) {
17
+ const { isSelected: isSelected } = state;
18
+ const { isPressed: isPressed, buttonProps: buttonProps } = (0, $701a24aa0da5b062$export$ea18c227d4417cc3)({
19
+ ...props,
20
+ onPress: (0, $h7Tql$chain)(state.toggle, props.onPress)
21
+ }, ref);
22
+ return {
23
+ isPressed: isPressed,
24
+ buttonProps: (0, $h7Tql$mergeProps)(buttonProps, {
25
+ 'aria-pressed': isSelected
26
+ })
27
+ };
28
+ }
29
+
30
+
31
+ export {$55f54f7887471b58$export$51e84d46ca0bc451 as useToggleButton};
32
+ //# sourceMappingURL=useToggleButton.module.js.map
@@ -0,0 +1,32 @@
1
+ import {useButton as $701a24aa0da5b062$export$ea18c227d4417cc3} from "./useButton.module.js";
2
+ import {chain as $h7Tql$chain, mergeProps as $h7Tql$mergeProps} from "@react-aria/utils";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ function $55f54f7887471b58$export$51e84d46ca0bc451(props, state, ref) {
17
+ const { isSelected: isSelected } = state;
18
+ const { isPressed: isPressed, buttonProps: buttonProps } = (0, $701a24aa0da5b062$export$ea18c227d4417cc3)({
19
+ ...props,
20
+ onPress: (0, $h7Tql$chain)(state.toggle, props.onPress)
21
+ }, ref);
22
+ return {
23
+ isPressed: isPressed,
24
+ buttonProps: (0, $h7Tql$mergeProps)(buttonProps, {
25
+ 'aria-pressed': isSelected
26
+ })
27
+ };
28
+ }
29
+
30
+
31
+ export {$55f54f7887471b58$export$51e84d46ca0bc451 as useToggleButton};
32
+ //# sourceMappingURL=useToggleButton.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA6BM,SAAS,0CAAgB,KAA2C,EAAE,KAAkB,EAAE,GAAmB;IAClH,MAAM,cAAC,UAAU,EAAC,GAAG;IACrB,MAAM,aAAC,SAAS,eAAE,WAAW,EAAC,GAAG,CAAA,GAAA,yCAAQ,EAAE;QACzC,GAAG,KAAK;QACR,SAAS,CAAA,GAAA,YAAI,EAAE,MAAM,MAAM,EAAE,MAAM,OAAO;IAC5C,GAAG;IAEH,OAAO;mBACL;QACA,aAAa,CAAA,GAAA,iBAAS,EAAE,aAAa;YACnC,gBAAgB;QAClB;IACF;AACF","sources":["packages/@react-aria/button/src/useToggleButton.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n AnchorHTMLAttributes,\n ButtonHTMLAttributes,\n ElementType,\n HTMLAttributes,\n InputHTMLAttributes,\n RefObject\n} from 'react';\nimport {AriaToggleButtonProps} from '@react-types/button';\nimport {ButtonAria, useButton} from './useButton';\nimport {chain, mergeProps} from '@react-aria/utils';\nimport {DOMAttributes} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\n\nexport interface AriaToggleButtonOptions<E extends ElementType> extends Omit<AriaToggleButtonProps<E>, 'children'> {}\n\n// Order with overrides is important: 'button' should be default\nexport function useToggleButton(props: AriaToggleButtonOptions<'button'>, state: ToggleState, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'a'>, state: ToggleState, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'div'>, state: ToggleState, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'input'>, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<'span'>, state: ToggleState, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;\nexport function useToggleButton(props: AriaToggleButtonOptions<ElementType>, state: ToggleState, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;\n/**\n * Provides the behavior and accessibility implementation for a toggle button component.\n * ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.\n */\nexport function useToggleButton(props: AriaToggleButtonOptions<ElementType>, state: ToggleState, ref: RefObject<any>): ButtonAria<HTMLAttributes<any>> {\n const {isSelected} = state;\n const {isPressed, buttonProps} = useButton({\n ...props,\n onPress: chain(state.toggle, props.onPress)\n }, ref);\n\n return {\n isPressed,\n buttonProps: mergeProps(buttonProps, {\n 'aria-pressed': isSelected\n })\n };\n}\n"],"names":[],"version":3,"file":"useToggleButton.module.js.map"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@react-aria/button",
3
+ "version": "3.0.0-nightly-641446f65-240905",
4
+ "description": "Spectrum UI components in React",
5
+ "license": "Apache-2.0",
6
+ "main": "dist/main.js",
7
+ "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
13
+ "types": "dist/types.d.ts",
14
+ "source": "src/index.ts",
15
+ "files": [
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "sideEffects": false,
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/adobe/react-spectrum"
23
+ },
24
+ "dependencies": {
25
+ "@react-aria/focus": "^3.0.0-nightly-641446f65-240905",
26
+ "@react-aria/interactions": "^3.0.0-nightly-641446f65-240905",
27
+ "@react-aria/utils": "^3.0.0-nightly-641446f65-240905",
28
+ "@react-stately/toggle": "^3.0.0-nightly-641446f65-240905",
29
+ "@react-types/button": "^3.0.0-nightly-641446f65-240905",
30
+ "@react-types/shared": "^3.0.0-nightly-641446f65-240905",
31
+ "@swc/helpers": "^0.5.0"
32
+ },
33
+ "peerDependencies": {
34
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "stableVersion": "3.9.8"
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ export {useButton} from './useButton';
13
+ export {useToggleButton} from './useToggleButton';
14
+ export type {AriaButtonOptions, ButtonAria} from './useButton';
15
+ export type {AriaButtonProps, AriaToggleButtonProps} from '@react-types/button';
@@ -0,0 +1,119 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {
14
+ AnchorHTMLAttributes,
15
+ ButtonHTMLAttributes,
16
+ ElementType,
17
+ HTMLAttributes,
18
+ InputHTMLAttributes,
19
+ RefObject
20
+ } from 'react';
21
+ import {AriaButtonProps} from '@react-types/button';
22
+ import {DOMAttributes} from '@react-types/shared';
23
+ import {filterDOMProps, mergeProps} from '@react-aria/utils';
24
+ import {useFocusable} from '@react-aria/focus';
25
+ import {usePress} from '@react-aria/interactions';
26
+
27
+ export interface AriaButtonOptions<E extends ElementType> extends Omit<AriaButtonProps<E>, 'children'> {}
28
+
29
+ export interface ButtonAria<T> {
30
+ /** Props for the button element. */
31
+ buttonProps: T,
32
+ /** Whether the button is currently pressed. */
33
+ isPressed: boolean
34
+ }
35
+
36
+ // Order with overrides is important: 'button' should be default
37
+ export function useButton(props: AriaButtonOptions<'button'>, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;
38
+ export function useButton(props: AriaButtonOptions<'a'>, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;
39
+ export function useButton(props: AriaButtonOptions<'div'>, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;
40
+ export function useButton(props: AriaButtonOptions<'input'>, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;
41
+ export function useButton(props: AriaButtonOptions<'span'>, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;
42
+ export function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;
43
+ /**
44
+ * Provides the behavior and accessibility implementation for a button component. Handles mouse, keyboard, and touch interactions,
45
+ * focus behavior, and ARIA props for both native button elements and custom element types.
46
+ * @param props - Props to be applied to the button.
47
+ * @param ref - A ref to a DOM element for the button.
48
+ */
49
+ export function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<any>): ButtonAria<HTMLAttributes<any>> {
50
+ let {
51
+ elementType = 'button',
52
+ isDisabled,
53
+ onPress,
54
+ onPressStart,
55
+ onPressEnd,
56
+ onPressUp,
57
+ onPressChange,
58
+ preventFocusOnPress,
59
+ // @ts-ignore - undocumented
60
+ allowFocusWhenDisabled,
61
+ // @ts-ignore
62
+ onClick: deprecatedOnClick,
63
+ href,
64
+ target,
65
+ rel,
66
+ type = 'button'
67
+ } = props;
68
+ let additionalProps;
69
+ if (elementType === 'button') {
70
+ additionalProps = {
71
+ type,
72
+ disabled: isDisabled
73
+ };
74
+ } else {
75
+ additionalProps = {
76
+ role: 'button',
77
+ tabIndex: isDisabled ? undefined : 0,
78
+ href: elementType === 'a' && isDisabled ? undefined : href,
79
+ target: elementType === 'a' ? target : undefined,
80
+ type: elementType === 'input' ? type : undefined,
81
+ disabled: elementType === 'input' ? isDisabled : undefined,
82
+ 'aria-disabled': !isDisabled || elementType === 'input' ? undefined : isDisabled,
83
+ rel: elementType === 'a' ? rel : undefined
84
+ };
85
+ }
86
+
87
+ let {pressProps, isPressed} = usePress({
88
+ onPressStart,
89
+ onPressEnd,
90
+ onPressChange,
91
+ onPress,
92
+ onPressUp,
93
+ isDisabled,
94
+ preventFocusOnPress,
95
+ ref
96
+ });
97
+
98
+ let {focusableProps} = useFocusable(props, ref);
99
+ if (allowFocusWhenDisabled) {
100
+ focusableProps.tabIndex = isDisabled ? -1 : focusableProps.tabIndex;
101
+ }
102
+ let buttonProps = mergeProps(focusableProps, pressProps, filterDOMProps(props, {labelable: true}));
103
+
104
+ return {
105
+ isPressed, // Used to indicate press state for visual
106
+ buttonProps: mergeProps(additionalProps, buttonProps, {
107
+ 'aria-haspopup': props['aria-haspopup'],
108
+ 'aria-expanded': props['aria-expanded'],
109
+ 'aria-controls': props['aria-controls'],
110
+ 'aria-pressed': props['aria-pressed'],
111
+ onClick: (e) => {
112
+ if (deprecatedOnClick) {
113
+ deprecatedOnClick(e);
114
+ console.warn('onClick is deprecated, please use onPress');
115
+ }
116
+ }
117
+ })
118
+ };
119
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {
14
+ AnchorHTMLAttributes,
15
+ ButtonHTMLAttributes,
16
+ ElementType,
17
+ HTMLAttributes,
18
+ InputHTMLAttributes,
19
+ RefObject
20
+ } from 'react';
21
+ import {AriaToggleButtonProps} from '@react-types/button';
22
+ import {ButtonAria, useButton} from './useButton';
23
+ import {chain, mergeProps} from '@react-aria/utils';
24
+ import {DOMAttributes} from '@react-types/shared';
25
+ import {ToggleState} from '@react-stately/toggle';
26
+
27
+ export interface AriaToggleButtonOptions<E extends ElementType> extends Omit<AriaToggleButtonProps<E>, 'children'> {}
28
+
29
+ // Order with overrides is important: 'button' should be default
30
+ export function useToggleButton(props: AriaToggleButtonOptions<'button'>, state: ToggleState, ref: RefObject<HTMLButtonElement | null>): ButtonAria<ButtonHTMLAttributes<HTMLButtonElement>>;
31
+ export function useToggleButton(props: AriaToggleButtonOptions<'a'>, state: ToggleState, ref: RefObject<HTMLAnchorElement | null>): ButtonAria<AnchorHTMLAttributes<HTMLAnchorElement>>;
32
+ export function useToggleButton(props: AriaToggleButtonOptions<'div'>, state: ToggleState, ref: RefObject<HTMLDivElement | null>): ButtonAria<HTMLAttributes<HTMLDivElement>>;
33
+ export function useToggleButton(props: AriaToggleButtonOptions<'input'>, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ButtonAria<InputHTMLAttributes<HTMLInputElement>>;
34
+ export function useToggleButton(props: AriaToggleButtonOptions<'span'>, state: ToggleState, ref: RefObject<HTMLSpanElement | null>): ButtonAria<HTMLAttributes<HTMLSpanElement>>;
35
+ export function useToggleButton(props: AriaToggleButtonOptions<ElementType>, state: ToggleState, ref: RefObject<Element | null>): ButtonAria<DOMAttributes>;
36
+ /**
37
+ * Provides the behavior and accessibility implementation for a toggle button component.
38
+ * ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.
39
+ */
40
+ export function useToggleButton(props: AriaToggleButtonOptions<ElementType>, state: ToggleState, ref: RefObject<any>): ButtonAria<HTMLAttributes<any>> {
41
+ const {isSelected} = state;
42
+ const {isPressed, buttonProps} = useButton({
43
+ ...props,
44
+ onPress: chain(state.toggle, props.onPress)
45
+ }, ref);
46
+
47
+ return {
48
+ isPressed,
49
+ buttonProps: mergeProps(buttonProps, {
50
+ 'aria-pressed': isSelected
51
+ })
52
+ };
53
+ }