Skip to content

Commit

Permalink
Merge pull request #483 from Cosium/export-field-types
Browse files Browse the repository at this point in the history
Export field types
  • Loading branch information
evert authored Sep 22, 2024
2 parents b8abae7 + 1a8a960 commit 1dcfff4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface BaseField<T> {
*
* This includes numbers, dates and time fields.
*/
interface RangeField<T> extends BaseField<T> {
export interface RangeField<T> extends BaseField<T> {
max?: number;
min?: number;
step?: number;
Expand All @@ -72,37 +72,37 @@ interface RangeField<T> extends BaseField<T> {
/**
* Toggles/checkboxes
*/
interface BooleanField extends BaseField<boolean> {
export interface BooleanField extends BaseField<boolean> {
type: 'checkbox' | 'radio';
}

/**
* Any field that encodes itself as a string but with no
* special features.
*/
interface BasicStringField extends BaseField<string> {
export interface BasicStringField extends BaseField<string> {
type: 'color' | 'email' | 'password' | 'search' | 'tel' | 'url';
minLength?: number;
maxLength?: number;
}

interface RangeStringField extends RangeField<string> {
export interface RangeStringField extends RangeField<string> {
type: 'date' | 'month' | 'time' | 'week';
}

interface DateTimeField extends RangeField<Date> {
export interface DateTimeField extends RangeField<Date> {
type: 'datetime' | 'datetime-local';
}

interface HiddenField extends BaseField<string | number | null | boolean> {
export interface HiddenField extends BaseField<string | number | null | boolean> {
type: 'hidden';
}

interface FileField extends BaseField<never> {
export interface FileField extends BaseField<never> {
type: 'file';
}

interface NumberField extends RangeField<number> {
export interface NumberField extends RangeField<number> {
type: 'number' | 'range';
}

Expand Down Expand Up @@ -166,7 +166,7 @@ export type OptionsDataSource = {
/**
* Encodes a field that has a list of options a user can choose from.
*/
type SelectFieldSingle = BaseField<string> & {
export type SelectFieldSingle = BaseField<string> & {
type: 'select';
renderAs?: 'radio' | 'dropdown';
multiple?: false;
Expand All @@ -175,21 +175,21 @@ type SelectFieldSingle = BaseField<string> & {
/**
* An options field where users can select more than 1 item
*/
type SelectFieldMulti = BaseField<string> & {
export type SelectFieldMulti = BaseField<string> & {
type: 'select';
renderAs?: 'checkbox' | 'dropdown';
multiple: true;
} & OptionsDataSource;


interface TextField extends BaseField<string> {
export interface TextField extends BaseField<string> {
type: 'text';
minLength?: number;
maxLength?: number;
pattern?: RegExp;
}

interface TextAreaField extends BaseField<string> {
export interface TextAreaField extends BaseField<string> {
type: 'textarea';
minLength?: number;
maxLength?: number;
Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ export { default as oauth2 } from './http/oauth2';
export { Problem } from './http/error';

export { Action } from './action';
export { Field } from './field';
export {
Field,
BooleanField,
BasicStringField,
DateTimeField,
FileField,
HiddenField,
NumberField,
SelectFieldSingle,
SelectFieldMulti,
RangeStringField,
TextAreaField,
TextField
} from './field';

export { FollowPromiseOne, FollowPromiseMany } from './follow-promise';

Expand Down

0 comments on commit 1dcfff4

Please sign in to comment.