-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: promote
ItemGroup
(#33701)
- Loading branch information
Showing
20 changed files
with
634 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# `ItemGroup` | ||
|
||
<div class="callout callout-alert"> | ||
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes. | ||
</div> | ||
|
||
`ItemGroup` displays a list of `Item`s grouped and styled together. | ||
|
||
## Usage | ||
|
||
`ItemGroup` should be used in combination with the [`Item` sub-component](/packages/components/src/item-group/item/README.md). | ||
|
||
```jsx | ||
import { | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalItem as Item, | ||
} from '@wordpress/components'; | ||
|
||
function Example() { | ||
return ( | ||
<ItemGroup> | ||
<Item>Code</Item> | ||
<Item>is</Item> | ||
<Item>Poetry</Item> | ||
</ItemGroup> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
### `isBordered`: `boolean` | ||
|
||
Renders borders around each items. | ||
|
||
- Required: No | ||
- Default: `false` | ||
|
||
### `isRounded`: `boolean` | ||
|
||
Renders with rounded corners. | ||
|
||
- Required: No | ||
- Default: `true` | ||
|
||
### `isSeparated`: `boolean` | ||
|
||
Renders items individually. Even if `isBordered` is `false`, a border in between each item will be still be displayed. | ||
|
||
- Required: No | ||
- Default: `false` | ||
|
||
### `size`: `'small' | 'medium' | 'large'` | ||
|
||
Determines the amount of padding within the component. | ||
When not defined, it defaults to the value from the context (which is `medium` by default). | ||
|
||
- Required: No | ||
- Default: `medium` | ||
|
||
### Context | ||
|
||
The [`Item` sub-component](/packages/components/src/item-group/item/README.md) is connected to `<ItemGroup />` using [Context](https://reactjs.org/docs/context.html). Therefore, `Item` receives the `size` prop from the `ItemGroup` parent component. | ||
|
||
In the following example, the `<Item />` will render with a size of `small`: | ||
|
||
```jsx | ||
import { | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalItem as Item, | ||
} from '@wordpress/components'; | ||
|
||
const Example = () => ( | ||
<ItemGroup size="small"> | ||
<Item>Item text</Item> | ||
</ItemGroup> | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './component'; | ||
export { useItemGroup } from './hook'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# `Item` | ||
|
||
<div class="callout callout-alert"> | ||
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes. | ||
</div> | ||
|
||
`Item` is used in combination with `ItemGroup` to display a list of items grouped and styled together. | ||
|
||
## Usage | ||
|
||
`Item` should be used in combination with the [`ItemGroup` component](/packages/components/src/item-group/item-group/README.md). | ||
|
||
```jsx | ||
import { | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalItem as Item, | ||
} from '@wordpress/components'; | ||
|
||
function Example() { | ||
return ( | ||
<ItemGroup> | ||
<Item>Code</Item> | ||
<Item>is</Item> | ||
<Item>Poetry</Item> | ||
</ItemGroup> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
### `isAction`: `boolean` | ||
|
||
Renders the item as an interactive `button` element. | ||
|
||
- Required: No | ||
- Default: `false` | ||
|
||
### `size`: `'small' | 'medium' | 'large'` | ||
|
||
Determines the amount of padding within the component. | ||
|
||
- Required: No | ||
- Default: `medium` | ||
|
||
### Context | ||
|
||
`Item` is connected to [the `<ItemGroup />` parent component](/packages/components/src/item-group/item-group/README.md) using [Context](https://reactjs.org/docs/context.html). Therefore, `Item` receives the `size` prop from the `ItemGroup` parent component. | ||
|
||
In the following example, the `<Item />` will render with a size of `small`: | ||
|
||
```jsx | ||
import { | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalItem as Item, | ||
} from '@wordpress/components'; | ||
|
||
const Example = () => ( | ||
<ItemGroup size="small"> | ||
<Item>...</Item> | ||
</ItemGroup> | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
// eslint-disable-next-line no-restricted-imports | ||
import type { Ref } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { ItemProps } from '../types'; | ||
import { useItem } from './hook'; | ||
import { contextConnect, PolymorphicComponentProps } from '../../ui/context'; | ||
import { View } from '../../view'; | ||
|
||
function Item( | ||
props: PolymorphicComponentProps< ItemProps, 'div' >, | ||
forwardedRef: Ref< any > | ||
) { | ||
const { role, wrapperClassName, ...otherProps } = useItem( props ); | ||
|
||
return ( | ||
<div role={ role } className={ wrapperClassName }> | ||
<View { ...otherProps } ref={ forwardedRef } /> | ||
</div> | ||
); | ||
} | ||
|
||
export default contextConnect( Item, 'Item' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './component'; | ||
export { useItem } from './hook'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.