Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export field types #483

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type Field =
* Fields can be used to automatically render forms or other UIs based on
* hypermedia actions.
*/
interface BaseField<T> {
export interface BaseField<T> {
reda-alaoui marked this conversation as resolved.
Show resolved Hide resolved
/**
* Name of the field.
*
Expand Down 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
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@ export { default as oauth2 } from './http/oauth2';
export { Problem } from './http/error';

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

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

Expand Down
Loading