Skip to content

Commit

Permalink
AnglePickerControl: Style to better fit in narrow contexts and impr…
Browse files Browse the repository at this point in the history
…ove RTL layout (#49046)

* Move `AngleCircle` inside `NumberControl` as `suffix`

* Restyle

* Have the degree symbol on the right for both RTL/LTR

* Restyle

* Add changelog entry

* Correct name

* Sort changelog entry
  • Loading branch information
stokesman authored Mar 17, 2023
1 parent 23392e8 commit 6434e0b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 37 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Enhancements

- `CustomGradientPicker`: improve initial state UI ([#49146](https://github.com/WordPress/gutenberg/pull/49146)).
- `AnglePickerControl`: Style to better fit in narrow contexts and improve RTL layout ([#49046](https://github.com/WordPress/gutenberg/pull/49046)).

## 23.6.0 (2023-03-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ function AngleCircle( {
ref={ angleCircleRef }
onMouseDown={ startDrag }
className="components-angle-picker-control__angle-circle"
style={ isDragging ? { cursor: 'grabbing' } : undefined }
{ ...props }
>
<CircleIndicatorWrapper
Expand Down
41 changes: 14 additions & 27 deletions packages/components/src/angle-picker-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ import classnames from 'classnames';
*/
import deprecated from '@wordpress/deprecated';
import { forwardRef } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { isRTL, __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { FlexBlock, FlexItem } from '../flex';
import { FlexBlock } from '../flex';
import { Spacer } from '../spacer';
import NumberControl from '../number-control';
import AngleCircle from './angle-circle';
import { Root } from './styles/angle-picker-control-styles';
import { space } from '../ui/utils/space';
import { Text } from '../text';
import { Spacer } from '../spacer';
import { COLORS } from '../utils/colors-values';
import { Root, UnitText } from './styles/angle-picker-control-styles';

import type { WordPressComponentProps } from '../ui/context';
import type { AnglePickerControlProps } from './types';
Expand Down Expand Up @@ -64,13 +61,18 @@ function UnforwardedAnglePickerControl(

const classes = classnames( 'components-angle-picker-control', className );

const unitText = <UnitText>°</UnitText>;
const [ prefixedUnitText, suffixedUnitText ] = isRTL()
? [ unitText, null ]
: [ null, unitText ];

return (
<Root
{ ...restProps }
ref={ ref }
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
className={ classes }
gap={ 4 }
gap={ 2 }
>
<FlexBlock>
<NumberControl
Expand All @@ -83,32 +85,17 @@ function UnforwardedAnglePickerControl(
step="1"
value={ value }
spinControls="none"
suffix={
<Spacer
as={ Text }
marginBottom={ 0 }
marginRight={ space( 3 ) }
style={ {
color: COLORS.ui.theme,
} }
>
°
</Spacer>
}
prefix={ prefixedUnitText }
suffix={ suffixedUnitText }
/>
</FlexBlock>
<FlexItem
style={ {
marginBottom: space( 1 ),
marginTop: 'auto',
} }
>
<Spacer marginBottom="1" marginTop="auto">
<AngleCircle
aria-hidden="true"
value={ value }
onChange={ onChange }
/>
</FlexItem>
</Spacer>
</Root>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import styled from '@emotion/styled';
import { Flex } from '../../flex';
import { COLORS } from '../../utils';
import { space } from '../../ui/utils/space';
import { Text } from '../../text';
import CONFIG from '../../utils/config-values';

import type { AnglePickerControlProps } from '../types';

const CIRCLE_SIZE = 32;
const INNER_CIRCLE_SIZE = 3;
const INNER_CIRCLE_SIZE = 6;

const deprecatedBottomMargin = ( {
__nextHasNoMarginBottom,
Expand All @@ -39,6 +40,10 @@ export const CircleRoot = styled.div`
height: ${ CIRCLE_SIZE }px;
overflow: hidden;
width: ${ CIRCLE_SIZE }px;
:active {
cursor: grabbing;
}
`;

export const CircleIndicatorWrapper = styled.div`
Expand All @@ -55,15 +60,17 @@ export const CircleIndicatorWrapper = styled.div`
export const CircleIndicator = styled.div`
background: ${ COLORS.ui.theme };
border-radius: 50%;
border: ${ INNER_CIRCLE_SIZE }px solid ${ COLORS.ui.theme };
bottom: 0;
box-sizing: border-box;
display: block;
height: 0px;
left: 0;
margin: auto;
left: 50%;
top: 4px;
transform: translateX( -50% );
position: absolute;
right: 0;
top: -${ CIRCLE_SIZE / 2 }px;
width: 0px;
width: ${ INNER_CIRCLE_SIZE }px;
height: ${ INNER_CIRCLE_SIZE }px;
`;

export const UnitText = styled( Text )`
color: ${ COLORS.ui.theme };
margin-right: ${ space( 3 ) };
`;

1 comment on commit 6434e0b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 6434e0b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4450827520
📝 Reported issues:

Please sign in to comment.