@instructure/ui-tray 11.6.0 → 11.6.1-snapshot-129

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +34 -288
  2. package/es/Tray/{index.js → v1/index.js} +2 -2
  3. package/es/Tray/v2/index.js +221 -0
  4. package/es/Tray/v2/props.js +26 -0
  5. package/es/Tray/v2/styles.js +131 -0
  6. package/es/{index.js → exports/a.js} +1 -1
  7. package/{src/index.ts → es/exports/b.js} +1 -3
  8. package/lib/Tray/v1/index.js +226 -0
  9. package/lib/Tray/{index.js → v2/index.js} +3 -4
  10. package/lib/Tray/v2/props.js +31 -0
  11. package/lib/Tray/v2/styles.js +137 -0
  12. package/lib/{index.js → exports/a.js} +2 -2
  13. package/lib/exports/b.js +12 -0
  14. package/package.json +43 -21
  15. package/src/Tray/{index.tsx → v1/index.tsx} +2 -2
  16. package/src/Tray/v2/README.md +100 -0
  17. package/src/Tray/v2/index.tsx +249 -0
  18. package/src/Tray/v2/props.ts +206 -0
  19. package/src/Tray/v2/styles.ts +158 -0
  20. package/src/exports/a.ts +26 -0
  21. package/src/exports/b.ts +26 -0
  22. package/tsconfig.build.tsbuildinfo +1 -1
  23. package/types/Tray/v1/index.d.ts.map +1 -0
  24. package/types/Tray/v1/props.d.ts.map +1 -0
  25. package/types/Tray/v1/styles.d.ts.map +1 -0
  26. package/types/Tray/v1/theme.d.ts.map +1 -0
  27. package/types/Tray/v2/index.d.ts +77 -0
  28. package/types/Tray/v2/index.d.ts.map +1 -0
  29. package/types/Tray/v2/props.d.ts +133 -0
  30. package/types/Tray/v2/props.d.ts.map +1 -0
  31. package/types/Tray/v2/styles.d.ts +20 -0
  32. package/types/Tray/v2/styles.d.ts.map +1 -0
  33. package/types/exports/a.d.ts +3 -0
  34. package/types/exports/a.d.ts.map +1 -0
  35. package/types/exports/b.d.ts +3 -0
  36. package/types/exports/b.d.ts.map +1 -0
  37. package/types/Tray/index.d.ts.map +0 -1
  38. package/types/Tray/props.d.ts.map +0 -1
  39. package/types/Tray/styles.d.ts.map +0 -1
  40. package/types/Tray/theme.d.ts.map +0 -1
  41. package/types/index.d.ts +0 -3
  42. package/types/index.d.ts.map +0 -1
  43. /package/es/Tray/{props.js → v1/props.js} +0 -0
  44. /package/es/Tray/{styles.js → v1/styles.js} +0 -0
  45. /package/es/Tray/{theme.js → v1/theme.js} +0 -0
  46. /package/lib/Tray/{props.js → v1/props.js} +0 -0
  47. /package/lib/Tray/{styles.js → v1/styles.js} +0 -0
  48. /package/lib/Tray/{theme.js → v1/theme.js} +0 -0
  49. /package/src/Tray/{README.md → v1/README.md} +0 -0
  50. /package/src/Tray/{props.ts → v1/props.ts} +0 -0
  51. /package/src/Tray/{styles.ts → v1/styles.ts} +0 -0
  52. /package/src/Tray/{theme.ts → v1/theme.ts} +0 -0
  53. /package/types/Tray/{index.d.ts → v1/index.d.ts} +0 -0
  54. /package/types/Tray/{props.d.ts → v1/props.d.ts} +0 -0
  55. /package/types/Tray/{styles.d.ts → v1/styles.d.ts} +0 -0
  56. /package/types/Tray/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,206 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React from 'react'
26
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
27
+ import type {
28
+ OtherHTMLAttributes,
29
+ TrayTheme,
30
+ LiveRegion,
31
+ UIElement
32
+ } from '@instructure/shared-types'
33
+ import type { TextDirectionContextConsumerProps } from '@instructure/ui-i18n'
34
+ import type {
35
+ TransitionType,
36
+ BaseTransitionStatesType
37
+ } from '@instructure/ui-motion'
38
+
39
+ type TrayOwnProps = {
40
+ label: string
41
+ /**
42
+ * The size (width) of the `<Tray />` when placement is `start` or `end`
43
+ */
44
+ size?: 'x-small' | 'small' | 'regular' | 'medium' | 'large'
45
+ /**
46
+ * Placement to determine where the `<Tray />` should display in the viewport
47
+ */
48
+ placement?: 'top' | 'bottom' | 'start' | 'end' | 'center'
49
+ /**
50
+ * Whether or not the `<Tray />` is open
51
+ */
52
+ open?: boolean
53
+ /**
54
+ * An element or a function returning an element to focus by default
55
+ */
56
+ defaultFocusElement?: UIElement
57
+ /**
58
+ *
59
+ * A function that returns a reference to the content element
60
+ */
61
+ contentRef?: (el: HTMLSpanElement | null) => void
62
+ /**
63
+ * Whether focus should be contained within the `<Tray/>` when it is open
64
+ */
65
+ shouldContainFocus?: boolean
66
+ /**
67
+ * Whether focus should be restored when the `<Tray/>` is closed
68
+ */
69
+ shouldReturnFocus?: boolean
70
+ /**
71
+ * Should the `<Tray />` hide when clicks occur outside the content
72
+ */
73
+ shouldCloseOnDocumentClick?: boolean
74
+ /**
75
+ * Callback fired when `<Tray />` content has been mounted in the DOM
76
+ */
77
+ onOpen?: (type?: TransitionType) => void
78
+ /**
79
+ * Callback fired when `<Tray />` has been unmounted from the DOM
80
+ */
81
+ onClose?: (type?: TransitionType) => void
82
+ /**
83
+ * Callback fired when the `<Tray />` is requesting to be closed
84
+ */
85
+ onDismiss?: (
86
+ event: React.UIEvent | React.FocusEvent,
87
+ documentClick?: boolean
88
+ ) => void
89
+ /**
90
+ * An element or a function returning an element to use as the mount node
91
+ * for the `<Tray />` (defaults to `document.body`)
92
+ */
93
+ mountNode?: Element | (() => Element | null) | null
94
+ /**
95
+ * Insert the element at the 'top' of the mountNode or at the 'bottom'
96
+ */
97
+ insertAt?: 'bottom' | 'top'
98
+ /**
99
+ * An element, function returning an element, or array of elements that will not be hidden from
100
+ * the screen reader when the `<Tray />` is open
101
+ */
102
+ liveRegion?: LiveRegion
103
+ /**
104
+ * Callback fired when the <Tray /> transitions in/out
105
+ */
106
+ onTransition?: (
107
+ toState: BaseTransitionStatesType,
108
+ fromState: BaseTransitionStatesType
109
+ ) => void
110
+ /**
111
+ * Callback fired before the <Tray /> transitions in
112
+ */
113
+ onEnter?: () => void
114
+ /**
115
+ * Callback fired as the <Tray /> begins to transition in
116
+ */
117
+ onEntering?: () => void
118
+ /**
119
+ * Callback fired after the <Tray /> finishes transitioning in
120
+ */
121
+ onEntered?: (type?: TransitionType) => void
122
+ /**
123
+ * Callback fired right before the <Tray /> transitions out
124
+ */
125
+ onExit?: () => void
126
+ /**
127
+ * Callback fired as the <Tray /> begins to transition out
128
+ */
129
+ onExiting?: () => void
130
+ /**
131
+ * Callback fired after the <Tray /> finishes transitioning out
132
+ */
133
+ onExited?: (type?: TransitionType) => void
134
+ /**
135
+ * Run the enter animation when the component mounts, if it is initially
136
+ * shown
137
+ */
138
+ transitionOnMount?: boolean
139
+ /**
140
+ * Run the enter animation
141
+ */
142
+ transitionEnter?: boolean
143
+ /**
144
+ * Run the exit animation
145
+ */
146
+ transitionExit?: boolean
147
+ /**
148
+ * Should the `<Tray />` have a border
149
+ */
150
+ border?: boolean
151
+ /**
152
+ * Should the `<Tray />` have a box shadow
153
+ */
154
+ shadow?: boolean
155
+ children?: React.ReactNode
156
+
157
+ /**
158
+ * Add Mask overlay to the `<Tray />`
159
+ */
160
+ enableMask?: boolean
161
+ }
162
+
163
+ type PropKeys = keyof TrayOwnProps
164
+
165
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
166
+
167
+ type TrayProps = TrayOwnProps &
168
+ TextDirectionContextConsumerProps &
169
+ WithStyleProps<TrayTheme, TrayStyle> &
170
+ OtherHTMLAttributes<TrayOwnProps>
171
+
172
+ type TrayStyle = ComponentStyle<'tray' | 'content'>
173
+ const allowedProps: AllowedPropKeys = [
174
+ 'label',
175
+ 'children',
176
+ 'size',
177
+ 'placement',
178
+ 'open',
179
+ 'defaultFocusElement',
180
+ 'contentRef',
181
+ 'shouldContainFocus',
182
+ 'shouldReturnFocus',
183
+ 'shouldCloseOnDocumentClick',
184
+ 'onOpen',
185
+ 'onClose',
186
+ 'onDismiss',
187
+ 'mountNode',
188
+ 'insertAt',
189
+ 'liveRegion',
190
+ 'onTransition',
191
+ 'onEnter',
192
+ 'onEntering',
193
+ 'onEntered',
194
+ 'onExit',
195
+ 'onExiting',
196
+ 'onExited',
197
+ 'transitionOnMount',
198
+ 'transitionEnter',
199
+ 'transitionExit',
200
+ 'border',
201
+ 'shadow',
202
+ 'enableMask'
203
+ ]
204
+ type TrayState = { transitioning: boolean; open: boolean }
205
+ export type { TrayProps, TrayStyle, TrayState }
206
+ export { allowedProps }
@@ -0,0 +1,158 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import type { NewComponentTypes } from '@instructure/ui-themes'
25
+ import { boxShadowObjectsToCSSString } from '@instructure/ui-themes'
26
+ import type { TrayProps, TrayStyle } from './props'
27
+
28
+ type StyleParams = {
29
+ border: TrayProps['border']
30
+ shadow: TrayProps['shadow']
31
+ size: TrayProps['size']
32
+ placement: TrayProps['placement']
33
+ }
34
+ /**
35
+ * ---
36
+ * private: true
37
+ * ---
38
+ * Generates the style object from the theme and provided additional information
39
+ * @param {Object} componentTheme The theme variable object.
40
+ * @param {Object} params the props and passed through data of the component, the style is applied to
41
+ * @return {Object} The final style object, which will be used in the component
42
+ */
43
+ const generateStyle = (
44
+ componentTheme: NewComponentTypes['Tray'],
45
+ params: StyleParams
46
+ ): TrayStyle => {
47
+ const { border, shadow, size, placement } = params
48
+
49
+ const borderStyle = {
50
+ borderWidth: 0,
51
+ borderColor: componentTheme.borderColor,
52
+ borderStyle: 'solid'
53
+ }
54
+
55
+ const shadowStyle = shadow
56
+ ? {
57
+ boxShadow: boxShadowObjectsToCSSString(componentTheme.boxShadow)
58
+ }
59
+ : {}
60
+
61
+ const contentStyle =
62
+ placement === 'start' || placement === 'end' || placement === 'center'
63
+ ? {
64
+ label: 'tray__content',
65
+ minHeight: '100vh'
66
+ }
67
+ : {}
68
+
69
+ const placementStyles = {
70
+ top: {
71
+ insetInlineStart: 0,
72
+ insetInlineEnd: 0,
73
+ top: 0
74
+ },
75
+ bottom: {
76
+ insetInlineStart: 0,
77
+ insetInlineEnd: 0,
78
+ bottom: 0
79
+ },
80
+ start: {
81
+ top: 0,
82
+ bottom: 0,
83
+ insetInlineStart: 0,
84
+ insetInlineEnd: 'auto'
85
+ },
86
+ end: {
87
+ top: 0,
88
+ bottom: 0,
89
+ insetInlineEnd: 0,
90
+ insetInlineStart: 'auto'
91
+ },
92
+ center: {
93
+ left: 0,
94
+ right: 0,
95
+ top: 0,
96
+ bottom: 0
97
+ }
98
+ }
99
+
100
+ const borderPlacementStyle = border
101
+ ? {
102
+ start: {
103
+ borderInlineEndWidth: componentTheme.borderWidth
104
+ },
105
+ end: {
106
+ borderInlineStartWidth: componentTheme.borderWidth
107
+ },
108
+ top: {
109
+ borderBottomWidth: componentTheme.borderWidth
110
+ },
111
+ bottom: {
112
+ borderTopWidth: componentTheme.borderWidth
113
+ },
114
+ center: {}
115
+ }
116
+ : {}
117
+
118
+ const sizeVariants = {
119
+ 'x-small': componentTheme.widthXs,
120
+ small: componentTheme.widthSm,
121
+ regular: componentTheme.widthMd,
122
+ medium: componentTheme.widthLg,
123
+ large: componentTheme.widthXl
124
+ }
125
+
126
+ const sizeStyle =
127
+ placement === 'start' || placement === 'end'
128
+ ? {
129
+ width: sizeVariants[size!]
130
+ }
131
+ : {}
132
+
133
+ return {
134
+ tray: {
135
+ label: 'tray',
136
+ padding: componentTheme.padding,
137
+ backgroundColor: componentTheme.backgroundColor,
138
+ position: 'fixed',
139
+ overflowY: 'auto',
140
+ overflowX: 'hidden',
141
+ boxSizing: 'border-box',
142
+ zIndex: componentTheme.zIndex,
143
+ maxWidth: '100vw',
144
+ maxHeight: '100vh',
145
+ ...shadowStyle,
146
+ ...placementStyles[placement!],
147
+ ...(border && borderStyle),
148
+ ...(border && borderPlacementStyle[placement!]),
149
+ ...sizeStyle
150
+ },
151
+ content: {
152
+ label: 'tray__content',
153
+ ...contentStyle
154
+ }
155
+ }
156
+ }
157
+
158
+ export default generateStyle
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export { Tray } from '../Tray/v1'
26
+ export type { TrayProps } from '../Tray/v1/props'
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export { Tray } from '../Tray/v2'
26
+ export type { TrayProps } from '../Tray/v2/props'