@react-stately/toggle 3.9.1 → 3.9.2
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
CHANGED
|
@@ -16,7 +16,10 @@ export interface ToggleState {
|
|
|
16
16
|
*/
|
|
17
17
|
export function useToggleState(props?: ToggleStateOptions): ToggleState;
|
|
18
18
|
export interface ToggleGroupProps {
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Whether single or multiple selection is enabled.
|
|
21
|
+
* @default 'single'
|
|
22
|
+
*/
|
|
20
23
|
selectionMode?: 'single' | 'multiple';
|
|
21
24
|
/** Whether the collection allows empty selection. */
|
|
22
25
|
disallowEmptySelection?: boolean;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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;;;OAGG;IACH,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;AC7ED,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 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAgDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,2CAAiB,EACrD,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW;QAAC,MAAM,YAAY;KAAC,GAChG,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAAO;QAAC,MAAM,mBAAmB;KAAC,GACrH,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/@react-stately/toggle/src/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple',\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean,\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void,\n /** Whether all items are disabled. */\n isDisabled?: boolean\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple',\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean,\n \n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>,\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void,\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(() => props.selectedKeys ? new Set(props.selectedKeys) : undefined, [props.selectedKeys]),\n useMemo(() => props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set(), [props.defaultSelectedKeys]),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n \n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAgDM,SAAS,0CAAoB,KAAuB;IACzD,IAAI,iBAAC,gBAAgB,kCAAU,sBAAsB,cAAE,aAAa,OAAM,GAAG;IAC7E,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yBAAiB,EACrD,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WAAW;QAAC,MAAM,YAAY;KAAC,GAChG,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OAAO;QAAC,MAAM,mBAAmB;KAAC,GACrH,MAAM,iBAAiB;IAGzB,OAAO;uBACL;oBACA;sBACA;yBACA;QACA,WAAU,GAAG;YACX,IAAI;YACJ,IAAI,kBAAkB,YAAY;gBAChC,OAAO,IAAI,IAAI;gBACf,IAAI,KAAK,GAAG,CAAC,QAAS,CAAA,CAAC,0BAA0B,KAAK,IAAI,GAAG,CAAA,GAC3D,KAAK,MAAM,CAAC;qBAEZ,KAAK,GAAG,CAAC;YAEb,OACE,OAAO,IAAI,IAAI,aAAa,GAAG,CAAC,QAAQ,CAAC,yBAAyB,EAAE,GAAG;gBAAC;aAAI;YAG9E,gBAAgB;QAClB;QACA,aAAY,GAAG,EAAE,UAAU;YACzB,IAAI,eAAe,aAAa,GAAG,CAAC,MAClC,IAAI,CAAC,SAAS,CAAC;QAEnB;IACF;AACF","sources":["packages/@react-stately/toggle/src/useToggleGroupState.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {Key} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo} from 'react';\n\nexport interface ToggleGroupProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: 'single' | 'multiple',\n /** Whether the collection allows empty selection. */\n disallowEmptySelection?: boolean,\n /** The currently selected keys in the collection (controlled). */\n selectedKeys?: Iterable<Key>,\n /** The initial selected keys in the collection (uncontrolled). */\n defaultSelectedKeys?: Iterable<Key>,\n /** Handler that is called when the selection changes. */\n onSelectionChange?: (keys: Set<Key>) => void,\n /** Whether all items are disabled. */\n isDisabled?: boolean\n}\n\nexport interface ToggleGroupState {\n /** Whether single or multiple selection is enabled. */\n readonly selectionMode: 'single' | 'multiple',\n\n /** Whether all items are disabled. */\n readonly isDisabled: boolean,\n \n /** A set of keys for items that are selected. */\n readonly selectedKeys: Set<Key>,\n\n /** Toggles the selected state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Sets whether the given key is selected. */\n setSelected(key: Key, isSelected: boolean): void,\n\n /** Replaces the set of selected keys. */\n setSelectedKeys(keys: Set<Key>): void\n}\n\n/**\n * Manages state for a group of toggles.\n * It supports both single and multiple selected items.\n */\nexport function useToggleGroupState(props: ToggleGroupProps): ToggleGroupState {\n let {selectionMode = 'single', disallowEmptySelection, isDisabled = false} = props;\n let [selectedKeys, setSelectedKeys] = useControlledState(\n useMemo(() => props.selectedKeys ? new Set(props.selectedKeys) : undefined, [props.selectedKeys]),\n useMemo(() => props.defaultSelectedKeys ? new Set(props.defaultSelectedKeys) : new Set(), [props.defaultSelectedKeys]),\n props.onSelectionChange\n );\n\n return {\n selectionMode,\n isDisabled,\n selectedKeys,\n setSelectedKeys,\n toggleKey(key) {\n let keys: Set<Key>;\n if (selectionMode === 'multiple') {\n keys = new Set(selectedKeys);\n if (keys.has(key) && (!disallowEmptySelection || keys.size > 1)) {\n keys.delete(key);\n } else {\n keys.add(key);\n }\n } else {\n keys = new Set(selectedKeys.has(key) && !disallowEmptySelection ? [] : [key]);\n }\n \n setSelectedKeys(keys);\n },\n setSelected(key, isSelected) {\n if (isSelected !== selectedKeys.has(key)) {\n this.toggleKey(key);\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useToggleGroupState.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/toggle",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.2",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@react-stately/utils": "^3.10.8",
|
|
30
|
-
"@react-types/checkbox": "^3.10.
|
|
31
|
-
"@react-types/shared": "^3.32.
|
|
30
|
+
"@react-types/checkbox": "^3.10.2",
|
|
31
|
+
"@react-types/shared": "^3.32.1",
|
|
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": "0bda51183baa23306342af32a82012ea0fe0f2dc"
|
|
41
41
|
}
|
|
@@ -15,7 +15,10 @@ import {useControlledState} from '@react-stately/utils';
|
|
|
15
15
|
import {useMemo} from 'react';
|
|
16
16
|
|
|
17
17
|
export interface ToggleGroupProps {
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Whether single or multiple selection is enabled.
|
|
20
|
+
* @default 'single'
|
|
21
|
+
*/
|
|
19
22
|
selectionMode?: 'single' | 'multiple',
|
|
20
23
|
/** Whether the collection allows empty selection. */
|
|
21
24
|
disallowEmptySelection?: boolean,
|