UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

25 lines (24 loc) 1.17 kB
import { FieldOptions, Label, WithoutLabel } from 'alinea/core'; import { ScalarField } from 'alinea/core/field/ScalarField'; /** A string record with option labels */ export type SelectItems<T extends string> = Record<T, Label>; /** Optional settings to configure a select field */ export interface SelectConfig<Key> extends FieldOptions<Key> { /** Width of the field in the dashboard UI (0-1) */ width?: number; /** Add instructional text to a field */ help?: string; /** Field is optional */ optional?: boolean; /** Display a minimal version */ inline?: boolean; /** Choose a custom placeholder (eg. 'Select an option') */ placeholder?: Label; } export interface SelectOptions<Key extends string> extends SelectConfig<Key> { items: Record<Key, string>; } export declare class SelectField<Key extends string> extends ScalarField<Key | null, SelectOptions<Key>> { } /** Create a select field configuration */ export declare function select<const Items extends Record<string, string>>(label: string, items: Items, options?: WithoutLabel<SelectConfig<Extract<keyof Items, string>>>): SelectField<Extract<keyof Items, string>>;