@semcore/select 3.0.13 → 3.0.14
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/CHANGELOG.md +6 -0
- package/lib/cjs/InputSearch.js +7 -7
- package/lib/cjs/Select.js +8 -8
- package/lib/es6/InputSearch.js +7 -7
- package/lib/es6/Select.js +8 -8
- package/package.json +1 -1
- package/src/InputSearch.jsx +0 -67
- package/src/Select.jsx +0 -291
- package/src/context.js +0 -3
- package/src/index.d.ts +0 -128
- package/src/index.js +0 -2
- package/src/style/input-search.shadow.css +0 -17
- package/src/style/select.shadow.css +0 -68
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
+
## [3.0.14] - 2022-07-21
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Version patch update due to children dependencies update (`@semcore/base-trigger` [3.0.8 ~> 3.0.9], `@semcore/icon` [2.28.0 ~> 2.29.0]).
|
|
10
|
+
|
|
5
11
|
## [3.0.13] - 2022-07-18
|
|
6
12
|
|
|
7
13
|
### Changed
|
package/lib/cjs/InputSearch.js
CHANGED
|
@@ -52,16 +52,16 @@ var style = (
|
|
|
52
52
|
/*__reshadow_css_start__*/
|
|
53
53
|
_core.sstyled.insert(
|
|
54
54
|
/*__inner_css_start__*/
|
|
55
|
-
".
|
|
55
|
+
".___SInputSearch_kmm9u_gg_._size_m_kmm9u_gg_{height:32px}.___SClose_kmm9u_gg_.__hide_kmm9u_gg_{visibility:hidden}.___SOutline_kmm9u_gg_{top:-1px;left:-1px;width:100%;border-radius:6px 6px 0 0}"
|
|
56
56
|
/*__inner_css_end__*/
|
|
57
|
-
, "
|
|
57
|
+
, "kmm9u_gg_")
|
|
58
58
|
/*__reshadow_css_end__*/
|
|
59
59
|
, {
|
|
60
|
-
"__SInputSearch": "
|
|
61
|
-
"_size_m": "
|
|
62
|
-
"__SClose": "
|
|
63
|
-
"_hide": "
|
|
64
|
-
"__SOutline": "
|
|
60
|
+
"__SInputSearch": "___SInputSearch_kmm9u_gg_",
|
|
61
|
+
"_size_m": "_size_m_kmm9u_gg_",
|
|
62
|
+
"__SClose": "___SClose_kmm9u_gg_",
|
|
63
|
+
"_hide": "__hide_kmm9u_gg_",
|
|
64
|
+
"__SOutline": "___SOutline_kmm9u_gg_"
|
|
65
65
|
});
|
|
66
66
|
var MAP_SIZE_TO_ICON = {
|
|
67
67
|
m: [_m["default"], _m2["default"]],
|
package/lib/cjs/Select.js
CHANGED
|
@@ -74,17 +74,17 @@ var style = (
|
|
|
74
74
|
/*__reshadow_css_start__*/
|
|
75
75
|
_core.sstyled.insert(
|
|
76
76
|
/*__inner_css_start__*/
|
|
77
|
-
".
|
|
77
|
+
".___SOptionCheckbox_kwu0e_gg_{margin-top:2px;margin-right:8px;margin-bottom:auto;position:relative;flex-shrink:0}.___SOptionCheckbox_kwu0e_gg_:before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:#fff;border:1px solid;border-radius:4px;border-color:#c4c7cf}.___SOptionCheckbox_kwu0e_gg_{width:16px;height:16px}.___SOptionCheckbox_kwu0e_gg_:after{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;margin:0 2px;background-repeat:no-repeat;background-position:50%;background-image:url(\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iNyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNOC4yNSAxTDQgNS4yNSAxLjc1IDMiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=\")}.___SOptionCheckbox_kwu0e_gg_._size_l_kwu0e_gg_{width:20px;height:20px}.___SOptionCheckbox_kwu0e_gg_._size_l_kwu0e_gg_:after{background-image:url(\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTEgMS41TDQuNzUgNy43NSAxIDQiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=\")}.___SOptionCheckbox_kwu0e_gg_.__checked_kwu0e_gg_:before{background-color:#008ff8;border-color:#008ff8}.___SOptionCheckbox_kwu0e_gg_.__theme_kwu0e_gg_:before{border-color:var(--theme_kwu0e)}.___SOptionCheckbox_kwu0e_gg_.__theme_kwu0e_gg_.__checked_kwu0e_gg_:before{background-color:var(--theme_kwu0e);border-color:var(--theme_kwu0e)}.___SOptionCheckbox_kwu0e_gg_.__selected_kwu0e_gg_{background-color:rgba(196,229,254,.7)}.___SOptionCheckbox_kwu0e_gg_.__selected_kwu0e_gg_:hover{background-color:rgba(196,229,254,.7)}"
|
|
78
78
|
/*__inner_css_end__*/
|
|
79
|
-
, "
|
|
79
|
+
, "kwu0e_gg_")
|
|
80
80
|
/*__reshadow_css_end__*/
|
|
81
81
|
, {
|
|
82
|
-
"__SOptionCheckbox": "
|
|
83
|
-
"_size_l": "
|
|
84
|
-
"_checked": "
|
|
85
|
-
"_theme": "
|
|
86
|
-
"--theme": "--
|
|
87
|
-
"_selected": "
|
|
82
|
+
"__SOptionCheckbox": "___SOptionCheckbox_kwu0e_gg_",
|
|
83
|
+
"_size_l": "_size_l_kwu0e_gg_",
|
|
84
|
+
"_checked": "__checked_kwu0e_gg_",
|
|
85
|
+
"_theme": "__theme_kwu0e_gg_",
|
|
86
|
+
"--theme": "--theme_kwu0e",
|
|
87
|
+
"_selected": "__selected_kwu0e_gg_"
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
function isSelectedOption(value, valueOption) {
|
package/lib/es6/InputSearch.js
CHANGED
|
@@ -28,16 +28,16 @@ var style = (
|
|
|
28
28
|
/*__reshadow_css_start__*/
|
|
29
29
|
_sstyled.insert(
|
|
30
30
|
/*__inner_css_start__*/
|
|
31
|
-
".
|
|
31
|
+
".___SInputSearch_kmm9u_gg_._size_m_kmm9u_gg_{height:32px}.___SClose_kmm9u_gg_.__hide_kmm9u_gg_{visibility:hidden}.___SOutline_kmm9u_gg_{top:-1px;left:-1px;width:100%;border-radius:6px 6px 0 0}"
|
|
32
32
|
/*__inner_css_end__*/
|
|
33
|
-
, "
|
|
33
|
+
, "kmm9u_gg_")
|
|
34
34
|
/*__reshadow_css_end__*/
|
|
35
35
|
, {
|
|
36
|
-
"__SInputSearch": "
|
|
37
|
-
"_size_m": "
|
|
38
|
-
"__SClose": "
|
|
39
|
-
"_hide": "
|
|
40
|
-
"__SOutline": "
|
|
36
|
+
"__SInputSearch": "___SInputSearch_kmm9u_gg_",
|
|
37
|
+
"_size_m": "_size_m_kmm9u_gg_",
|
|
38
|
+
"__SClose": "___SClose_kmm9u_gg_",
|
|
39
|
+
"_hide": "__hide_kmm9u_gg_",
|
|
40
|
+
"__SOutline": "___SOutline_kmm9u_gg_"
|
|
41
41
|
});
|
|
42
42
|
var MAP_SIZE_TO_ICON = {
|
|
43
43
|
m: [SearchM, CloseM],
|
package/lib/es6/Select.js
CHANGED
|
@@ -42,17 +42,17 @@ var style = (
|
|
|
42
42
|
/*__reshadow_css_start__*/
|
|
43
43
|
_sstyled.insert(
|
|
44
44
|
/*__inner_css_start__*/
|
|
45
|
-
".
|
|
45
|
+
".___SOptionCheckbox_kwu0e_gg_{margin-top:2px;margin-right:8px;margin-bottom:auto;position:relative;flex-shrink:0}.___SOptionCheckbox_kwu0e_gg_:before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:#fff;border:1px solid;border-radius:4px;border-color:#c4c7cf}.___SOptionCheckbox_kwu0e_gg_{width:16px;height:16px}.___SOptionCheckbox_kwu0e_gg_:after{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;margin:0 2px;background-repeat:no-repeat;background-position:50%;background-image:url(\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iNyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNOC4yNSAxTDQgNS4yNSAxLjc1IDMiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=\")}.___SOptionCheckbox_kwu0e_gg_._size_l_kwu0e_gg_{width:20px;height:20px}.___SOptionCheckbox_kwu0e_gg_._size_l_kwu0e_gg_:after{background-image:url(\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTEgMS41TDQuNzUgNy43NSAxIDQiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=\")}.___SOptionCheckbox_kwu0e_gg_.__checked_kwu0e_gg_:before{background-color:#008ff8;border-color:#008ff8}.___SOptionCheckbox_kwu0e_gg_.__theme_kwu0e_gg_:before{border-color:var(--theme_kwu0e)}.___SOptionCheckbox_kwu0e_gg_.__theme_kwu0e_gg_.__checked_kwu0e_gg_:before{background-color:var(--theme_kwu0e);border-color:var(--theme_kwu0e)}.___SOptionCheckbox_kwu0e_gg_.__selected_kwu0e_gg_{background-color:rgba(196,229,254,.7)}.___SOptionCheckbox_kwu0e_gg_.__selected_kwu0e_gg_:hover{background-color:rgba(196,229,254,.7)}"
|
|
46
46
|
/*__inner_css_end__*/
|
|
47
|
-
, "
|
|
47
|
+
, "kwu0e_gg_")
|
|
48
48
|
/*__reshadow_css_end__*/
|
|
49
49
|
, {
|
|
50
|
-
"__SOptionCheckbox": "
|
|
51
|
-
"_size_l": "
|
|
52
|
-
"_checked": "
|
|
53
|
-
"_theme": "
|
|
54
|
-
"--theme": "--
|
|
55
|
-
"_selected": "
|
|
50
|
+
"__SOptionCheckbox": "___SOptionCheckbox_kwu0e_gg_",
|
|
51
|
+
"_size_l": "_size_l_kwu0e_gg_",
|
|
52
|
+
"_checked": "__checked_kwu0e_gg_",
|
|
53
|
+
"_theme": "__theme_kwu0e_gg_",
|
|
54
|
+
"--theme": "--theme_kwu0e",
|
|
55
|
+
"_selected": "__selected_kwu0e_gg_"
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
function isSelectedOption(value, valueOption) {
|
package/package.json
CHANGED
package/src/InputSearch.jsx
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import createComponent, { Component, sstyled, Root } from '@semcore/core';
|
|
3
|
-
import SearchM from '@semcore/icon/Search/m';
|
|
4
|
-
import CloseM from '@semcore/icon/Close/m';
|
|
5
|
-
import Input from '@semcore/input';
|
|
6
|
-
import { selectContext } from './context';
|
|
7
|
-
|
|
8
|
-
import style from './style/input-search.shadow.css';
|
|
9
|
-
|
|
10
|
-
const MAP_SIZE_TO_ICON = {
|
|
11
|
-
m: [SearchM, CloseM],
|
|
12
|
-
l: [SearchM, CloseM],
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
class InputSearch extends Component {
|
|
16
|
-
static displayName = 'InputSearch';
|
|
17
|
-
|
|
18
|
-
static style = style;
|
|
19
|
-
|
|
20
|
-
static defaultProps = {
|
|
21
|
-
defaultValue: '',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
static contextType = selectContext;
|
|
25
|
-
|
|
26
|
-
uncontrolledProps() {
|
|
27
|
-
return {
|
|
28
|
-
value: null,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
handleClear = (e) => {
|
|
33
|
-
this.handlers.value('', e);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
render() {
|
|
37
|
-
const Value = Root;
|
|
38
|
-
const SInputSearch = Input;
|
|
39
|
-
const SClose = Input.Addon;
|
|
40
|
-
const { size, value, styles } = this.asProps;
|
|
41
|
-
const finalSize = size || this.context.size;
|
|
42
|
-
const hideClose = !value;
|
|
43
|
-
const IconClose = MAP_SIZE_TO_ICON[finalSize][1];
|
|
44
|
-
const IconSearch = MAP_SIZE_TO_ICON[finalSize][0];
|
|
45
|
-
|
|
46
|
-
return sstyled(styles)(
|
|
47
|
-
<SInputSearch size={finalSize} styles={styles}>
|
|
48
|
-
<Input.Addon>
|
|
49
|
-
<IconSearch />
|
|
50
|
-
</Input.Addon>
|
|
51
|
-
<Value render={Input.Value} autoFocus />
|
|
52
|
-
<SClose
|
|
53
|
-
role="button"
|
|
54
|
-
/* hide through css because the width of the input changes */
|
|
55
|
-
hide={hideClose}
|
|
56
|
-
aria-hidden={hideClose}
|
|
57
|
-
interactive
|
|
58
|
-
onClick={this.handleClear}
|
|
59
|
-
>
|
|
60
|
-
<IconClose />
|
|
61
|
-
</SClose>
|
|
62
|
-
</SInputSearch>,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default createComponent(InputSearch);
|
package/src/Select.jsx
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import cn from 'classnames';
|
|
3
|
-
import createComponent, { Component, Root, sstyled } from '@semcore/core';
|
|
4
|
-
import DropdownMenu from '@semcore/dropdown-menu';
|
|
5
|
-
import { ButtonTrigger } from '@semcore/base-trigger';
|
|
6
|
-
import Divider from '@semcore/divider';
|
|
7
|
-
import findComponent from '@semcore/utils/lib/findComponent';
|
|
8
|
-
import logger from '@semcore/utils/lib/logger';
|
|
9
|
-
import resolveColor from '@semcore/utils/lib/color';
|
|
10
|
-
import addonTextChildren from '@semcore/utils/lib/addonTextChildren';
|
|
11
|
-
import InputSearch from './InputSearch';
|
|
12
|
-
import { useBox } from '@semcore/flex-box';
|
|
13
|
-
import { selectContext } from './context';
|
|
14
|
-
|
|
15
|
-
import style from './style/select.shadow.css';
|
|
16
|
-
|
|
17
|
-
function isSelectedOption(value, valueOption) {
|
|
18
|
-
return Array.isArray(value) ? value.includes(valueOption) : valueOption === value;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function isEmptyValue(value) {
|
|
22
|
-
return Array.isArray(value) ? value.length === 0 : value === null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getEmptyValue(multiselect) {
|
|
26
|
-
return multiselect ? [] : null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class RootSelect extends Component {
|
|
30
|
-
static displayName = 'Select';
|
|
31
|
-
|
|
32
|
-
static style = style;
|
|
33
|
-
|
|
34
|
-
static defaultProps = (props) => ({
|
|
35
|
-
placeholder: props.multiselect ? 'Select options' : 'Select option',
|
|
36
|
-
size: 'm',
|
|
37
|
-
defaultValue: getEmptyValue(props.multiselect),
|
|
38
|
-
defaultVisible: false,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
firstSelectedOptionRef = React.createRef();
|
|
42
|
-
|
|
43
|
-
isScrolledToFirstOption = false;
|
|
44
|
-
|
|
45
|
-
uncontrolledProps() {
|
|
46
|
-
return {
|
|
47
|
-
visible: null,
|
|
48
|
-
value: null,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getTriggerProps() {
|
|
53
|
-
const {
|
|
54
|
-
size,
|
|
55
|
-
disabled,
|
|
56
|
-
visible,
|
|
57
|
-
state,
|
|
58
|
-
placeholder,
|
|
59
|
-
value,
|
|
60
|
-
options,
|
|
61
|
-
forwardRef,
|
|
62
|
-
name,
|
|
63
|
-
multiselect,
|
|
64
|
-
} = this.asProps;
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
empty: isEmptyValue(value),
|
|
68
|
-
size,
|
|
69
|
-
value,
|
|
70
|
-
name,
|
|
71
|
-
$hiddenRef: forwardRef,
|
|
72
|
-
multiselect,
|
|
73
|
-
state,
|
|
74
|
-
placeholder,
|
|
75
|
-
disabled,
|
|
76
|
-
active: visible,
|
|
77
|
-
onClear: this.handlerClear,
|
|
78
|
-
children: this.renderChildrenTrigger(value, options),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
getOptionProps(props) {
|
|
83
|
-
const { value } = this.asProps;
|
|
84
|
-
const selected = isSelectedOption(value, props.value);
|
|
85
|
-
const other = {};
|
|
86
|
-
this._optionSelected = selected;
|
|
87
|
-
|
|
88
|
-
if (selected && !this.isScrolledToFirstOption) {
|
|
89
|
-
other.ref = this.firstSelectedOptionRef;
|
|
90
|
-
this.isScrolledToFirstOption = true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
selected,
|
|
95
|
-
onClick: this.bindHandlerOptionClick(props.value),
|
|
96
|
-
...other,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
getOptionCheckboxProps(props) {
|
|
101
|
-
const { size } = this.asProps;
|
|
102
|
-
const hasOption = props.value === undefined;
|
|
103
|
-
const optionProps = hasOption ? {} : this.getOptionProps(props);
|
|
104
|
-
const selected = this._optionSelected;
|
|
105
|
-
this._optionSelected = null;
|
|
106
|
-
return {
|
|
107
|
-
...optionProps,
|
|
108
|
-
size,
|
|
109
|
-
selected,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
getDividerProps() {
|
|
114
|
-
return { my: 1 };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
renderChildrenTrigger(value, options) {
|
|
118
|
-
if (options) {
|
|
119
|
-
return [].concat(value).reduce((acc, value) => {
|
|
120
|
-
const selectedOption = options.find((o) => isSelectedOption(value, o.value));
|
|
121
|
-
if (!selectedOption) return acc;
|
|
122
|
-
if (acc.length) acc.push(', ');
|
|
123
|
-
acc.push(selectedOption.label || selectedOption.value);
|
|
124
|
-
return acc;
|
|
125
|
-
}, []);
|
|
126
|
-
}
|
|
127
|
-
return Array.isArray(value)
|
|
128
|
-
? value.reduce((acc, value) => {
|
|
129
|
-
if (acc.length) acc.push(', ');
|
|
130
|
-
acc.push(value);
|
|
131
|
-
return acc;
|
|
132
|
-
}, [])
|
|
133
|
-
: value;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
bindHandlerOptionClick = (optionValue) => (e) => {
|
|
137
|
-
let newValue = optionValue;
|
|
138
|
-
const { value, multiselect } = this.asProps;
|
|
139
|
-
if (Array.isArray(value)) {
|
|
140
|
-
if (value.includes(optionValue)) {
|
|
141
|
-
newValue = value.filter((v) => v !== optionValue);
|
|
142
|
-
} else {
|
|
143
|
-
newValue = value.concat(optionValue);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
this.handlers.value(newValue, e);
|
|
147
|
-
if (!multiselect) this.handlers.visible(false);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
handlerClear = (e) => {
|
|
151
|
-
const { value } = this.asProps;
|
|
152
|
-
const emptyValue = getEmptyValue(Array.isArray(value));
|
|
153
|
-
this.handlers.value(emptyValue, e);
|
|
154
|
-
this.handlers.visible(false);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
scrollToSelectedOption() {
|
|
158
|
-
setTimeout(() => {
|
|
159
|
-
this.firstSelectedOptionRef.current?.scrollIntoView({
|
|
160
|
-
block: 'nearest',
|
|
161
|
-
inline: 'nearest',
|
|
162
|
-
});
|
|
163
|
-
}, 0);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
componentDidMount() {
|
|
167
|
-
const { visible } = this.asProps;
|
|
168
|
-
if (visible) {
|
|
169
|
-
this.scrollToSelectedOption();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
componentDidUpdate(prevProps, prevState) {
|
|
174
|
-
const { visible } = this.asProps;
|
|
175
|
-
if (visible) {
|
|
176
|
-
this.isScrolledToFirstOption = false;
|
|
177
|
-
|
|
178
|
-
if (prevProps.visible === undefined) {
|
|
179
|
-
if (prevState.visible !== visible) this.scrollToSelectedOption();
|
|
180
|
-
} else {
|
|
181
|
-
if (prevProps.visible !== visible) this.scrollToSelectedOption();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
render() {
|
|
187
|
-
const { Children, options, multiselect, ...other } = this.asProps;
|
|
188
|
-
const advanceMode = findComponent(Children, [
|
|
189
|
-
Select.Trigger.displayName,
|
|
190
|
-
Select.Popper.displayName,
|
|
191
|
-
]);
|
|
192
|
-
|
|
193
|
-
logger.warn(
|
|
194
|
-
options && advanceMode,
|
|
195
|
-
"Don't use at the same time 'options' property and '<Select.Trigger/>/<Select.Popper/>'",
|
|
196
|
-
other['data-ui-name'] || Select.displayName,
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
if (options) {
|
|
200
|
-
return (
|
|
201
|
-
<Root render={DropdownMenu}>
|
|
202
|
-
<Select.Trigger {...other} />
|
|
203
|
-
<Select.Menu>
|
|
204
|
-
{options.map((option, i) => {
|
|
205
|
-
return (
|
|
206
|
-
<Select.Option key={i} {...option}>
|
|
207
|
-
{multiselect && <Select.Option.Checkbox />}
|
|
208
|
-
{option.children}
|
|
209
|
-
</Select.Option>
|
|
210
|
-
);
|
|
211
|
-
})}
|
|
212
|
-
</Select.Menu>
|
|
213
|
-
</Root>
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return (
|
|
218
|
-
<Root render={DropdownMenu}>
|
|
219
|
-
<Children />
|
|
220
|
-
</Root>
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function Trigger({ Children, name, value, $hiddenRef, tag: Tag = ButtonTrigger }) {
|
|
226
|
-
return (
|
|
227
|
-
<Root render={DropdownMenu.Trigger} tag={Tag} placeholder="Select option">
|
|
228
|
-
{addonTextChildren(
|
|
229
|
-
Children,
|
|
230
|
-
Tag.Text || ButtonTrigger.Text,
|
|
231
|
-
Tag.Addon || ButtonTrigger.Addon,
|
|
232
|
-
)}
|
|
233
|
-
{name && <input type="hidden" defaultValue={value} name={name} ref={$hiddenRef} />}
|
|
234
|
-
</Root>
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function Checkbox(props) {
|
|
239
|
-
const [SOptionCheckbox, componentProps] = useBox(props, props.forwardRef);
|
|
240
|
-
const { size, theme, selected } = props;
|
|
241
|
-
const styles = sstyled(props.styles);
|
|
242
|
-
|
|
243
|
-
const { className, style } = styles.cn('SOptionCheckbox', {
|
|
244
|
-
size,
|
|
245
|
-
'use:theme': resolveColor(theme),
|
|
246
|
-
checked: selected,
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
return (
|
|
250
|
-
<SOptionCheckbox
|
|
251
|
-
{...componentProps}
|
|
252
|
-
className={cn(className, componentProps.className) || undefined}
|
|
253
|
-
style={{ ...style, ...componentProps.style }}
|
|
254
|
-
/>
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const InputSearchWrapper = function () {
|
|
259
|
-
return <Root render={InputSearch} />;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
const Select = createComponent(
|
|
263
|
-
RootSelect,
|
|
264
|
-
{
|
|
265
|
-
Trigger: [
|
|
266
|
-
Trigger,
|
|
267
|
-
{
|
|
268
|
-
Addon: ButtonTrigger.Addon,
|
|
269
|
-
Text: ButtonTrigger.Text,
|
|
270
|
-
},
|
|
271
|
-
],
|
|
272
|
-
Popper: DropdownMenu.Popper,
|
|
273
|
-
List: DropdownMenu.List,
|
|
274
|
-
Menu: DropdownMenu.Menu,
|
|
275
|
-
Option: [
|
|
276
|
-
DropdownMenu.Item,
|
|
277
|
-
{
|
|
278
|
-
Addon: DropdownMenu.Item.Addon,
|
|
279
|
-
Checkbox,
|
|
280
|
-
},
|
|
281
|
-
],
|
|
282
|
-
OptionTitle: DropdownMenu.ItemTitle,
|
|
283
|
-
OptionHint: DropdownMenu.ItemHint,
|
|
284
|
-
Divider,
|
|
285
|
-
InputSearch: InputSearchWrapper,
|
|
286
|
-
Input: InputSearchWrapper,
|
|
287
|
-
},
|
|
288
|
-
{ parent: DropdownMenu, context: selectContext },
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
export default Select;
|
package/src/context.js
DELETED
package/src/index.d.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import React, { ComponentProps } from 'react';
|
|
2
|
-
import { CProps, Merge, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
3
|
-
import DropdownMenu, {
|
|
4
|
-
IDropdownMenuContext,
|
|
5
|
-
IDropdownMenuItemProps,
|
|
6
|
-
IDropdownMenuProps,
|
|
7
|
-
IDropdownMenuHandlers,
|
|
8
|
-
} from '@semcore/dropdown-menu';
|
|
9
|
-
import { ButtonTrigger, IBaseTriggerProps } from '@semcore/base-trigger';
|
|
10
|
-
import Divider from '@semcore/divider';
|
|
11
|
-
import { IInputValueProps } from '@semcore/input';
|
|
12
|
-
import { IBoxProps } from '@semcore/flex-box';
|
|
13
|
-
|
|
14
|
-
export interface ISelectInputSearch extends IInputValueProps {}
|
|
15
|
-
|
|
16
|
-
export type OptionValue = string | number;
|
|
17
|
-
export type SelectValue = string | number | Array<string | number> | null;
|
|
18
|
-
|
|
19
|
-
export type SelectOption = {
|
|
20
|
-
value: OptionValue;
|
|
21
|
-
children?: React.ReactNode;
|
|
22
|
-
label?: React.ReactNode;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export interface ISelectProps<T extends SelectValue = SelectValue>
|
|
26
|
-
extends IDropdownMenuProps,
|
|
27
|
-
IBaseTriggerProps {
|
|
28
|
-
/**
|
|
29
|
-
* Multiple select
|
|
30
|
-
*/
|
|
31
|
-
multiselect?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Options array
|
|
34
|
-
*/
|
|
35
|
-
options?: SelectOption[];
|
|
36
|
-
/**
|
|
37
|
-
* The value or values array selected by default when using multiselect
|
|
38
|
-
* @type SelectValue
|
|
39
|
-
*/
|
|
40
|
-
defaultValue?: T;
|
|
41
|
-
/**
|
|
42
|
-
* The selected value or values array when using multiselect
|
|
43
|
-
* @type SelectValue
|
|
44
|
-
*/
|
|
45
|
-
value?: T;
|
|
46
|
-
/**
|
|
47
|
-
* Callback on value change
|
|
48
|
-
* @type (value: SelectValue, e: React.SyntheticEvent) => boolean | void
|
|
49
|
-
*/
|
|
50
|
-
onChange?: (value: T, e: React.SyntheticEvent) => boolean | void;
|
|
51
|
-
/**
|
|
52
|
-
* Trigger placeholder at not selected value
|
|
53
|
-
*/
|
|
54
|
-
placeholder?: React.ReactNode;
|
|
55
|
-
/**
|
|
56
|
-
* Trigger state
|
|
57
|
-
*/
|
|
58
|
-
state?: 'normal' | 'valid' | 'invalid';
|
|
59
|
-
/**
|
|
60
|
-
* Disables select
|
|
61
|
-
*/
|
|
62
|
-
disabled?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Input name
|
|
65
|
-
*/
|
|
66
|
-
name?: string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface ISelectOption {
|
|
70
|
-
value?: string | number;
|
|
71
|
-
[key: string]: any;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface ISelectOptionProps extends IDropdownMenuItemProps {
|
|
75
|
-
/** Value of the option */
|
|
76
|
-
value: string | number;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface ISelectOptionCheckboxProps extends ISelectOptionProps {
|
|
80
|
-
/** Checkbox theme */
|
|
81
|
-
theme?: string;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
declare const InputSearch: <T>(props: ISelectInputSearch & T) => ReturnEl;
|
|
85
|
-
|
|
86
|
-
export interface ISelectContext extends IDropdownMenuContext {
|
|
87
|
-
getOptionProps: PropGetterFn;
|
|
88
|
-
getOptionCheckboxProps: PropGetterFn;
|
|
89
|
-
getDividerProps: PropGetterFn;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface ISelectHandlers extends IDropdownMenuHandlers {
|
|
93
|
-
value: (index: SelectValue) => void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
declare const Select: (<T, V extends SelectValue = SelectValue>(
|
|
97
|
-
props: CProps<ISelectProps<V> & T, ISelectContext, ISelectHandlers>,
|
|
98
|
-
) => ReturnEl) & {
|
|
99
|
-
Trigger: (<T>(
|
|
100
|
-
props: Merge<
|
|
101
|
-
ComponentProps<typeof DropdownMenu.Trigger>,
|
|
102
|
-
ComponentProps<typeof ButtonTrigger>
|
|
103
|
-
> &
|
|
104
|
-
T,
|
|
105
|
-
) => ReturnEl) & {
|
|
106
|
-
Addon: typeof ButtonTrigger.Addon;
|
|
107
|
-
Text: typeof ButtonTrigger.Text;
|
|
108
|
-
};
|
|
109
|
-
Popper: typeof DropdownMenu.Popper;
|
|
110
|
-
List: typeof DropdownMenu.List;
|
|
111
|
-
Menu: typeof DropdownMenu.Menu;
|
|
112
|
-
Option: (<T>(
|
|
113
|
-
props: CProps<ISelectOptionProps & T, ISelectContext, ISelectHandlers>,
|
|
114
|
-
) => ReturnEl) & {
|
|
115
|
-
Addon: typeof DropdownMenu.Item.Addon;
|
|
116
|
-
Checkbox: <T>(
|
|
117
|
-
props: CProps<IBoxProps & { theme?: string; selected?: boolean } & T>,
|
|
118
|
-
) => ReturnEl;
|
|
119
|
-
};
|
|
120
|
-
OptionTitle: typeof DropdownMenu.ItemTitle;
|
|
121
|
-
OptionHint: typeof DropdownMenu.ItemHint;
|
|
122
|
-
Divider: typeof Divider;
|
|
123
|
-
InputSearch: typeof InputSearch;
|
|
124
|
-
Input: typeof InputSearch;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export { InputSearch };
|
|
128
|
-
export default Select;
|
package/src/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
@import '@semcore/utils/style/var.css';
|
|
2
|
-
|
|
3
|
-
SInputSearch[size='m'] {
|
|
4
|
-
height: 32px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
SClose[hide] {
|
|
8
|
-
visibility: hidden;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/* Style for Input */
|
|
12
|
-
SOutline {
|
|
13
|
-
top: -1px;
|
|
14
|
-
left: -1px;
|
|
15
|
-
width: 100%;
|
|
16
|
-
border-radius: var(--rounded-m) var(--rounded-m) 0 0;
|
|
17
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
@import '@semcore/utils/style/var.css';
|
|
2
|
-
|
|
3
|
-
SOptionCheckbox {
|
|
4
|
-
margin-top: 2px;
|
|
5
|
-
margin-right: 8px;
|
|
6
|
-
margin-bottom: auto;
|
|
7
|
-
position: relative;
|
|
8
|
-
flex-shrink: 0;
|
|
9
|
-
|
|
10
|
-
&::before {
|
|
11
|
-
content: '';
|
|
12
|
-
position: absolute;
|
|
13
|
-
top: 0;
|
|
14
|
-
left: 0;
|
|
15
|
-
right: 0;
|
|
16
|
-
bottom: 0;
|
|
17
|
-
background: #fff;
|
|
18
|
-
border: 1px solid;
|
|
19
|
-
border-radius: var(--rounded-s);
|
|
20
|
-
border-color: var(--gray-200);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
width: 16px;
|
|
24
|
-
height: 16px;
|
|
25
|
-
|
|
26
|
-
&::after {
|
|
27
|
-
content: '';
|
|
28
|
-
position: absolute;
|
|
29
|
-
top: 0;
|
|
30
|
-
left: 0;
|
|
31
|
-
right: 0;
|
|
32
|
-
bottom: 0;
|
|
33
|
-
margin: 0 2px;
|
|
34
|
-
background-repeat: no-repeat;
|
|
35
|
-
background-position: center center;
|
|
36
|
-
background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAiIGhlaWdodD0iNyIgdmlld0JveD0iMCAwIDEwIDciIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik04LjI1IDFMNCA1LjI1TDEuNzUgMyIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
SOptionCheckbox[size='l'] {
|
|
41
|
-
width: 20px;
|
|
42
|
-
height: 20px;
|
|
43
|
-
&::after {
|
|
44
|
-
background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iOSIgdmlld0JveD0iMCAwIDEyIDkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik0xMSAxLjVMNC43NSA3Ljc1TDEgNCIgc3Ryb2tlPSJ3aGl0ZSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4KPC9zdmc+Cg==');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
SOptionCheckbox[checked]:before {
|
|
49
|
-
background-color: var(--blue-400);
|
|
50
|
-
border-color: var(--blue-400);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
SOptionCheckbox[theme]:before {
|
|
54
|
-
border-color: var(--theme);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
SOptionCheckbox[theme][checked]:before {
|
|
58
|
-
background-color: var(--theme);
|
|
59
|
-
border-color: var(--theme);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
SOptionCheckbox[selected] {
|
|
63
|
-
background-color: color-mod(var(--blue-100) a(70%));
|
|
64
|
-
|
|
65
|
-
&:hover {
|
|
66
|
-
background-color: color-mod(var(--blue-100) a(70%));
|
|
67
|
-
}
|
|
68
|
-
}
|