Skip to content

Commit

Permalink
feat(tables): add emptyLabel prop to DataTable
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Nov 13, 2024
1 parent 9a48fef commit b7f025a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .storybook/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ const ARG_TYPE_TYPED: Meta['argTypes'] = {
}
}
},
OPTIONAL_REACT_NODE: {
control: 'text',
table: {
type: {
summary: 'ReactNode | undefined'
}
}
},
OPTIONAL_SIZE: {
control: 'radio',
// eslint-disable-next-line object-shorthand
Expand Down
8 changes: 5 additions & 3 deletions src/tables/DataTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getSortedRowModel,
useReactTable
} from '@tanstack/react-table'
import { useState } from 'react'
import { useState, type ReactNode } from 'react'
import styled from 'styled-components'

import { Td } from './Td'
Expand All @@ -18,13 +18,15 @@ import type { AnyObject } from '../../types/definitions'
export type DataTableProps<T extends AnyObject> = {
columns: Array<ColumnDef<T>>
data: T[] | undefined
emptyLabel?: ReactNode
initialSorting: SortingState
tableOptions?: Partial<TableOptions<T>> | undefined
withoutHead?: boolean | undefined
}
export function DataTable<T extends AnyObject>({
columns,
data,
emptyLabel,
initialSorting,
tableOptions,
withoutHead = false
Expand All @@ -49,11 +51,11 @@ export function DataTable<T extends AnyObject>({

return (
<>
{!data && <p>Chargement en cours...</p>}
{!data && <p className="Table-DataTable--loadingLabel">Chargement en cours...</p>}

{data && (
<>
{!data.length && <p>Aucune donnée.</p>}
{!data.length && (emptyLabel ?? <p className="Table-DataTable--emptyLabel">Aucune donnée.</p>)}

{data.length > 0 && (
<SimpleTable.Table>
Expand Down
1 change: 1 addition & 0 deletions stories/tables/DataTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const meta: Meta<DataTableProps<FakeBasicTableDataItem>> = {
component: DataTable,

argTypes: {
emptyLabel: ARG_TYPE.OPTIONAL_REACT_NODE,
tableOptions: {
...ARG_TYPE.NO_CONTROL_INPUT,
table: {
Expand Down

0 comments on commit b7f025a

Please sign in to comment.