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

fix: tables not rendering checkbox component #25

Merged
merged 3 commits into from
Apr 20, 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
2 changes: 1 addition & 1 deletion packages/react/src/components/table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const defaultProps = {
export const Default: StoryFn = (args: TableProps) => (
<Table {...args}>
<Table.Head>
<Table.Column>Name</Table.Column>
<Table.Column isRowHeader>Name</Table.Column>
<Table.Column>Title</Table.Column>
<Table.Column>Email</Table.Column>
<Table.Column>Role</Table.Column>
Expand Down
9 changes: 5 additions & 4 deletions packages/react/src/components/table/TableCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as Polymophic from '@/utilities/polymorphic'
import type { TableVariantProps } from '@giantnodes/theme'
import type { CellProps } from 'react-aria-components'

import React from 'react'
Expand All @@ -8,7 +9,7 @@ import { useTableContext } from '@/components/table/use-table.hook'

const __ELEMENT_TYPE__ = 'td'

type ComponentOwnProps = CellProps
type ComponentOwnProps = CellProps & Pick<TableVariantProps, 'size'>

type ComponentProps<T extends React.ElementType> = Polymophic.ComponentPropsWithRef<T, ComponentOwnProps>

Expand All @@ -18,18 +19,18 @@ type ComponentType = <T extends React.ElementType = typeof __ELEMENT_TYPE__>(

const Component: ComponentType = React.forwardRef(
<T extends React.ElementType = typeof __ELEMENT_TYPE__>(props: ComponentProps<T>, ref: Polymophic.Ref<T>) => {
const { as, children, className, ...rest } = props
const { as, children, className, size, ...rest } = props

const Element = as ?? Cell

const { slots } = useTableContext()

const component = React.useMemo<CellProps>(
() => ({
className: slots.td({ className: className?.toString() }),
className: slots.td({ className: className?.toString(), size }),
...rest,
}),
[className, rest, slots]
[className, rest, size, slots]
)

return (
Expand Down
9 changes: 5 additions & 4 deletions packages/react/src/components/table/TableColumn.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as Polymophic from '@/utilities/polymorphic'
import type { TableVariantProps } from '@giantnodes/theme'
import type { ColumnProps } from 'react-aria-components'

import React from 'react'
Expand All @@ -8,7 +9,7 @@ import { useTableContext } from '@/components/table/use-table.hook'

const __ELEMENT_TYPE__ = 'th'

type ComponentOwnProps = ColumnProps
type ComponentOwnProps = ColumnProps & Pick<TableVariantProps, 'size'>

type ComponentProps<T extends React.ElementType> = Polymophic.ComponentPropsWithRef<T, ComponentOwnProps>

Expand All @@ -18,18 +19,18 @@ type ComponentType = <T extends React.ElementType = typeof __ELEMENT_TYPE__>(

const Component: ComponentType = React.forwardRef(
<T extends React.ElementType = typeof __ELEMENT_TYPE__>(props: ComponentProps<T>, ref: Polymophic.Ref<T>) => {
const { as, children, className, ...rest } = props
const { as, children, className, size, ...rest } = props

const Element = as ?? Column

const { slots } = useTableContext()

const component = React.useMemo<ColumnProps>(
() => ({
className: slots.th({ className: className?.toString() }),
className: slots.th({ className: className?.toString(), size }),
...rest,
}),
[className, rest, slots]
[className, rest, size, slots]
)

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/table/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type * as Polymophic from '@/utilities/polymorphic'
import type { TableHeaderProps } from 'react-aria-components'

import React from 'react'
import { Checkbox, Collection, TableHeader, useTableOptions } from 'react-aria-components'
import { Collection, TableHeader, useTableOptions } from 'react-aria-components'

import Checkbox from '@/components/checkbox/Checkbox'
import TableColumn from '@/components/table/TableColumn'
import { useTableContext } from '@/components/table/use-table.hook'

Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/table/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type * as Polymophic from '@/utilities/polymorphic'
import type { RowProps } from 'react-aria-components'

import React from 'react'
import { Button, Checkbox, Collection, Row, useTableOptions } from 'react-aria-components'
import { Button, Collection, Row, useTableOptions } from 'react-aria-components'

import Checkbox from '@/components/checkbox/Checkbox'
import TableCell from '@/components/table/TableCell'
import { useTableContext } from '@/components/table/use-table.hook'

Expand Down