-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(Slider): export function for preparing initial value #1637
Changes from all commits
8d29b18
fda2088
21fd175
143584f
2b3e8dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './Slider'; | ||
export type {SliderSize, SliderValue, SliderProps, BaseSliderRefType} from './types'; | ||
export {prepareSliderInnerState} from './utils'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,11 @@ function createMarks(points: number[]): RcSliderProps['marks'] { | |
return marks; | ||
} | ||
|
||
export function getInnerState({ | ||
/** | ||
* Calculates the basic properties of the Slider component depending on the passed parameters | ||
* @returns {SliderInnerState} Properties to pass to the Slider | ||
*/ | ||
export function prepareSliderInnerState({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why user might needed this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I need it to use in RangeSliderPicker component to get inner state. And I don't want to duplicate the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amje, I don't know is it really "fix" but not "chore"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's important to note this change in the changelog because you have changed the implementation |
||
max = 100, | ||
min = 0, | ||
availableValues, | ||
|
@@ -134,24 +138,26 @@ export function getInnerState({ | |
state.marks = createMarks(calculateInfoPoints({count: marksCount, max, min})); | ||
} | ||
|
||
if (value && Array.isArray(value)) { | ||
state.range = true; | ||
state.value = prepareArrayValue({min: state.min, max: state.max, value}); | ||
} else if (defaultValue && Array.isArray(defaultValue)) { | ||
state.range = true; | ||
state.defaultValue = prepareArrayValue({ | ||
min: state.min, | ||
max: state.max, | ||
value: defaultValue, | ||
}); | ||
} else if (value) { | ||
state.value = prepareSingleValue({min: state.min, max: state.max, value}); | ||
if (value === undefined) { | ||
const isArray = Array.isArray(defaultValue); | ||
state.range = isArray; | ||
state.defaultValue = isArray | ||
? prepareArrayValue({ | ||
min: state.min, | ||
max: state.max, | ||
value: defaultValue, | ||
}) | ||
: prepareSingleValue({ | ||
min: state.min, | ||
max: state.max, | ||
value: defaultValue, | ||
}); | ||
} else { | ||
state.defaultValue = prepareSingleValue({ | ||
min: state.min, | ||
max: state.max, | ||
value: defaultValue, | ||
}); | ||
const isArray = Array.isArray(value); | ||
state.range = isArray; | ||
state.value = isArray | ||
? prepareArrayValue({min: state.min, max: state.max, value}) | ||
: prepareSingleValue({min: state.min, max: state.max, value}); | ||
} | ||
|
||
return state; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide some jsdoc here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, forgot to do it, thanks
143584f