chore(ui): add tsdocs for DataTable components (#11087)
Add TSDocs for `DataTable` components to generate better docs for their props
This commit is contained in:
1 parent
5ff45f27a1
commit
75ae707e4d
13 files changed
+85
No files matched your search
@@ -77,6 +77,7 @@ const DataTableActionCell = <TData,>({
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableActionCell.displayName = "DataTable.ActionCell"
|
||||||
|
|
||||||
export { DataTableActionCell }
|
export { DataTableActionCell }
|
||||||
export type { DataTableActionCellProps }
|
export type { DataTableActionCellProps }
|
||||||
|
|||||||
@@ -6,9 +6,17 @@ import { useDataTableContext } from "@/blocks/data-table/context/use-data-table-
|
|||||||
import { CommandBar } from "@/components/command-bar"
|
import { CommandBar } from "@/components/command-bar"
|
||||||
|
|
||||||
interface DataTableCommandBarProps {
|
interface DataTableCommandBarProps {
|
||||||
|
/**
|
||||||
|
* The label to show when items are selected. If a function is passed,
|
||||||
|
* it will be called with the count of selected items.
|
||||||
|
*/
|
||||||
selectedLabel?: ((count: number) => string) | string
|
selectedLabel?: ((count: number) => string) | string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component adds a command bar to the data table, which is used
|
||||||
|
* to show commands that can be executed on the selected rows.
|
||||||
|
*/
|
||||||
const DataTableCommandBar = (props: DataTableCommandBarProps) => {
|
const DataTableCommandBar = (props: DataTableCommandBarProps) => {
|
||||||
const { instance } = useDataTableContext()
|
const { instance } = useDataTableContext()
|
||||||
|
|
||||||
@@ -55,6 +63,7 @@ const DataTableCommandBar = (props: DataTableCommandBarProps) => {
|
|||||||
</CommandBar>
|
</CommandBar>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableCommandBar.displayName = "DataTable.CommandBar"
|
||||||
|
|
||||||
export { DataTableCommandBar }
|
export { DataTableCommandBar }
|
||||||
export type { DataTableCommandBarProps }
|
export type { DataTableCommandBarProps }
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ const DataTableFilterBar = ({
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableFilterBar.displayName = "DataTable.FilterBar"
|
||||||
|
|
||||||
const DataTableFilterBarSkeleton = ({
|
const DataTableFilterBarSkeleton = ({
|
||||||
filterCount,
|
filterCount,
|
||||||
|
|||||||
@@ -8,9 +8,16 @@ import { Tooltip } from "@/components/tooltip"
|
|||||||
import { Funnel } from "@medusajs/icons"
|
import { Funnel } from "@medusajs/icons"
|
||||||
|
|
||||||
interface DataTableFilterMenuProps {
|
interface DataTableFilterMenuProps {
|
||||||
|
/**
|
||||||
|
* The tooltip to show when hovering over the filter menu.
|
||||||
|
*/
|
||||||
tooltip?: string
|
tooltip?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component adds a filter menu to the data table, allowing users
|
||||||
|
* to filter the table's data.
|
||||||
|
*/
|
||||||
const DataTableFilterMenu = (props: DataTableFilterMenuProps) => {
|
const DataTableFilterMenu = (props: DataTableFilterMenuProps) => {
|
||||||
const { instance } = useDataTableContext()
|
const { instance } = useDataTableContext()
|
||||||
|
|
||||||
@@ -56,6 +63,7 @@ const DataTableFilterMenu = (props: DataTableFilterMenuProps) => {
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableFilterMenu.displayName = "DataTable.FilterMenu"
|
||||||
|
|
||||||
const DataTableFilterMenuSkeleton = () => {
|
const DataTableFilterMenuSkeleton = () => {
|
||||||
return <Skeleton className="size-7" />
|
return <Skeleton className="size-7" />
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ const DataTableFilter = ({ id, filter }: DataTableFilterProps) => {
|
|||||||
</Popover>
|
</Popover>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableFilter.displayName = "DataTable.Filter"
|
||||||
|
|
||||||
type DataTableFilterDateContentProps = {
|
type DataTableFilterDateContentProps = {
|
||||||
id: string
|
id: string
|
||||||
|
|||||||
@@ -7,9 +7,15 @@ import { Skeleton } from "@/components/skeleton"
|
|||||||
import { Table } from "@/components/table"
|
import { Table } from "@/components/table"
|
||||||
|
|
||||||
interface DataTablePaginationProps {
|
interface DataTablePaginationProps {
|
||||||
|
/**
|
||||||
|
* The translations for strings in the pagination component.
|
||||||
|
*/
|
||||||
translations?: React.ComponentProps<typeof Table.Pagination>["translations"]
|
translations?: React.ComponentProps<typeof Table.Pagination>["translations"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component adds a pagination component and functionality to the data table.
|
||||||
|
*/
|
||||||
const DataTablePagination = (props: DataTablePaginationProps) => {
|
const DataTablePagination = (props: DataTablePaginationProps) => {
|
||||||
const { instance } = useDataTableContext()
|
const { instance } = useDataTableContext()
|
||||||
|
|
||||||
@@ -38,6 +44,7 @@ const DataTablePagination = (props: DataTablePaginationProps) => {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTablePagination.displayName = "DataTable.Pagination"
|
||||||
|
|
||||||
const DataTablePaginationSkeleton = () => {
|
const DataTablePaginationSkeleton = () => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -8,11 +8,24 @@ import * as React from "react"
|
|||||||
import { useDataTableContext } from "@/blocks/data-table/context/use-data-table-context"
|
import { useDataTableContext } from "@/blocks/data-table/context/use-data-table-context"
|
||||||
|
|
||||||
interface DataTableSearchProps {
|
interface DataTableSearchProps {
|
||||||
|
/**
|
||||||
|
* If true, the search input will be focused on mount.
|
||||||
|
*/
|
||||||
autoFocus?: boolean
|
autoFocus?: boolean
|
||||||
|
/**
|
||||||
|
* Additional classes to pass to the search input.
|
||||||
|
*/
|
||||||
className?: string
|
className?: string
|
||||||
|
/**
|
||||||
|
* The placeholder text to show in the search input.
|
||||||
|
*/
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component adds a search input to the data table, allowing users
|
||||||
|
* to search through the table's data.
|
||||||
|
*/
|
||||||
const DataTableSearch = (props: DataTableSearchProps) => {
|
const DataTableSearch = (props: DataTableSearchProps) => {
|
||||||
const { className, ...rest } = props
|
const { className, ...rest } = props
|
||||||
const { instance } = useDataTableContext()
|
const { instance } = useDataTableContext()
|
||||||
@@ -43,6 +56,7 @@ const DataTableSearch = (props: DataTableSearchProps) => {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableSearch.displayName = "DataTable.Search"
|
||||||
|
|
||||||
const DataTableSearchSkeleton = () => {
|
const DataTableSearchSkeleton = () => {
|
||||||
return <Skeleton className="h-7 w-[128px]" />
|
return <Skeleton className="h-7 w-[128px]" />
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const DataTableSelectCell = <TData,>(props: DataTableSelectCellProps<TData>) =>
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableSelectCell.displayName = "DataTable.SelectCell"
|
||||||
|
|
||||||
interface DataTableSelectHeaderProps<TData> {
|
interface DataTableSelectHeaderProps<TData> {
|
||||||
ctx: DataTableHeaderContext<TData, unknown>
|
ctx: DataTableHeaderContext<TData, unknown>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ const DataTableSortingIcon = (props: SortingIconProps) => {
|
|||||||
</svg>
|
</svg>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableSortingIcon.displayName = "DataTable.SortingIcon"
|
||||||
|
|
||||||
export { DataTableSortingIcon }
|
export { DataTableSortingIcon }
|
||||||
export type { SortingIconProps }
|
export type { SortingIconProps }
|
||||||
|
|||||||
@@ -10,9 +10,16 @@ import { ArrowDownMini, ArrowUpMini, DescendingSorting } from "@medusajs/icons"
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
interface DataTableSortingMenuProps {
|
interface DataTableSortingMenuProps {
|
||||||
|
/**
|
||||||
|
* The tooltip to show when hovering over the sorting menu.
|
||||||
|
*/
|
||||||
tooltip?: string
|
tooltip?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component adds a sorting menu to the data table, allowing users
|
||||||
|
* to sort the table's data.
|
||||||
|
*/
|
||||||
const DataTableSortingMenu = (props: DataTableSortingMenuProps) => {
|
const DataTableSortingMenu = (props: DataTableSortingMenuProps) => {
|
||||||
const { instance } = useDataTableContext()
|
const { instance } = useDataTableContext()
|
||||||
|
|
||||||
@@ -114,6 +121,7 @@ const DataTableSortingMenu = (props: DataTableSortingMenuProps) => {
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableSortingMenu.displayName = "DataTable.SortingMenu"
|
||||||
|
|
||||||
function getSortLabel(column: DataTableColumn<any, unknown>) {
|
function getSortLabel(column: DataTableColumn<any, unknown>) {
|
||||||
const meta = column.columnDef.meta as DataTableSortableColumnDefMeta | undefined
|
const meta = column.columnDef.meta as DataTableSortableColumnDefMeta | undefined
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ interface DataTableTableProps {
|
|||||||
emptyState?: DataTableEmptyStateProps
|
emptyState?: DataTableEmptyStateProps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component renders the table in a data table, supporting advanced features.
|
||||||
|
*/
|
||||||
const DataTableTable = (props: DataTableTableProps) => {
|
const DataTableTable = (props: DataTableTableProps) => {
|
||||||
const [hoveredRowId, setHoveredRowId] = React.useState<string | null>(null)
|
const [hoveredRowId, setHoveredRowId] = React.useState<string | null>(null)
|
||||||
const isKeyDown = React.useRef(false)
|
const isKeyDown = React.useRef(false)
|
||||||
@@ -254,6 +257,7 @@ const DataTableTable = (props: DataTableTableProps) => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DataTableTable.displayName = "DataTable.Table"
|
||||||
|
|
||||||
interface DataTableEmptyStateDisplayProps {
|
interface DataTableEmptyStateDisplayProps {
|
||||||
state: DataTableEmptyState
|
state: DataTableEmptyState
|
||||||
|
|||||||
@@ -11,11 +11,23 @@ interface DataTableToolbarTranslations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface DataTableToolbarProps {
|
interface DataTableToolbarProps {
|
||||||
|
/**
|
||||||
|
* Additional classes to pass to the wrapper `div` of the component.
|
||||||
|
*/
|
||||||
className?: string
|
className?: string
|
||||||
|
/**
|
||||||
|
* The children to show in the toolbar.
|
||||||
|
*/
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
|
/**
|
||||||
|
* The translations of strings in the toolbar.
|
||||||
|
*/
|
||||||
translations?: DataTableToolbarTranslations
|
translations?: DataTableToolbarTranslations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toolbar shown for the data table.
|
||||||
|
*/
|
||||||
const DataTableToolbar = (props: DataTableToolbarProps) => {
|
const DataTableToolbar = (props: DataTableToolbarProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col divide-y">
|
<div className="flex flex-col divide-y">
|
||||||
|
|||||||
@@ -14,12 +14,29 @@ import { DataTableToolbar } from "./components/data-table-toolbar"
|
|||||||
import { DataTableContextProvider } from "./context/data-table-context-provider"
|
import { DataTableContextProvider } from "./context/data-table-context-provider"
|
||||||
import { UseDataTableReturn } from "./use-data-table"
|
import { UseDataTableReturn } from "./use-data-table"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The props of the `DataTable` component.
|
||||||
|
*/
|
||||||
interface DataTableProps<TData> {
|
interface DataTableProps<TData> {
|
||||||
|
/**
|
||||||
|
* The instance returned by the `useDataTable` hook.
|
||||||
|
*/
|
||||||
instance: UseDataTableReturn<TData>
|
instance: UseDataTableReturn<TData>
|
||||||
|
/**
|
||||||
|
* The children of the component.
|
||||||
|
*/
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
|
/**
|
||||||
|
* Additional classes to pass to the wrapper `div` of the component.
|
||||||
|
*/
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component creates a data table with filters, pagination, sorting, and more.
|
||||||
|
* It's built on top of the `Table` component while expanding its functionality.
|
||||||
|
* The `DataTable` is useful to create tables similar to those in the Medusa Admin dashboard.
|
||||||
|
*/
|
||||||
const Root = <TData,>({
|
const Root = <TData,>({
|
||||||
instance,
|
instance,
|
||||||
children,
|
children,
|
||||||
@@ -33,6 +50,7 @@ const Root = <TData,>({
|
|||||||
</DataTableContextProvider>
|
</DataTableContextProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Root.displayName = "DataTable"
|
||||||
|
|
||||||
const DataTable = Object.assign(Root, {
|
const DataTable = Object.assign(Root, {
|
||||||
Table: DataTableTable,
|
Table: DataTableTable,
|
||||||
|
|||||||
Reference in new issue
Block a user