@confi/conflux-react-ui-test-package
Version:
Modern and minimalist React UI library.
52 lines (46 loc) • 3.56 kB
JavaScript
import _JSXStyle from "styled-jsx/style";
import React, { useMemo } from 'react';
import withDefaults from '../utils/with-defaults';
import useTheme from '../styles/use-theme';
import { useAutoCompleteContext } from './auto-complete-context';
import Ellipsis from '../shared/ellipsis';
var defaultProps = {};
var getSizes = function getSizes(size) {
var fontSizes = {
mini: '.7rem',
small: '.75rem',
medium: '.875rem',
large: '1rem'
};
return fontSizes[size];
};
var AutoCompleteItem = function AutoCompleteItem(_ref) {
var identValue = _ref.value,
children = _ref.children;
var theme = useTheme();
var _useAutoCompleteConte = useAutoCompleteContext(),
value = _useAutoCompleteConte.value,
updateValue = _useAutoCompleteConte.updateValue,
size = _useAutoCompleteConte.size,
updateVisible = _useAutoCompleteConte.updateVisible;
var selectHandler = function selectHandler() {
updateValue && updateValue(identValue);
updateVisible && updateVisible(false);
};
var isActive = useMemo(function () {
return value === identValue;
}, [identValue, value]);
var fontSize = useMemo(function () {
return getSizes(size);
}, [size]);
return /*#__PURE__*/React.createElement("div", {
onClick: selectHandler,
className: _JSXStyle.dynamic([["868092965", [fontSize, theme.layout.gapHalf, theme.layout.gap, theme.palette.background, theme.palette.foreground, theme.layout.radius, theme.layout.radius, theme.layout.radius, theme.layout.radius, theme.palette.accents_1, theme.palette.accents_1, theme.palette.success]]]) + " " + "item ".concat(isActive ? 'active' : '')
}, /*#__PURE__*/React.createElement(Ellipsis, {
height: "calc(1.688 * ".concat(theme.layout.gap, ")")
}, children), /*#__PURE__*/React.createElement(_JSXStyle, {
id: "868092965",
dynamic: [fontSize, theme.layout.gapHalf, theme.layout.gap, theme.palette.background, theme.palette.foreground, theme.layout.radius, theme.layout.radius, theme.layout.radius, theme.layout.radius, theme.palette.accents_1, theme.palette.accents_1, theme.palette.success]
}, ".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:calc(1.688 * ").concat(theme.layout.gap, ");background-color:").concat(theme.palette.background, ";color:").concat(theme.palette.foreground, ";-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.layout.radius, ";border-top-right-radius:").concat(theme.layout.radius, ";}.item.__jsx-style-dynamic-selector:last-of-type{border-bottom-left-radius:").concat(theme.layout.radius, ";border-bottom-right-radius:").concat(theme.layout.radius, ";}.item.__jsx-style-dynamic-selector:hover{background-color:").concat(theme.palette.accents_1, ";}.item.active.__jsx-style-dynamic-selector{background-color:").concat(theme.palette.accents_1, ";color:").concat(theme.palette.success, ";}")));
};
export default withDefaults(AutoCompleteItem, defaultProps);