@instructure/ui-popover 8.12.1-snapshot.7 → 8.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/es/Popover/PopoverLocator.js +9 -3
- package/es/Popover/index.js +78 -75
- package/es/Popover/props.js +1 -176
- package/lib/Popover/PopoverLocator.js +11 -4
- package/lib/Popover/index.js +79 -76
- package/lib/Popover/props.js +2 -177
- package/package.json +20 -21
- package/src/Popover/index.tsx +102 -170
- package/src/Popover/props.ts +168 -138
- package/types/Popover/index.d.ts +72 -87
- package/types/Popover/index.d.ts.map +1 -1
- package/types/Popover/props.d.ts +166 -20
- package/types/Popover/props.d.ts.map +1 -1
- package/LICENSE.md +0 -27
package/src/Popover/props.ts
CHANGED
|
@@ -33,270 +33,300 @@ import type { Shadow, Stacking } from '@instructure/emotion'
|
|
|
33
33
|
import type {
|
|
34
34
|
PlacementPropValues,
|
|
35
35
|
PositionConstraint,
|
|
36
|
-
PositionMountNode
|
|
36
|
+
PositionMountNode,
|
|
37
|
+
PositionObject
|
|
37
38
|
} from '@instructure/ui-position'
|
|
38
39
|
import type { BidirectionalProps } from '@instructure/ui-i18n'
|
|
39
|
-
import type {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'top',
|
|
45
|
-
'bottom',
|
|
46
|
-
'start',
|
|
47
|
-
'end',
|
|
48
|
-
'top start',
|
|
49
|
-
'top center',
|
|
50
|
-
'top end',
|
|
51
|
-
'top stretch',
|
|
52
|
-
'bottom start',
|
|
53
|
-
'bottom center',
|
|
54
|
-
'bottom end',
|
|
55
|
-
'bottom stretch',
|
|
56
|
-
'start top',
|
|
57
|
-
'start center',
|
|
58
|
-
'start bottom',
|
|
59
|
-
'start stretch',
|
|
60
|
-
'end top',
|
|
61
|
-
'end center',
|
|
62
|
-
'end bottom',
|
|
63
|
-
'end stretch',
|
|
64
|
-
'center start',
|
|
65
|
-
'center end',
|
|
66
|
-
'offscreen'
|
|
67
|
-
]
|
|
40
|
+
import type {
|
|
41
|
+
PropValidators,
|
|
42
|
+
LiveRegion,
|
|
43
|
+
UIElement
|
|
44
|
+
} from '@instructure/shared-types'
|
|
68
45
|
|
|
69
46
|
type PopoverOwnProps = {
|
|
70
|
-
isShowingContent?: boolean
|
|
71
|
-
defaultIsShowingContent?: boolean
|
|
72
|
-
on?: ('click' | 'hover' | 'focus') | ('click' | 'hover' | 'focus')[]
|
|
73
|
-
withArrow?: boolean
|
|
74
|
-
color?: 'primary' | 'primary-inverse'
|
|
75
|
-
shadow?: Shadow
|
|
76
|
-
stacking?: Stacking
|
|
77
|
-
contentRef?: (...args: any[]) => any
|
|
78
|
-
defaultFocusElement?: React.ReactElement | ((...args: any[]) => any)
|
|
79
|
-
screenReaderLabel?: string
|
|
80
|
-
offsetX?: string | number
|
|
81
|
-
offsetY?: string | number
|
|
82
|
-
placement: PlacementPropValues
|
|
83
|
-
constrain?: PositionConstraint
|
|
84
|
-
mountNode?: PositionMountNode
|
|
85
|
-
positionTarget?: PositionMountNode
|
|
86
|
-
insertAt?: 'bottom' | 'top'
|
|
87
|
-
liveRegion?: LiveRegion
|
|
88
|
-
id?: string
|
|
89
|
-
shouldAlignArrow?: boolean
|
|
90
|
-
shouldTrackPosition?: boolean
|
|
91
|
-
shouldRenderOffscreen?: boolean
|
|
92
|
-
shouldContainFocus?: boolean
|
|
93
|
-
shouldReturnFocus?: boolean
|
|
94
|
-
shouldCloseOnDocumentClick?: boolean
|
|
95
|
-
shouldCloseOnEscape?: boolean
|
|
96
|
-
shouldFocusContentOnTriggerBlur?: boolean
|
|
97
|
-
onShowContent?: (...args: any[]) => any
|
|
98
|
-
onHideContent?: (...args: any[]) => any
|
|
99
|
-
onPositioned?: (...args: any[]) => any
|
|
100
|
-
onPositionChanged?: (...args: any[]) => any
|
|
101
|
-
onClick?: (...args: any[]) => any
|
|
102
|
-
onFocus?: (...args: any[]) => any
|
|
103
|
-
onBlur?: (...args: any[]) => any
|
|
104
|
-
onKeyDown?: (...args: any[]) => any
|
|
105
|
-
onKeyUp?: (...args: any[]) => any
|
|
106
|
-
onMouseOver?: (...args: any[]) => any
|
|
107
|
-
onMouseOut?: (...args: any[]) => any
|
|
108
|
-
renderTrigger?: React.ReactNode | ((...args: any[]) => any)
|
|
109
|
-
children?: React.ReactNode | ((...args: any[]) => React.ReactNode)
|
|
110
|
-
elementRef?: (element: Element | null) => void
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
type PopoverProps = PopoverOwnProps & BidirectionalProps
|
|
114
|
-
|
|
115
|
-
type PropKeys = keyof PopoverOwnProps
|
|
116
|
-
|
|
117
|
-
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
118
|
-
|
|
119
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
120
47
|
/**
|
|
121
48
|
* Whether or not the `<Popover />` content is shown
|
|
122
49
|
*/
|
|
123
|
-
isShowingContent
|
|
50
|
+
isShowingContent?: boolean
|
|
51
|
+
|
|
124
52
|
/**
|
|
125
53
|
* Whether or not to show the content by default, when uncontrolled
|
|
126
54
|
*/
|
|
127
|
-
defaultIsShowingContent
|
|
55
|
+
defaultIsShowingContent?: boolean
|
|
56
|
+
|
|
128
57
|
/**
|
|
129
58
|
* The action that causes the content to display (`click`, `hover`, `focus`)
|
|
130
59
|
*/
|
|
131
|
-
on
|
|
132
|
-
|
|
133
|
-
PropTypes.arrayOf(PropTypes.oneOf(['click', 'hover', 'focus']))
|
|
134
|
-
]),
|
|
60
|
+
on?: ('click' | 'hover' | 'focus') | ('click' | 'hover' | 'focus')[]
|
|
61
|
+
|
|
135
62
|
/**
|
|
136
63
|
* Whether or not an arrow pointing to the trigger should be rendered
|
|
137
64
|
*/
|
|
138
|
-
withArrow
|
|
65
|
+
withArrow?: boolean
|
|
66
|
+
|
|
139
67
|
/**
|
|
140
68
|
* Color variant of the popover content
|
|
141
69
|
*/
|
|
142
|
-
color
|
|
143
|
-
|
|
144
|
-
* The placement of the content in relation to the trigger
|
|
145
|
-
*/
|
|
146
|
-
placement: PropTypes.oneOf(placementPropValues),
|
|
70
|
+
color?: 'primary' | 'primary-inverse'
|
|
71
|
+
|
|
147
72
|
/**
|
|
148
73
|
* Controls the shadow depth for the `<Popover />`
|
|
149
74
|
*/
|
|
150
|
-
shadow
|
|
75
|
+
shadow?: Shadow
|
|
76
|
+
|
|
151
77
|
/**
|
|
152
78
|
* Controls the z-index depth for the `<Popover />` content
|
|
153
79
|
*/
|
|
154
|
-
stacking
|
|
80
|
+
stacking?: Stacking
|
|
81
|
+
|
|
155
82
|
/**
|
|
156
83
|
* A function that returns a reference to the content element
|
|
157
84
|
*/
|
|
158
|
-
contentRef:
|
|
85
|
+
contentRef?: (contentElement: Element | null) => void
|
|
86
|
+
|
|
159
87
|
/**
|
|
160
88
|
* An element or a function returning an element to focus by default
|
|
161
89
|
*/
|
|
162
|
-
defaultFocusElement
|
|
90
|
+
defaultFocusElement?: UIElement
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* An element, function returning an element, or array of elements that will
|
|
94
|
+
* not be hidden from the screen reader when the `<Popover />` is open
|
|
95
|
+
*/
|
|
96
|
+
liveRegion?: LiveRegion
|
|
97
|
+
|
|
163
98
|
/**
|
|
164
99
|
* An accessible label for the `<Popover />` content
|
|
165
100
|
*/
|
|
166
|
-
screenReaderLabel
|
|
101
|
+
screenReaderLabel?: string
|
|
102
|
+
|
|
167
103
|
/**
|
|
168
104
|
* The horizontal offset for the positioned content
|
|
169
105
|
*/
|
|
170
|
-
offsetX
|
|
106
|
+
offsetX?: string | number
|
|
107
|
+
|
|
171
108
|
/**
|
|
172
109
|
* The vertical offset for the positioned content
|
|
173
110
|
*/
|
|
174
|
-
offsetY
|
|
111
|
+
offsetY?: string | number
|
|
112
|
+
|
|
113
|
+
// TODO: remove list when types can be read from other packages
|
|
114
|
+
/**
|
|
115
|
+
* The placement of the content in relation to the trigger
|
|
116
|
+
*
|
|
117
|
+
* One of: 'top', 'bottom', 'start', 'end', 'top start', 'top center',
|
|
118
|
+
* 'top end', 'top stretch', 'bottom start', 'bottom center', 'bottom end',
|
|
119
|
+
* 'bottom stretch', 'start top', 'start center', 'start bottom',
|
|
120
|
+
* 'start stretch', 'end top', 'end center', 'end bottom', 'end stretch',
|
|
121
|
+
* 'center start', 'center end', 'offscreen'
|
|
122
|
+
*/
|
|
123
|
+
placement?: PlacementPropValues
|
|
124
|
+
|
|
175
125
|
/**
|
|
176
126
|
* The parent in which to constrain the popover.
|
|
127
|
+
*
|
|
177
128
|
* One of: 'window', 'scroll-parent', 'parent', 'none', an element,
|
|
178
129
|
* or a function returning an element
|
|
179
130
|
*/
|
|
180
|
-
constrain
|
|
181
|
-
|
|
182
|
-
* Target element for positioning the Popover (if it differs from the trigger)
|
|
183
|
-
*/
|
|
184
|
-
positionTarget: PropTypes.oneOfType([element, PropTypes.func]),
|
|
131
|
+
constrain?: PositionConstraint
|
|
132
|
+
|
|
185
133
|
/**
|
|
186
134
|
* An element or a function returning an element to use as the mount node
|
|
187
135
|
* for the `<Popover />` (defaults to `document.body`)
|
|
188
136
|
*/
|
|
189
|
-
mountNode
|
|
137
|
+
mountNode?: PositionMountNode
|
|
138
|
+
|
|
190
139
|
/**
|
|
191
|
-
*
|
|
140
|
+
* Target element for positioning the Popover (if it differs from the trigger)
|
|
192
141
|
*/
|
|
193
|
-
|
|
142
|
+
positionTarget?: PositionMountNode
|
|
143
|
+
|
|
194
144
|
/**
|
|
195
|
-
*
|
|
196
|
-
* not be hidden from the screen reader when the `<Popover />` is open
|
|
145
|
+
* Insert the element at the 'top' of the mountNode or at the 'bottom'
|
|
197
146
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
PropTypes.element,
|
|
201
|
-
PropTypes.func
|
|
202
|
-
]),
|
|
147
|
+
insertAt?: 'bottom' | 'top'
|
|
148
|
+
|
|
203
149
|
/**
|
|
204
150
|
* An id is generated if not supplied.
|
|
205
151
|
*/
|
|
206
|
-
id
|
|
152
|
+
id?: string
|
|
153
|
+
|
|
207
154
|
/**
|
|
208
155
|
* Whether or not the content should offset to align by its arrow
|
|
209
156
|
*/
|
|
210
|
-
shouldAlignArrow
|
|
157
|
+
shouldAlignArrow?: boolean
|
|
158
|
+
|
|
211
159
|
/**
|
|
212
160
|
* Whether or not position should be tracked or just set on initial render
|
|
213
161
|
*/
|
|
214
|
-
shouldTrackPosition
|
|
162
|
+
shouldTrackPosition?: boolean
|
|
163
|
+
|
|
215
164
|
/**
|
|
216
165
|
* Should the `<Popover />` render offscreen when visually hidden
|
|
217
166
|
*/
|
|
218
|
-
shouldRenderOffscreen
|
|
167
|
+
shouldRenderOffscreen?: boolean
|
|
168
|
+
|
|
219
169
|
/**
|
|
220
170
|
* Whether focus should contained within the `<Popover/>` when it is open
|
|
221
171
|
*/
|
|
222
|
-
shouldContainFocus
|
|
172
|
+
shouldContainFocus?: boolean
|
|
173
|
+
|
|
223
174
|
/**
|
|
224
175
|
* Whether focus should be returned to the trigger when the `<Popover/>` is closed
|
|
225
176
|
*/
|
|
226
|
-
shouldReturnFocus
|
|
177
|
+
shouldReturnFocus?: boolean
|
|
178
|
+
|
|
227
179
|
/**
|
|
228
180
|
* Should the `<Popover />` hide when clicks occur outside the content
|
|
229
181
|
*/
|
|
230
|
-
shouldCloseOnDocumentClick
|
|
182
|
+
shouldCloseOnDocumentClick?: boolean
|
|
183
|
+
|
|
231
184
|
/**
|
|
232
185
|
* Should the `<Popover />` hide when the escape key is pressed
|
|
233
186
|
*/
|
|
234
|
-
shouldCloseOnEscape
|
|
187
|
+
shouldCloseOnEscape?: boolean
|
|
188
|
+
|
|
235
189
|
/**
|
|
236
190
|
* Should the content become focused when the trigger is blurred
|
|
237
191
|
*/
|
|
238
|
-
shouldFocusContentOnTriggerBlur
|
|
192
|
+
shouldFocusContentOnTriggerBlur?: boolean
|
|
193
|
+
|
|
239
194
|
/**
|
|
240
195
|
* Callback fired when content is shown. When controlled, this callback is
|
|
241
196
|
* fired when the Popover expects to be shown
|
|
242
197
|
*/
|
|
243
|
-
onShowContent:
|
|
198
|
+
onShowContent?: (event: Event) => void
|
|
199
|
+
|
|
244
200
|
/**
|
|
245
201
|
* Callback fired when content is hidden. When controlled, this callback is
|
|
246
202
|
* fired when the Popover expects to be hidden
|
|
247
203
|
*/
|
|
248
|
-
onHideContent:
|
|
204
|
+
onHideContent?: (event: Event, args: { documentClick: boolean }) => void
|
|
205
|
+
|
|
249
206
|
/**
|
|
250
207
|
* Callback fired when content has been is initially positioned.
|
|
251
208
|
* If `shouldRenderOffscreen` is true, it will only fire once, the first
|
|
252
209
|
* time the content is shown
|
|
253
210
|
*/
|
|
254
|
-
onPositioned:
|
|
211
|
+
onPositioned?: (position: PositionObject) => void
|
|
212
|
+
|
|
255
213
|
/**
|
|
256
214
|
* Callback fired when the position changes
|
|
257
215
|
*/
|
|
258
|
-
onPositionChanged:
|
|
216
|
+
onPositionChanged?: (position: PositionObject) => void
|
|
217
|
+
|
|
259
218
|
/**
|
|
260
219
|
* Callback fired when component is clicked
|
|
261
220
|
*/
|
|
262
|
-
onClick:
|
|
221
|
+
onClick?: (event: Event) => void
|
|
222
|
+
|
|
263
223
|
/**
|
|
264
224
|
* Callback fired when trigger is focused
|
|
265
225
|
*/
|
|
266
|
-
onFocus:
|
|
226
|
+
onFocus?: (event: Event) => void
|
|
227
|
+
|
|
267
228
|
/**
|
|
268
229
|
* Callback fired when component is blurred
|
|
269
230
|
*/
|
|
270
|
-
onBlur:
|
|
231
|
+
onBlur?: (event: Event) => void
|
|
232
|
+
|
|
271
233
|
/**
|
|
272
234
|
* Callback fired on keydown
|
|
273
235
|
*/
|
|
274
|
-
onKeyDown:
|
|
236
|
+
onKeyDown?: (event: Event) => void
|
|
237
|
+
|
|
275
238
|
/**
|
|
276
239
|
* Callback fired on keyup
|
|
277
240
|
*/
|
|
278
|
-
onKeyUp:
|
|
279
|
-
|
|
241
|
+
onKeyUp?: (event: Event) => void
|
|
242
|
+
|
|
280
243
|
/**
|
|
281
244
|
* Callback fired when mouse is over trigger
|
|
282
245
|
*/
|
|
283
|
-
onMouseOver:
|
|
246
|
+
onMouseOver?: (event: Event) => void
|
|
247
|
+
|
|
284
248
|
/**
|
|
285
249
|
* Callback fired when mouse leaves trigger
|
|
286
250
|
*/
|
|
287
|
-
onMouseOut:
|
|
251
|
+
onMouseOut?: (event: Event) => void
|
|
252
|
+
|
|
288
253
|
/**
|
|
289
254
|
* The element that triggers the popover
|
|
290
255
|
*/
|
|
291
|
-
renderTrigger
|
|
256
|
+
renderTrigger?: React.ReactNode | (() => React.ReactNode)
|
|
257
|
+
|
|
292
258
|
/**
|
|
293
259
|
* The content to be shown by the popover
|
|
294
260
|
*/
|
|
295
|
-
children
|
|
261
|
+
children?: React.ReactNode | (() => React.ReactNode)
|
|
296
262
|
|
|
297
263
|
/**
|
|
298
264
|
* Provides a reference to the underlying HTML root element
|
|
299
265
|
*/
|
|
266
|
+
elementRef?: (element: Element | null) => void
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
type PopoverProps = PopoverOwnProps & BidirectionalProps
|
|
270
|
+
|
|
271
|
+
type PopoverState = {
|
|
272
|
+
placement: PopoverOwnProps['placement']
|
|
273
|
+
offsetX: PopoverOwnProps['offsetX']
|
|
274
|
+
offsetY: PopoverOwnProps['offsetY']
|
|
275
|
+
isShowingContent?: boolean
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type PropKeys = keyof PopoverOwnProps
|
|
279
|
+
|
|
280
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
281
|
+
|
|
282
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
283
|
+
isShowingContent: PropTypes.bool,
|
|
284
|
+
defaultIsShowingContent: PropTypes.bool,
|
|
285
|
+
on: PropTypes.oneOfType([
|
|
286
|
+
PropTypes.oneOf(['click', 'hover', 'focus']),
|
|
287
|
+
PropTypes.arrayOf(PropTypes.oneOf(['click', 'hover', 'focus']))
|
|
288
|
+
]),
|
|
289
|
+
withArrow: PropTypes.bool,
|
|
290
|
+
color: PropTypes.oneOf(['primary', 'primary-inverse']),
|
|
291
|
+
placement: PositionPropTypes.placement,
|
|
292
|
+
shadow: ThemeablePropTypes.shadow,
|
|
293
|
+
stacking: ThemeablePropTypes.stacking,
|
|
294
|
+
contentRef: PropTypes.func,
|
|
295
|
+
defaultFocusElement: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
|
|
296
|
+
screenReaderLabel: PropTypes.string,
|
|
297
|
+
offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
298
|
+
offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
299
|
+
constrain: PositionPropTypes.constrain,
|
|
300
|
+
positionTarget: PropTypes.oneOfType([element, PropTypes.func]),
|
|
301
|
+
mountNode: PositionPropTypes.mountNode,
|
|
302
|
+
insertAt: PropTypes.oneOf(['bottom', 'top']),
|
|
303
|
+
liveRegion: PropTypes.oneOfType([
|
|
304
|
+
PropTypes.arrayOf(PropTypes.element),
|
|
305
|
+
PropTypes.element,
|
|
306
|
+
PropTypes.func
|
|
307
|
+
]),
|
|
308
|
+
id: PropTypes.string,
|
|
309
|
+
shouldAlignArrow: PropTypes.bool,
|
|
310
|
+
shouldTrackPosition: PropTypes.bool,
|
|
311
|
+
shouldRenderOffscreen: PropTypes.bool,
|
|
312
|
+
shouldContainFocus: PropTypes.bool,
|
|
313
|
+
shouldReturnFocus: PropTypes.bool,
|
|
314
|
+
shouldCloseOnDocumentClick: PropTypes.bool,
|
|
315
|
+
shouldCloseOnEscape: PropTypes.bool,
|
|
316
|
+
shouldFocusContentOnTriggerBlur: PropTypes.bool,
|
|
317
|
+
onShowContent: PropTypes.func,
|
|
318
|
+
onHideContent: PropTypes.func,
|
|
319
|
+
onPositioned: PropTypes.func,
|
|
320
|
+
onPositionChanged: PropTypes.func,
|
|
321
|
+
onClick: PropTypes.func,
|
|
322
|
+
onFocus: PropTypes.func,
|
|
323
|
+
onBlur: PropTypes.func,
|
|
324
|
+
onKeyDown: PropTypes.func,
|
|
325
|
+
onKeyUp: PropTypes.func,
|
|
326
|
+
onMouseOver: PropTypes.func,
|
|
327
|
+
onMouseOut: PropTypes.func,
|
|
328
|
+
renderTrigger: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
329
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
300
330
|
elementRef: PropTypes.func
|
|
301
331
|
}
|
|
302
332
|
|
|
@@ -344,5 +374,5 @@ const allowedProps: AllowedPropKeys = [
|
|
|
344
374
|
'elementRef'
|
|
345
375
|
]
|
|
346
376
|
|
|
347
|
-
export type { PopoverProps }
|
|
377
|
+
export type { PopoverProps, PopoverState }
|
|
348
378
|
export { propTypes, allowedProps }
|