@codeleap/web 3.22.0 → 3.22.2
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
CHANGED
|
@@ -386,6 +386,10 @@ export const Modal = (props) => {
|
|
|
386
386
|
setIndex(visible, modalId.current)
|
|
387
387
|
}, visible ? 0 : 500)
|
|
388
388
|
}
|
|
389
|
+
|
|
390
|
+
return () => {
|
|
391
|
+
if (scrollLock) modalScrollLock(false, modalId.current)
|
|
392
|
+
}
|
|
389
393
|
}, [visible])
|
|
390
394
|
|
|
391
395
|
const content = <ModalContent {...props} visible={visible} toggle={toggle} id={modalId.current} />
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { jsx } from '@emotion/react'
|
|
3
3
|
import React, { useRef, forwardRef, useImperativeHandle } from 'react'
|
|
4
|
-
import { FormTypes, useValidate, useState, TypeGuards, onUpdate, IconPlaceholder } from '@codeleap/common'
|
|
4
|
+
import { FormTypes, useValidate, useState, TypeGuards, onUpdate, IconPlaceholder, useEffect } from '@codeleap/common'
|
|
5
5
|
import _Select, { components, MenuListProps, MenuProps, MultiValueProps, NoticeProps } from 'react-select'
|
|
6
6
|
import Async from 'react-select/async'
|
|
7
7
|
import { useSelectStyles } from './styles'
|
|
@@ -241,6 +241,12 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
|
|
|
241
241
|
|
|
242
242
|
const [selectedOption, setSelectedOption] = hasSelectedOptionState ? [_selectedOption, _setSelectedOption] : useState(initialValue ?? value)
|
|
243
243
|
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
if (loadInitialValue && !selectedOption && !!initialValue) {
|
|
246
|
+
setSelectedOption(initialValue)
|
|
247
|
+
}
|
|
248
|
+
}, [!!initialValue])
|
|
249
|
+
|
|
244
250
|
const [_isFocused, setIsFocused] = useState(false)
|
|
245
251
|
const [loadedOptions, setLoadedOptions] = useState(false)
|
|
246
252
|
const [keyDownActive, setKeyDownActive] = useState(false)
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
export * from './styles'
|
|
22
22
|
|
|
23
23
|
export type SliderProps = Partial<Omit<PrimitiveSliderProps, 'value' | 'onValueChange'>> & Pick<InputBaseProps, 'disabled' | 'debugName' | 'description' | 'label'> & {
|
|
24
|
-
debounce?: number | null
|
|
25
24
|
indicatorLabel?: {
|
|
26
25
|
order?: number[]
|
|
27
26
|
separator?: string
|
|
@@ -44,7 +43,7 @@ export type TrackMarkProps = {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
const DefaultSliderTrackMark = (props: TrackMarkProps) => {
|
|
47
|
-
const {
|
|
46
|
+
const { style } = props
|
|
48
47
|
|
|
49
48
|
if (!TypeGuards.isString(props.content)) {
|
|
50
49
|
return <React.Fragment>
|
|
@@ -65,8 +64,8 @@ export const Slider = (props: SliderProps) => {
|
|
|
65
64
|
} = selectInputBaseProps(props)
|
|
66
65
|
|
|
67
66
|
const {
|
|
68
|
-
debounce = null,
|
|
69
67
|
onValueChange,
|
|
68
|
+
onValueCommit,
|
|
70
69
|
value: _value,
|
|
71
70
|
label,
|
|
72
71
|
debugName,
|
|
@@ -82,7 +81,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
82
81
|
min = 0,
|
|
83
82
|
indicatorLabel = null,
|
|
84
83
|
description = null,
|
|
85
|
-
minStepsBetweenThumbs =
|
|
84
|
+
minStepsBetweenThumbs = 0,
|
|
86
85
|
step = 1,
|
|
87
86
|
onPressThumbSetValue = false,
|
|
88
87
|
onPressThumb = null,
|
|
@@ -91,6 +90,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
91
90
|
|
|
92
91
|
const isUniqueValue = !TypeGuards.isArray(_value)
|
|
93
92
|
const value = isUniqueValue ? [_value] : _value
|
|
93
|
+
|
|
94
94
|
const _defaultValue = TypeGuards.isArray(defaultSliderValue) ? defaultSliderValue : [defaultSliderValue]
|
|
95
95
|
|
|
96
96
|
const defaultValueRef = useRef<PrimitiveSliderProps['defaultValue']>(_defaultValue)
|
|
@@ -104,34 +104,12 @@ export const Slider = (props: SliderProps) => {
|
|
|
104
104
|
|
|
105
105
|
const SliderTrackMark = trackMarkComponent
|
|
106
106
|
|
|
107
|
-
const currentThumbRef = useRef(null)
|
|
108
|
-
|
|
109
107
|
const handleChange: SliderProps['onValueChange'] = (newValue: Array<number>) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const copyValue = [...value]
|
|
116
|
-
|
|
117
|
-
const i = currentThumbRef.current
|
|
118
|
-
const _newValue = newValue[currentThumbRef.current]
|
|
119
|
-
|
|
120
|
-
const hasLeftThumb = i !== 0
|
|
121
|
-
const hasRightThumb = i + 1 < newValue.length
|
|
122
|
-
|
|
123
|
-
const previousThumbValue = hasLeftThumb ? (copyValue[i - 1] + minStepsBetweenThumbs) : null
|
|
124
|
-
const nextThumbValue = hasRightThumb ? (copyValue[i + 1] - minStepsBetweenThumbs) : null
|
|
125
|
-
|
|
126
|
-
if (previousThumbValue && _newValue <= previousThumbValue) {
|
|
127
|
-
copyValue[i] = previousThumbValue
|
|
128
|
-
} else if (nextThumbValue && _newValue >= nextThumbValue) {
|
|
129
|
-
copyValue[i] = nextThumbValue
|
|
130
|
-
} else {
|
|
131
|
-
copyValue[i] = _newValue
|
|
132
|
-
}
|
|
108
|
+
onValueChange(isUniqueValue ? newValue?.[0] : newValue)
|
|
109
|
+
}
|
|
133
110
|
|
|
134
|
-
|
|
111
|
+
const handleValueCommit = (newValue: Array<number>) => {
|
|
112
|
+
onValueCommit?.(newValue)
|
|
135
113
|
}
|
|
136
114
|
|
|
137
115
|
const variantStyles = useDefaultComponentStyle<'u:Slider', typeof SliderPresets>('u:Slider', {
|
|
@@ -234,15 +212,15 @@ export const Slider = (props: SliderProps) => {
|
|
|
234
212
|
<SliderContainer
|
|
235
213
|
{...sliderProps}
|
|
236
214
|
step={step}
|
|
237
|
-
minStepsBetweenThumbs={minStepsBetweenThumbs}
|
|
238
|
-
style={containerStyle}
|
|
239
|
-
defaultValue={defaultValue}
|
|
240
|
-
value={value}
|
|
241
|
-
onValueCommit={() => null}
|
|
242
|
-
onValueChange={handleChange}
|
|
243
215
|
min={min}
|
|
244
216
|
max={max}
|
|
245
217
|
disabled={disabled}
|
|
218
|
+
defaultValue={defaultValue}
|
|
219
|
+
onValueCommit={handleValueCommit}
|
|
220
|
+
onValueChange={handleChange}
|
|
221
|
+
style={containerStyle}
|
|
222
|
+
value={value}
|
|
223
|
+
minStepsBetweenThumbs={minStepsBetweenThumbs}
|
|
246
224
|
>
|
|
247
225
|
<SliderTrack style={trackStyle}>
|
|
248
226
|
<SliderRange style={selectedTrackStyle} />
|
|
@@ -256,10 +234,7 @@ export const Slider = (props: SliderProps) => {
|
|
|
256
234
|
onClick={() => {
|
|
257
235
|
if (onPressThumbSetValue) onValueChange?.(value)
|
|
258
236
|
if (TypeGuards.isFunction(onPressThumb)) onPressThumb?.(value, i)
|
|
259
|
-
|
|
260
|
-
currentThumbRef.current = i
|
|
261
237
|
}}
|
|
262
|
-
onMouseEnter={() => currentThumbRef.current = i}
|
|
263
238
|
/>
|
|
264
239
|
))}
|
|
265
240
|
</SliderContainer>
|