UNPKG

@geezee/react-ui

Version:

Modern and minimalist React UI library.

63 lines (56 loc) 3.75 kB
import _JSXStyle from "styled-jsx/style"; import React, { useMemo } from 'react'; import FuzzyMatch from '../shared/fuzzy-match'; import useTheme from '../styles/use-theme'; import withDefaults from '../utils/with-defaults'; import { useAutoCompleteContext } from './auto-complete-context'; var defaultProps = { variant: 'line' }; var getSizes = function getSizes(size) { var fontSizes = { mini: '.7rem', small: '.75rem', medium: '.875rem', large: '1rem' }; return fontSizes[size]; }; var AutoCompleteItem = function AutoCompleteItem(_ref) { var variant = _ref.variant, label = _ref.label, children = _ref.children, isLabelOnly = _ref.isLabelOnly; var theme = useTheme(); var isSolid = variant === 'solid'; var _useAutoCompleteConte = useAutoCompleteContext(), value = _useAutoCompleteConte.value, onSelect = _useAutoCompleteConte.onSelect, size = _useAutoCompleteConte.size, updateVisible = _useAutoCompleteConte.updateVisible; var selectHandler = function selectHandler() { onSelect && onSelect(label); updateVisible && updateVisible(false); }; var fontSize = useMemo(function () { return getSizes(size); }, [size]); // The 'isLabelOnly' is only used inside the component, // Automatically adjust width when only label children is included. var itemHeight = useMemo(function () { if (isLabelOnly) return "calc(2.5 * ".concat(theme.layout.gap, ")"); return 'auto'; }, [isLabelOnly, theme.layout.gap]); return /*#__PURE__*/React.createElement("div", { onClick: selectHandler, className: _JSXStyle.dynamic([["2926508839", [fontSize, theme.layout.gapHalf, itemHeight, theme.palette.cNeutral7, theme.expressiveness.R2, theme.expressiveness.R2, theme.expressiveness.R2, theme.expressiveness.R2, theme.palette.cTheme1, theme.palette.cTheme6]]]) + " " + "item ".concat(isSolid ? 'solid' : 'line') }, isLabelOnly ? /*#__PURE__*/React.createElement(FuzzyMatch, { color: "primary", query: value || '', label: label, height: "calc(2.5 * ".concat(theme.layout.gap, ")") }) : children, /*#__PURE__*/React.createElement(_JSXStyle, { id: "2926508839", dynamic: [fontSize, theme.layout.gapHalf, itemHeight, theme.palette.cNeutral7, theme.expressiveness.R2, theme.expressiveness.R2, theme.expressiveness.R2, theme.expressiveness.R2, theme.palette.cTheme1, theme.palette.cTheme6] }, ".item.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;font-weight:normal;white-space:pre;font-size:".concat(fontSize, ";padding:0 ").concat(theme.layout.gapHalf, ";height:").concat(itemHeight, ";color:").concat(theme.palette.cNeutral7, ";-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;border:0;cursor:pointer;-webkit-transition:background 0.2s ease 0s,border-color 0.2s ease 0s;transition:background 0.2s ease 0s,border-color 0.2s ease 0s;}.item.__jsx-style-dynamic-selector:first-of-type{border-top-left-radius:").concat(theme.expressiveness.R2, ";border-top-right-radius:").concat(theme.expressiveness.R2, ";}.item.__jsx-style-dynamic-selector:last-of-type{border-bottom-left-radius:").concat(theme.expressiveness.R2, ";border-bottom-right-radius:").concat(theme.expressiveness.R2, ";}.item.__jsx-style-dynamic-selector:hover{background-color:").concat(theme.palette.cTheme1, ";}.item.active.__jsx-style-dynamic-selector{color:").concat(theme.palette.cTheme6, ";}"))); }; export default withDefaults(AutoCompleteItem, defaultProps);