DataTypePicker
Picks one field data type from a set the caller passes, each drawn with its label and its glyph.
It is the list picker configured with a glyph row and a chip for its value: the same control, popup, press rule and keyboard as every other picker.
Install
Section titled “Install”pnpm dlx shadcn@latest add https://sg-widgets.vercel.app/r/react/data-type-picker.jsonpnpm dlx shadcn-svelte@latest add https://sg-widgets.vercel.app/r/svelte/data-type-picker.jsonReact
Loading the React demo…
Svelte
Loading the Svelte demo…
| chosen | emitted |
|---|---|
| a row | that data type’s API name |
| the clear control | null |
The widget offers types and nothing else. It holds no list of its own, so which types can be
created is the caller’s to decide.
A value outside types still draws, with its label and glyph, and keeps a row of its own. A value
the widget has never heard of draws under the name it was given, with the document glyph. With
readonly that is how a field read from a site shows its type, whatever the site answered. An empty
string reads as no value.
| prop | type | default | meaning |
|---|---|---|---|
types | readonly string[] | [] | The data types on offer, by API name, in the order they are listed. |
value | string | null | null | The chosen data type, by API name, or null when nothing is chosen. bind:value in Svelte, value with onValueChange in React. |
labels | Readonly<Record<string, string>> | — | Labels of the caller's own, by API name. They win over the built-in ones. |
placeholder | string | 'Select a data type' | Shown with no selection. |
emptyLabel | string | 'No rows' | Shown when no type is on offer. |
searchable | boolean | false | Offers a search box, which narrows the set in the browser. |
searchPlaceholder | string | 'Search data types…' | Placeholder of the search box. |
clearable | boolean | false | Offers a control that clears the value. |
readonly | boolean | false | Keeps full contrast and drops the chevron, the popup and the clear control. |
disabled | boolean | false | Greys the control and takes it out of the tab order. |
invalid | boolean | false | Sets aria-invalid and the destructive ring. |
showCode | boolean | true | Draws the API name as a row's right-aligned secondary, when it says more than the label. |
secondary | (option) => string | the API name | A row's right-aligned value, of the caller's own making. |
subLabel | (option) => string | — | The muted line under a row's label. |
size | 'sm' | 'md' | 'lg' | 'md' | Control height: 7, 8 and 9. |
open | boolean | false | Whether the popup is showing. Two-way in Svelte. |
class / className | string | — | Merged after the widget's own classes. |
Every other attribute is spread onto the root: id, aria-*, data-*, key handlers and a ref
to the root element.
A row is the row anatomy of the design rules: the glyph as the leading mark, the label as the row’s text, and the API name right-aligned where it differs from the label.
The labels are this library’s wording, since the API names a data type by its API name only. Pass
labels to reword one, or to name a type the widget does not know.
import { dataTypeLabel, DATA_TYPE_LABELS } from 'sg-widgets-core';
dataTypeLabel('date_time'); // 'Date and time'dataTypeLabel('sg_future_type'); // 'sg_future_type'Events
Section titled “Events”| event | payload | when |
|---|---|---|
onValueChange | string | null | A data type was chosen, or the clear control was pressed. |
onOpenChange | boolean | The popup opened or closed. |
onOpenChange fires when the popup opens or closes. Svelte also binds it with bind:open.
None. The rows are the shared picker row; the closed state is a chip.
Keyboard
Section titled “Keyboard”| key | does |
|---|---|
| Space, Enter, ↓ | Opens the list |
| ↑ ↓ | Moves the highlight |
| typing | Narrows the list, where the picker is searchable |
| Enter | Selects the highlighted data type and closes |
| Backspace | In an empty search box, clears the data type, where the picker is clearable |
| Esc | Closes and keeps the selection |
| Tab | Leaves the control, or reaches the clear control when there is one |
FieldGlyphs
Section titled “FieldGlyphs”The glyph a data type is drawn with. Core names a lucide icon per data type, and this map resolves the name to the icon component of each framework; a type core does not know takes the document.
import { fieldGlyph } from '@/components/field-glyphs';
const Glyph = fieldGlyph('date_time');API behaviour
Section titled “API behaviour”A site refuses some data types at creation. One site created text, float, number, date,
date_time, list, url, duration, percent and footage with no extra property, checkbox
with a default value, and entity and multi_entity with one valid type; it refused color,
image and calculated (019_create_fields). The set a caller offers follows what its own site
accepts.