This repository has been archived by the owner on Jul 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builders.js
56 lines (49 loc) · 1.61 KB
/
builders.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// This module exports public helpers for building a Param Spec
// Think of it a bit like PropTypes.<type>
// It also essentially enumerates the subset of PropTypes supported for Component Params.
// TODO: we can support UI tooltips in param specs :)
import * as types from "./types";
import ParamType from "./ParamType";
/**
* Spec this Parameter as a string,
* with the default value specfied, or an empty string.
*
* Use `stringUndefined()` if you don't want an empty string by default.
* @param {*} label
* @param {*} defaultValue
*/
export const string = (label, defaultValue = "") =>
new ParamType(label, types.string, defaultValue);
/**
* Spec this Parameter as a string,
* with NO default value.
* @param {*} label
*/
export const stringUndefined = label => new ParamType(label, types.string);
/**
* Spec this Parameter as an enum,
* accepting only the valid values provided.
*
* The default value must be one of the valid values.
* @param {*} label
* @param {*} validValues
* @param {*} defaultValue
*/
export const oneOf = (label, validValues, defaultValue) =>
new ParamType(label, types.oneOf, defaultValue, validValues);
/**
* Spec this Parameter as a number,
* with the default value specifed, or `0`.
* @param {*} label
* @param {*} defaultValue
*/
export const number = (label, defaultValue = 0) =>
new ParamType(label, types.number, defaultValue);
/**
* Spec this Parameter as a boolean,
* with the default value specifed, or `false`.
* @param {*} label
* @param {*} defaultValue
*/
export const bool = (label, defaultValue = false) =>
new ParamType(label, types.bool, defaultValue);