haya-select 1.0.15 → 1.0.16
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/package.json +1 -1
- package/src/select/index.jsx +28 -27
- package/src/select/option-group.jsx +16 -0
- package/src/select/option.jsx +31 -0
- package/src/select/style.scss +23 -10
package/package.json
CHANGED
package/src/select/index.jsx
CHANGED
|
@@ -6,7 +6,10 @@ import debounce from "debounce"
|
|
|
6
6
|
import EventListener from "@kaspernj/api-maker/src/event-listener"
|
|
7
7
|
import idForComponent from "@kaspernj/api-maker/src/inputs/id-for-component.mjs"
|
|
8
8
|
import nameForComponent from "@kaspernj/api-maker/src/inputs/name-for-component.mjs"
|
|
9
|
+
import Option from "./option"
|
|
10
|
+
import OptionGroup from "./option-group"
|
|
9
11
|
import PropTypes from "prop-types"
|
|
12
|
+
import React from "react"
|
|
10
13
|
|
|
11
14
|
const nameForComponentWithMultiple = (component) => {
|
|
12
15
|
let name = nameForComponent(component)
|
|
@@ -117,6 +120,7 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
117
120
|
<div
|
|
118
121
|
className={classNames("haya-select", className)}
|
|
119
122
|
data-id={idForComponent(this)}
|
|
123
|
+
data-toggles={Boolean(toggleOptions)}
|
|
120
124
|
{...restProps}
|
|
121
125
|
>
|
|
122
126
|
{opened &&
|
|
@@ -145,16 +149,25 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
145
149
|
</div>
|
|
146
150
|
}
|
|
147
151
|
{currentOptions.map((currentOption) =>
|
|
148
|
-
<div className="current-option" key={`current-value-${
|
|
149
|
-
{
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
<div className="current-option" key={currentOption.key || `current-value-${currentOption.value}`}>
|
|
153
|
+
{currentOption.type == "group" &&
|
|
154
|
+
<div style={{fontWeight: "bold"}}>
|
|
155
|
+
{currentOption.text}
|
|
156
|
+
</div>
|
|
157
|
+
}
|
|
158
|
+
{currentOption.type != "group" &&
|
|
159
|
+
<>
|
|
160
|
+
{nameForComponentWithMultiple(this) &&
|
|
161
|
+
<input
|
|
162
|
+
id={idForComponent(this)}
|
|
163
|
+
name={nameForComponentWithMultiple(this)}
|
|
164
|
+
type="hidden"
|
|
165
|
+
value={digg(currentOption, "value")}
|
|
166
|
+
/>
|
|
167
|
+
}
|
|
168
|
+
{this.presentOption(currentOption)}
|
|
169
|
+
</>
|
|
156
170
|
}
|
|
157
|
-
{this.presentOption(currentOption)}
|
|
158
171
|
</div>
|
|
159
172
|
)}
|
|
160
173
|
</>
|
|
@@ -208,21 +221,11 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
208
221
|
}
|
|
209
222
|
|
|
210
223
|
hayaSelectOption({key, loadedOption}) {
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
if (loadedOption.type == "group") {
|
|
225
|
+
return <OptionGroup key={key} option={loadedOption} />
|
|
226
|
+
}
|
|
213
227
|
|
|
214
|
-
return
|
|
215
|
-
<div
|
|
216
|
-
className="haya-select-option"
|
|
217
|
-
data-selected={selected}
|
|
218
|
-
data-value={digg(loadedOption, "value")}
|
|
219
|
-
key={key}
|
|
220
|
-
onClick={(e) => this.onOptionClicked(e, loadedOption)}
|
|
221
|
-
style={{cursor: "pointer"}}
|
|
222
|
-
>
|
|
223
|
-
{this.presentOption(loadedOption)}
|
|
224
|
-
</div>
|
|
225
|
-
)
|
|
228
|
+
return <Option currentOptions={this.state.currentOptions} key={key} option={loadedOption} onOptionClicked={this.onOptionClicked} presentOption={this.presentOption} />
|
|
226
229
|
}
|
|
227
230
|
|
|
228
231
|
loadOptionsFromArray(options, searchValue) {
|
|
@@ -270,9 +273,7 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
270
273
|
scrollLeft: document.documentElement.scrollLeft,
|
|
271
274
|
scrollTop: document.documentElement.scrollTop
|
|
272
275
|
},
|
|
273
|
-
() =>
|
|
274
|
-
digg(this, "searchTextInputRef", "current").focus()
|
|
275
|
-
}
|
|
276
|
+
() => digg(this, "searchTextInputRef", "current").focus()
|
|
276
277
|
)
|
|
277
278
|
}
|
|
278
279
|
|
|
@@ -321,7 +322,7 @@ export default class HayaSelect extends React.PureComponent {
|
|
|
321
322
|
<EventListener event="click" onCalled={this.onWindowClicked} target={window} />
|
|
322
323
|
{loadedOptions?.map((loadedOption) =>
|
|
323
324
|
this.hayaSelectOption({
|
|
324
|
-
key: `loaded-option-${
|
|
325
|
+
key: loadedOption.key || `loaded-option-${loadedOption.value}`,
|
|
325
326
|
loadedOption
|
|
326
327
|
})
|
|
327
328
|
)}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import PropTypes from "prop-types"
|
|
2
|
+
import React from "react"
|
|
3
|
+
|
|
4
|
+
export default class OptionGroup extends React.PureComponent {
|
|
5
|
+
static propTypes = {
|
|
6
|
+
option: PropTypes.object.isRequired
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
render() {
|
|
10
|
+
return (
|
|
11
|
+
<div className="haya-select--option-group">
|
|
12
|
+
{this.props.option.text}
|
|
13
|
+
</div>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {digs} from "diggerize"
|
|
2
|
+
import PropTypes from "prop-types"
|
|
3
|
+
import React from "react"
|
|
4
|
+
|
|
5
|
+
export default class Option extends React.PureComponent {
|
|
6
|
+
static propTypes = {
|
|
7
|
+
currentOptions: PropTypes.array.isRequired,
|
|
8
|
+
onOptionClicked: PropTypes.func.isRequired,
|
|
9
|
+
option: PropTypes.object.isRequired,
|
|
10
|
+
presentOption: PropTypes.func.isRequired
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
render() {
|
|
14
|
+
const {currentOptions, option} = digs(this.props, "currentOptions", "option")
|
|
15
|
+
const selected = Boolean(currentOptions.find((currentOption) => currentOption.value == option.value))
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div
|
|
19
|
+
className="haya-select-option"
|
|
20
|
+
data-selected={selected}
|
|
21
|
+
data-value={option.value}
|
|
22
|
+
onClick={this.onClick}
|
|
23
|
+
style={{cursor: "pointer"}}
|
|
24
|
+
>
|
|
25
|
+
{this.props.presentOption(option)}
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onClick = (e) => this.props.onOptionClicked(e, this.props.option)
|
|
31
|
+
}
|
package/src/select/style.scss
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
.haya-select
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
.haya-select {
|
|
2
|
+
.haya-select-current-selected {
|
|
3
|
+
display: flex;
|
|
4
|
+
background-color: #fff;
|
|
5
|
+
border: 1px solid #999;
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
padding: 5px;
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
&[data-opened="false"] {
|
|
10
|
+
border-radius: 4px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&[data-opened="true"] {
|
|
14
|
+
border-radius: 4px 4px 0 0;
|
|
15
|
+
}
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
.current-option + .current-option {
|
|
18
|
+
margin-left: 6px;
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
}
|
|
15
22
|
|
|
@@ -39,4 +46,10 @@
|
|
|
39
46
|
background-color: steelblue;
|
|
40
47
|
}
|
|
41
48
|
}
|
|
49
|
+
|
|
50
|
+
.haya-select--option-group {
|
|
51
|
+
padding: 4px 8px;
|
|
52
|
+
color: #000;
|
|
53
|
+
font-weight: bold;
|
|
54
|
+
}
|
|
42
55
|
}
|