-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat(Slider): introduce Slider component #1243
Conversation
Playwright Test Component is ready. |
Preview is ready. |
@Arucard89 Do we want it to be part of v6? |
Actually I don't know. What's plan? But I need Slider in uikit to create RangeInputPicker |
@@ -0,0 +1,449 @@ | |||
@use 'sass:math'; | |||
@use '../../variables'; | |||
@use '../sliderVariables'; |
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.
Let's name the file variables.scss
and use alias: @use '../variables' as slider-variables
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.
@@ -0,0 +1,50 @@ | |||
import type {SliderProps as RcSliderProps, SliderRef as RcSliderRef} from 'rc-slider'; |
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.
Please call the file just types.ts
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.
@use '../sliderVariables'; | ||
@use '../../../../styles/mixins'; | ||
|
||
$block: '.#{variables.$ns-new}base-slider'; |
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.
Instead of base-slider
I would call it ReactSlider
to show that is external component
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.
Consider, please, this variant:
rc-slider has prop prefixCls
for this purpose. If it is undefined then it add default classname and classname prefix 'rc-slider' to all components inside it. Using it we save accordance between component name and classname. And also show that component is external.
Whole classname of BaseComponent will look like this:
'rc-slider g-base-slider g-base-slider_size_s rc-slider-horizontal'
src/components/Slider/Slider.scss
Outdated
|
||
&__error { | ||
&_size_xl { | ||
@include mixins.text-body-2; |
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.
We have one size in inputs, slider should follow the same rules
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.
You mean that error always should have text-body-1? But then it will not correspond to design. Is it OK?
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.
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, it should corelate with other control's errors
src/components/Slider/Slider.tsx
Outdated
infoPointCount = 0, | ||
availableValues, | ||
withTooltip = false, | ||
error, |
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.
error
-> errorMessage
+ validationState: 'invalid'
, check the TextInput or TextArea component for reference
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.
src/components/Slider/Slider.tsx
Outdated
min = 0, | ||
max = 100, | ||
step = 1, | ||
infoPointCount = 0, |
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.
Maybe name this prop marks
or marksCount
?
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, your names are good(especially marksCount) and I like them but I took this name from RangeInputPicker. I thought that saving of the name would made transition to new component easier.
What do you think?
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.
It's a great opportunity to change the API
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.
src/components/Slider/Slider.tsx
Outdated
withTooltip = false, | ||
error, | ||
disabled = false, | ||
keyboard = true, |
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.
Component must always be accessible with keyboard, this prop not needed
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.
src/components/Slider/Slider.tsx
Outdated
) { | ||
const baseSliderRef = React.useRef<BaseSliderRefType>(null); | ||
|
||
React.useImperativeHandle(ref, () => ({ |
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.
Let the ref
be normal ref to HTMLElement, and for this case use apiRef
dedicated prop
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.
@@ -0,0 +1 @@ | |||
export * from './Slider'; |
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.
Let's be explicit here, we should export component and alose types we assume are public
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.
dd079a5
to
cde5020
Compare
@amje , hi. I've fixed all comments. Check them, please |
7c3dcb4
to
a82983d
Compare
src/components/Slider/Slider.scss
Outdated
} | ||
} | ||
|
||
&__error { |
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.
There are rules for &__error
at the top of the file
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.
src/components/Slider/types.ts
Outdated
onChange?: (value: ValueType) => void; | ||
/** Fires when ontouchend or onmouseup is triggered. Provides change event as an callback's argument */ | ||
onChangeComplete?: (value: ValueType) => void; |
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.
If handlers receive only the value, then we call them onUpdate*
, not onChange
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.
src/components/Slider/types.ts
Outdated
/** Indicates that the user cannot interact with the control */ | ||
disabled?: boolean; | ||
/** Text of an error to show */ | ||
errorText?: string; |
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.
Let's name this errorMessage
, like in TextInput and TextArea
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.
@@ -0,0 +1,2 @@ | |||
export * from './Slider'; | |||
export type {SliderSize, SliderValue, SliderProps, BaseSliderRefType} from './types'; |
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.
Why BaseSliderRefType
need to be exported?
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.
Slider has prop:
apiRef?: React.RefObject<BaseSliderRefType>;
So we need to export this type to allow user write variable type correctly.
export default { | ||
title: 'Components/Inputs/Slider', | ||
component: Slider, | ||
tags: ['autodocs'], |
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.
We don't use autodocs. Instead we use mdx for docs, check Button's stories for a reference
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.
fixed: c433487
d9f9a6b
to
7671677
Compare
@amje hi. I fixed all comments. Could you review it? |
Tickets: DATAUI-1616, UXRFC-199