Skip to content
Open
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
16 changes: 14 additions & 2 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ export type TableProps = {
/** Default: false */
bottomCaption?: boolean;
style?: CSSProperties;
/** Default medium */
size?: "small" | "medium" | "large";
colorVariant?: TableProps.ColorVariant;
};

export namespace TableProps {
type ExtractColorVariant<FrClassName> = FrClassName extends `fr-table--${infer AccentColor}`
? Exclude<
AccentColor,
"no-scroll" | "no-caption" | "caption-bottom" | "layout-fixed" | "bordered"
| "no-scroll"
| "no-caption"
| "caption-bottom"
| "layout-fixed"
| "bordered"
| "multiline"
| "sm"
| "lg"
>
: never;

Expand All @@ -53,6 +62,7 @@ export const Table = memo(
bottomCaption = false,
colorVariant,
className,
size = "medium",
style,
...rest
} = props;
Expand All @@ -77,7 +87,9 @@ export const Table = memo(
"fr-table--no-scroll": noScroll,
"fr-table--layout-fixed": fixed,
"fr-table--no-caption": noCaption,
"fr-table--caption-bottom": bottomCaption
"fr-table--caption-bottom": bottomCaption,
"fr-table--sm": size === "small",
"fr-table--lg": size === "large"
},
colorVariant !== undefined && `fr-table--${colorVariant}`
),
Expand Down
11 changes: 11 additions & 0 deletions stories/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ const { meta, getStory } = getStoryFactory({
"description": "Move caption to bottom",
"type": { "name": "boolean" }
},
"size": {
"options": (() => {
const options = ["small", "medium", "large"] as const;

assert<Equals<typeof options[number], NonNullable<TableProps["size"]>>>();

return options;
})(),
"control": { "type": "radio" },
"defaultValue": "medium"
},
"colorVariant": {
"options": (() => {
const options = [
Expand Down