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

[RAC] Breadcrumbs: add Breadcrumb render props docs and export interface #6489

Merged
merged 3 commits into from
Jun 4, 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
17 changes: 16 additions & 1 deletion packages/react-aria-components/docs/Breadcrumbs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,19 @@ The `className` and `style` props also accept functions which receive states for
<Link className={({isCurrent}) => isCurrent ? 'bg-gray-700' : 'bg-gray-600'} />
```

Render props may also be used as children to alter what elements are rendered based on the current state. For example, you could render a link for all the breadcrumb items except the current one.

```jsx
<Breadcrumbs items={items}>
{(item) => (
<Breadcrumb>
{({isCurrent}) => isCurrent ? <strong>{item.label}</strong> : <Link>{item.label}</Link>}
</Breadcrumb>
)}
</Breadcrumbs>
```


The states, selectors, and render props for all components used in `Breadcrumbs` are documented below.

### Breadcrumbs
Expand All @@ -342,7 +355,9 @@ The states, selectors, and render props for all components used in `Breadcrumbs`

### Breadcrumb

A `Breadcrumb` can be targeted with the `.react-aria-Breadcrumb` CSS selector, or by overriding with a custom `className`. It is rendered as an `<li>` element, and should contain a `<Link>`. It may also include another element such as a [separator icon](#separator-icons).
A `Breadcrumb` can be targeted with the `.react-aria-Breadcrumb` CSS selector, or by overriding with a custom `className`. It is rendered as an `<li>` element, and should contain a `<Link>`. It may also include another element such as a [separator icon](#separator-icons). Breadcrumb support the following states and render props:

<StateTable properties={docs.exports.BreadcrumbRenderProps.properties} />

### Link

Expand Down
12 changes: 10 additions & 2 deletions packages/react-aria-components/src/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import {AriaBreadcrumbsProps} from 'react-aria';
import {Collection, Node} from 'react-stately';
import {CollectionChildren, CollectionProps, createLeafComponent, useCollection} from './Collection';
import {ContextValue, forwardRefType, SlotProps, StyleProps, useContextProps, useRenderProps, useSlottedContext} from './utils';
import {ContextValue, forwardRefType, RenderProps, SlotProps, StyleProps, useContextProps, useRenderProps, useSlottedContext} from './utils';
import {filterDOMProps} from '@react-aria/utils';
import {Key} from '@react-types/shared';
import {LinkContext} from './Link';
Expand Down Expand Up @@ -67,7 +67,15 @@ function BreadcrumbsInner<T extends object>({props, collection, breadcrumbsRef:
const _Breadcrumbs = /*#__PURE__*/ (forwardRef as forwardRefType)(Breadcrumbs);
export {_Breadcrumbs as Breadcrumbs};

export interface BreadcrumbProps extends StyleProps {
export interface BreadcrumbRenderProps {
/**
* Whether the breadcrumb is for the current page.
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

* @selector [data-current]
*/
isCurrent: boolean
}

export interface BreadcrumbProps extends RenderProps<BreadcrumbRenderProps> {
/** A unique id for the breadcrumb, which will be passed to `onAction` when the breadcrumb is pressed. */
id?: Key,
/** The children of the breadcrumb, typically a `<Link>`. */
Expand Down
2 changes: 1 addition & 1 deletion packages/react-aria-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export {DIRECTORY_DRAG_TYPE, isDirectoryDropItem, isFileDropItem, isTextDropItem
export {FormValidationContext} from 'react-stately';
export {parseColor, getColorChannels} from '@react-stately/color';

export type {BreadcrumbsProps, BreadcrumbProps} from './Breadcrumbs';
export type {BreadcrumbsProps, BreadcrumbProps, BreadcrumbRenderProps} from './Breadcrumbs';
export type {ButtonProps, ButtonRenderProps} from './Button';
export type {CalendarCellProps, CalendarProps, CalendarRenderProps, CalendarGridProps, CalendarGridHeaderProps, CalendarGridBodyProps, CalendarHeaderCellProps, CalendarCellRenderProps, RangeCalendarProps, RangeCalendarRenderProps} from './Calendar';
export type {CheckboxGroupProps, CheckboxGroupRenderProps, CheckboxRenderProps, CheckboxProps} from './Checkbox';
Expand Down