@react-stately/toggle 3.8.5 → 3.9.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/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useToggleState.main.js +5 -0
- package/dist/useToggleState.main.js.map +1 -1
- package/dist/useToggleState.mjs +5 -0
- package/dist/useToggleState.module.js +5 -0
- package/dist/useToggleState.module.js.map +1 -1
- package/package.json +5 -5
- package/src/useToggleState.ts +6 -0
package/dist/types.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { ToggleStateOptions };
|
|
|
4
4
|
export interface ToggleState {
|
|
5
5
|
/** Whether the toggle is selected. */
|
|
6
6
|
readonly isSelected: boolean;
|
|
7
|
+
/** Whether the toggle is selected by default. */
|
|
8
|
+
readonly defaultSelected: boolean;
|
|
7
9
|
/** Updates selection state. */
|
|
8
10
|
setSelected(isSelected: boolean): void;
|
|
9
11
|
/** Toggle the selection state. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;
|
|
1
|
+
{"mappings":";;AAgBA,OAAY,EAAC,kBAAkB,EAAC,CAAC;AAEjC;IACE,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,iDAAiD;IACjD,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAElC,+BAA+B;IAC/B,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvC,kCAAkC;IAClC,MAAM,IAAI,IAAI,CAAA;CACf;AAED;;GAEG;AACH,+BAA+B,KAAK,GAAE,kBAAuB,GAAG,WAAW,CA0B1E;AC7CD;IACE,uDAAuD;IACvD,aAAa,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IACtC,qDAAqD;IACrD,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,kEAAkE;IAClE,YAAY,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC7B,kEAAkE;IAClE,mBAAmB,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IACpC,yDAAyD;IACzD,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAC7C,sCAAsC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;IACE,uDAAuD;IACvD,QAAQ,CAAC,aAAa,EAAE,QAAQ,GAAG,UAAU,CAAC;IAE9C,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,yDAAyD;IACzD,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAE1B,8CAA8C;IAC9C,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAEjD,yCAAyC;IACzC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,oCAAoC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAkC7E;AC1ED,YAAY,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-stately/toggle/src/packages/@react-stately/toggle/src/useToggleState.ts","packages/@react-stately/toggle/src/packages/@react-stately/toggle/src/useToggleGroupState.ts","packages/@react-stately/toggle/src/packages/@react-stately/toggle/src/index.ts","packages/@react-stately/toggle/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 */\n\nexport {useToggleState} from './useToggleState';\nexport {useToggleGroupState} from './useToggleGroupState';\n\nexport type {ToggleProps} from '@react-types/checkbox';\nexport type {ToggleState, ToggleStateOptions} from './useToggleState';\nexport type {ToggleGroupProps, ToggleGroupState} from './useToggleGroupState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
var $g7qpO$reactstatelyutils = require("@react-stately/utils");
|
|
2
|
+
var $g7qpO$react = require("react");
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
function $parcel$export(e, n, v, s) {
|
|
@@ -17,19 +18,23 @@ $parcel$export(module.exports, "useToggleState", () => $d84f98b140466b44$export$
|
|
|
17
18
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
19
|
* governing permissions and limitations under the License.
|
|
19
20
|
*/
|
|
21
|
+
|
|
20
22
|
function $d84f98b140466b44$export$8042c6c013fd5226(props = {}) {
|
|
21
23
|
let { isReadOnly: isReadOnly } = props;
|
|
22
24
|
// have to provide an empty function so useControlledState doesn't throw a fit
|
|
23
25
|
// can't use useControlledState's prop calling because we need the event object from the change
|
|
24
26
|
let [isSelected, setSelected] = (0, $g7qpO$reactstatelyutils.useControlledState)(props.isSelected, props.defaultSelected || false, props.onChange);
|
|
27
|
+
let [initialValue] = (0, $g7qpO$react.useState)(isSelected);
|
|
25
28
|
function updateSelected(value) {
|
|
26
29
|
if (!isReadOnly) setSelected(value);
|
|
27
30
|
}
|
|
28
31
|
function toggleState() {
|
|
29
32
|
if (!isReadOnly) setSelected(!isSelected);
|
|
30
33
|
}
|
|
34
|
+
var _props_defaultSelected;
|
|
31
35
|
return {
|
|
32
36
|
isSelected: isSelected,
|
|
37
|
+
defaultSelected: (_props_defaultSelected = props.defaultSelected) !== null && _props_defaultSelected !== void 0 ? _props_defaultSelected : initialValue,
|
|
33
38
|
setSelected: updateSelected,
|
|
34
39
|
toggle: toggleState
|
|
35
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAyBM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,2CAAiB,EAAE,MAAM,UAAU,EAAE,MAAM,eAAe,IAAI,OAAO,MAAM,QAAQ;IACnH,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;QAImB;IAFnB,OAAO;oBACL;QACA,iBAAiB,CAAA,yBAAA,MAAM,eAAe,cAArB,oCAAA,yBAAyB;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/@react-stately/toggle/src/useToggleState.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 {ToggleStateOptions} from '@react-types/checkbox';\nimport {useControlledState} from '@react-stately/utils';\nimport {useState} from 'react';\n\nexport type {ToggleStateOptions};\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean,\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean,\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void,\n\n /** Toggle the selection state. */\n toggle(): void\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(props.isSelected, props.defaultSelected || false, props.onChange);\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.main.js.map"}
|
package/dist/useToggleState.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {useControlledState as $d8rik$useControlledState} from "@react-stately/utils";
|
|
2
|
+
import {useState as $d8rik$useState} from "react";
|
|
2
3
|
|
|
3
4
|
/*
|
|
4
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -11,19 +12,23 @@ import {useControlledState as $d8rik$useControlledState} from "@react-stately/ut
|
|
|
11
12
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
13
|
* governing permissions and limitations under the License.
|
|
13
14
|
*/
|
|
15
|
+
|
|
14
16
|
function $3017fa7ffdddec74$export$8042c6c013fd5226(props = {}) {
|
|
15
17
|
let { isReadOnly: isReadOnly } = props;
|
|
16
18
|
// have to provide an empty function so useControlledState doesn't throw a fit
|
|
17
19
|
// can't use useControlledState's prop calling because we need the event object from the change
|
|
18
20
|
let [isSelected, setSelected] = (0, $d8rik$useControlledState)(props.isSelected, props.defaultSelected || false, props.onChange);
|
|
21
|
+
let [initialValue] = (0, $d8rik$useState)(isSelected);
|
|
19
22
|
function updateSelected(value) {
|
|
20
23
|
if (!isReadOnly) setSelected(value);
|
|
21
24
|
}
|
|
22
25
|
function toggleState() {
|
|
23
26
|
if (!isReadOnly) setSelected(!isSelected);
|
|
24
27
|
}
|
|
28
|
+
var _props_defaultSelected;
|
|
25
29
|
return {
|
|
26
30
|
isSelected: isSelected,
|
|
31
|
+
defaultSelected: (_props_defaultSelected = props.defaultSelected) !== null && _props_defaultSelected !== void 0 ? _props_defaultSelected : initialValue,
|
|
27
32
|
setSelected: updateSelected,
|
|
28
33
|
toggle: toggleState
|
|
29
34
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {useControlledState as $d8rik$useControlledState} from "@react-stately/utils";
|
|
2
|
+
import {useState as $d8rik$useState} from "react";
|
|
2
3
|
|
|
3
4
|
/*
|
|
4
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -11,19 +12,23 @@ import {useControlledState as $d8rik$useControlledState} from "@react-stately/ut
|
|
|
11
12
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
13
|
* governing permissions and limitations under the License.
|
|
13
14
|
*/
|
|
15
|
+
|
|
14
16
|
function $3017fa7ffdddec74$export$8042c6c013fd5226(props = {}) {
|
|
15
17
|
let { isReadOnly: isReadOnly } = props;
|
|
16
18
|
// have to provide an empty function so useControlledState doesn't throw a fit
|
|
17
19
|
// can't use useControlledState's prop calling because we need the event object from the change
|
|
18
20
|
let [isSelected, setSelected] = (0, $d8rik$useControlledState)(props.isSelected, props.defaultSelected || false, props.onChange);
|
|
21
|
+
let [initialValue] = (0, $d8rik$useState)(isSelected);
|
|
19
22
|
function updateSelected(value) {
|
|
20
23
|
if (!isReadOnly) setSelected(value);
|
|
21
24
|
}
|
|
22
25
|
function toggleState() {
|
|
23
26
|
if (!isReadOnly) setSelected(!isSelected);
|
|
24
27
|
}
|
|
28
|
+
var _props_defaultSelected;
|
|
25
29
|
return {
|
|
26
30
|
isSelected: isSelected,
|
|
31
|
+
defaultSelected: (_props_defaultSelected = props.defaultSelected) !== null && _props_defaultSelected !== void 0 ? _props_defaultSelected : initialValue,
|
|
27
32
|
setSelected: updateSelected,
|
|
28
33
|
toggle: toggleState
|
|
29
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAyBM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,yBAAiB,EAAE,MAAM,UAAU,EAAE,MAAM,eAAe,IAAI,OAAO,MAAM,QAAQ;IACnH,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;QAImB;IAFnB,OAAO;oBACL;QACA,iBAAiB,CAAA,yBAAA,MAAM,eAAe,cAArB,oCAAA,yBAAyB;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/@react-stately/toggle/src/useToggleState.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 {ToggleStateOptions} from '@react-types/checkbox';\nimport {useControlledState} from '@react-stately/utils';\nimport {useState} from 'react';\n\nexport type {ToggleStateOptions};\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean,\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean,\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void,\n\n /** Toggle the selection state. */\n toggle(): void\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(props.isSelected, props.defaultSelected || false, props.onChange);\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/toggle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-stately/utils": "^3.10.
|
|
30
|
-
"@react-types/checkbox": "^3.
|
|
31
|
-
"@react-types/shared": "^3.
|
|
29
|
+
"@react-stately/utils": "^3.10.8",
|
|
30
|
+
"@react-types/checkbox": "^3.10.0",
|
|
31
|
+
"@react-types/shared": "^3.31.0",
|
|
32
32
|
"@swc/helpers": "^0.5.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "8b9348ff255e018b2dd9b27e2a45507cadfa1d35"
|
|
41
41
|
}
|
package/src/useToggleState.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import {ToggleStateOptions} from '@react-types/checkbox';
|
|
14
14
|
import {useControlledState} from '@react-stately/utils';
|
|
15
|
+
import {useState} from 'react';
|
|
15
16
|
|
|
16
17
|
export type {ToggleStateOptions};
|
|
17
18
|
|
|
@@ -19,6 +20,9 @@ export interface ToggleState {
|
|
|
19
20
|
/** Whether the toggle is selected. */
|
|
20
21
|
readonly isSelected: boolean,
|
|
21
22
|
|
|
23
|
+
/** Whether the toggle is selected by default. */
|
|
24
|
+
readonly defaultSelected: boolean,
|
|
25
|
+
|
|
22
26
|
/** Updates selection state. */
|
|
23
27
|
setSelected(isSelected: boolean): void,
|
|
24
28
|
|
|
@@ -35,6 +39,7 @@ export function useToggleState(props: ToggleStateOptions = {}): ToggleState {
|
|
|
35
39
|
// have to provide an empty function so useControlledState doesn't throw a fit
|
|
36
40
|
// can't use useControlledState's prop calling because we need the event object from the change
|
|
37
41
|
let [isSelected, setSelected] = useControlledState(props.isSelected, props.defaultSelected || false, props.onChange);
|
|
42
|
+
let [initialValue] = useState(isSelected);
|
|
38
43
|
|
|
39
44
|
function updateSelected(value) {
|
|
40
45
|
if (!isReadOnly) {
|
|
@@ -50,6 +55,7 @@ export function useToggleState(props: ToggleStateOptions = {}): ToggleState {
|
|
|
50
55
|
|
|
51
56
|
return {
|
|
52
57
|
isSelected,
|
|
58
|
+
defaultSelected: props.defaultSelected ?? initialValue,
|
|
53
59
|
setSelected: updateSelected,
|
|
54
60
|
toggle: toggleState
|
|
55
61
|
};
|