Field type picker
One field type among thirteen, each with its pixel glyph and its SQLite storage.
import { FieldTypePicker, FieldTypeGlyph, FIELD_TYPES } from "@forgeron/ui";Type
import { FieldTypePicker, type FieldType } from "@forgeron/ui";
import { useState } from "react";
export default function Default() {
const [type, setType] = useState<FieldType>("relation");
return <FieldTypePicker showLabel value={type} onChange={setType} />;
}- TextTEXT
- Long textTEXT
- NumberREAL
- CheckboxINTEGER
- DateTEXT
- Date and timeTEXT
- SelectTEXT
- Multi-selectTEXT
- RelationTEXT
- FileTEXT
- EmailTEXT
- URLTEXT
- JSONTEXT
// Every type with its pixel glyph and what SQLite stores it as.
import { FIELD_TYPES, FieldTypeGlyph } from "@forgeron/ui";
export default function Glyphs() {
return (
<ul
style={{
display: "grid",
gridTemplateColumns: "repeat(auto-fill, minmax(180px, 1fr))",
gap: 8,
width: "100%",
margin: 0,
padding: 0,
listStyle: "none",
}}
>
{FIELD_TYPES.map((t) => (
<li
key={t.type}
style={{
display: "flex",
alignItems: "center",
gap: 8,
padding: "8px 10px",
border: "1px solid var(--line)",
font: "400 13px/18px var(--font-sans)",
}}
>
<FieldTypeGlyph type={t.type} size={24} />
<span style={{ flex: 1 }}>{t.label}</span>
<span style={{ font: "400 11px/16px var(--font-mono)", color: "var(--ink-dim)" }}>
{t.storage}
</span>
</li>
))}
</ul>
);
}Column type
// A few types, as a chip in a dense row.
import { FieldTypePicker } from "@forgeron/ui";
export default function Chip() {
return (
<FieldTypePicker
variant="chip"
label="Column type"
types={["text", "number", "date", "boolean"]}
showStorage={false}
defaultValue="number"
/>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
value / defaultValue | FieldType | — | text, longText, number, boolean, date, datetime, select, multiSelect, relation, file, email, url, json. |
onChange | (type) => void | — | When a type is chosen. |
types | FieldType[] | all | The types offered. |
showStorage | boolean | true | TEXT, REAL, INTEGER at the end of each row. |
label | string | "Type" | Names the control. |
variant | "field" | "chip" | "field" | A form control, or a chip in a row. |
className | string | — | Extra classes. |