Skip to content
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

Merged
merged 56 commits into from
Feb 19, 2024
Merged

Conversation

Arucard89
Copy link
Contributor

Tickets: DATAUI-1616, UXRFC-199

@gravity-ui-bot
Copy link
Contributor

Playwright Test Component is ready.

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

@Arucard89 Arucard89 marked this pull request as ready for review January 26, 2024 06:57
@Arucard89 Arucard89 changed the title feat: introduce Slider component feat(Slider): introduce Slider component Jan 26, 2024
@amje
Copy link
Contributor

amje commented Jan 30, 2024

@Arucard89 Do we want it to be part of v6?

@Arucard89
Copy link
Contributor Author

@Arucard89 Do we want it to be part of v6?

Actually I don't know. What's plan?
This component corresponds to the design. And I'm waiting for decision.
It would great if you can review it and we introduce Slider with v6.
Also it is fine if we add it in some minor version.

But I need Slider in uikit to create RangeInputPicker

@@ -0,0 +1,449 @@
@use 'sass:math';
@use '../../variables';
@use '../sliderVariables';
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

@Arucard89 Arucard89 Jan 31, 2024

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'

1837e16


&__error {
&_size_xl {
@include mixins.text-body-2;
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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

infoPointCount = 0,
availableValues,
withTooltip = false,
error,
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min = 0,
max = 100,
step = 1,
infoPointCount = 0,
Copy link
Contributor

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?

Copy link
Contributor Author

@Arucard89 Arucard89 Jan 31, 2024

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?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withTooltip = false,
error,
disabled = false,
keyboard = true,
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

) {
const baseSliderRef = React.useRef<BaseSliderRefType>(null);

React.useImperativeHandle(ref, () => ({
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arucard89 Arucard89 force-pushed the DATAUI-1616(UXRFC-199)-Slider branch 4 times, most recently from dd079a5 to cde5020 Compare February 4, 2024 21:14
@Arucard89
Copy link
Contributor Author

@amje , hi. I've fixed all comments. Check them, please

@Arucard89 Arucard89 force-pushed the DATAUI-1616(UXRFC-199)-Slider branch 3 times, most recently from 7c3dcb4 to a82983d Compare February 7, 2024 12:05
}
}

&__error {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 45 to 47
onChange?: (value: ValueType) => void;
/** Fires when ontouchend or onmouseup is triggered. Provides change event as an callback's argument */
onChangeComplete?: (value: ValueType) => void;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Indicates that the user cannot interact with the control */
disabled?: boolean;
/** Text of an error to show */
errorText?: string;
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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?

Copy link
Contributor Author

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'],
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: c433487

@Arucard89 Arucard89 force-pushed the DATAUI-1616(UXRFC-199)-Slider branch 2 times, most recently from d9f9a6b to 7671677 Compare February 8, 2024 08:50
@Arucard89
Copy link
Contributor Author

@amje hi. I fixed all comments. Could you review it?

@korvin89 korvin89 merged commit a1bf754 into main Feb 19, 2024
4 checks passed
@korvin89 korvin89 deleted the DATAUI-1616(UXRFC-199)-Slider branch February 19, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants