Skip to content

Commit

Permalink
components: Use updated range styles (#33824)
Browse files Browse the repository at this point in the history
* Use updated range styles

* Add CHANGELOG entry

* Fix focus styles for Chrome and Safari

* Fix tooltip offset

* Remove default rail color value

* Remove margin and fix border radius

* Fix disabled styles

* Fix marks and simplify tooltip positioning
  • Loading branch information
sarayourfriend committed Aug 6, 2021
1 parent 14d80aa commit e5506ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Listen to `resize` events correctly in `useBreakpointIndex`. This hook is used in `useResponsiveValue` and consequently in the `Flex` and `Grid` components ([#33902](https://github.com/WordPress/gutenberg/pull/33902))

### Breaking Change

- Updated the visual styles of the RangeControl component ([#33824](https://github.com/WordPress/gutenberg/pull/33824))

## 15.0.0 (2021-07-29)

### Breaking Change
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/range-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ function RangeControl(
style={ { width: fillValueOffset } }
trackColor={ trackColor }
/>
<ThumbWrapper style={ offsetStyle }>
<ThumbWrapper style={ offsetStyle } disabled={ disabled }>
<Thumb
aria-hidden={ true }
isFocused={ isThumbFocused }
disabled={ disabled }
/>
</ThumbWrapper>
{ enableTooltip && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { COLORS, reduceMotion, rtl } from '../../utils';
import { space } from '../../ui/utils/space';

const rangeHeight = () => css( { height: 30, minHeight: 30 } );
const thumbSize = 20;
const thumbSize = 12;

export const Root = styled.div`
-webkit-tap-highlight-color: transparent;
Expand All @@ -37,15 +37,13 @@ export const Wrapper = styled.div`
color: ${ COLORS.blue.medium.focus };
display: block;
flex: 1;
padding-top: 15px;
padding-top: 18px;
position: relative;
width: 100%;
${ wrapperColor };
${ rangeHeight };
${ wrapperMargin };
${ rtl( { marginLeft: 10 } ) }
`;

export const BeforeIconWrapper = styled.span`
Expand Down Expand Up @@ -83,6 +81,7 @@ export const Rail = styled.span`
position: absolute;
margin-top: 14px;
top: 0;
border-radius: 9999px;
${ railBackgroundColor };
`;
Expand All @@ -101,7 +100,7 @@ const trackBackgroundColor = ( { disabled, trackColor } ) => {

export const Track = styled.span`
background-color: currentColor;
border-radius: 1px;
border-radius: 9999px;
box-sizing: border-box;
height: 3px;
pointer-events: none;
Expand Down Expand Up @@ -164,48 +163,64 @@ export const MarkLabel = styled.span`
${ markLabelFill };
`;

const thumbColor = ( { disabled } ) =>
disabled
? css`
background-color: ${ COLORS.lightGray[ 800 ] };
`
: css`
background-color: var( --wp-admin-theme-color );
`;

export const ThumbWrapper = styled.span`
align-items: center;
box-sizing: border-box;
display: flex;
height: ${ thumbSize }px;
justify-content: center;
margin-top: 5px;
margin-top: 9px;
outline: 0;
pointer-events: none;
position: absolute;
top: 0;
user-select: none;
width: ${ thumbSize }px;
border-radius: 50%;
transform: translateX( 4.5px );
${ rtl( { marginLeft: -10 } ) }
${ thumbColor };
${ rtl( { marginLeft: -10 } ) };
`;

const thumbFocus = ( { isFocused } ) => {
return css( {
borderColor: isFocused ? COLORS.ui.borderFocus : COLORS.darkGray[ 200 ],
boxShadow: isFocused
? `
0 0 0 1px ${ COLORS.ui.borderFocus }
`
: `
0 0 0 rgba(0, 0, 0, 0)
`,
} );
return isFocused
? css`
&::before {
content: ' ';
position: absolute;
background-color: transparent;
box-shadow: 0 0 0 1.5px var( --wp-admin-theme-color );
border-radius: 50%;
height: ${ thumbSize + 4 }px;
width: ${ thumbSize + 4 }px;
top: -2px;
left: -2px;
}
`
: '';
};

export const Thumb = styled.span`
align-items: center;
background-color: white;
border-radius: 50%;
border: 1px solid ${ COLORS.darkGray[ 200 ] };
box-sizing: border-box;
height: 100%;
outline: 0;
position: absolute;
user-select: none;
width: 100%;
${ thumbColor };
${ thumbFocus };
`;

Expand Down

0 comments on commit e5506ed

Please sign in to comment.