Skip to content

Commit

Permalink
RangeControl: Improve disabled rendering and interactions
Browse files Browse the repository at this point in the history
This update improves the UI rendering of the RangeControl, sepcifically by muting the Rail, Track, and Marks. The disabled prop is also passed along to the inner (number) Input and Reset value button.
  • Loading branch information
Jon Q committed Mar 9, 2020
1 parent b11bc56 commit c97c754
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/components/src/range-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const BaseRangeControl = forwardRef(
/>
<RangeRail
aria-hidden={ true }
disabled={ disabled }
marks={ marks }
max={ max }
min={ min }
Expand All @@ -201,6 +202,7 @@ const BaseRangeControl = forwardRef(
<Track
aria-hidden={ true }
className="components-range-control__track"
disabled={ disabled }
style={ { width: fillValueOffset } }
/>
<ThumbWrapper style={ offsetStyle }>
Expand Down Expand Up @@ -230,6 +232,7 @@ const BaseRangeControl = forwardRef(
<InputNumber
aria-label={ label }
className="components-range-control__number"
disabled={ disabled }
inputMode="decimal"
max={ max }
min={ min }
Expand All @@ -243,7 +246,7 @@ const BaseRangeControl = forwardRef(
<ActionRightWrapper>
<Button
className="components-range-control__reset"
disabled={ value === undefined }
disabled={ disabled || value === undefined }
isSecondary
isSmall
onClick={ handleOnReset }
Expand Down
20 changes: 17 additions & 3 deletions packages/components/src/range-control/rail.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import RangeMark from './mark';
import { MarksWrapper, Rail } from './styles/range-control-styles';

export default function RangeRail( {
disabled = false,
marks = false,
min = 0,
max = 100,
Expand All @@ -18,9 +19,10 @@ export default function RangeRail( {
} ) {
return (
<>
<Rail { ...restProps } />
<Rail disabled={ disabled } { ...restProps } />
{ marks && (
<Marks
disabled={ disabled }
marks={ marks }
min={ min }
max={ max }
Expand All @@ -32,7 +34,14 @@ export default function RangeRail( {
);
}

function Marks( { marks = false, min = 0, max = 100, step = 1, value = 0 } ) {
function Marks( {
disabled = false,
marks = false,
min = 0,
max = 100,
step = 1,
value = 0,
} ) {
const marksData = useMarks( { marks, min, max, step, value } );

return (
Expand All @@ -41,7 +50,12 @@ function Marks( { marks = false, min = 0, max = 100, step = 1, value = 0 } ) {
className="components-range-control__marks"
>
{ marksData.map( ( mark ) => (
<RangeMark { ...mark } key={ mark.key } aria-hidden="true" />
<RangeMark
{ ...mark }
key={ mark.key }
aria-hidden="true"
disabled={ disabled }
/>
) ) }
</MarksWrapper>
);
Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/range-control/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const RangeControlWithState = ( props ) => {

const DefaultExample = () => {
const [ isRtl, setIsRtl ] = useState( false );
const [ value, setValue ] = useState( undefined );

const rtl = boolean( 'RTL', false );
const props = {
allowReset: boolean( 'allowReset', false ),
disabled: boolean( 'disabled', false ),
label: text( 'label', 'Range Label' ),
help: text( 'help', '' ),
min: number( 'min', 0 ),
Expand All @@ -39,8 +40,12 @@ const DefaultExample = () => {
beforeIcon: text( 'beforeIcon', '' ),
afterIcon: text( 'afterIcon', '' ),
withInputField: boolean( 'withInputField', true ),
value,
onChange: setValue,
};

const rtl = boolean( 'RTL', false );

useEffect( () => {
if ( rtl !== isRtl ) {
setIsRtl( rtl );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const AfterIconWrapper = styled.span`
${rtl( { marginLeft: 16 } )}
`;

const disabledRailBackgroundColor = ( { disabled } ) => {
if ( ! disabled ) return '';
return css( {
backgroundColor: color( 'lightGray.400' ),
} );
};

export const Rail = styled.span`
background-color: ${color( 'lightGray.600' )};
box-sizing: border-box;
Expand All @@ -64,8 +71,17 @@ export const Rail = styled.span`
position: absolute;
margin-top: 14px;
top: 0;
${disabledRailBackgroundColor};
`;

const disabledBackgroundColor = ( { disabled } ) => {
if ( ! disabled ) return '';
return css( {
backgroundColor: color( 'lightGray.800' ),
} );
};

export const Track = styled.span`
background-color: currentColor;
border-radius: 1px;
Expand All @@ -76,6 +92,8 @@ export const Track = styled.span`
position: absolute;
margin-top: 14px;
top: 0;
${disabledBackgroundColor};
`;

export const MarksWrapper = styled.span`
Expand All @@ -101,6 +119,7 @@ export const Mark = styled.span`
width: 1px;
${markFill};
${disabledBackgroundColor};
`;

const markLabelFill = ( { isFilled } ) => {
Expand Down
Loading

0 comments on commit c97c754

Please sign in to comment.