haya-select 1.0.41 → 1.0.42
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 +76 -66
package/package.json
CHANGED
package/src/select/index.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {anythingDifferent} from "set-state-compare/src/diff-utils"
|
|
2
2
|
import config from "../config.js"
|
|
3
|
-
import {digg, digs} from "diggerize"
|
|
3
|
+
import {dig, digg, digs} from "diggerize"
|
|
4
4
|
import debounce from "debounce"
|
|
5
5
|
import idForComponent from "@kaspernj/api-maker/src/inputs/id-for-component.mjs"
|
|
6
6
|
import nameForComponent from "@kaspernj/api-maker/src/inputs/name-for-component.mjs"
|
|
@@ -44,6 +44,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
44
44
|
placeholder: PropTypes.node,
|
|
45
45
|
search: PropTypes.bool.isRequired,
|
|
46
46
|
selectContainerStyle: PropTypes.object,
|
|
47
|
+
styles: PropTypes.object,
|
|
47
48
|
toggled: PropTypes.object,
|
|
48
49
|
toggleOptions: PropTypes.arrayOf(PropTypes.shape({
|
|
49
50
|
icon: PropTypes.string.isRequired,
|
|
@@ -166,62 +167,44 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
166
167
|
|
|
167
168
|
render() {
|
|
168
169
|
const {currentSelectedRef, endOfSelectRef} = this.tt
|
|
169
|
-
const {
|
|
170
|
-
attribute,
|
|
171
|
-
className,
|
|
172
|
-
defaultToggled,
|
|
173
|
-
defaultValue,
|
|
174
|
-
defaultValues,
|
|
175
|
-
id,
|
|
176
|
-
model,
|
|
177
|
-
multiple,
|
|
178
|
-
name,
|
|
179
|
-
onChange,
|
|
180
|
-
onOptionsClosed,
|
|
181
|
-
options,
|
|
182
|
-
placeholder,
|
|
183
|
-
search,
|
|
184
|
-
selectContainerStyle,
|
|
185
|
-
toggleOptions,
|
|
186
|
-
...restProps
|
|
187
|
-
} = this.props
|
|
170
|
+
const {className, placeholder, toggleOptions} = this.props
|
|
188
171
|
const {opened, optionsPlacement} = this.s
|
|
189
172
|
const currentOptions = this.getCurrentOptions()
|
|
190
173
|
const BodyPortal = config.getBodyPortal()
|
|
191
174
|
|
|
192
|
-
const selectContainerStyleActual =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
selectContainerStyle
|
|
206
|
-
)
|
|
175
|
+
const selectContainerStyleActual = this.stylingFor("selectContainer", {
|
|
176
|
+
display: "flex",
|
|
177
|
+
flexDirection: "row",
|
|
178
|
+
alignItems: "center",
|
|
179
|
+
backgroundColor: "#fff",
|
|
180
|
+
border: "1px solid #999",
|
|
181
|
+
borderRadius: 4,
|
|
182
|
+
color: "#000",
|
|
183
|
+
cursor: "pointer",
|
|
184
|
+
paddingTop: 5,
|
|
185
|
+
paddingBottom: 5,
|
|
186
|
+
paddingLeft: 5
|
|
187
|
+
})
|
|
207
188
|
|
|
208
189
|
if (opened) {
|
|
209
190
|
if (optionsPlacement == "above") {
|
|
210
191
|
selectContainerStyleActual.borderTopLeftRadius = 0
|
|
211
192
|
selectContainerStyleActual.borderTopRightRadius = 0
|
|
212
|
-
selectContainerStyleActual.borderBottomRightRadius =
|
|
213
|
-
selectContainerStyleActual.borderBottomLeftRadius =
|
|
193
|
+
selectContainerStyleActual.borderBottomRightRadius = selectContainerStyleActual.borderRadius
|
|
194
|
+
selectContainerStyleActual.borderBottomLeftRadius = selectContainerStyleActual.borderRadius
|
|
195
|
+
|
|
196
|
+
delete selectContainerStyleActual.borderRadius
|
|
214
197
|
} else if (optionsPlacement == "below") {
|
|
215
|
-
selectContainerStyleActual.borderTopLeftRadius =
|
|
216
|
-
selectContainerStyleActual.borderTopRightRadius =
|
|
198
|
+
selectContainerStyleActual.borderTopLeftRadius = selectContainerStyleActual.borderRadius
|
|
199
|
+
selectContainerStyleActual.borderTopRightRadius = selectContainerStyleActual.borderRadius
|
|
217
200
|
selectContainerStyleActual.borderBottomRightRadius = 0
|
|
218
201
|
selectContainerStyleActual.borderBottomLeftRadius = 0
|
|
202
|
+
|
|
203
|
+
delete selectContainerStyleActual.borderRadius
|
|
219
204
|
}
|
|
220
|
-
} else {
|
|
221
|
-
selectContainerStyleActual.borderRadius = 4
|
|
222
205
|
}
|
|
223
206
|
|
|
224
|
-
const chevronStyle = {fontSize: 24}
|
|
207
|
+
const chevronStyle = this.stylingFor("chevron", {fontSize: 24})
|
|
225
208
|
|
|
226
209
|
if (opened) {
|
|
227
210
|
chevronStyle.marginBottom = -9
|
|
@@ -231,8 +214,15 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
231
214
|
|
|
232
215
|
return (
|
|
233
216
|
<View
|
|
234
|
-
dataSet={{
|
|
235
|
-
|
|
217
|
+
dataSet={{
|
|
218
|
+
class: className,
|
|
219
|
+
component: "haya-select",
|
|
220
|
+
id: idForComponent(this),
|
|
221
|
+
opened,
|
|
222
|
+
optionsPlacement,
|
|
223
|
+
toggles: Boolean(toggleOptions)
|
|
224
|
+
}}
|
|
225
|
+
style={this.stylingFor("main")}
|
|
236
226
|
>
|
|
237
227
|
{opened &&
|
|
238
228
|
<BodyPortal>
|
|
@@ -247,7 +237,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
247
237
|
<View
|
|
248
238
|
dataSet={{class: "current-selected"}}
|
|
249
239
|
ref={currentSelectedRef}
|
|
250
|
-
style={{flexWrap: "wrap"}}
|
|
240
|
+
style={this.stylingFor("currentSelected", {width: "calc(100% - 27px)", flexWrap: "wrap"})}
|
|
251
241
|
>
|
|
252
242
|
{opened &&
|
|
253
243
|
<TextInput
|
|
@@ -256,19 +246,19 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
256
246
|
onChangeText={this.tt.onChangeSearchText}
|
|
257
247
|
placeholder={this.t(".search_dot_dot_dot")}
|
|
258
248
|
ref={this.tt.searchTextInputRef}
|
|
259
|
-
style={{
|
|
249
|
+
style={this.stylingFor("searchTextInput", {
|
|
260
250
|
width: "100%",
|
|
261
251
|
border: 0,
|
|
262
252
|
outline: "none",
|
|
263
253
|
padding: 0
|
|
264
|
-
}}
|
|
254
|
+
})}
|
|
265
255
|
value={this.state.searchText}
|
|
266
256
|
/>
|
|
267
257
|
}
|
|
268
258
|
{!opened &&
|
|
269
259
|
<>
|
|
270
260
|
{currentOptions.length == 0 &&
|
|
271
|
-
<Text style={{color: "grey"}}>
|
|
261
|
+
<Text style={this.stylingFor("nothingSelected", {color: "grey"})}>
|
|
272
262
|
{placeholder || this.t(".nothing_selected")}
|
|
273
263
|
</Text>
|
|
274
264
|
}
|
|
@@ -281,10 +271,14 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
281
271
|
/>
|
|
282
272
|
}
|
|
283
273
|
{currentOptions.map((currentOption) =>
|
|
284
|
-
<View
|
|
274
|
+
<View
|
|
275
|
+
dataSet={{class: "current-option"}}
|
|
276
|
+
key={currentOption.key || `current-value-${currentOption.value}`}
|
|
277
|
+
style={this.stylingFor("currentOption", {marginRight: 6})}
|
|
278
|
+
>
|
|
285
279
|
{currentOption.type == "group" &&
|
|
286
|
-
<View style={{fontWeight: "bold"}}>
|
|
287
|
-
<Text>
|
|
280
|
+
<View style={this.stylingFor("currentOptionGroup", {fontWeight: "bold"})}>
|
|
281
|
+
<Text style={this.stylingFor("currentOptionGroupText")}>
|
|
288
282
|
{currentOption.text}
|
|
289
283
|
</Text>
|
|
290
284
|
</View>
|
|
@@ -309,14 +303,14 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
309
303
|
</View>
|
|
310
304
|
<View
|
|
311
305
|
className="chevron-container"
|
|
312
|
-
style={{
|
|
306
|
+
style={this.stylingFor("chevronContainer", {
|
|
313
307
|
display: "flex",
|
|
314
308
|
alignItems: "center",
|
|
315
309
|
justifyContent: "center",
|
|
316
310
|
height: "100%",
|
|
317
311
|
marginRight: 8,
|
|
318
312
|
marginLeft: "auto"
|
|
319
|
-
}}
|
|
313
|
+
})}
|
|
320
314
|
>
|
|
321
315
|
<Text style={chevronStyle}>
|
|
322
316
|
{opened &&
|
|
@@ -548,18 +542,20 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
548
542
|
<View
|
|
549
543
|
dataSet={{class: "options-container", id: idForComponent(this)}}
|
|
550
544
|
ref={optionsContainerRef}
|
|
551
|
-
style={
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
545
|
+
style={
|
|
546
|
+
this.stylingFor("optionsContainer", {
|
|
547
|
+
position: "absolute",
|
|
548
|
+
left: optionsLeft + scrollLeft,
|
|
549
|
+
top: optionsTop + scrollTop - 1,
|
|
550
|
+
zIndex: 99999,
|
|
551
|
+
visibility: optionsVisibility,
|
|
552
|
+
width: optionsWidth,
|
|
553
|
+
backgroundColor: "#fff",
|
|
554
|
+
border: "1px solid #999",
|
|
555
|
+
maxHeight: 300,
|
|
556
|
+
overflowY: "auto"
|
|
557
|
+
})
|
|
558
|
+
}
|
|
563
559
|
>
|
|
564
560
|
{loadedOptions?.map((loadedOption) =>
|
|
565
561
|
this.hayaSelectOption({
|
|
@@ -640,6 +636,18 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
640
636
|
this.setState(newState)
|
|
641
637
|
}
|
|
642
638
|
|
|
639
|
+
stylingFor(stylingName, style = {}) {
|
|
640
|
+
let customStyling = dig(this, "props", "styles", stylingName)
|
|
641
|
+
|
|
642
|
+
if (typeof customStyling == "function") customStyling = customStyling({state: this.state, style})
|
|
643
|
+
|
|
644
|
+
if (customStyling) {
|
|
645
|
+
return Object.assign(style, customStyling)
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return style
|
|
649
|
+
}
|
|
650
|
+
|
|
643
651
|
iconForOption(option) {
|
|
644
652
|
const {toggleOptions} = this.props || {}
|
|
645
653
|
const toggled = this.getToggled()
|
|
@@ -680,7 +688,9 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
680
688
|
}
|
|
681
689
|
{currentValue.content}
|
|
682
690
|
{!currentValue.content &&
|
|
683
|
-
<Text
|
|
691
|
+
<Text className="option-presentation-text" style={this.stylingFor("optionPresentationText", {whiteSpace: "nowrap"})}>
|
|
692
|
+
{currentValue.text}
|
|
693
|
+
</Text>
|
|
684
694
|
}
|
|
685
695
|
{("html" in currentValue) &&
|
|
686
696
|
<div dangerouslySetInnerHTML={{__html: digg(currentValue, "html")}} />
|