-
Notifications
You must be signed in to change notification settings - Fork 15
/
shared-prop-types.js
146 lines (140 loc) · 3.54 KB
/
shared-prop-types.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { mutuallyExclusive } from '@dhis2/prop-types'
import PropTypes from 'prop-types'
/**
* Status propType
* @return {PropType} Mutually exclusive status: valid/warning/error
*/
export const statusPropType = mutuallyExclusive(
['valid', 'warning', 'error'],
PropTypes.bool
)
// Exported for storybook
export const statusArgType = {
table: {
type: {
summary: 'bool',
detail: "'valid', 'warning', and 'error' are mutually exclusive props",
},
},
control: { type: 'boolean' },
}
export const buttonVariantArgType =
// No description because it should be set for the component description
{
table: { type: { summary: 'bool' } },
control: { type: 'boolean' },
}
/**
* Size variant propType
* @return {PropType} Mutually exclusive variants:
* small/large
*/
export const sizePropType = mutuallyExclusive(
['small', 'large', 'extrasmall', 'fluid'],
PropTypes.bool
)
export const sizeArgType = {
// No description because it should be set in the component description
table: {
type: {
summary: 'bool',
detail: 'size props are mutually exclusive',
},
},
control: {
type: 'boolean',
},
}
/**
* Inside alignment props
* @return {PropType} PropType that validates the inside alignment.
*/
export const insideAlignmentPropType = PropTypes.oneOf([
'top',
'middle',
'bottom',
])
export const insideAlignmentArgType = {
description: 'Inside alignment of the component',
table: {
type: {
summary: "'top' | 'middle' | 'bottom'",
},
},
control: {
type: 'select',
options: ['top', 'middle', 'bottom'],
},
}
/**
* Placement properties against reference element
* @return {PropType} PropType that validates placements.
*/
export const popperPlacementPropType = PropTypes.oneOf([
'auto',
'auto-start',
'auto-end',
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'right',
'right-start',
'right-end',
'left',
'left-start',
'left-end',
])
export const popperPlacementArgType = {
description: 'Placement properties relative to reference element',
table: {
type: {
summary: 'string (one of several)',
detail: 'see options in menu',
},
},
control: {
type: 'select',
options: [
'auto',
'auto-start',
'auto-end',
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'right',
'right-start',
'right-end',
'left',
'left-start',
'left-end',
],
},
}
/**
* Either a DOM node, React ref or a virtual element
* @return {PropType} Validate that prop is either a function or an
* instance of an Element.
*/
export const popperReferencePropType = PropTypes.oneOfType([
// DOM node
PropTypes.instanceOf(Element),
// React ref - React.useRef() or React.createRef()
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
// Virtual element
PropTypes.shape({ getBoundingClientRect: PropTypes.func }),
])
export const popperReferenceArgType = {
description:
'A reference to the element to position against: either a DOM node, React ref, \
or an instance of an element',
table: {
type: { summary: 'DOM node | React ref | Virtual element' },
},
control: { type: null },
}