This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
feat(slider): v1 #1559
Merged
Merged
feat(slider): v1 #1559
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3775a2d
feat(slider): v1
bmdalex 08912a9
addressed comments and fixed build errors
bmdalex 096ea52
improved slider styles and functionality
bmdalex a64bf40
- implemented border styles;
bmdalex 6053059
cleanup
bmdalex 24cc7b0
add screenshot tests
bmdalex cb9db60
example wip
bmdalex e7023c6
finished usage example
bmdalex 027ca32
removed icon and iconPosition
bmdalex 87499c6
fixed visual tests
bmdalex 72eac66
addressed PR comments
bmdalex 0ab9f46
reverted input changes
bmdalex dc39ed4
moved selectors to styling file
bmdalex 0de145a
some changes in test files
bmdalex 5a449ed
improved styles for onChange in Slider
bmdalex 4ea9de6
added navigation tests for slider in rtl mode
bmdalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import * as React from 'react' | ||
| import { Slider } from '@stardust-ui/react' | ||
| import { useBooleanKnob, useStringKnob } from '@stardust-ui/docs-components' | ||
|
|
||
| const SliderPlayground: React.FunctionComponent = () => { | ||
| const [min] = useStringKnob({ name: 'min', initialValue: '0' }) | ||
| const [max] = useStringKnob({ name: 'max', initialValue: '50' }) | ||
| const [step] = useStringKnob({ name: 'step', initialValue: '1' }) | ||
| const [value, setValue] = useStringKnob({ name: 'value', initialValue: '10' }) | ||
|
|
||
| const [disabled] = useBooleanKnob({ name: 'disabled' }) | ||
| const [fluid] = useBooleanKnob({ name: 'fluid' }) | ||
| const [vertical] = useBooleanKnob({ name: 'vertical' }) | ||
|
|
||
| return ( | ||
| <Slider | ||
| disabled={disabled} | ||
| fluid={fluid} | ||
| min={min} | ||
| max={max} | ||
| step={step} | ||
| value={value} | ||
| vertical={vertical} | ||
| onChange={(e, data) => setValue(data.value)} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| export default SliderPlayground |
8 changes: 8 additions & 0 deletions
8
docs/src/examples/components/Slider/Rtl/SliderExample.rtl.steps.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import getScreenerSteps from '../commonScreenerSteps' | ||
|
|
||
| const config: ScreenerTestsConfig = { | ||
| themes: ['teams', 'teamsDark', 'teamsHighContrast'], | ||
| steps: getScreenerSteps(), | ||
| } | ||
|
|
||
| export default config |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Slider/Rtl/SliderExample.rtl.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import * as React from 'react' | ||
| import { Slider } from '@stardust-ui/react' | ||
|
|
||
| const SliderExampleRtl = () => <Slider /> | ||
|
|
||
| export default SliderExampleRtl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import NonPublicSection from 'docs/src/components/ComponentDoc/NonPublicSection' | ||
|
|
||
| const Rtl = () => ( | ||
| <NonPublicSection title="Rtl"> | ||
| <ComponentExample examplePath="components/Slider/Rtl/SliderExample.rtl" /> | ||
| </NonPublicSection> | ||
| ) | ||
|
|
||
| export default Rtl |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Slider/States/SliderExampleDisabled.shorthand.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import * as React from 'react' | ||
| import { Slider } from '@stardust-ui/react' | ||
|
|
||
| const SliderExampleDisabledShorthand = () => <Slider disabled /> | ||
|
|
||
| export default SliderExampleDisabledShorthand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import * as React from 'react' | ||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const States = () => ( | ||
| <ExampleSection title="States"> | ||
| <ComponentExample | ||
| title="Disabled" | ||
| description="A slider can be read-only and unable to change states." | ||
| examplePath="components/Slider/States/SliderExampleDisabled" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default States |
8 changes: 8 additions & 0 deletions
8
docs/src/examples/components/Slider/Types/SliderExample.shorthand.steps.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import getScreenerSteps from '../commonScreenerSteps' | ||
|
|
||
| const config: ScreenerTestsConfig = { | ||
| themes: ['teams', 'teamsDark', 'teamsHighContrast'], | ||
| steps: getScreenerSteps(), | ||
| } | ||
|
|
||
| export default config | ||
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Slider/Types/SliderExample.shorthand.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import * as React from 'react' | ||
| import { Slider } from '@stardust-ui/react' | ||
|
|
||
| const SliderExampleShorthand = () => <Slider /> | ||
|
|
||
| export default SliderExampleShorthand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Types = () => ( | ||
| <ExampleSection title="Types"> | ||
| <ComponentExample | ||
| title="Default" | ||
| description="A default slider." | ||
| examplePath="components/Slider/Types/SliderExample" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Types |
66 changes: 66 additions & 0 deletions
66
docs/src/examples/components/Slider/Usage/SliderExampleAction.shorthand.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import * as React from 'react' | ||
| import { Button, Input, Slider, Flex } from '@stardust-ui/react' | ||
| import { useBooleanKnob } from '@stardust-ui/docs-components' | ||
|
|
||
| interface SliderAction { | ||
| type: 'toggle_mute' | 'change_value' | ||
| value?: string | number | ||
| } | ||
|
|
||
| interface SliderState { | ||
| mute: boolean | ||
| value: string | number | ||
| currentValue: string | number | ||
| minValue: string | number | ||
| } | ||
|
|
||
| const stateReducer = (state: SliderState, action: SliderAction) => { | ||
| switch (action.type) { | ||
| case 'toggle_mute': | ||
| const mute = !state.mute | ||
| const value = mute ? state.minValue : state.currentValue | ||
|
|
||
| if (!mute && value <= state.minValue) return { ...state } | ||
| return { ...state, mute, value, currentValue: state.value } | ||
|
|
||
| case 'change_value': | ||
| return { ...state, mute: action.value <= state.minValue, value: action.value } | ||
|
|
||
| default: | ||
| throw new Error(`Action ${action.type} is not supported`) | ||
| } | ||
| } | ||
|
|
||
| const SliderExampleActionShorthand = () => { | ||
| const [vertical] = useBooleanKnob({ name: 'vertical', initialValue: false }) | ||
| const { min, max } = { min: 0, max: 100 } | ||
|
|
||
| const [state, dispatch] = React.useReducer(stateReducer, { | ||
| mute: false, | ||
| value: min + (max - min) / 2, | ||
| currentValue: min, | ||
| minValue: min, | ||
| }) | ||
|
|
||
| const handeChange = React.useCallback( | ||
| (e, data) => dispatch({ type: 'change_value', value: data.value }), | ||
| [], | ||
| ) | ||
|
|
||
| const commonProps = { vertical, min, max, value: state.value, onChange: handeChange } | ||
|
|
||
| return ( | ||
| <Flex inline hAlign="center" vAlign="center" gap="gap.smaller" column={vertical}> | ||
| <Button | ||
| text | ||
| iconOnly | ||
| icon={state.mute ? 'mic-off' : 'mic'} | ||
| onClick={() => dispatch({ type: 'toggle_mute' })} | ||
| /> | ||
| <Slider {...commonProps} /> | ||
| <Input type="number" input={{ styles: { width: '64px' } }} {...commonProps} /> | ||
| </Flex> | ||
| ) | ||
| } | ||
|
|
||
| export default SliderExampleActionShorthand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import * as React from 'react' | ||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Usage = () => ( | ||
| <ExampleSection title="Usage"> | ||
| <ComponentExample | ||
| title="Slider with action element and input" | ||
| description={ | ||
| <div> | ||
| <span>This example contains:</span> | ||
| <ul> | ||
| <li> | ||
| a <code>Slider</code> that allows the user to choose a value from within a specific | ||
| range of values. | ||
| </li> | ||
| <li> | ||
| a <code>Button</code> that changes its icon and toggles the <code>Slider</code> value | ||
| when clicked (between current value and minimum value). | ||
| </li> | ||
| <li> | ||
| an <code>Input</code> that changes and displays the current <code>Slider</code> value. | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| } | ||
| examplePath="components/Slider/Usage/SliderExampleAction" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Usage |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Slider/Variations/SliderExampleFluid.shorthand.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import * as React from 'react' | ||
| import { Slider } from '@stardust-ui/react' | ||
|
|
||
| const SliderExampleFluidShorthand = () => <Slider fluid /> | ||
|
|
||
| export default SliderExampleFluidShorthand |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Slider/Variations/SliderExampleVertical.shorthand.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import * as React from 'react' | ||
| import { Slider } from '@stardust-ui/react' | ||
|
|
||
| const SliderExampleVerticalShorthand = () => <Slider vertical /> | ||
|
|
||
| export default SliderExampleVerticalShorthand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Variations = () => ( | ||
| <ExampleSection title="Variations"> | ||
| <ComponentExample | ||
| title="Vertical" | ||
| description="A slider can be displayed vertically." | ||
| examplePath="components/Slider/Variations/SliderExampleVertical" | ||
| /> | ||
| <ComponentExample | ||
| title="Fluid" | ||
| description="A slider can take up the width of its container." | ||
| examplePath="components/Slider/Variations/SliderExampleFluid" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Variations |
29 changes: 29 additions & 0 deletions
29
docs/src/examples/components/Slider/commonScreenerSteps.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Slider } from '@stardust-ui/react/src' | ||
|
|
||
| const selectors = { | ||
| input: `.${Slider.slotClassNames.input}`, | ||
| } | ||
|
|
||
| const focusSliderStep: ScreenerStep = (builder, keys) => builder.keys('body', keys.tab) | ||
|
|
||
| const getScreenerSteps = (): ScreenerSteps => [ | ||
| (builder, keys) => focusSliderStep(builder, keys).snapshot('Focuses the slider'), | ||
| (builder, keys) => | ||
| focusSliderStep(builder, keys) | ||
| .keys(selectors.input, keys.rightArrow) | ||
| .keys(selectors.input, keys.rightArrow) | ||
| .keys(selectors.input, keys.rightArrow) | ||
| .keys(selectors.input, keys.rightArrow) | ||
| .keys(selectors.input, keys.rightArrow) | ||
| .snapshot('Navigates to the right with the right arrow key'), | ||
| (builder, keys) => | ||
| focusSliderStep(builder, keys) | ||
| .keys(selectors.input, keys.upArrow) | ||
| .keys(selectors.input, keys.upArrow) | ||
| .keys(selectors.input, keys.upArrow) | ||
| .keys(selectors.input, keys.upArrow) | ||
| .keys(selectors.input, keys.upArrow) | ||
| .snapshot('Navigates to the right with the up arrow key'), | ||
| ] | ||
|
|
||
| export default getScreenerSteps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import Types from './Types' | ||
| import States from './States' | ||
| import Variations from './Variations' | ||
| import Usage from './Usage' | ||
| import Rtl from './Rtl' | ||
|
|
||
| const SliderExamples = () => ( | ||
| <> | ||
| <Types /> | ||
| <States /> | ||
| <Variations /> | ||
| <Usage /> | ||
| <Rtl /> | ||
| </> | ||
| ) | ||
|
|
||
| export default SliderExamples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.