@react-aria/toggle 3.12.4 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {useToggle as $d2c8e2b0480f3f34$export$cbe85ee05b554577} from "./useToggle.mjs";
1
+ import {useToggle as $c8c63151410eb892$re_export$useToggle} from "react-aria/private/toggle/useToggle";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useToggle as $d2c8e2b0480f3f34$export$cbe85ee05b554577} from "./useToggl
13
13
  */
14
14
 
15
15
 
16
- export {$d2c8e2b0480f3f34$export$cbe85ee05b554577 as useToggle};
16
+ export {$c8c63151410eb892$re_export$useToggle as useToggle};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- var $ee1b638d33c90dcc$exports = require("./useToggle.main.js");
1
+ var $jomzG$reactariaprivatetoggleuseToggle = require("react-aria/private/toggle/useToggle");
2
2
 
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "useToggle", () => $ee1b638d33c90dcc$exports.useToggle);
8
+ $parcel$export(module.exports, "useToggle", function () { return $jomzG$reactariaprivatetoggleuseToggle.useToggle; });
9
9
  /*
10
10
  * Copyright 2020 Adobe. All rights reserved.
11
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toggle/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 */\n\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toggle/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 */\n\nexport {useToggle} from 'react-aria/private/toggle/useToggle';\n\nexport type {AriaToggleProps, ToggleAria} from 'react-aria/private/toggle/useToggle';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useToggle as $d2c8e2b0480f3f34$export$cbe85ee05b554577} from "./useToggle.module.js";
1
+ import {useToggle as $c8c63151410eb892$re_export$useToggle} from "react-aria/private/toggle/useToggle";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useToggle as $d2c8e2b0480f3f34$export$cbe85ee05b554577} from "./useToggl
13
13
  */
14
14
 
15
15
 
16
- export {$d2c8e2b0480f3f34$export$cbe85ee05b554577 as useToggle};
16
+ export {$c8c63151410eb892$re_export$useToggle as useToggle};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toggle/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 */\n\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/toggle/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 */\n\nexport {useToggle} from 'react-aria/private/toggle/useToggle';\n\nexport type {AriaToggleProps, ToggleAria} from 'react-aria/private/toggle/useToggle';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useToggle } from 'react-aria/private/toggle/useToggle';
2
+ export type { AriaToggleProps, ToggleAria } from 'react-aria/private/toggle/useToggle';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-aria/toggle",
3
- "version": "3.12.4",
3
+ "version": "3.13.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,12 +26,8 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/interactions": "^3.27.0",
30
- "@react-aria/utils": "^3.33.0",
31
- "@react-stately/toggle": "^3.9.4",
32
- "@react-types/checkbox": "^3.10.3",
33
- "@react-types/shared": "^3.33.0",
34
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-aria": "3.48.0"
35
31
  },
36
32
  "peerDependencies": {
37
33
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
@@ -40,5 +36,8 @@
40
36
  "publishConfig": {
41
37
  "access": "public"
42
38
  },
43
- "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
44
43
  }
package/src/index.ts CHANGED
@@ -10,6 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {useToggle} from './useToggle';
14
- export type {AriaToggleProps} from '@react-types/checkbox';
15
- export type {ToggleAria} from './useToggle';
13
+ export {useToggle} from 'react-aria/private/toggle/useToggle';
14
+
15
+ export type {AriaToggleProps, ToggleAria} from 'react-aria/private/toggle/useToggle';
package/dist/types.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { AriaToggleProps } from "@react-types/checkbox";
2
- import { InputHTMLAttributes, LabelHTMLAttributes } from "react";
3
- import { RefObject } from "@react-types/shared";
4
- import { ToggleState } from "@react-stately/toggle";
5
- export interface ToggleAria {
6
- /** Props to be spread on the label element. */
7
- labelProps: LabelHTMLAttributes<HTMLLabelElement>;
8
- /** Props to be spread on the input element. */
9
- inputProps: InputHTMLAttributes<HTMLInputElement>;
10
- /** Whether the toggle is selected. */
11
- isSelected: boolean;
12
- /** Whether the toggle is in a pressed state. */
13
- isPressed: boolean;
14
- /** Whether the toggle is disabled. */
15
- isDisabled: boolean;
16
- /** Whether the toggle is read only. */
17
- isReadOnly: boolean;
18
- /** Whether the toggle is invalid. */
19
- isInvalid: boolean;
20
- }
21
- /**
22
- * Handles interactions for toggle elements, e.g. Checkboxes and Switches.
23
- */
24
- export function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ToggleAria;
25
- export type { AriaToggleProps } from '@react-types/checkbox';
26
-
27
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;AAmBA;IACE,+CAA+C;IAC/C,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,+CAA+C;IAC/C,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,sCAAsC;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,gDAAgD;IAChD,SAAS,EAAE,OAAO,CAAC;IACnB,sCAAsC;IACtC,UAAU,EAAE,OAAO,CAAC;IACpB,uCAAuC;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;GAEG;AACH,0BAA0B,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,UAAU,CAsFzH;AChHD,YAAY,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/toggle/src/packages/@react-aria/toggle/src/useToggle.ts","packages/@react-aria/toggle/src/packages/@react-aria/toggle/src/index.ts","packages/@react-aria/toggle/src/index.ts"],"sourcesContent":[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 */\n\nexport {useToggle} from './useToggle';\nexport type {AriaToggleProps} from '@react-types/checkbox';\nexport type {ToggleAria} from './useToggle';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,92 +0,0 @@
1
- var $2jyrz$reactariautils = require("@react-aria/utils");
2
- var $2jyrz$reactariainteractions = require("@react-aria/interactions");
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, "useToggle", () => $ee1b638d33c90dcc$export$cbe85ee05b554577);
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 $ee1b638d33c90dcc$export$cbe85ee05b554577(props, state, ref) {
23
- let { isDisabled: isDisabled = false, isReadOnly: isReadOnly = false, value: value, name: name, form: form, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, validationState: validationState = 'valid', isInvalid: isInvalid, onPressStart: onPressStart, onPressEnd: onPressEnd, onPressChange: onPressChange, onPress: onPress, onPressUp: onPressUp, onClick: onClick } = props;
24
- let onChange = (e)=>{
25
- // since we spread props on label, onChange will end up there as well as in here.
26
- // so we have to stop propagation at the lowest level that we care about
27
- e.stopPropagation();
28
- state.setSelected(e.target.checked);
29
- };
30
- let hasChildren = children != null;
31
- let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
32
- if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') console.warn('If you do not provide children, you must specify an aria-label for accessibility');
33
- // Handle press state for keyboard interactions and cases where labelProps is not used.
34
- let { pressProps: pressProps, isPressed: isPressed } = (0, $2jyrz$reactariainteractions.usePress)({
35
- onPressStart: onPressStart,
36
- onPressEnd: onPressEnd,
37
- onPressChange: onPressChange,
38
- onPress: onPress,
39
- onPressUp: onPressUp,
40
- onClick: onClick,
41
- isDisabled: isDisabled
42
- });
43
- // Handle press state on the label.
44
- let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $2jyrz$reactariainteractions.usePress)({
45
- onPressStart: onPressStart,
46
- onPressEnd: onPressEnd,
47
- onPressChange: onPressChange,
48
- onPressUp: onPressUp,
49
- onClick: onClick,
50
- onPress (e) {
51
- var _ref_current;
52
- onPress === null || onPress === void 0 ? void 0 : onPress(e);
53
- state.toggle();
54
- (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
55
- },
56
- isDisabled: isDisabled || isReadOnly
57
- });
58
- let { focusableProps: focusableProps } = (0, $2jyrz$reactariainteractions.useFocusable)(props, ref);
59
- let interactions = (0, $2jyrz$reactariautils.mergeProps)(pressProps, focusableProps);
60
- let domProps = (0, $2jyrz$reactariautils.filterDOMProps)(props, {
61
- labelable: true
62
- });
63
- (0, $2jyrz$reactariautils.useFormReset)(ref, state.defaultSelected, state.setSelected);
64
- return {
65
- labelProps: (0, $2jyrz$reactariautils.mergeProps)(labelProps, {
66
- onClick: (e)=>e.preventDefault()
67
- }),
68
- inputProps: (0, $2jyrz$reactariautils.mergeProps)(domProps, {
69
- 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,
70
- 'aria-errormessage': props['aria-errormessage'],
71
- 'aria-controls': props['aria-controls'],
72
- 'aria-readonly': isReadOnly || undefined,
73
- onChange: onChange,
74
- disabled: isDisabled,
75
- ...value == null ? {} : {
76
- value: value
77
- },
78
- name: name,
79
- form: form,
80
- type: 'checkbox',
81
- ...interactions
82
- }),
83
- isSelected: state.isSelected,
84
- isPressed: isPressed || isLabelPressed,
85
- isDisabled: isDisabled,
86
- isReadOnly: isReadOnly,
87
- isInvalid: isInvalid || validationState === 'invalid'
88
- };
89
- }
90
-
91
-
92
- //# sourceMappingURL=useToggle.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAuC;IAC3G,IAAI,cACF,aAAa,mBACb,aAAa,cACb,KAAK,QACL,IAAI,QACJ,IAAI,YACJ,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,mBACjC,kBAAkB,oBAClB,SAAS,gBACT,YAAY,cACZ,UAAU,iBACV,aAAa,WACb,OAAO,aACP,SAAS,WACT,OAAO,EACR,GAAG;IAEJ,IAAI,WAAW,CAAC;QACd,iFAAiF;QACjF,wEAAwE;QACxE,EAAE,eAAe;QACjB,MAAM,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO;IACpC;IAEA,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,gBAAgB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC5D,QAAQ,IAAI,CAAC;IAGf,uFAAuF;IACvF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;sBACrC;oBACA;uBACA;iBACA;mBACA;iBACA;oBACA;IACF;IAEA,mCAAmC;IACnC,IAAI,EAAC,YAAY,UAAU,EAAE,WAAW,cAAc,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;sBACjE;oBACA;uBACA;mBACA;iBACA;QACA,SAAQ,CAAC;gBAGP;YAFA,oBAAA,8BAAA,QAAU;YACV,MAAM,MAAM;aACZ,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,KAAK;QACpB;QACA,YAAY,cAAc;IAC5B;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE,OAAO;IAC3C,IAAI,eAAe,CAAA,GAAA,gCAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,CAAA,GAAA,kCAAW,EAAE,KAAK,MAAM,eAAe,EAAE,MAAM,WAAW;IAE1D,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,cAAc;sBAC/B;YACA,UAAU;YACV,GAAI,SAAS,OAAO,CAAC,IAAI;uBAAC;YAAK,CAAC;kBAChC;kBACA;YACA,MAAM;YACN,GAAG,YAAY;QACjB;QACA,YAAY,MAAM,UAAU;QAC5B,WAAW,aAAa;oBACxB;oBACA;QACA,WAAW,aAAa,oBAAoB;IAC9C;AACF","sources":["packages/@react-aria/toggle/src/useToggle.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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable, usePress} from '@react-aria/interactions';\n\nexport interface ToggleAria {\n /** Props to be spread on the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to be spread on the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the toggle is selected. */\n isSelected: boolean,\n /** Whether the toggle is in a pressed state. */\n isPressed: boolean,\n /** Whether the toggle is disabled. */\n isDisabled: boolean,\n /** Whether the toggle is read only. */\n isReadOnly: boolean,\n /** Whether the toggle is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Handles interactions for toggle elements, e.g. Checkboxes and Switches.\n */\nexport function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ToggleAria {\n let {\n isDisabled = false,\n isReadOnly = false,\n value,\n name,\n form,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby,\n validationState = 'valid',\n isInvalid,\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n onPressUp,\n onClick\n } = props;\n\n let onChange = (e) => {\n // since we spread props on label, onChange will end up there as well as in here.\n // so we have to stop propagation at the lowest level that we care about\n e.stopPropagation();\n state.setSelected(e.target.checked);\n };\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n // Handle press state for keyboard interactions and cases where labelProps is not used.\n let {pressProps, isPressed} = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n onPressUp,\n onClick,\n isDisabled\n });\n\n // Handle press state on the label.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPressUp,\n onClick,\n onPress(e) {\n onPress?.(e);\n state.toggle();\n ref.current?.focus();\n },\n isDisabled: isDisabled || isReadOnly\n });\n\n let {focusableProps} = useFocusable(props, ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n\n useFormReset(ref, state.defaultSelected, state.setSelected);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-controls': props['aria-controls'],\n 'aria-readonly': isReadOnly || undefined,\n onChange,\n disabled: isDisabled,\n ...(value == null ? {} : {value}),\n name,\n form,\n type: 'checkbox',\n ...interactions\n }),\n isSelected: state.isSelected,\n isPressed: isPressed || isLabelPressed,\n isDisabled,\n isReadOnly,\n isInvalid: isInvalid || validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"useToggle.main.js.map"}
@@ -1,87 +0,0 @@
1
- import {mergeProps as $bvdLj$mergeProps, filterDOMProps as $bvdLj$filterDOMProps, useFormReset as $bvdLj$useFormReset} from "@react-aria/utils";
2
- import {usePress as $bvdLj$usePress, useFocusable as $bvdLj$useFocusable} from "@react-aria/interactions";
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 $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
17
- let { isDisabled: isDisabled = false, isReadOnly: isReadOnly = false, value: value, name: name, form: form, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, validationState: validationState = 'valid', isInvalid: isInvalid, onPressStart: onPressStart, onPressEnd: onPressEnd, onPressChange: onPressChange, onPress: onPress, onPressUp: onPressUp, onClick: onClick } = props;
18
- let onChange = (e)=>{
19
- // since we spread props on label, onChange will end up there as well as in here.
20
- // so we have to stop propagation at the lowest level that we care about
21
- e.stopPropagation();
22
- state.setSelected(e.target.checked);
23
- };
24
- let hasChildren = children != null;
25
- let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
26
- if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') console.warn('If you do not provide children, you must specify an aria-label for accessibility');
27
- // Handle press state for keyboard interactions and cases where labelProps is not used.
28
- let { pressProps: pressProps, isPressed: isPressed } = (0, $bvdLj$usePress)({
29
- onPressStart: onPressStart,
30
- onPressEnd: onPressEnd,
31
- onPressChange: onPressChange,
32
- onPress: onPress,
33
- onPressUp: onPressUp,
34
- onClick: onClick,
35
- isDisabled: isDisabled
36
- });
37
- // Handle press state on the label.
38
- let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $bvdLj$usePress)({
39
- onPressStart: onPressStart,
40
- onPressEnd: onPressEnd,
41
- onPressChange: onPressChange,
42
- onPressUp: onPressUp,
43
- onClick: onClick,
44
- onPress (e) {
45
- var _ref_current;
46
- onPress === null || onPress === void 0 ? void 0 : onPress(e);
47
- state.toggle();
48
- (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
49
- },
50
- isDisabled: isDisabled || isReadOnly
51
- });
52
- let { focusableProps: focusableProps } = (0, $bvdLj$useFocusable)(props, ref);
53
- let interactions = (0, $bvdLj$mergeProps)(pressProps, focusableProps);
54
- let domProps = (0, $bvdLj$filterDOMProps)(props, {
55
- labelable: true
56
- });
57
- (0, $bvdLj$useFormReset)(ref, state.defaultSelected, state.setSelected);
58
- return {
59
- labelProps: (0, $bvdLj$mergeProps)(labelProps, {
60
- onClick: (e)=>e.preventDefault()
61
- }),
62
- inputProps: (0, $bvdLj$mergeProps)(domProps, {
63
- 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,
64
- 'aria-errormessage': props['aria-errormessage'],
65
- 'aria-controls': props['aria-controls'],
66
- 'aria-readonly': isReadOnly || undefined,
67
- onChange: onChange,
68
- disabled: isDisabled,
69
- ...value == null ? {} : {
70
- value: value
71
- },
72
- name: name,
73
- form: form,
74
- type: 'checkbox',
75
- ...interactions
76
- }),
77
- isSelected: state.isSelected,
78
- isPressed: isPressed || isLabelPressed,
79
- isDisabled: isDisabled,
80
- isReadOnly: isReadOnly,
81
- isInvalid: isInvalid || validationState === 'invalid'
82
- };
83
- }
84
-
85
-
86
- export {$d2c8e2b0480f3f34$export$cbe85ee05b554577 as useToggle};
87
- //# sourceMappingURL=useToggle.module.js.map
@@ -1,87 +0,0 @@
1
- import {mergeProps as $bvdLj$mergeProps, filterDOMProps as $bvdLj$filterDOMProps, useFormReset as $bvdLj$useFormReset} from "@react-aria/utils";
2
- import {usePress as $bvdLj$usePress, useFocusable as $bvdLj$useFocusable} from "@react-aria/interactions";
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 $d2c8e2b0480f3f34$export$cbe85ee05b554577(props, state, ref) {
17
- let { isDisabled: isDisabled = false, isReadOnly: isReadOnly = false, value: value, name: name, form: form, children: children, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, validationState: validationState = 'valid', isInvalid: isInvalid, onPressStart: onPressStart, onPressEnd: onPressEnd, onPressChange: onPressChange, onPress: onPress, onPressUp: onPressUp, onClick: onClick } = props;
18
- let onChange = (e)=>{
19
- // since we spread props on label, onChange will end up there as well as in here.
20
- // so we have to stop propagation at the lowest level that we care about
21
- e.stopPropagation();
22
- state.setSelected(e.target.checked);
23
- };
24
- let hasChildren = children != null;
25
- let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
26
- if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') console.warn('If you do not provide children, you must specify an aria-label for accessibility');
27
- // Handle press state for keyboard interactions and cases where labelProps is not used.
28
- let { pressProps: pressProps, isPressed: isPressed } = (0, $bvdLj$usePress)({
29
- onPressStart: onPressStart,
30
- onPressEnd: onPressEnd,
31
- onPressChange: onPressChange,
32
- onPress: onPress,
33
- onPressUp: onPressUp,
34
- onClick: onClick,
35
- isDisabled: isDisabled
36
- });
37
- // Handle press state on the label.
38
- let { pressProps: labelProps, isPressed: isLabelPressed } = (0, $bvdLj$usePress)({
39
- onPressStart: onPressStart,
40
- onPressEnd: onPressEnd,
41
- onPressChange: onPressChange,
42
- onPressUp: onPressUp,
43
- onClick: onClick,
44
- onPress (e) {
45
- var _ref_current;
46
- onPress === null || onPress === void 0 ? void 0 : onPress(e);
47
- state.toggle();
48
- (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
49
- },
50
- isDisabled: isDisabled || isReadOnly
51
- });
52
- let { focusableProps: focusableProps } = (0, $bvdLj$useFocusable)(props, ref);
53
- let interactions = (0, $bvdLj$mergeProps)(pressProps, focusableProps);
54
- let domProps = (0, $bvdLj$filterDOMProps)(props, {
55
- labelable: true
56
- });
57
- (0, $bvdLj$useFormReset)(ref, state.defaultSelected, state.setSelected);
58
- return {
59
- labelProps: (0, $bvdLj$mergeProps)(labelProps, {
60
- onClick: (e)=>e.preventDefault()
61
- }),
62
- inputProps: (0, $bvdLj$mergeProps)(domProps, {
63
- 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,
64
- 'aria-errormessage': props['aria-errormessage'],
65
- 'aria-controls': props['aria-controls'],
66
- 'aria-readonly': isReadOnly || undefined,
67
- onChange: onChange,
68
- disabled: isDisabled,
69
- ...value == null ? {} : {
70
- value: value
71
- },
72
- name: name,
73
- form: form,
74
- type: 'checkbox',
75
- ...interactions
76
- }),
77
- isSelected: state.isSelected,
78
- isPressed: isPressed || isLabelPressed,
79
- isDisabled: isDisabled,
80
- isReadOnly: isReadOnly,
81
- isInvalid: isInvalid || validationState === 'invalid'
82
- };
83
- }
84
-
85
-
86
- export {$d2c8e2b0480f3f34$export$cbe85ee05b554577 as useToggle};
87
- //# sourceMappingURL=useToggle.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA6BM,SAAS,0CAAU,KAAsB,EAAE,KAAkB,EAAE,GAAuC;IAC3G,IAAI,cACF,aAAa,mBACb,aAAa,cACb,KAAK,QACL,IAAI,QACJ,IAAI,YACJ,QAAQ,EACR,cAAc,SAAS,EACvB,mBAAmB,cAAc,mBACjC,kBAAkB,oBAClB,SAAS,gBACT,YAAY,cACZ,UAAU,iBACV,aAAa,WACb,OAAO,aACP,SAAS,WACT,OAAO,EACR,GAAG;IAEJ,IAAI,WAAW,CAAC;QACd,iFAAiF;QACjF,wEAAwE;QACxE,EAAE,eAAe;QACjB,MAAM,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO;IACpC;IAEA,IAAI,cAAc,YAAY;IAC9B,IAAI,eAAe,aAAa,QAAQ,kBAAkB;IAC1D,IAAI,CAAC,eAAe,CAAC,gBAAgB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC5D,QAAQ,IAAI,CAAC;IAGf,uFAAuF;IACvF,IAAI,cAAC,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;sBACrC;oBACA;uBACA;iBACA;mBACA;iBACA;oBACA;IACF;IAEA,mCAAmC;IACnC,IAAI,EAAC,YAAY,UAAU,EAAE,WAAW,cAAc,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;sBACjE;oBACA;uBACA;mBACA;iBACA;QACA,SAAQ,CAAC;gBAGP;YAFA,oBAAA,8BAAA,QAAU;YACV,MAAM,MAAM;aACZ,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,KAAK;QACpB;QACA,YAAY,cAAc;IAC5B;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,eAAe,CAAA,GAAA,iBAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,CAAA,GAAA,mBAAW,EAAE,KAAK,MAAM,eAAe,EAAE,MAAM,WAAW;IAE1D,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EAAE,YAAY;YAAC,SAAS,CAAA,IAAK,EAAE,cAAc;QAAE;QACpE,YAAY,CAAA,GAAA,iBAAS,EAAE,UAAU;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,cAAc;sBAC/B;YACA,UAAU;YACV,GAAI,SAAS,OAAO,CAAC,IAAI;uBAAC;YAAK,CAAC;kBAChC;kBACA;YACA,MAAM;YACN,GAAG,YAAY;QACjB;QACA,YAAY,MAAM,UAAU;QAC5B,WAAW,aAAa;oBACxB;oBACA;QACA,WAAW,aAAa,oBAAoB;IAC9C;AACF","sources":["packages/@react-aria/toggle/src/useToggle.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 {AriaToggleProps} from '@react-types/checkbox';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {InputHTMLAttributes, LabelHTMLAttributes} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useFocusable, usePress} from '@react-aria/interactions';\n\nexport interface ToggleAria {\n /** Props to be spread on the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props to be spread on the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the toggle is selected. */\n isSelected: boolean,\n /** Whether the toggle is in a pressed state. */\n isPressed: boolean,\n /** Whether the toggle is disabled. */\n isDisabled: boolean,\n /** Whether the toggle is read only. */\n isReadOnly: boolean,\n /** Whether the toggle is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Handles interactions for toggle elements, e.g. Checkboxes and Switches.\n */\nexport function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ToggleAria {\n let {\n isDisabled = false,\n isReadOnly = false,\n value,\n name,\n form,\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby,\n validationState = 'valid',\n isInvalid,\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n onPressUp,\n onClick\n } = props;\n\n let onChange = (e) => {\n // since we spread props on label, onChange will end up there as well as in here.\n // so we have to stop propagation at the lowest level that we care about\n e.stopPropagation();\n state.setSelected(e.target.checked);\n };\n\n let hasChildren = children != null;\n let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;\n if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') {\n console.warn('If you do not provide children, you must specify an aria-label for accessibility');\n }\n\n // Handle press state for keyboard interactions and cases where labelProps is not used.\n let {pressProps, isPressed} = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPress,\n onPressUp,\n onClick,\n isDisabled\n });\n\n // Handle press state on the label.\n let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({\n onPressStart,\n onPressEnd,\n onPressChange,\n onPressUp,\n onClick,\n onPress(e) {\n onPress?.(e);\n state.toggle();\n ref.current?.focus();\n },\n isDisabled: isDisabled || isReadOnly\n });\n\n let {focusableProps} = useFocusable(props, ref);\n let interactions = mergeProps(pressProps, focusableProps);\n let domProps = filterDOMProps(props, {labelable: true});\n\n useFormReset(ref, state.defaultSelected, state.setSelected);\n\n return {\n labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),\n inputProps: mergeProps(domProps, {\n 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-controls': props['aria-controls'],\n 'aria-readonly': isReadOnly || undefined,\n onChange,\n disabled: isDisabled,\n ...(value == null ? {} : {value}),\n name,\n form,\n type: 'checkbox',\n ...interactions\n }),\n isSelected: state.isSelected,\n isPressed: isPressed || isLabelPressed,\n isDisabled,\n isReadOnly,\n isInvalid: isInvalid || validationState === 'invalid'\n };\n}\n"],"names":[],"version":3,"file":"useToggle.module.js.map"}
package/src/useToggle.ts DELETED
@@ -1,126 +0,0 @@
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 {AriaToggleProps} from '@react-types/checkbox';
14
- import {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';
15
- import {InputHTMLAttributes, LabelHTMLAttributes} from 'react';
16
- import {RefObject} from '@react-types/shared';
17
- import {ToggleState} from '@react-stately/toggle';
18
- import {useFocusable, usePress} from '@react-aria/interactions';
19
-
20
- export interface ToggleAria {
21
- /** Props to be spread on the label element. */
22
- labelProps: LabelHTMLAttributes<HTMLLabelElement>,
23
- /** Props to be spread on the input element. */
24
- inputProps: InputHTMLAttributes<HTMLInputElement>,
25
- /** Whether the toggle is selected. */
26
- isSelected: boolean,
27
- /** Whether the toggle is in a pressed state. */
28
- isPressed: boolean,
29
- /** Whether the toggle is disabled. */
30
- isDisabled: boolean,
31
- /** Whether the toggle is read only. */
32
- isReadOnly: boolean,
33
- /** Whether the toggle is invalid. */
34
- isInvalid: boolean
35
- }
36
-
37
- /**
38
- * Handles interactions for toggle elements, e.g. Checkboxes and Switches.
39
- */
40
- export function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefObject<HTMLInputElement | null>): ToggleAria {
41
- let {
42
- isDisabled = false,
43
- isReadOnly = false,
44
- value,
45
- name,
46
- form,
47
- children,
48
- 'aria-label': ariaLabel,
49
- 'aria-labelledby': ariaLabelledby,
50
- validationState = 'valid',
51
- isInvalid,
52
- onPressStart,
53
- onPressEnd,
54
- onPressChange,
55
- onPress,
56
- onPressUp,
57
- onClick
58
- } = props;
59
-
60
- let onChange = (e) => {
61
- // since we spread props on label, onChange will end up there as well as in here.
62
- // so we have to stop propagation at the lowest level that we care about
63
- e.stopPropagation();
64
- state.setSelected(e.target.checked);
65
- };
66
-
67
- let hasChildren = children != null;
68
- let hasAriaLabel = ariaLabel != null || ariaLabelledby != null;
69
- if (!hasChildren && !hasAriaLabel && process.env.NODE_ENV !== 'production') {
70
- console.warn('If you do not provide children, you must specify an aria-label for accessibility');
71
- }
72
-
73
- // Handle press state for keyboard interactions and cases where labelProps is not used.
74
- let {pressProps, isPressed} = usePress({
75
- onPressStart,
76
- onPressEnd,
77
- onPressChange,
78
- onPress,
79
- onPressUp,
80
- onClick,
81
- isDisabled
82
- });
83
-
84
- // Handle press state on the label.
85
- let {pressProps: labelProps, isPressed: isLabelPressed} = usePress({
86
- onPressStart,
87
- onPressEnd,
88
- onPressChange,
89
- onPressUp,
90
- onClick,
91
- onPress(e) {
92
- onPress?.(e);
93
- state.toggle();
94
- ref.current?.focus();
95
- },
96
- isDisabled: isDisabled || isReadOnly
97
- });
98
-
99
- let {focusableProps} = useFocusable(props, ref);
100
- let interactions = mergeProps(pressProps, focusableProps);
101
- let domProps = filterDOMProps(props, {labelable: true});
102
-
103
- useFormReset(ref, state.defaultSelected, state.setSelected);
104
-
105
- return {
106
- labelProps: mergeProps(labelProps, {onClick: e => e.preventDefault()}),
107
- inputProps: mergeProps(domProps, {
108
- 'aria-invalid': isInvalid || validationState === 'invalid' || undefined,
109
- 'aria-errormessage': props['aria-errormessage'],
110
- 'aria-controls': props['aria-controls'],
111
- 'aria-readonly': isReadOnly || undefined,
112
- onChange,
113
- disabled: isDisabled,
114
- ...(value == null ? {} : {value}),
115
- name,
116
- form,
117
- type: 'checkbox',
118
- ...interactions
119
- }),
120
- isSelected: state.isSelected,
121
- isPressed: isPressed || isLabelPressed,
122
- isDisabled,
123
- isReadOnly,
124
- isInvalid: isInvalid || validationState === 'invalid'
125
- };
126
- }