Skip to content

Commit

Permalink
ColorPicker: Style without accessing InputControl internals (#59069)
Browse files Browse the repository at this point in the history
* ColorPicker: Use internal API for borderless select

* Set width without touching internals

* Update changelog
  • Loading branch information
mirka authored Feb 15, 2024
1 parent 109947d commit f33e8b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 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 @@

- `CustomSelectControl`: Remove deprecated `__nextUnconstrainedWidth` prop and promote to default behavior ([#58974](https://github.com/WordPress/gutenberg/pull/58974)).

### Internal

- `ColorPicker`: Style without accessing internal `InputControl` classes ([#59069](https://github.com/WordPress/gutenberg/pull/59069)).

## 26.0.1 (2024-02-13)

### Bug Fix
Expand Down
33 changes: 22 additions & 11 deletions packages/components/src/color-picker/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { useContextSystem, contextConnect } from '../context';
import {
useContextSystem,
contextConnect,
ContextSystemProvider,
} from '../context';
import {
ColorfulWrapper,
SelectControl,
Expand All @@ -39,6 +43,9 @@ const options = [
{ label: 'Hex', value: 'hex' as const },
];

// `isBorderless` is still experimental and not a public prop for InputControl yet.
const BORDERLESS_SELECT_CONTROL_CONTEXT = { InputBase: { isBorderless: true } };

const UnconnectedColorPicker = (
props: ColorPickerProps,
forwardedRef: ForwardedRef< any >
Expand Down Expand Up @@ -107,16 +114,20 @@ const UnconnectedColorPicker = (
/>
<AuxiliaryColorArtefactWrapper>
<AuxiliaryColorArtefactHStackHeader justify="space-between">
<SelectControl
__nextHasNoMarginBottom
options={ options }
value={ colorType }
onChange={ ( nextColorType ) =>
setColorType( nextColorType as ColorType )
}
label={ __( 'Color format' ) }
hideLabelFromVision
/>
<ContextSystemProvider
value={ BORDERLESS_SELECT_CONTROL_CONTEXT }
>
<SelectControl
__nextHasNoMarginBottom
options={ options }
value={ colorType }
onChange={ ( nextColorType ) =>
setColorType( nextColorType as ColorType )
}
label={ __( 'Color format' ) }
hideLabelFromVision
/>
</ContextSystemProvider>
<ColorCopyButton
color={ safeColordColor }
colorType={ copyFormat || colorType }
Expand Down
16 changes: 1 addition & 15 deletions packages/components/src/color-picker/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,15 @@ import { boxSizingReset } from '../utils';
import Button from '../button';
import { Flex } from '../flex';
import { HStack } from '../h-stack';
import {
BackdropUI,
Container as InputControlContainer,
} from '../input-control/styles/input-control-styles';
import CONFIG from '../utils/config-values';

export const NumberControlWrapper = styled( NumberControl )`
${ InputControlContainer } {
width: ${ space( 24 ) };
}
width: ${ space( 24 ) };
`;

export const SelectControl = styled( InnerSelectControl )`
margin-left: ${ space( -2 ) };
width: 5em;
/*
* Remove border, but preserve focus styles
* TODO: this override should be removed,
* see https://github.com/WordPress/gutenberg/pull/50609
*/
select:not( :focus ) ~ ${ BackdropUI }${ BackdropUI }${ BackdropUI } {
border-color: transparent;
}
`;

export const RangeControl = styled( InnerRangeControl )`
Expand Down

1 comment on commit f33e8b6

@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 f33e8b6.
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/7918012244
📝 Reported issues:

Please sign in to comment.