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

TreeSelect: Deprecate 36px default size #67855

Merged
merged 5 commits into from
Dec 13, 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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Deprecations

- `TreeSelect`: Deprecate 36px default size ([#67855](https://github.com/WordPress/gutenberg/pull/67855)).
- `SelectControl`: Deprecate 36px default size ([#66898](https://github.com/WordPress/gutenberg/pull/66898)).

## 29.0.0 (2024-12-11)
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/input-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export interface InputBaseProps extends BaseProps, FlexProps {
* If you want to apply standard padding in accordance with the size variant, wrap the element in
* the provided `<InputControlPrefixWrapper>` component.
*
* @example
* ```jsx
Copy link
Member Author

Choose a reason for hiding this comment

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

Tweaking so the code snippets render correctly in a Markdown file.

* import {
* __experimentalInputControl as InputControl,
* __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
Expand All @@ -145,6 +145,7 @@ export interface InputBaseProps extends BaseProps, FlexProps {
* <InputControl
* prefix={<InputControlPrefixWrapper>@</InputControlPrefixWrapper>}
* />
* ```
*/
prefix?: ReactNode;
/**
Expand All @@ -154,7 +155,7 @@ export interface InputBaseProps extends BaseProps, FlexProps {
* If you want to apply standard padding in accordance with the size variant, wrap the element in
* the provided `<InputControlSuffixWrapper>` component.
*
* @example
* ```jsx
* import {
* __experimentalInputControl as InputControl,
* __experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
Expand All @@ -163,6 +164,7 @@ export interface InputBaseProps extends BaseProps, FlexProps {
* <InputControl
* suffix={<InputControlSuffixWrapper>%</InputControlSuffixWrapper>}
* />
* ```
*/
suffix?: ReactNode;
/**
Expand Down
171 changes: 143 additions & 28 deletions packages/components/src/tree-select/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# TreeSelect

TreeSelect component is used to generate select input fields.
<!-- This file is generated automatically and cannot be edited directly. Make edits via TypeScript types and TSDocs. -->
Copy link
Member Author

Choose a reason for hiding this comment

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

Taking this opportunity to convert this to an auto-generated README.


## Usage
<p class="callout callout-info">See the <a href="https://wordpress.github.io/gutenberg/?path=/docs/components-treeselect--docs">WordPress Storybook</a> for more detailed, interactive documentation.</p>

Render a user interface to select the parent page in a hierarchy of pages:
Generates a hierarchical select input.

```jsx
import { useState } from 'react';
Expand All @@ -15,7 +15,8 @@ const MyTreeSelect = () => {

return (
<TreeSelect
__nextHasNoMarginBottom
__nextHasNoMarginBottom
__next40pxDefaultSize
label="Parent page"
noOptionLabel="No parent page"
onChange={ ( newPage ) => setPage( newPage ) }
Expand Down Expand Up @@ -50,51 +51,165 @@ const MyTreeSelect = () => {
);
}
```

## Props

The set of props accepted by the component will be specified below.
Props not included in this set will be applied to the SelectControl component being used.
Copy link
Member

Choose a reason for hiding this comment

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

I think this is useful information that we removed by auto-generating the README. Can we make sure it gets included?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmm right, I think this is something we need to address at the package level. The majority of our components that do pass down props, we don't say that explicitly (e.g. in the canonical Storybook props docs), even though the TS types include them.

Extracted to #67979

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to be addressed as a follow-up 👍

### `__next40pxDefaultSize`

Start opting into the larger default height that will become the default size in a future version.

- Type: `boolean`
- Required: No
- Default: `false`

### `__nextHasNoMarginBottom`

Start opting into the new margin-free styles that will become the default in a future version.

- Type: `boolean`
- Required: No
- Default: `false`

### `children`

As an alternative to the `options` prop, `optgroup`s and `options` can be
passed in as `children` for more customizability.

- Type: `ReactNode`
- Required: No

### `disabled`

### label
If true, the `input` will be disabled.

- Type: `boolean`
- Required: No
- Default: `false`

### `hideLabelFromVision`

If true, the label will only be visible to screen readers.

- Type: `boolean`
- Required: No
- Default: `false`

### `help`

Additional description for the control.

Only use for meaningful description or instructions for the control. An element containing the description will be programmatically associated to the BaseControl by the means of an `aria-describedby` attribute.

- Type: `ReactNode`
- Required: No

### `label`

If this property is added, a label will be generated using label property as the content.

- Type: `String`
- Required: No
- Type: `ReactNode`
- Required: No

### `labelPosition`

The position of the label.

### noOptionLabel
- Type: `"top" | "bottom" | "side" | "edge"`
- Required: No
- Default: `'top'`

### `noOptionLabel`

If this property is added, an option will be added with this label to represent empty selection.

- Type: `String`
- Required: No
- Type: `string`
- Required: No

### `onChange`

A function that receives the value of the new option that is being selected as input.

- Type: `(value: string, extra?: { event?: ChangeEvent<HTMLSelectElement>; }) => void`
- Required: No

### `options`

An array of option property objects to be rendered,
each with a `label` and `value` property, as well as any other
`<option>` attributes.

### onChange
- Type: `readonly ({ label: string; value: string; } & Omit<OptionHTMLAttributes<HTMLOptionElement>, "label" | "value">)[]`
- Required: No

A function that receives the id of the new node element that is being selected.
### `prefix`

Renders an element on the left side of the input.

By default, the prefix is aligned with the edge of the input border, with no padding.
If you want to apply standard padding in accordance with the size variant, wrap the element in
the provided `<InputControlPrefixWrapper>` component.

```jsx
import {
__experimentalInputControl as InputControl,
__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
} from '@wordpress/components';

<InputControl
prefix={<InputControlPrefixWrapper>@</InputControlPrefixWrapper>}
/>
```

- Type: `function`
- Required: Yes
- Type: `ReactNode`
- Required: No

### selectedId
### `selectedId`

The id of the currently selected node.

- Type: `string` | `string[]`
- Required: No
- Type: `string`
- Required: No

### tree
### `size`

Adjusts the size of the input.

- Type: `"default" | "small" | "compact" | "__unstable-large"`
- Required: No
- Default: `'default'`

### `suffix`

Renders an element on the right side of the input.

By default, the suffix is aligned with the edge of the input border, with no padding.
If you want to apply standard padding in accordance with the size variant, wrap the element in
the provided `<InputControlSuffixWrapper>` component.

```jsx
import {
__experimentalInputControl as InputControl,
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
} from '@wordpress/components';

<InputControl
suffix={<InputControlSuffixWrapper>%</InputControlSuffixWrapper>}
/>
```

- Type: `ReactNode`
- Required: No

### `tree`

An array containing the tree objects with the possible nodes the user can select.

- Type: `Object[]`
- Required: No
- Type: `Tree[]`
- Required: No

#### __nextHasNoMarginBottom
### `variant`

Start opting into the new margin-free styles that will become the default in a future version.
The style variant of the control.

- Type: `Boolean`
- Required: No
- Default: `false`
- Type: `"default" | "minimal"`
- Required: No
- Default: `'default'`
5 changes: 5 additions & 0 deletions packages/components/src/tree-select/docs-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "../../schemas/docs-manifest.json",
"displayName": "TreeSelect",
"filePath": "./index.tsx"
}
12 changes: 10 additions & 2 deletions packages/components/src/tree-select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SelectControl } from '../select-control';
import type { TreeSelectProps, Tree, Truthy } from './types';
import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';
import { ContextSystemProvider } from '../context';
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';

const CONTEXT_VALUE = {
BaseControl: {
Expand All @@ -35,18 +36,19 @@ function getSelectOptions(
}

/**
* TreeSelect component is used to generate select input fields.
* Generates a hierarchical select input.
*
* ```jsx
* import { useState } from 'react';
* import { TreeSelect } from '@wordpress/components';
* import { useState } from '@wordpress/element';
*
* const MyTreeSelect = () => {
* const [ page, setPage ] = useState( 'p21' );
*
* return (
* <TreeSelect
* __nextHasNoMarginBottom
* __next40pxDefaultSize
* label="Parent page"
* noOptionLabel="No parent page"
* onChange={ ( newPage ) => setPage( newPage ) }
Expand Down Expand Up @@ -99,6 +101,12 @@ export function TreeSelect( props: TreeSelectProps ) {
].filter( < T, >( option: T ): option is Truthy< T > => !! option );
}, [ noOptionLabel, tree ] );

maybeWarnDeprecated36pxSize( {
componentName: 'TreeSelect',
size: restProps.size,
__next40pxDefaultSize: restProps.__next40pxDefaultSize,
} );

return (
<ContextSystemProvider value={ CONTEXT_VALUE }>
<SelectControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const TreeSelectWithState: StoryFn< typeof TreeSelect > = ( props ) => {
export const Default = TreeSelectWithState.bind( {} );
Default.args = {
__nextHasNoMarginBottom: true,
__next40pxDefaultSize: true,
label: 'Label Text',
noOptionLabel: 'No parent page',
help: 'Help text to explain the select control.',
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/tree-select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ export interface Tree {
// `TreeSelect` inherits props from `SelectControl`, but only
// in single selection mode (ie. when the `multiple` prop is not defined).
export interface TreeSelectProps
extends Omit< SelectControlSingleSelectionProps, 'value' | 'multiple' > {
extends Omit<
SelectControlSingleSelectionProps,
'value' | 'multiple' | 'onChange'
> {
/**
* If this property is added, an option will be added with this label to represent empty selection.
*/
noOptionLabel?: string;
/**
* A function that receives the value of the new option that is being selected as input.
*/
onChange?: SelectControlSingleSelectionProps[ 'onChange' ];
Comment on lines +27 to +30
Copy link
Member Author

Choose a reason for hiding this comment

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

Overriding the prop description here because the original description includes mentions of a multiple prop, which doesn't exist in this component.

/**
* An array containing the tree objects with the possible nodes the user can select.
*/
Expand Down
Loading