Skip to content

Commit

Permalink
Components: polish heading level component APIs (#47788)
Browse files Browse the repository at this point in the history
* ToolsPanel: mark `headingLevel` as optional, assign default value, add to README

* Rename `paletteLabelLevel` to `paletteLabelHeadingLevel`

* Sort props alphabetically

* Sync READMEs, correct types

* CHANGELOG
  • Loading branch information
ciampo committed Feb 6, 2023
1 parent dc32380 commit 15db909
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 24 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- `ColorPalette`, `GradientPicker`, `PaletteEdit`, `ToolsPanel`: add new props to set a custom heading level ([43848](https://github.com/WordPress/gutenberg/pull/43848) and [#47788](https://github.com/WordPress/gutenberg/pull/47788)).

### Internal

- `ComboboxControl`: Convert to TypeScript ([#47581](https://github.com/WordPress/gutenberg/pull/47581)).
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/color-palette/README.md
Expand Up @@ -66,6 +66,13 @@ colors.
- Required: No
- Default: `false`

### `headingLevel`: `1 | 2 | 3 | 4 | 5 | 6 | '1' | '2' | '3' | '4' | '5' | '6'`

The heading level.

- Required: No
- Default: `2`

### `value`: `string`

Currently active value.
Expand Down
12 changes: 6 additions & 6 deletions packages/components/src/color-palette/types.ts
Expand Up @@ -72,6 +72,12 @@ export type ColorPaletteProps = Pick< PaletteProps, 'onChange' > & {
* @default false
*/
enableAlpha?: boolean;
/**
* The heading level.
*
* @default 2
*/
headingLevel?: HeadingSize;
/**
* Currently active value.
*/
Expand All @@ -82,10 +88,4 @@ export type ColorPaletteProps = Pick< PaletteProps, 'onChange' > & {
* @default false
*/
__experimentalIsRenderedInSidebar?: boolean;
/**
* The heaeding level.
*
* @default 2
*/
headingLevel?: HeadingSize;
};
8 changes: 8 additions & 0 deletions packages/components/src/gradient-picker/README.md
Expand Up @@ -101,3 +101,11 @@ Start opting into the new margin-free styles that will become the default in a f
- Type: `Boolean`
- Required: No
- Default: `false`

### headingLevel

The heading level.

- Type: `1 | 2 | 3 | 4 | 5 | 6 | '1' | '2' | '3' | '4' | '5' | '6'`
- Required: No
- Default: `2`
4 changes: 2 additions & 2 deletions packages/components/src/palette-edit/index.js
Expand Up @@ -313,7 +313,7 @@ export default function PaletteEdit( {
colors = EMPTY_ARRAY,
onChange,
paletteLabel,
paletteLabelLevel = 2,
paletteLabelHeadingLevel = 2,
emptyMessage,
canOnlyChangeValues,
canReset,
Expand Down Expand Up @@ -348,7 +348,7 @@ export default function PaletteEdit( {
return (
<PaletteEditStyles>
<PaletteHStackHeader>
<PaletteHeading level={ paletteLabelLevel }>
<PaletteHeading level={ paletteLabelHeadingLevel }>
{ paletteLabel }
</PaletteHeading>
<PaletteActionsContainer>
Expand Down
Expand Up @@ -18,6 +18,13 @@ This component is generated automatically by its parent

## Props

### `headingLevel`: `1 | 2 | 3 | 4 | 5 | 6 | '1' | '2' | '3' | '4' | '5' | '6'`

The heading level of the panel's header.

- Required: No
- Default: `2`

### `label`: `string`

Text to be displayed within the panel header. It is also passed along as the
Expand Down
10 changes: 6 additions & 4 deletions packages/components/src/tools-panel/tools-panel-header/hook.ts
Expand Up @@ -15,10 +15,11 @@ import type { ToolsPanelHeaderProps } from '../types';
export function useToolsPanelHeader(
props: WordPressComponentProps< ToolsPanelHeaderProps, 'h2' >
) {
const { className, ...otherProps } = useContextSystem(
props,
'ToolsPanelHeader'
);
const {
className,
headingLevel = 2,
...otherProps
} = useContextSystem( props, 'ToolsPanelHeader' );

const cx = useCx();
const classes = useMemo( () => {
Expand Down Expand Up @@ -47,6 +48,7 @@ export function useToolsPanelHeader(
dropdownMenuClassName,
hasMenuItems,
headingClassName,
headingLevel,
menuItems,
className: classes,
};
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/tools-panel/tools-panel/README.md
Expand Up @@ -156,6 +156,13 @@ wrapper element allowing the panel to lay them out accordingly.

- Required: No

### `headingLevel`: `1 | 2 | 3 | 4 | 5 | 6 | '1' | '2' | '3' | '4' | '5' | '6'`

The heading level of the panel's header.

- Required: No
- Default: `2`

### `label`: `string`

Text to be displayed within the panel's header and as the `aria-label` for the
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/tools-panel/tools-panel/hook.ts
Expand Up @@ -57,6 +57,7 @@ export function useToolsPanel(
) {
const {
className,
headingLevel = 2,
resetAll,
panelId,
hasInnerWrapper,
Expand Down Expand Up @@ -307,6 +308,7 @@ export function useToolsPanel(

return {
...otherProps,
headingLevel,
panelContext,
resetAllItems,
toggleItem,
Expand Down
20 changes: 12 additions & 8 deletions packages/components/src/tools-panel/types.ts
Expand Up @@ -21,6 +21,12 @@ export type ToolsPanelProps = {
* wrapper element allowing the panel to lay them out accordingly.
*/
hasInnerWrapper: boolean;
/**
* The heading level of the panel's header.
*
* @default 2
*/
headingLevel?: HeadingSize;
/**
* Text to be displayed within the panel's header and as the `aria-label`
* for the panel's dropdown menu.
Expand Down Expand Up @@ -52,13 +58,15 @@ export type ToolsPanelProps = {
* last visible `ToolsPanelItem` within the `ToolsPanel`.
*/
__experimentalLastVisibleItemClass?: string;
/**
* The heading level of the panel's header.
*/
headingLevel: HeadingSize;
};

export type ToolsPanelHeaderProps = {
/**
* The heading level of the panel's header.
*
* @default 2
*/
headingLevel?: HeadingSize;
/**
* Text to be displayed within the panel header. It is also passed along as
* the `label` for the panel header's `DropdownMenu`.
Expand All @@ -76,10 +84,6 @@ export type ToolsPanelHeaderProps = {
* `onSelect` or `onDeselect` callbacks as appropriate.
*/
toggleItem: ( label: string ) => void;
/**
* The heading level of the panel's header.
*/
headingLevel: HeadingSize;
};

export type ToolsPanelItem = {
Expand Down
Expand Up @@ -55,7 +55,7 @@ export default function ColorPalettePanel( { name } ) {
colors={ themeColors }
onChange={ setThemeColors }
paletteLabel={ __( 'Theme' ) }
paletteLabelLevel={ 3 }
paletteLabelHeadingLevel={ 3 }
/>
) }
{ !! defaultColors &&
Expand All @@ -67,14 +67,14 @@ export default function ColorPalettePanel( { name } ) {
colors={ defaultColors }
onChange={ setDefaultColors }
paletteLabel={ __( 'Default' ) }
paletteLabelLevel={ 3 }
paletteLabelHeadingLevel={ 3 }
/>
) }
<PaletteEdit
colors={ customColors }
onChange={ setCustomColors }
paletteLabel={ __( 'Custom' ) }
paletteLabelLevel={ 3 }
paletteLabelHeadingLevel={ 3 }
emptyMessage={ __(
'Custom colors are empty! Add some colors to create your own color palette.'
) }
Expand Down
Expand Up @@ -75,7 +75,7 @@ export default function GradientPalettePanel( { name } ) {
gradients={ themeGradients }
onChange={ setThemeGradients }
paletteLabel={ __( 'Theme' ) }
paletteLabelLevel={ 3 }
paletteLabelHeadingLevel={ 3 }
/>
) }
{ !! defaultGradients &&
Expand Down

0 comments on commit 15db909

Please sign in to comment.