SchemaViewer
The columns of a table and their types: which is the key, which can be empty, what each one points to. A table on desktop, cards on phones.
import { SchemaViewer, SchemaViewerSkeleton } from '@sypnia/ui/react'
Columns of orders
A key, a reference, defaults and a column that can be empty.
| Column | Type | Rules | Default |
|---|---|---|---|
id | uuid | Primary key | gen_random_uuid() |
customer_id | uuid | Points to customers.id | |
total | numeric(10,2) | 0 | |
status | text | 'pending' | |
email | text | Unique | |
note | text | Can be empty | |
placed_at | timestamptz | now() |
Code
import { SchemaViewer } from '@sypnia/ui/react';
// The columns of a table in words: which is the key, which can be empty, what each one points to.
export default function Orders() {
return (
<SchemaViewer label="Columns of orders" columns={[
{ name: 'id', type: 'uuid', primaryKey: true, default: 'gen_random_uuid()' },
{ name: 'customer_id', type: 'uuid', references: 'customers.id' },
{ name: 'total', type: 'numeric(10,2)', default: '0' },
{ name: 'status', type: 'text', default: "'pending'" },
{ name: 'email', type: 'text', unique: true },
{ name: 'note', type: 'text', nullable: true },
{ name: 'placed_at', type: 'timestamptz', default: 'now()' },
]} />
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
| Column | Type | Rules | Default |
|---|---|---|---|
id | int8 | Primary key | |
name | text | Unique |
Code
import { SchemaViewer, SchemaViewerSkeleton } from '@sypnia/ui/react';
export default function Skeleton() {
return (
<div className="sy-stack">
<SchemaViewer label="Columns of tags" columns={[{ name: 'id', type: 'int8', primaryKey: true }, { name: 'name', type: 'text', unique: true }]} />
<SchemaViewerSkeleton rows={2} />
</div>
);
} When to use it
Use it when
- Showing the shape of a table to someone who will query or fill it.
Do not use it when
- The person changes the columns: a form for each column.
For everyone
- Rules are in words (Primary key, Can be empty, Points to), not only icons.
- On phones every column is a card.
Props
| SchemaViewer | Type | Default |
|---|---|---|
columnsrequired | SchemaColumn[] | undefined | |
labelrequired | string | |
loading | boolean |
| SchemaViewerSkeleton | Type | Default |
|---|---|---|
rows | number | 6 |