@instructure/ui-tray 8.25.1-snapshot.0 → 8.26.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/src/Tray/props.ts CHANGED
@@ -32,168 +32,161 @@ import type {
32
32
  OtherHTMLAttributes,
33
33
  PropValidators,
34
34
  TrayTheme,
35
- LiveRegion
35
+ LiveRegion,
36
+ UIElement
36
37
  } from '@instructure/shared-types'
37
38
  import type { BidirectionalProps } from '@instructure/ui-i18n'
38
- import type { TransitionType } from '@instructure/ui-motion'
39
+ import type {
40
+ TransitionType,
41
+ BaseTransitionStatesType
42
+ } from '@instructure/ui-motion'
39
43
 
40
44
  type TrayOwnProps = {
41
45
  label: string
42
- size?: 'x-small' | 'small' | 'regular' | 'medium' | 'large'
43
- placement?: 'top' | 'bottom' | 'start' | 'end' | 'center'
44
- open?: boolean
45
- defaultFocusElement?: React.ReactElement | ((...args: any[]) => any)
46
- contentRef?: (...args: any[]) => any
47
- shouldContainFocus?: boolean
48
- shouldReturnFocus?: boolean
49
- shouldCloseOnDocumentClick?: boolean
50
- onOpen?: (type?: TransitionType) => void
51
- onClose?: (type?: TransitionType) => void
52
- onDismiss?: (...args: any[]) => any
53
- mountNode?: any // TODO: PropTypes.oneOfType([element, PropTypes.func])
54
- insertAt?: 'bottom' | 'top'
55
- liveRegion?: LiveRegion
56
- onTransition?: (...args: any[]) => any
57
- onEnter?: (...args: any[]) => any
58
- onEntering?: (...args: any[]) => any
59
- onEntered?: (type?: TransitionType) => void
60
- onExit?: (...args: any[]) => any
61
- onExiting?: (...args: any[]) => any
62
- onExited?: (type?: TransitionType) => void
63
- border?: boolean
64
- shadow?: boolean
65
- children?: React.ReactNode
66
- }
67
-
68
- type PropKeys = keyof TrayOwnProps
69
-
70
- type AllowedPropKeys = Readonly<Array<PropKeys>>
71
-
72
- type TrayProps = TrayOwnProps &
73
- BidirectionalProps &
74
- WithStyleProps<TrayTheme, TrayStyle> &
75
- OtherHTMLAttributes<TrayOwnProps>
76
-
77
- type TrayStyle = ComponentStyle<'tray' | 'content'>
78
-
79
- const propTypes: PropValidators<PropKeys> = {
80
- label: PropTypes.string.isRequired,
81
- children: PropTypes.node,
82
-
83
46
  /**
84
47
  * The size (width) of the `<Tray />` when placement is `start` or `end`
85
48
  */
86
- size: PropTypes.oneOf(['x-small', 'small', 'regular', 'medium', 'large']),
87
-
49
+ size?: 'x-small' | 'small' | 'regular' | 'medium' | 'large'
88
50
  /**
89
51
  * Placement to determine where the `<Tray />` should display in the viewport
90
52
  */
91
- placement: PropTypes.oneOf(['top', 'bottom', 'start', 'end', 'center']),
92
-
53
+ placement?: 'top' | 'bottom' | 'start' | 'end' | 'center'
93
54
  /**
94
55
  * Whether or not the `<Tray />` is open
95
56
  */
96
- open: PropTypes.bool,
97
-
57
+ open?: boolean
98
58
  /**
99
59
  * An element or a function returning an element to focus by default
100
60
  */
101
- defaultFocusElement: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
102
-
61
+ defaultFocusElement?: UIElement
103
62
  /**
104
63
  *
105
64
  * A function that returns a reference to the content element
106
65
  */
107
- contentRef: PropTypes.func,
108
-
66
+ contentRef?: (el: HTMLSpanElement | null) => void
109
67
  /**
110
68
  * Whether focus should be contained within the `<Tray/>` when it is open
111
69
  */
112
- shouldContainFocus: PropTypes.bool,
113
-
70
+ shouldContainFocus?: boolean
114
71
  /**
115
72
  * Whether focus should be restored when the `<Tray/>` is closed
116
73
  */
117
- shouldReturnFocus: PropTypes.bool,
118
-
74
+ shouldReturnFocus?: boolean
119
75
  /**
120
76
  * Should the `<Tray />` hide when clicks occur outside the content
121
77
  */
122
- shouldCloseOnDocumentClick: PropTypes.bool,
123
-
78
+ shouldCloseOnDocumentClick?: boolean
124
79
  /**
125
80
  * Callback fired when `<Tray />` content has been mounted in the DOM
126
81
  */
127
- onOpen: PropTypes.func,
128
-
82
+ onOpen?: (type?: TransitionType) => void
129
83
  /**
130
84
  * Callback fired when `<Tray />` has been unmounted from the DOM
131
85
  */
132
- onClose: PropTypes.func,
133
-
86
+ onClose?: (type?: TransitionType) => void
134
87
  /**
135
88
  * Callback fired when the `<Tray />` is requesting to be closed
136
89
  */
137
- onDismiss: PropTypes.func,
138
-
90
+ onDismiss?: (
91
+ event: React.UIEvent | React.FocusEvent,
92
+ documentClick?: boolean
93
+ ) => void
139
94
  /**
140
95
  * An element or a function returning an element to use as the mount node
141
96
  * for the `<Tray />` (defaults to `document.body`)
142
97
  */
143
- mountNode: PropTypes.oneOfType([element, PropTypes.func]),
144
-
98
+ mountNode?: Element | (() => Element | null) | null
145
99
  /**
146
100
  * Insert the element at the 'top' of the mountNode or at the 'bottom'
147
101
  */
148
- insertAt: PropTypes.oneOf(['bottom', 'top']),
149
-
102
+ insertAt?: 'bottom' | 'top'
150
103
  /**
151
104
  * An element, function returning an element, or array of elements that will not be hidden from
152
105
  * the screen reader when the `<Tray />` is open
153
106
  */
154
- liveRegion: PropTypes.oneOfType([
155
- PropTypes.arrayOf(PropTypes.element),
156
- PropTypes.element,
157
- PropTypes.func
158
- ]),
159
-
107
+ liveRegion?: LiveRegion
160
108
  /**
161
109
  * Callback fired when the <Tray /> transitions in/out
162
110
  */
163
- onTransition: PropTypes.func,
111
+ onTransition?: (
112
+ toState: BaseTransitionStatesType,
113
+ fromState: BaseTransitionStatesType
114
+ ) => void
164
115
  /**
165
116
  * Callback fired before the <Tray /> transitions in
166
117
  */
167
- onEnter: PropTypes.func,
118
+ onEnter?: () => void
168
119
  /**
169
120
  * Callback fired as the <Tray /> begins to transition in
170
121
  */
171
- onEntering: PropTypes.func,
122
+ onEntering?: () => void
172
123
  /**
173
124
  * Callback fired after the <Tray /> finishes transitioning in
174
125
  */
175
- onEntered: PropTypes.func,
126
+ onEntered?: (type?: TransitionType) => void
176
127
  /**
177
128
  * Callback fired right before the <Tray /> transitions out
178
129
  */
179
- onExit: PropTypes.func,
130
+ onExit?: () => void
180
131
  /**
181
132
  * Callback fired as the <Tray /> begins to transition out
182
133
  */
183
- onExiting: PropTypes.func,
134
+ onExiting?: () => void
184
135
  /**
185
136
  * Callback fired after the <Tray /> finishes transitioning out
186
137
  */
187
- onExited: PropTypes.func,
188
-
138
+ onExited?: (type?: TransitionType) => void
189
139
  /**
190
140
  * Should the `<Tray />` have a border
191
141
  */
192
- border: PropTypes.bool,
193
-
142
+ border?: boolean
194
143
  /**
195
144
  * Should the `<Tray />` have a box shadow
196
145
  */
146
+ shadow?: boolean
147
+ children?: React.ReactNode
148
+ }
149
+
150
+ type PropKeys = keyof TrayOwnProps
151
+
152
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
153
+
154
+ type TrayProps = TrayOwnProps &
155
+ BidirectionalProps &
156
+ WithStyleProps<TrayTheme, TrayStyle> &
157
+ OtherHTMLAttributes<TrayOwnProps>
158
+
159
+ type TrayStyle = ComponentStyle<'tray' | 'content'>
160
+
161
+ const propTypes: PropValidators<PropKeys> = {
162
+ label: PropTypes.string.isRequired,
163
+ children: PropTypes.node,
164
+ size: PropTypes.oneOf(['x-small', 'small', 'regular', 'medium', 'large']),
165
+ placement: PropTypes.oneOf(['top', 'bottom', 'start', 'end', 'center']),
166
+ open: PropTypes.bool,
167
+ defaultFocusElement: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
168
+ contentRef: PropTypes.func,
169
+ shouldContainFocus: PropTypes.bool,
170
+ shouldReturnFocus: PropTypes.bool,
171
+ shouldCloseOnDocumentClick: PropTypes.bool,
172
+ onOpen: PropTypes.func,
173
+ onClose: PropTypes.func,
174
+ onDismiss: PropTypes.func,
175
+ mountNode: PropTypes.oneOfType([element, PropTypes.func]),
176
+ insertAt: PropTypes.oneOf(['bottom', 'top']),
177
+ liveRegion: PropTypes.oneOfType([
178
+ PropTypes.arrayOf(PropTypes.element),
179
+ PropTypes.element,
180
+ PropTypes.func
181
+ ]),
182
+ onTransition: PropTypes.func,
183
+ onEnter: PropTypes.func,
184
+ onEntering: PropTypes.func,
185
+ onEntered: PropTypes.func,
186
+ onExit: PropTypes.func,
187
+ onExiting: PropTypes.func,
188
+ onExited: PropTypes.func,
189
+ border: PropTypes.bool,
197
190
  shadow: PropTypes.bool
198
191
  }
199
192
 
@@ -224,6 +217,6 @@ const allowedProps: AllowedPropKeys = [
224
217
  'border',
225
218
  'shadow'
226
219
  ]
227
-
228
- export type { TrayProps, TrayStyle }
220
+ type TrayState = { transitioning: boolean }
221
+ export type { TrayProps, TrayStyle, TrayState }
229
222
  export { propTypes, allowedProps }