@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
63 lines (61 loc) • 3.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.selectors = void 0;
var _store = require("@base-ui-components/utils/store");
var _itemEquality = require("../utils/itemEquality");
var _resolveValueLabel = require("../utils/resolveValueLabel");
const selectors = exports.selectors = {
id: (0, _store.createSelector)(state => state.id),
modal: (0, _store.createSelector)(state => state.modal),
multiple: (0, _store.createSelector)(state => state.multiple),
items: (0, _store.createSelector)(state => state.items),
itemToStringLabel: (0, _store.createSelector)(state => state.itemToStringLabel),
itemToStringValue: (0, _store.createSelector)(state => state.itemToStringValue),
isItemEqualToValue: (0, _store.createSelector)(state => state.isItemEqualToValue),
value: (0, _store.createSelector)(state => state.value),
open: (0, _store.createSelector)(state => state.open),
mounted: (0, _store.createSelector)(state => state.mounted),
forceMount: (0, _store.createSelector)(state => state.forceMount),
transitionStatus: (0, _store.createSelector)(state => state.transitionStatus),
touchModality: (0, _store.createSelector)(state => state.touchModality),
activeIndex: (0, _store.createSelector)(state => state.activeIndex),
selectedIndex: (0, _store.createSelector)(state => state.selectedIndex),
isActive: (0, _store.createSelector)((state, index) => state.activeIndex === index),
isSelected: (0, _store.createSelector)((state, index, candidate) => {
const comparer = state.isItemEqualToValue;
const storeValue = state.value;
if (state.multiple) {
return Array.isArray(storeValue) && storeValue.some(item => (0, _itemEquality.compareItemEquality)(item, candidate, comparer));
}
// `selectedIndex` is only updated after the items mount for the first time,
// the value check avoids a re-render for the initially selected item.
if (state.selectedIndex === index && state.selectedIndex !== null) {
return true;
}
return (0, _itemEquality.compareItemEquality)(storeValue, candidate, comparer);
}),
isSelectedByFocus: (0, _store.createSelector)((state, index) => {
return state.selectedIndex === index;
}),
popupProps: (0, _store.createSelector)(state => state.popupProps),
triggerProps: (0, _store.createSelector)(state => state.triggerProps),
triggerElement: (0, _store.createSelector)(state => state.triggerElement),
positionerElement: (0, _store.createSelector)(state => state.positionerElement),
listElement: (0, _store.createSelector)(state => state.listElement),
scrollUpArrowVisible: (0, _store.createSelector)(state => state.scrollUpArrowVisible),
scrollDownArrowVisible: (0, _store.createSelector)(state => state.scrollDownArrowVisible),
hasScrollArrows: (0, _store.createSelector)(state => state.hasScrollArrows),
serializedValue: (0, _store.createSelector)(state => {
const {
multiple,
value,
itemToStringValue
} = state;
if (multiple && Array.isArray(value) && value.length === 0) {
return '';
}
return (0, _resolveValueLabel.stringifyAsValue)(value, itemToStringValue);
})
};