import styled from "@emotion/styled"; import { WebComponentProps, TableGenerator, } from "../../utils/ui-component-props.types"; const Table = styled.table` text-align: left; width: 100%; font-size: 0.875rem; margin-bottom: 1rem; thead tr { background-color: var(--bg-color-tertiary); } tbody tr th { width: 5rem; } `; export const TableHeader = styled.div` font-size: 1rem; margin: 0.75rem 0; `; /** * Both css and slots only document name and description, so we can share * the table generation logic here. */ const createBaseTable = (entries) => { if (!entries) return undefined; const rows = entries.map((entry, index) => { const name = entry.name; const description = entry.docs; if (!name || !description) return undefined; return ( {name} {description} ); }); return (
{rows}
Name Description
); }; /** * For attributes, we need to document more information than the base ones, * so we create multiple tables. */ const attrTableGenerator = (docs) => { let count = 0; const tables = docs?.props.map((prop) => { const groupId = `prop-${prop.attr || String(count)}`; if (!prop.attr) { count++; } return (
{prop.attr && ( )} {prop.default && ( )}
{prop.name}
Attribute {prop.attr}
Description {prop.docs}
Type {prop.type}
Default {prop.default}
); }); return tables; }; const cssTableGenerator = (docs) => { return createBaseTable(docs.styles); }; const slotsTableGenerator = (docs) => { return createBaseTable(docs.slots); }; export const tableGeneratorMap: Record = { attr: attrTableGenerator, css: cssTableGenerator, slots: slotsTableGenerator, };