@s-ui/react-molecule-select
Version:
`MoleculeSelect` is a customized `select` created from a combination of `AtomInput`, `MoleculeInputTags`, `MoleculeDropdownList` and `MoleculeDropdownOption`
44 lines • 1.95 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { Children, createContext, useContext } from 'react';
import cx from 'classnames';
import { inputSizes } from '@s-ui/react-atom-input';
import { atomTagSizes } from '@s-ui/react-atom-tag';
import { moleculeDropdownListSizes } from '@s-ui/react-molecule-dropdown-list';
export var BASE_CLASS = "sui-MoleculeSelect";
export var CLASS_FOCUS = BASE_CLASS + "--focus";
export var CLASS_DISABLED = "is-disabled";
export var CLASS_READ_ONLY = "is-read-only";
export var SELECT_STATES = {
ERROR: 'error',
SUCCESS: 'success',
ALERT: 'alert'
};
export var SELECT_INPUT_SIZES = _extends({}, inputSizes);
export var SELECT_TAG_SIZES = _extends({}, atomTagSizes);
export var SELECT_DROPDOWN_LIST_SIZES = _extends({}, moleculeDropdownListSizes);
export var DropdownContext = /*#__PURE__*/createContext();
export var useDropdown = function useDropdown() {
return useContext(DropdownContext);
};
export var ENABLED_KEYS = ['Enter', 'ArrowDown', 'ArrowUp'];
export var SELECTION_KEYS = [' ', 'Enter'];
export var getOptionData = function getOptionData(children) {
var optionsData = {};
Children.forEach(children, function (child) {
var _child$props = child.props,
children = _child$props.children,
value = _child$props.value;
optionsData[value] = children;
});
return optionsData;
};
export var getClassName = function getClassName(_ref) {
var _cx;
var state = _ref.state,
errorState = _ref.errorState,
disabled = _ref.disabled,
readOnly = _ref.readOnly,
className = _ref.className,
isBorderless = _ref.isBorderless;
return cx(BASE_CLASS, errorState && BASE_CLASS + "--" + SELECT_STATES.ERROR, errorState === false && BASE_CLASS + "--" + SELECT_STATES.SUCCESS, state && BASE_CLASS + "--" + state, isBorderless && BASE_CLASS + "--isBorderless", (_cx = {}, _cx[CLASS_DISABLED] = disabled, _cx[CLASS_READ_ONLY] = readOnly, _cx), className);
};