Skip to content

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'

On this page
  1. Columns of orders
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

Columns of orders

A key, a reference, defaults and a column that can be empty.

ColumnTypeRulesDefault
iduuidPrimary keygen_random_uuid()
customer_iduuidPoints to customers.id
totalnumeric(10,2)0
statustext'pending'
emailtextUnique
notetextCan be empty
placed_attimestamptznow()
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.

ColumnTypeRulesDefault
idint8Primary key
nametextUnique
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

SchemaViewerTypeDefault
columnsrequired SchemaColumn[] | undefined
labelrequired string
loading boolean
SchemaViewerSkeletonTypeDefault
rows number 6
  1. Columns of orders
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms