Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColorPicker: Style without accessing InputControl internals #59069

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading