Skip to content

Commit

Permalink
docs(site): add ts-table docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps committed Apr 16, 2024
1 parent d3f052f commit b10b2a6
Show file tree
Hide file tree
Showing 9 changed files with 4,765 additions and 13,502 deletions.
1 change: 1 addition & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export type {
TableProps,
TableRowProps,
TableSortIndicatorProps,
TableOptions,
} from './table'
export { Tag } from './tag'
export type { TagProps } from './tag'
Expand Down
36 changes: 36 additions & 0 deletions packages/docs/examples/ts-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import { TsTable } from '@vtex/shoreline-ts-table'
import { Tag } from '@vtex/shoreline'

const data: Product[] = [
{
name: 'iPhone 15',
description: 'A nice phone',
brand: 'Apple',
category: 'smartphones',
},
]

interface Product {
name: string
description: string
brand: string
category: string
}

export default function Example() {
return (
<TsTable
data={data}
columns={[
{ accessorKey: 'name' },
{ accessorKey: 'description' },
{
accessorKey: 'brand',
cell: (cell) => <Tag>{cell.renderValue()}</Tag>,
},
{ accessorKey: 'category' },
]}
/>
)
}
2 changes: 2 additions & 0 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"@vtex/shoreline-icons": "workspace:*",
"@vtex/shoreline-theme-sunrise": "workspace:*",
"@vtex/shoreline-utils": "workspace:*",
"@vtex/shoreline-ts-table": "workspace:*",
"@tanstack/react-table": "8.16.0",
"fs-extra": "11.2.0",
"google": "link:@next/third-parties/google",
"next": "13.4.7",
Expand Down
1 change: 1 addition & 0 deletions packages/docs/pages/components/table/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tanstack-table": "@tanstack/react-table",
"best-practices": "Best Practices",
"figma-usage": "Figma Usage",
"table-body": "TableBody",
Expand Down
19 changes: 19 additions & 0 deletions packages/docs/pages/components/table/tanstack-table.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Usage with @tanstack/react-table

<ComponentDescription name="ts-table" />

The `@vtex/shoreline-ts-table` has `@tanstack/react-table` as peer dependency.

```sh npm2yarn copy
npm i @tanstack/react-table @vtex/shoreline-ts-table
```

<Preview name="ts-table" />

## Required props

<PropsDocs name="ts-table" required />

## Optional props

<PropsDocs name="ts-table" />
4 changes: 4 additions & 0 deletions packages/docs/scripts/build-props.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ const files = [
getPath('components', 'tooltip', 'tooltip-provider'),
getPath('components', 'tooltip', 'tooltip-popover'),
getPath('components', 'tooltip', 'tooltip-arrow'),
/**
* ts-table
*/
join(dirname(''), `../ts-table/src/ts-table.tsx`),
/**
* Date
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-table/src/ts-table-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const TsTableHeader = forwardRef(function TsTableHeader<T>(
header.column.columnDef.header,
header.getContext()
)}
<TableSortIndicator sorted={header.column.getIsSorted()} />
<TableSortIndicator sorted={header.column.getIsSorted() as any} />
</TableHeaderCell>
))}
</TableRow>
Expand Down
21 changes: 11 additions & 10 deletions packages/ts-table/src/ts-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
getSortedRowModel,
} from '@tanstack/react-table'
import { forwardRef, useMergeRef } from '@vtex/shoreline-utils'
import type { TableProps } from '@vtex/shoreline-components'
import type {
TableOptions as ShorelineTableOptions,
TableProps,
} from '@vtex/shoreline-components'
import {
Table,
TableRow,
Expand Down Expand Up @@ -139,20 +142,16 @@ export const TsTable = forwardRef(function TsTable<T>(

type CoreProps = 'data' | 'columns' | 'getRowCanExpand'

type Options<T> = Omit<TableOptions<T>, CoreProps | 'getCoreRowModel'> &
Partial<Pick<TableOptions<T>, 'getCoreRowModel'>>

type TsMirrorProps<T> = Pick<TableOptions<T>, CoreProps>

export interface TsTableProps<T>
extends TableProps,
TsMirrorProps<T>,
export interface TsTableOptions<T>
extends ShorelineTableOptions,
Pick<TableOptions<T>, CoreProps>,
Pick<TsTableRowProps<T>, 'rowClick' | 'renderDetail'> {
/**
* Other TanStack/Table options
* @see https://tanstack.com/table/v8/docs/api/core/table
*/
options?: Options<T>
options?: Omit<TableOptions<T>, CoreProps | 'getCoreRowModel'> &
Partial<Pick<TableOptions<T>, 'getCoreRowModel'>>
/**
* Defines if columns will be sortable
* @default false
Expand All @@ -171,3 +170,5 @@ export interface TsTableProps<T>
*/
virtualizer?: UseVirtualizerModelReturn
}

export type TsTableProps<T> = TsTableOptions<T> & TableProps
Loading

0 comments on commit b10b2a6

Please sign in to comment.