Skip to content

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.

Terminal window
pnpm dlx shadcn@latest add https://sg-widgets.vercel.app/r/react/data-type-picker.json
Terminal window
pnpm dlx shadcn-svelte@latest add https://sg-widgets.vercel.app/r/svelte/data-type-picker.json
DataTypePicker: a given set, a search box, own labels, and types outside the set shown read-only

React

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.

proptypedefaultmeaning
typesreadonly string[][]The data types on offer, by API name, in the order they are listed.
valuestring | nullnullThe chosen data type, by API name, or null when nothing is chosen. bind:value in Svelte, value with onValueChange in React.
labelsReadonly<Record<string, string>>—Labels of the caller's own, by API name. They win over the built-in ones.
placeholderstring'Select a data type'Shown with no selection.
emptyLabelstring'No rows'Shown when no type is on offer.
searchablebooleanfalseOffers a search box, which narrows the set in the browser.
searchPlaceholderstring'Search data types…'Placeholder of the search box.
clearablebooleanfalseOffers a control that clears the value.
readonlybooleanfalseKeeps full contrast and drops the chevron, the popup and the clear control.
disabledbooleanfalseGreys the control and takes it out of the tab order.
invalidbooleanfalseSets aria-invalid and the destructive ring.
showCodebooleantrueDraws the API name as a row's right-aligned secondary, when it says more than the label.
secondary(option) => stringthe API nameA 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.
openbooleanfalseWhether the popup is showing. Two-way in Svelte.
class / classNamestring—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'
eventpayloadwhen
onValueChangestring | nullA data type was chosen, or the clear control was pressed.
onOpenChangebooleanThe 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.

keydoes
Space, Enter, ↓Opens the list
↑ ↓Moves the highlight
typingNarrows the list, where the picker is searchable
EnterSelects the highlighted data type and closes
BackspaceIn an empty search box, clears the data type, where the picker is clearable
EscCloses and keeps the selection
TabLeaves the control, or reaches the clear control when there is one

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');

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.