Skip to content

Commit

Permalink
Slider Redesign (uber#3761)
Browse files Browse the repository at this point in the history
* feat(slider): add support for marks

* feat(slider): update scenarios and label styles

* feat(slider): fix lint, flow and examples

* test(vrt): update visual snapshots for 423ff2e [skip ci] (uber#3762)

Co-authored-by: UberOpenSourceBot <[email protected]>

* feat(slider): update disabled styles

* test(vrt): update visual snapshots for fe4f441 [skip ci] (uber#3764)

Co-authored-by: UberOpenSourceBot <[email protected]>

Co-authored-by: UberOpenSourceBot <[email protected]>
Co-authored-by: UberOpenSourceBot <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2020
1 parent 130570d commit 2bef0dc
Show file tree
Hide file tree
Showing 41 changed files with 238 additions and 108 deletions.
6 changes: 6 additions & 0 deletions documentation-site/components/yard/config/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ const SliderConfig: TConfig = {
description:
'The granularity the slider can step through value. Default step is 1.',
},
marks: {
value: false,
type: PropTypes.Boolean,
description: 'Display a mark at each step.',
},
disabled: {
value: false,
type: PropTypes.Boolean,
Expand All @@ -96,6 +101,7 @@ const SliderConfig: TConfig = {
'Tick',
'TickBar',
'Track',
'Mark',
],
sharedProps: {
$disabled: 'disabled',
Expand Down
6 changes: 6 additions & 0 deletions documentation-site/examples/slider/custom-ticks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ function CustomTicks() {
}
}}
overrides={{
Root: {
style: {
marginTop: '24px',
},
},
InnerThumb: () => null,
ThumbValue: ({$value}) => (
<div
className={css({
Expand Down
6 changes: 6 additions & 0 deletions documentation-site/examples/slider/custom-ticks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ function CustomTicks() {
step={100}
onChange={({value}) => setValue(value)}
overrides={{
Root: {
style: {
marginTop: '24px',
},
},
InnerThumb: () => null,
ThumbValue: ({$value}) => (
<div
className={css({
Expand Down
15 changes: 15 additions & 0 deletions documentation-site/examples/slider/marks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @flow
import * as React from 'react';
import {Slider} from 'baseui/slider';

export default () => {
const [value, setValue] = React.useState([60]);
return (
<Slider
value={value}
step={10}
marks
onChange={({value}) => value && setValue(value)}
/>
);
};
14 changes: 14 additions & 0 deletions documentation-site/examples/slider/marks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as React from 'react';
import {Slider} from 'baseui/slider';

export default () => {
const [value, setValue] = React.useState([60]);
return (
<Slider
value={value}
step={10}
marks
onChange={({value}) => value && setValue(value)}
/>
);
};
5 changes: 5 additions & 0 deletions documentation-site/pages/components/slider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Layout from '../../components/layout';
import Exports from '../../components/exports';

import Basic from 'examples/slider/basic.js';
import Marks from 'examples/slider/marks.js';
import Stateful from 'examples/slider/stateful.js';
import Disabled from 'examples/slider/disabled.js';
import Range from 'examples/slider/range.js';
Expand Down Expand Up @@ -60,6 +61,10 @@ The component is also **optimized for iOS and Android devices**.
<Basic />
</Example>

<Example title="Marks" path="slider/marks.js">
<Marks />
</Example>

<Example title="Range" path="slider/range.js">
<Range />
</Example>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
"react-is": "^16.8.6",
"react-movable": "^2.4.0",
"react-multi-ref": "^1.0.0",
"react-range": "^1.6.3",
"react-range": "^1.7.0",
"react-uid": "^2.3.0",
"react-virtualized": "^9.21.1",
"react-virtualized-auto-sizer": "^1.0.2",
Expand Down
22 changes: 12 additions & 10 deletions src/slider/__tests__/slider-custom-label.scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import {Slider} from '../index.js';
export default function Scenario() {
const [rangeValue, setRangeValue] = React.useState([45, 50]);
return (
<Slider
value={rangeValue}
onChange={({value}) => value && setRangeValue(value)}
overrides={{
ThumbValue: {
props: {
valueToLabel: l => l + ':00 AM',
<div style={{margin: '64px'}}>
<Slider
value={rangeValue}
onChange={({value}) => value && setRangeValue(value)}
overrides={{
ThumbValue: {
props: {
valueToLabel: l => l + ':00 AM',
},
},
},
}}
/>
}}
/>
</div>
);
}
1 change: 1 addition & 0 deletions src/slider/__tests__/slider-disabled.scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function Scenario() {
<div
style={{
maxWidth: '500px',
margin: '64px',
}}
>
<StatefulSlider initialState={{value: [50]}} disabled />
Expand Down
31 changes: 31 additions & 0 deletions src/slider/__tests__/slider-marks.scenario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (c) 2018-2020 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
/* eslint-disable react/display-name*/

import * as React from 'react';

import {StatefulSlider} from '../index.js';

export default function Scenario() {
return (
<div
style={{
maxWidth: '500px',
margin: '64px',
}}
>
<StatefulSlider
initialState={{value: [20]}}
step={10}
min={0}
max={100}
marks
/>
</div>
);
}
1 change: 1 addition & 0 deletions src/slider/__tests__/slider-range.scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function Scenario() {
<div
style={{
maxWidth: '500px',
margin: '64px',
}}
>
<StatefulSlider initialState={{value: [25, 60]}} />
Expand Down
2 changes: 1 addition & 1 deletion src/slider/__tests__/slider-rtl.scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SliderScenario from './slider.scenario.js';
export default function Scenario() {
return (
<ThemeProvider theme={{...LightTheme, direction: 'rtl'}}>
<div dir="rtl">
<div dir="rtl" style={{margin: '64px'}}>
<SliderScenario />
</div>
</ThemeProvider>
Expand Down
1 change: 1 addition & 0 deletions src/slider/__tests__/slider-step.scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function Scenario() {
<div
style={{
maxWidth: '500px',
margin: '64px',
}}
>
<StatefulSlider
Expand Down
1 change: 1 addition & 0 deletions src/slider/__tests__/slider.scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function Scenario() {
<div
style={{
maxWidth: '500px',
margin: '64px',
}}
>
<StatefulSlider />
Expand Down
6 changes: 6 additions & 0 deletions src/slider/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface SliderOverrides {
Thumb?: Override<SharedProps>;
InnerThumb?: Override<SharedProps>;
ThumbValue?: Override<SharedProps>;
Mark?: Override<SharedProps>;
}

export interface SliderProps {
Expand All @@ -34,6 +35,7 @@ export interface SliderProps {
step?: number;
overrides?: SliderOverrides;
disabled?: boolean;
marks?: boolean;
onChange?: (e: State) => any;
onFinalChange?: (e: State) => any;
}
Expand All @@ -44,6 +46,7 @@ export interface StatefulSliderProps {
min?: number;
max?: number;
step?: number;
marks?: boolean;
onChange?: (e: State) => any;
onFinalChange?: (e: State) => any;
}
Expand All @@ -54,6 +57,7 @@ export interface StatefulContainerProps {
min?: number;
max?: number;
step?: number;
marks?: boolean;
initialState?: State;
stateReducer?: StateReducer;
onChange?: (e: State) => any;
Expand All @@ -67,6 +71,7 @@ export type SharedProps = {
$min: number;
$thumbIndex: number;
$value: Array<number>;
$marks: boolean;
};

export const Slider: React.FC<SliderProps>;
Expand All @@ -87,5 +92,6 @@ export const StyledThumb: StyletronComponent<any>;
export const StyledInnerThumb: StyletronComponent<any>;
export const StyledTick: StyletronComponent<any>;
export const StyledTickBar: StyletronComponent<any>;
export const StyledMark: StyletronComponent<any>;

export const STATE_CHANGE_TYPE: STATE_CHANGE_TYPE;
1 change: 1 addition & 0 deletions src/slider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export {
Tick as StyledTick,
TickBar as StyledTickBar,
ThumbValue as StyledThumbValue,
Mark as StyledMark,
} from './styled-components.js';
export type * from './types.js';
Loading

0 comments on commit 2bef0dc

Please sign in to comment.