Table
Usage
Name | Symbol | Position | Mass |
---|---|---|---|
Carbon | C | 6 | 12.011 |
Nitrogen | N | 7 | 14.007 |
Yttrium | Y | 39 | 88.906 |
Properties
Element name | Symbol | Position | Atomic mass | Description | |
---|---|---|---|---|---|
1 | Na | 11 | 22.99 | A soft metal that reacts vigorously with water. | |
2 | Mg | 12 | 24.305 | A metal used in lightweight alloys. | |
3 | Al | 13 | 26.982 | A lightweight, corrosion-resistant metal. | |
4 | Si | 14 | 28.085 | A key component in semiconductors. | |
5 | P | 15 | 30.974 | Essential for DNA and energy transfer in cells. | |
6 | S | 16 | 32.06 | A yellow, nonmetallic element used in fertilizers. | |
7 | Cl | 17 | 35.45 | A reactive halogen used for water purification. | |
8 | Ar | 18 | 39.948 | A noble gas used in light bulbs and welding. | |
9 | K | 19 | 39.098 | An essential element for human health. | |
10 | Ca | 20 | 40.078 | A metal crucial for bones and teeth. | |
11 | Fe | 26 | 55.845 | A key element in hemoglobin, the oxygen-carrying molecule in blood. | |
12 | Cu | 29 | 63.546 | A conductor of electricity used in wiring. | |
13 | Zn | 30 | 65.38 | An essential trace element for humans. | |
14 | Y | 39 | 88.906 | A rare-earth metal used in lasers and superconductors. | |
15 | Ba | 56 | 137.33 | A metal used in medical imaging. | |
16 | Ce | 58 | 140.12 | A rare-earth element used in catalytic converters. | |
17 | H | 1 | 1.008 | The lightest element and most abundant chemical substance in the universe. | |
18 | He | 2 | 4.0026 | A noble gas used in balloons and cooling systems. | |
19 | Li | 3 | 6.94 | A soft, silvery metal used in rechargeable batteries. | |
20 | Be | 4 | 9.0122 | A hard metal used in aerospace materials. | |
21 | B | 5 | 10.81 | An element used in glass and detergents. | |
22 | C | 6 | 12.011 | A versatile element, the basis for organic life. | |
23 | N | 7 | 14.007 | Makes up 78% of Earth's atmosphere. | |
24 | O | 8 | 15.999 | Essential for respiration in most living organisms. | |
25 | F | 9 | 18.998 | A highly reactive gas used in toothpaste. | |
26 | Ne | 10 | 20.18 | A noble gas used in neon signs and lighting. |
Structure
Independent Components
import { Table, TableBody, TableCaption, TableData, TableHead, TableHeader, TableRow } from "@/ui/table";
const data = [
{ name: "Sodium", symbol: "Na", position: 11, mass: 22.99 },
{ name: "Magnesium", symbol: "Mg", position: 12, mass: 24.305 }
// others
];
export function TableDemo() {
return (
<Table>
<TableCaption>
Flat Component Structure
<br />
(Independent Components)
</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Symbol</TableHead>
<TableHead>Position</TableHead>
<TableHead>Mass</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data.slice(0, 3).map(i => (
<TableRow key={i.name}>
<TableData>{i.name}</TableData>
<TableData>{i.symbol}</TableData>
<TableData>{i.position}</TableData>
<TableData>{i.mass}</TableData>
</TableRow>
))}
</TableBody>
</Table>
);
}
Compound Components
"use client";
import { Table } from "@/ui/table";
const data = [
{ name: "Sodium", symbol: "Na", position: 11, mass: 22.99 },
{ name: "Magnesium", symbol: "Mg", position: 12, mass: 24.305 }
// others
];
export function TableDemo() {
return (
<Table>
<Table.Caption>
Namespaced Component Structure
<br />
(Compound Components)
</Table.Caption>
<Table.Header>
<Table.Row>
<Table.Head>Name</Table.Head>
<Table.Head>Symbol</Table.Head>
<Table.Head>Position</Table.Head>
<Table.Head>Mass</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{data.slice(3, 6).map(i => (
<Table.Row key={i.name}>
<Table.Data>{i.name}</Table.Data>
<Table.Data>{i.symbol}</Table.Data>
<Table.Data>{i.position}</Table.Data>
<Table.Data>{i.mass}</Table.Data>
</Table.Row>
))}
</Table.Body>
</Table>
);
}
Declarative Props API
import { Table, dataRenderer, type TableDataProps } from "@/ui/table";
const data = [
{
name: "Sodium",
symbol: "Na",
position: 11,
mass: 22.99,
description: "A soft metal that reacts vigorously with water."
},
{
name: "Magnesium",
symbol: "Mg",
position: 12,
mass: 24.305,
description: "A metal used in lightweight alloys."
}
// others
];
const tableData: TableDataProps = {
caption: "Some elements from periodic table",
head: ["Element name", "Symbol", "Element position", "Atomic mass", "Description"],
body: dataRenderer(data, ["name", "symbol", "position", "mass", "description"])
};
export function TableDemo() {
return <Table data={tableData} overflow spacing={{ x: "16px", y: "20px" }} />;
}
API References
Styles API
type T = "root" | "table" | "thead" | "tbody" | "tfoot" | "tr" | "th" | "td" | "caption";
Styles API | Type | Default | Annotation |
---|---|---|---|
unstyled? | Partial<Record<T, boolean>> | false | if true , default styles will be removed |
className? | string | undefined | pass to root component <div> |
classNames? | Partial<Record<T, string>> | undefined | |
style? | CSSProperties | undefined | pass to root component <div> |
styles? | Partial<Record<T, CSSProperties>> | undefined |
Props API
type Spacing = { x?: number | string; y?: number | string };
type Striped = boolean | "odd" | "even";
type Variant = "horizontal" | "vertical";
Props API | Type | Default | Annotation |
---|---|---|---|
data? | TableData | undefined | Data that should be used to generate table, ignored if children prop is set |
variant? | Variant | horizontal | Determines whether the first column in each row is sticky or not |
layout? | ["tableLayout"] | auto | Value of table-layout style |
striped? | Striped | undefined | Determines whether every odd/even row background should be changed to strippedColor |
captionSide? | "top" | "bottom" | bottom | Determines on which side Table.Caption is displayed |
tableOverflow? | boolean | true | Set table scroll area |
stickyHeader? | boolean | true | Determines whether Table.Thead should be sticky |
stickyHeaderOffset? | number | string | 0 | Offset from top at which Table.Thead should become sticky |
spacing? | Spacing | { x = 0, y = 8 } | x = Horizontal, y = Vertical cells spacing or any valid CSS value for padding |
highlightOnHover? | boolean | true | Determines whether table rows background should change to highlightOnHoverColor when hovered |
withTableBorder? | boolean | true | Determines whether the table should have outer border |
withColumnBorders? | boolean | false | Determines whether the table should have borders between columns |
withRowBorders? | boolean | true | Determines whether the table should have borders between rows |
stickyHeader? | boolean | false | Set table scroll area |
highlightOnHoverColor? | Property.Color | hsl(var(--primitive)) | Background color of table rows when hovered, key of CSS color |
borderColor? | Property.Color | hsl(var(--border)) | Color of table borders, key of CSS color |
stripedColor? | Property.Color | hsl(var(--background-box)) | Background color of striped rows, key of CSS color |