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 component #164

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

feat: Slider component #164

wants to merge 11 commits into from

Conversation

raechelo
Copy link

@raechelo raechelo commented Jan 13, 2025

Closes

✅ Pull Request Checklist:

  • Included link to corresponding GitHub Issue.
  • The commit message follows conventional commit extended guidelines.
  • Added/updated unit tests and storybook for this change (for bug fixes / features).
  • Added/updated documentation (for bug fixes / features)
  • Filled out test instructions.

📝 Test Instructions:

open the ladle page and view the Slider component. There are a handful of stories for review, including:

  • controlled range slider
  • controlled single value slider
  • uncontrolled range slier
  • uncontrolled single value slider
  • slider with output (RAC components indicate an output value, but our designs indicate an input value. The above components feature the input, but that inclusion can be toggled in the props menu by toggling includeTextField and includeOutputField

❓ Does this PR introduce a breaking change?

  • Yes
  • No

💬 Other information

I'm happy to hear any and all feedback, especially on variable names and naming conventions. I'm sure there are some internal practices I was not aware of!

I didn't have a ticket for this, because I don't have Jira access yet, but here is the screenshot I was given and attempted to match.
image

Comment on lines +111 to +122
<div
className={sliderBar}
style={{
position: 'absolute',
left: state.getThumbValue(1)
? `${state.getThumbValue(0)}%`
: 0,
width: state.getThumbValue(1)
? `${(state.getThumbValue(1) || 0) - (state.getThumbValue(0) || 0)}%`
: `${state.getThumbValue(0)}%`,
}}
/>
Copy link
Author

Choose a reason for hiding this comment

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

i tried a handful of ways to implement the bar, and I doubt this is the correct way. Any advice is greatly appreciated! I used this example for this implementation.

Because of how this is implemented, it does mean there are two slider bars when using the Range Slider. 😬😞

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, let's go over this when we have time

@@ -0,0 +1,312 @@
import {
Copy link
Author

Choose a reason for hiding this comment

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

i have a feeling i didn't organize this file properly, please lmk if there is a better way to do this!

@@ -0,0 +1,145 @@
import { style } from '@vanilla-extract/css';
Copy link
Author

Choose a reason for hiding this comment

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

I eyeballed all the styles from the pic, so I doubt they're fully accurate. If anything should be tweaked, I am happy to do so!

{({ state }: SliderRenderProps) => (
<>
<div
className={sliderBar}
Copy link
Author

Choose a reason for hiding this comment

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

i think i applied this incorrectly, but was unable to get it working with the same method the Picker stories were using. User error, i'm sure 😆

},
thumb: {
container: style({
' input': {
Copy link
Author

Choose a reason for hiding this comment

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

looks like this is the line that is causing the build to fail. I wasn't sure how to properly address this issue, because the RAC component has an grandchild element of input, which holds a 90px width. The tooltip in the story is hovering over the input rather than the main level component, thus the width change. Below are a few pictures to better explain.

Screenshot 2025-01-13 at 2 48 00 PM Screenshot 2025-01-13 at 2 47 05 PM Screenshot 2025-01-13 at 2 46 51 PM

Copy link
Author

Choose a reason for hiding this comment

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

fwiw, this is how RAC implements the component. You can see the same input width in this screenshot:

Screenshot 2025-01-13 at 2 54 40 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll look at this together. But the rule that you appear to be breaking is that (aside from pseudo selectors), styles can only target the current element:
https://vanilla-extract.style/documentation/styling/#complex-selectors

};
track: {
container: string;
track: string; // TODO: adjust the styles to use this class
Copy link
Author

Choose a reason for hiding this comment

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

i have the TODO here, but i'm not quite sure i actually need to make that change 🤔💭

sliderTrackStateVars,
type ThemeContext,
} from '../../src';
import type { SliderThumbState } from '../../src/components/slider/types';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you're not importing from root? I see it commented out above

sliderStateVars,
sliderThumbStateVars,
sliderTrackStateVars,
type LabelAlignment,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be prefixed with Slider to not cause a naming conflict

} from '@vanilla-extract/css';
import type { SliderClassNames } from './types';
import { layers, typographyVars } from '../../styles';
import { containerQueries } from '@/utils';
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 hold off on using import aliases for the moment


export type LabelAlignment = 'top' | 'left';

export type SliderRenderProps = RACSliderRenderProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll likely want to wrap these with AsType

BaseSliderProps;

type BaseSliderThumbProps = {
children?: RenderPropsChildren<SliderRenderProps>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to redefine children here unless you're actually changing the type (which I don't think you are). And then you could simplify why getting rid of the BaseSlideThumbProps and just add the classNames prop directly to the join

Copy link
Contributor

Choose a reason for hiding this comment

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

This applies below too

@@ -122,6 +129,18 @@ export type DefaultsContext = DefaultsOf<{
// biome-ignore lint/style/useNamingConvention: component name should be PascalCase
Select: SelectProps<object>;
// biome-ignore lint/style/useNamingConvention: component name should be PascalCase
Slider: SliderProps;
// biome-ignore lint/style/useNamingConvention: component name should be PascalCase
Copy link
Contributor

Choose a reason for hiding this comment

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

Dear lord, who did this Biome commenting? Can you create an issue to convert to range suppression biomejs/biome#4569 please?

@@ -86,6 +87,8 @@ export type ThemeContext = {
// biome-ignore lint/style/useNamingConvention: component name should be PascalCase
Select?: SelectClassNames;
// biome-ignore lint/style/useNamingConvention: component name should be PascalCase
Slider?: SliderClassNames;
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too

Comment on lines +111 to +122
<div
className={sliderBar}
style={{
position: 'absolute',
left: state.getThumbValue(1)
? `${state.getThumbValue(0)}%`
: 0,
width: state.getThumbValue(1)
? `${(state.getThumbValue(1) || 0) - (state.getThumbValue(0) || 0)}%`
: `${state.getThumbValue(0)}%`,
}}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, let's go over this when we have time

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.

2 participants