@smart-react-components/ui 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Select/Option.js CHANGED
@@ -27,4 +27,5 @@ const Option = ({ active, children, cursorKey, hasHover, hasWaveEffect, isDisabl
27
27
  const content = (react_1.default.createElement(DropdownItemElement_1.default, { cursor: `$cursor.${cursorKey}`, hasHover: hasHover, isActive: isActive(), isDisabled: isDisabled, isOutline: isOutline, isSoft: isSoft, palette: palette, onClick: handleOnClick }, children));
28
28
  return hasWaveEffect ? react_1.default.createElement(WaveEffect_1.default, { palette: waveEffectPalette }, content) : content;
29
29
  };
30
+ Option.displayName = 'Option';
30
31
  exports.default = Option;
@@ -19,4 +19,5 @@ const OptionGroup = ({ children, active, hasHover, hasWaveEffect, isDisabled, is
19
19
  setActive,
20
20
  waveEffectPalette }, (isDisabled && { isDisabled })));
21
21
  })));
22
+ OptionGroup.displayName = 'OptionGroup';
22
23
  exports.default = OptionGroup;
@@ -0,0 +1,34 @@
1
+ import { ChangeEvents } from '@smart-react-components/core/element-props/change-events';
2
+ import { FocusEvents } from '@smart-react-components/core/element-props/focus-events';
3
+ import { IntrinsicStyledCoreProps } from '@smart-react-components/core/element-props/intrinsic-styled-core-props';
4
+ import { KeyboardEvents } from '@smart-react-components/core/element-props/keyboard-events';
5
+ import { ContentElement, JSXChildren, JSXElementProps, PaletteProp, ResponsiveProp, SetState, ShapeProp, SizeProp } from '@smart-react-components/core/types';
6
+ import React from 'react';
7
+ export interface Props extends Partial<ResponsiveProp<'size', SizeProp>>, IntrinsicStyledCoreProps, ChangeEvents, FocusEvents, KeyboardEvents {
8
+ children: JSXChildren;
9
+ containerProps?: JSXElementProps;
10
+ dropdownProps?: JSXElementProps;
11
+ hasBorder?: boolean;
12
+ hasHover?: boolean;
13
+ hasWaveEffect?: boolean;
14
+ hasSpellCheck?: boolean;
15
+ inputProps?: JSXElementProps;
16
+ isBlock?: boolean;
17
+ isDisabled?: boolean;
18
+ isOutline?: boolean;
19
+ isReadOnly?: boolean;
20
+ isRequired?: boolean;
21
+ isSoft?: boolean;
22
+ label?: ContentElement;
23
+ leftAddon?: ContentElement;
24
+ palette?: PaletteProp;
25
+ placeholder?: string;
26
+ rightAddon?: ContentElement;
27
+ setValue: SetState<string>;
28
+ shape?: ShapeProp;
29
+ template?: JSX.Element;
30
+ value: string;
31
+ waveEffectPalette?: PaletteProp;
32
+ }
33
+ declare const SelectSearchBox: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLInputElement>>;
34
+ export default SelectSearchBox;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const element_props_1 = __importDefault(require("@smart-react-components/core/element-props"));
7
+ const change_events_1 = __importDefault(require("@smart-react-components/core/element-props/change-events"));
8
+ const focus_events_1 = __importDefault(require("@smart-react-components/core/element-props/focus-events"));
9
+ const intrinsic_styled_flex_props_1 = __importDefault(require("@smart-react-components/core/element-props/intrinsic-styled-flex-props"));
10
+ const intrinsic_styled_margin_props_1 = __importDefault(require("@smart-react-components/core/element-props/intrinsic-styled-margin-props"));
11
+ const intrinsic_styled_size_props_1 = __importDefault(require("@smart-react-components/core/element-props/intrinsic-styled-size-props"));
12
+ const keyboard_events_1 = __importDefault(require("@smart-react-components/core/element-props/keyboard-events"));
13
+ const react_1 = __importDefault(require("react"));
14
+ const styled_components_1 = require("styled-components");
15
+ const DropdownListElement_1 = __importDefault(require("../components/Dropdown/DropdownListElement"));
16
+ const wave_effect_1 = require("../util/wave-effect");
17
+ const Dropdown_1 = __importDefault(require("../Dropdown"));
18
+ const Input_1 = __importDefault(require("../Input"));
19
+ const SelectSearchBox = react_1.default.forwardRef((props, forwardRef) => {
20
+ const theme = (0, styled_components_1.useTheme)();
21
+ const [dropdownStatus, setDropdownStatus] = react_1.default.useState(false);
22
+ const lastOptionList = react_1.default.useRef([]);
23
+ const applySearch = react_1.default.useCallback((children, list, value) => {
24
+ children.forEach(item => {
25
+ switch (item.type.displayName) {
26
+ case 'Option':
27
+ if (!value || item.props.value.trim().toLowerCase().includes(value)) {
28
+ list.push(item);
29
+ }
30
+ break;
31
+ case 'OptionGroup':
32
+ const group = react_1.default.cloneElement(item, { children: [] });
33
+ if (item.props.children) {
34
+ applySearch(Array.isArray(item.props.children) ? item.props.children : [item.props.children], group.props.children, value);
35
+ }
36
+ if (group.props.children.length > 0) {
37
+ list.push(group);
38
+ }
39
+ break;
40
+ }
41
+ });
42
+ }, []);
43
+ const optionList = react_1.default.useMemo(() => {
44
+ /**
45
+ * Returns the same list when the dropdown gets closed since it is not needed to update during the closing animation.
46
+ */
47
+ if (!dropdownStatus && lastOptionList.current.length > 0) {
48
+ return lastOptionList.current;
49
+ }
50
+ const children = [];
51
+ const value = props.value.trim().toLowerCase();
52
+ applySearch(Array.isArray(props.children) ? props.children : [props.children], children, value);
53
+ if (dropdownStatus) {
54
+ lastOptionList.current = children;
55
+ }
56
+ return children;
57
+ }, [props.children, props.value, dropdownStatus]);
58
+ const waveEffectPalette = react_1.default.useMemo(() => (0, wave_effect_1.getWaveEffectPalette)(props, theme.$.vars.isDarkMode), [props.waveEffectPalette, props.palette, props.isOutline, props.isSoft, theme.$.vars.isDarkMode]);
59
+ const handleOptionClick = value => {
60
+ setDropdownStatus(false);
61
+ props.setValue(value);
62
+ };
63
+ return (react_1.default.createElement(Dropdown_1.default, { elementProps: props.dropdownProps, status: dropdownStatus, setStatus: setDropdownStatus },
64
+ react_1.default.createElement(Input_1.default, Object.assign({}, (0, element_props_1.default)(props, [change_events_1.default, focus_events_1.default, intrinsic_styled_flex_props_1.default, intrinsic_styled_margin_props_1.default, intrinsic_styled_size_props_1.default, keyboard_events_1.default]), { containerProps: props.containerProps, hasBorder: props.hasBorder, hasSpellCheck: props.hasSpellCheck, inputProps: props.inputProps, isBlock: props.isBlock, isDisabled: props.isDisabled, isOutline: props.isOutline, isReadOnly: props.isReadOnly, isRequired: props.isRequired, isSoft: props.isSoft, label: props.label, leftAddon: props.leftAddon, palette: props.palette, placeholder: props.placeholder, ref: forwardRef, rightAddon: props.rightAddon, setValue: props.setValue, shape: props.shape, size: props.size, sizeSm: props.sizeSm, sizeMd: props.sizeMd, sizeLg: props.sizeLg, sizeXl: props.sizeXl, template: props.template, value: props.value })),
65
+ react_1.default.createElement(DropdownListElement_1.default, { dropdownListSize: props.size, dropdownListSizeSm: props.sizeSm, dropdownListSizeMd: props.sizeMd, dropdownListSizeLg: props.sizeLg, dropdownListSizeXl: props.sizeXl, isOutline: props.isOutline, isSoft: props.isSoft, palette: props.palette }, optionList.map((item, idx) => {
66
+ var _a;
67
+ return item && react_1.default.cloneElement(item, Object.assign({ key: (_a = item.key) !== null && _a !== void 0 ? _a : idx, active: props.value, cursorKey: 'selectBox', hasHover: props.hasHover, hasWaveEffect: props.hasWaveEffect, isEmbedded: false, isOutline: props.isOutline, isSoft: props.isSoft, palette: props.palette, setActive: handleOptionClick, waveEffectPalette }, (props.isDisabled && { isDisabled: true })));
68
+ }))));
69
+ });
70
+ SelectSearchBox.defaultProps = {
71
+ containerProps: {},
72
+ dropdownProps: {},
73
+ hasHover: true,
74
+ hasWaveEffect: true,
75
+ isOutline: true,
76
+ palette: 'primary',
77
+ size: 'medium',
78
+ };
79
+ exports.default = SelectSearchBox;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-react-components/ui",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "license": "MIT",
5
5
  "main": "index.js",
6
6
  "description": "SRC UI includes React and Styled components.",
@@ -60,8 +60,7 @@
60
60
  "copy": "cp package.json lib/package.json && cp README.md lib/README.md && cp ../LICENSE lib/LICENSE",
61
61
  "dev": "tsc -w --outDir lib",
62
62
  "lint": "eslint src",
63
- "release": "../scripts/release.sh ui true",
64
- "release-no-version": "../scripts/release.sh ui false",
63
+ "release": "../scripts/release.sh ui",
65
64
  "test": "jest"
66
65
  },
67
66
  "devDependencies": {