diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c2cffa225..8abb4de9ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Features - Split action handlers with "OR" condition in accessibility behaviors @sophieH29 ([#1622](https://github.com/stardust-ui/react/pull/1622)) - Add `headerAction` slot to the `Dialog` component @mnajdova ([#1617](https://github.com/stardust-ui/react/pull/1617)) +- Add `Slider` component @Bugaa92 ([#1559](https://github.com/stardust-ui/react/pull/1559)) ## [v0.34.1](https://github.com/stardust-ui/react/tree/v0.34.1) (2019-07-11) diff --git a/docs/src/examples/components/Slider/Playground.tsx b/docs/src/examples/components/Slider/Playground.tsx new file mode 100644 index 0000000000..abaa7fed81 --- /dev/null +++ b/docs/src/examples/components/Slider/Playground.tsx @@ -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 ( + setValue(data.value)} + /> + ) +} + +export default SliderPlayground diff --git a/docs/src/examples/components/Slider/Rtl/SliderExample.rtl.steps.ts b/docs/src/examples/components/Slider/Rtl/SliderExample.rtl.steps.ts new file mode 100644 index 0000000000..5262188359 --- /dev/null +++ b/docs/src/examples/components/Slider/Rtl/SliderExample.rtl.steps.ts @@ -0,0 +1,8 @@ +import getScreenerSteps from '../commonScreenerSteps' + +const config: ScreenerTestsConfig = { + themes: ['teams', 'teamsDark', 'teamsHighContrast'], + steps: getScreenerSteps(), +} + +export default config diff --git a/docs/src/examples/components/Slider/Rtl/SliderExample.rtl.tsx b/docs/src/examples/components/Slider/Rtl/SliderExample.rtl.tsx new file mode 100644 index 0000000000..a941ffb404 --- /dev/null +++ b/docs/src/examples/components/Slider/Rtl/SliderExample.rtl.tsx @@ -0,0 +1,6 @@ +import * as React from 'react' +import { Slider } from '@stardust-ui/react' + +const SliderExampleRtl = () => + +export default SliderExampleRtl diff --git a/docs/src/examples/components/Slider/Rtl/index.tsx b/docs/src/examples/components/Slider/Rtl/index.tsx new file mode 100644 index 0000000000..09aaa1fa46 --- /dev/null +++ b/docs/src/examples/components/Slider/Rtl/index.tsx @@ -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 = () => ( + + + +) + +export default Rtl diff --git a/docs/src/examples/components/Slider/States/SliderExampleDisabled.shorthand.tsx b/docs/src/examples/components/Slider/States/SliderExampleDisabled.shorthand.tsx new file mode 100644 index 0000000000..6dbc8f8343 --- /dev/null +++ b/docs/src/examples/components/Slider/States/SliderExampleDisabled.shorthand.tsx @@ -0,0 +1,6 @@ +import * as React from 'react' +import { Slider } from '@stardust-ui/react' + +const SliderExampleDisabledShorthand = () => + +export default SliderExampleDisabledShorthand diff --git a/docs/src/examples/components/Slider/States/index.tsx b/docs/src/examples/components/Slider/States/index.tsx new file mode 100644 index 0000000000..bf71e865b9 --- /dev/null +++ b/docs/src/examples/components/Slider/States/index.tsx @@ -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 = () => ( + + + +) + +export default States diff --git a/docs/src/examples/components/Slider/Types/SliderExample.shorthand.steps.ts b/docs/src/examples/components/Slider/Types/SliderExample.shorthand.steps.ts new file mode 100644 index 0000000000..5262188359 --- /dev/null +++ b/docs/src/examples/components/Slider/Types/SliderExample.shorthand.steps.ts @@ -0,0 +1,8 @@ +import getScreenerSteps from '../commonScreenerSteps' + +const config: ScreenerTestsConfig = { + themes: ['teams', 'teamsDark', 'teamsHighContrast'], + steps: getScreenerSteps(), +} + +export default config diff --git a/docs/src/examples/components/Slider/Types/SliderExample.shorthand.tsx b/docs/src/examples/components/Slider/Types/SliderExample.shorthand.tsx new file mode 100644 index 0000000000..14f33505a7 --- /dev/null +++ b/docs/src/examples/components/Slider/Types/SliderExample.shorthand.tsx @@ -0,0 +1,6 @@ +import * as React from 'react' +import { Slider } from '@stardust-ui/react' + +const SliderExampleShorthand = () => + +export default SliderExampleShorthand diff --git a/docs/src/examples/components/Slider/Types/index.tsx b/docs/src/examples/components/Slider/Types/index.tsx new file mode 100644 index 0000000000..43195a394e --- /dev/null +++ b/docs/src/examples/components/Slider/Types/index.tsx @@ -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 = () => ( + + + +) + +export default Types diff --git a/docs/src/examples/components/Slider/Usage/SliderExampleAction.shorthand.tsx b/docs/src/examples/components/Slider/Usage/SliderExampleAction.shorthand.tsx new file mode 100644 index 0000000000..ad667c5e32 --- /dev/null +++ b/docs/src/examples/components/Slider/Usage/SliderExampleAction.shorthand.tsx @@ -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 ( + +