Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-stately/list

Package Overview
Dependencies
Maintainers
1
Versions
795
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/list - npm Package Compare versions

Comparing version 3.0.2 to 3.1.0

src/useSingleSelectListState.ts

49

dist/main.js
var {
useControlledState
} = require("@react-stately/utils");
var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
var {
useCollection

@@ -15,2 +21,6 @@ } = require("@react-stately/collections");

function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
let $b42f1d5166481a4c34c86bbfb4215e1$var$_Symbol$iterator;

@@ -133,2 +143,41 @@ $b42f1d5166481a4c34c86bbfb4215e1$var$_Symbol$iterator = Symbol.iterator;

exports.useListState = useListState;
/**
* Provides state management for list-like components with single selection.
* Handles building a collection of items from props, and manages selection state.
*/
function useSingleSelectListState(props) {
let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey, props.onSelectionChange);
let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);
let {
collection,
disabledKeys,
selectionManager
} = useListState(_babelRuntimeHelpersExtends({}, props, {
selectionMode: 'single',
disallowEmptySelection: true,
selectedKeys,
onSelectionChange: keys => {
let key = keys.values().next().value; // Always fire onSelectionChange, even if the key is the same
// as the current key (useControlledState does not).
if (key === selectedKey && props.onSelectionChange) {
props.onSelectionChange(key);
}
setSelectedKey(key);
}
}));
let selectedItem = selectedKey ? collection.getItem(selectedKey) : null;
return {
collection,
disabledKeys,
selectionManager,
selectedKey,
setSelectedKey,
selectedItem
};
}
exports.useSingleSelectListState = useSingleSelectListState;
//# sourceMappingURL=main.js.map

@@ -0,1 +1,3 @@

import { useControlledState } from "@react-stately/utils";
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
import { useCollection } from "@react-stately/collections";

@@ -119,2 +121,39 @@ import { SelectionManager, useMultipleSelectionState } from "@react-stately/selection";

}
/**
* Provides state management for list-like components with single selection.
* Handles building a collection of items from props, and manages selection state.
*/
export function useSingleSelectListState(props) {
let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey, props.onSelectionChange);
let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);
let {
collection,
disabledKeys,
selectionManager
} = useListState(_babelRuntimeHelpersEsmExtends({}, props, {
selectionMode: 'single',
disallowEmptySelection: true,
selectedKeys,
onSelectionChange: keys => {
let key = keys.values().next().value; // Always fire onSelectionChange, even if the key is the same
// as the current key (useControlledState does not).
if (key === selectedKey && props.onSelectionChange) {
props.onSelectionChange(key);
}
setSelectedKey(key);
}
}));
let selectedItem = selectedKey ? collection.getItem(selectedKey) : null;
return {
collection,
disabledKeys,
selectionManager,
selectedKey,
setSelectedKey,
selectedItem
};
}
//# sourceMappingURL=module.js.map

17

dist/types.d.ts

@@ -1,2 +0,2 @@

import { Collection, CollectionBase, MultipleSelection, Node } from "@react-types/shared";
import { Collection, CollectionBase, MultipleSelection, Node, SingleSelection } from "@react-types/shared";
import { Key } from "react";

@@ -19,3 +19,18 @@ import { SelectionManager } from "@react-stately/selection";

export function useListState<T extends object>(props: ListProps<T>): ListState<T>;
export interface SingleSelectListProps<T> extends CollectionBase<T>, SingleSelection {
}
export interface SingleSelectListState<T> extends ListState<T> {
/** The key for the currently selected item. */
readonly selectedKey: Key;
/** Sets the selected key. */
setSelectedKey(key: Key): void;
/** The value of the currently selected item. */
readonly selectedItem: Node<T>;
}
/**
* Provides state management for list-like components with single selection.
* Handles building a collection of items from props, and manages selection state.
*/
export function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T>;
//# sourceMappingURL=types.d.ts.map

12

package.json
{
"name": "@react-stately/list",
"version": "3.0.2",
"version": "3.1.0",
"description": "Spectrum UI components in React",

@@ -21,6 +21,6 @@ "license": "Apache-2.0",

"@babel/runtime": "^7.6.2",
"@react-stately/collections": "^3.0.2",
"@react-stately/selection": "^3.0.2",
"@react-stately/utils": "^3.0.2",
"@react-types/shared": "^3.0.2"
"@react-stately/collections": "^3.1.0",
"@react-stately/selection": "^3.1.0",
"@react-stately/utils": "^3.1.0",
"@react-types/shared": "^3.1.0"
},

@@ -33,3 +33,3 @@ "peerDependencies": {

},
"gitHead": "05003506f02a0ec173f3448f1801cbdf12b47bc7"
"gitHead": "211099972fe75ee581892efd01a7f89dfb9cdf69"
}

@@ -6,3 +6,3 @@ /*

* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software distributed under

@@ -15,1 +15,2 @@ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS

export * from './useListState';
export * from './useSingleSelectListState';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc