-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { forwardRefType } from '@react-types/shared'; | ||
import type { ForwardedRef } from 'react'; | ||
import type { GridListItemProps, GridListProps } from 'react-aria-components'; | ||
|
||
import { cva } from 'class-variance-authority'; | ||
import { forwardRef } from 'react'; | ||
import { | ||
GridList as AriaGridList, | ||
GridListItem as AriaGridListItem, | ||
composeRenderProps, | ||
} from 'react-aria-components'; | ||
|
||
import styles from './styles/GridList.module.css'; | ||
|
||
const list = cva(styles.list); | ||
const item = cva(styles.item); | ||
|
||
const _GridList = <T extends object>( | ||
props: GridListProps<T>, | ||
ref: ForwardedRef<HTMLDivElement>, | ||
) => { | ||
return ( | ||
<AriaGridList | ||
{...props} | ||
ref={ref} | ||
className={composeRenderProps(props.className, (className, renderProps) => | ||
list({ ...renderProps, className }), | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
/** | ||
* A grid list displays a list of interactive items, with support for keyboard navigation, single or multiple selection, and row actions. | ||
* | ||
* https://react-spectrum.adobe.com/react-aria/GridList.html | ||
*/ | ||
const GridList = (forwardRef as forwardRefType)(_GridList); | ||
|
||
const _GridListItem = <T extends object>(props: GridListItemProps<T>, ref: ForwardedRef<T>) => { | ||
const textValue = | ||
props.textValue || (typeof props.children === 'string' ? props.children : undefined); | ||
return ( | ||
<AriaGridListItem | ||
textValue={textValue} | ||
{...props} | ||
ref={ref} | ||
className={composeRenderProps(props.className, (className, renderProps) => | ||
item({ ...renderProps, className }), | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
/** | ||
* A GridListItem represents an individual item in a GridList. | ||
* | ||
* https://react-spectrum.adobe.com/react-aria/GridList.html | ||
*/ | ||
const GridListItem = (forwardRef as forwardRefType)(_GridListItem); | ||
|
||
export { GridList, GridListItem }; | ||
export type { GridListProps, GridListItemProps }; |
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,17 @@ | ||
.list { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.item { | ||
composes: interactive from './base.module.css'; | ||
display: flex; | ||
align-items: center; | ||
box-shadow: inset 0 -1px 0 0 var(--lp-color-border-ui-secondary); | ||
outline: none; | ||
padding-block: var(--lp-spacing-300); | ||
|
||
&[data-hovered] { | ||
background-color: var(--lp-color-bg-ui-secondary); | ||
} | ||
} |
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,32 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { GridList, GridListItem } from '../src'; | ||
|
||
const meta: Meta<typeof GridList> = { | ||
component: GridList, | ||
// @ts-ignore | ||
subcomponents: { GridListItem }, | ||
title: 'Components/Collections/GridList', | ||
parameters: { | ||
status: { | ||
type: import.meta.env.STORYBOOK_PACKAGE_STATUS__COMPONENTS, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof GridList>; | ||
|
||
export const Example: Story = { | ||
args: { | ||
children: ( | ||
<> | ||
<GridListItem>Item one</GridListItem> | ||
<GridListItem>Item two</GridListItem> | ||
<GridListItem>Item three</GridListItem> | ||
</> | ||
), | ||
selectionMode: 'single', | ||
}, | ||
}; |
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