Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Aug 9, 2024
1 parent f12b7fd commit a9e31ed
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
7 changes: 5 additions & 2 deletions packages/components/src/base-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const MyCustomTextareaControl = ({ children, ...baseProps }) => (
const { baseControlProps, controlProps } = useBaseControlProps( baseProps );

return (
<BaseControl { ...baseControlProps } __nextHasNoMarginBottom={ true }>
<BaseControl { ...baseControlProps } __nextHasNoMarginBottom>
<textarea { ...controlProps }>
{ children }
</textarea>
Expand Down Expand Up @@ -92,7 +92,10 @@ It should only be used in cases where the children being rendered inside BaseCon
import { BaseControl } from '@wordpress/components';

const MyBaseControl = () => (
<BaseControl help="This button is already accessibly labeled.">
<BaseControl
__nextHasNoMarginBottom
help="This button is already accessibly labeled."
>
<BaseControl.VisualLabel>Author</BaseControl.VisualLabel>
<Button>Select an author</Button>
</BaseControl>
Expand Down
89 changes: 48 additions & 41 deletions packages/components/src/base-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,6 @@ import { contextConnectWithoutRef, useContextSystem } from '../context';

export { useBaseControlProps } from './hooks';

/**
* `BaseControl` is a component used to generate labels and help text for components handling user inputs.
*
* ```jsx
* import { BaseControl, useBaseControlProps } from '@wordpress/components';
*
* // Render a `BaseControl` for a textarea input
* const MyCustomTextareaControl = ({ children, ...baseProps }) => (
* // `useBaseControlProps` is a convenience hook to get the props for the `BaseControl`
* // and the inner control itself. Namely, it takes care of generating a unique `id`,
* // properly associating it with the `label` and `help` elements.
* const { baseControlProps, controlProps } = useBaseControlProps( baseProps );
*
* return (
* <BaseControl { ...baseControlProps } __nextHasNoMarginBottom={ true }>
* <textarea { ...controlProps }>
* { children }
* </textarea>
* </BaseControl>
* );
* );
* ```
*/
const UnconnectedBaseControl = (
props: WordPressComponentProps< BaseControlProps, null >
) => {
Expand Down Expand Up @@ -105,23 +82,6 @@ const UnconnectedBaseControl = (
);
};

/**
* `BaseControl.VisualLabel` is used to render a purely visual label inside a `BaseControl` component.
*
* It should only be used in cases where the children being rendered inside `BaseControl` are already accessibly labeled,
* e.g., a button, but we want an additional visual label for that section equivalent to the labels `BaseControl` would
* otherwise use if the `label` prop was passed.
*
* @example
* import { BaseControl } from '@wordpress/components';
*
* const MyBaseControl = () => (
* <BaseControl help="This button is already accessibly labeled.">
* <BaseControl.VisualLabel>Author</BaseControl.VisualLabel>
* <Button>Select an author</Button>
* </BaseControl>
* );
*/
const UnforwardedVisualLabel = (
props: WordPressComponentProps< BaseControlVisualLabelProps, 'span' >,
ref: ForwardedRef< any >
Expand All @@ -141,9 +101,56 @@ const UnforwardedVisualLabel = (

export const VisualLabel = forwardRef( UnforwardedVisualLabel );

/**
* `BaseControl` is a component used to generate labels and help text for components handling user inputs.
*
* ```jsx
* import { BaseControl, useBaseControlProps } from '@wordpress/components';
*
* // Render a `BaseControl` for a textarea input
* const MyCustomTextareaControl = ({ children, ...baseProps }) => (
* // `useBaseControlProps` is a convenience hook to get the props for the `BaseControl`
* // and the inner control itself. Namely, it takes care of generating a unique `id`,
* // properly associating it with the `label` and `help` elements.
* const { baseControlProps, controlProps } = useBaseControlProps( baseProps );
*
* return (
* <BaseControl { ...baseControlProps } __nextHasNoMarginBottom>
* <textarea { ...controlProps }>
* { children }
* </textarea>
* </BaseControl>
* );
* );
* ```
*/
export const BaseControl = Object.assign(
contextConnectWithoutRef( UnconnectedBaseControl, 'BaseControl' ),
{ VisualLabel }

{
/**
* `BaseControl.VisualLabel` is used to render a purely visual label inside a `BaseControl` component.
*
* It should only be used in cases where the children being rendered inside `BaseControl` are already accessibly labeled,
* e.g., a button, but we want an additional visual label for that section equivalent to the labels `BaseControl` would
* otherwise use if the `label` prop was passed.
*
* ```jsx
* import { BaseControl } from '@wordpress/components';
*
* const MyBaseControl = () => (
* <BaseControl
* __nextHasNoMarginBottom
* help="This button is already accessibly labeled."
* >
* <BaseControl.VisualLabel>Author</BaseControl.VisualLabel>
* <Button>Select an author</Button>
* </BaseControl>
* );
* ```
*/
VisualLabel,
}
);

export default BaseControl;

0 comments on commit a9e31ed

Please sign in to comment.