@instructure/ui-view 11.7.3 → 11.7.4-pr-snapshot-1781695314229

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 (51) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/LICENSE.md +1 -0
  3. package/{lib/ContextView/v2/props.js → babel.config.cjs} +12 -7
  4. package/es/ContextView/v1/index.js +5 -5
  5. package/es/ContextView/v1/styles.js +0 -1
  6. package/es/ContextView/v2/index.js +4 -4
  7. package/es/ContextView/v2/styles.js +0 -1
  8. package/es/View/v1/index.js +4 -4
  9. package/es/View/v2/index.js +3 -6
  10. package/es/View/v2/props.js +1 -1
  11. package/es/exports/a.js +3 -2
  12. package/es/exports/b.js +3 -2
  13. package/package.json +14 -19
  14. package/src/ContextView/v1/index.tsx +5 -4
  15. package/src/ContextView/v2/index.tsx +4 -3
  16. package/src/View/v1/index.tsx +4 -3
  17. package/src/View/v2/index.tsx +3 -9
  18. package/src/View/v2/props.ts +0 -12
  19. package/src/exports/a.ts +2 -2
  20. package/src/exports/b.ts +2 -2
  21. package/tsconfig.build.tsbuildinfo +1 -1
  22. package/types/ContextView/v1/index.d.ts +1 -0
  23. package/types/ContextView/v1/index.d.ts.map +1 -1
  24. package/types/ContextView/v2/index.d.ts +1 -0
  25. package/types/ContextView/v2/index.d.ts.map +1 -1
  26. package/types/View/v1/index.d.ts +2 -1
  27. package/types/View/v1/index.d.ts.map +1 -1
  28. package/types/View/v2/index.d.ts +2 -2
  29. package/types/View/v2/index.d.ts.map +1 -1
  30. package/types/View/v2/props.d.ts +0 -11
  31. package/types/View/v2/props.d.ts.map +1 -1
  32. package/types/exports/a.d.ts +2 -2
  33. package/types/exports/a.d.ts.map +1 -1
  34. package/types/exports/b.d.ts +2 -2
  35. package/types/exports/b.d.ts.map +1 -1
  36. package/lib/ContextView/v1/index.js +0 -133
  37. package/lib/ContextView/v1/props.js +0 -31
  38. package/lib/ContextView/v1/styles.js +0 -267
  39. package/lib/ContextView/v1/theme.js +0 -49
  40. package/lib/ContextView/v2/index.js +0 -132
  41. package/lib/ContextView/v2/styles.js +0 -267
  42. package/lib/View/v1/index.js +0 -182
  43. package/lib/View/v1/props.js +0 -34
  44. package/lib/View/v1/styles.js +0 -423
  45. package/lib/View/v1/theme.js +0 -109
  46. package/lib/View/v2/index.js +0 -181
  47. package/lib/View/v2/props.js +0 -34
  48. package/lib/View/v2/styles.js +0 -432
  49. package/lib/exports/a.js +0 -19
  50. package/lib/exports/b.js +0 -19
  51. package/lib/package.json +0 -1
@@ -1,423 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _uiI18n = require("@instructure/ui-i18n");
8
- var _emotion = require("@instructure/emotion");
9
- var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
10
- var _alpha = require("@instructure/ui-color-utils/lib/alpha.js");
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
-
35
- const getBorderStyle = ({
36
- borderRadius,
37
- borderWidth,
38
- dir,
39
- theme
40
- }) => {
41
- const isRtlDirection = dir === _uiI18n.DIRECTION.rtl;
42
- return {
43
- borderRadius: (0, _emotion.getShorthandPropValue)('View', theme, isRtlDirection ? (0, _emotion.mirrorShorthandCorners)(borderRadius) : borderRadius, 'borderRadius', true),
44
- borderWidth: (0, _emotion.getShorthandPropValue)('View', theme, isRtlDirection ? (0, _emotion.mirrorShorthandEdges)(borderWidth) : borderWidth, 'borderWidth')
45
- };
46
- };
47
- const getSpacingStyle = ({
48
- margin,
49
- padding,
50
- dir,
51
- theme
52
- }) => {
53
- const isRtlDirection = dir === _uiI18n.DIRECTION.rtl;
54
- return {
55
- margin: (0, _emotion.getShorthandPropValue)('View', theme, isRtlDirection ? (0, _emotion.mirrorShorthandEdges)(margin) : margin, 'margin'),
56
- padding: (0, _emotion.getShorthandPropValue)('View', theme, isRtlDirection ? (0, _emotion.mirrorShorthandEdges)(padding) : padding, 'padding')
57
- };
58
- };
59
- const getOffsetStyle = ({
60
- insetBlockStart,
61
- insetBlockEnd,
62
- insetInlineStart,
63
- insetInlineEnd,
64
- dir
65
- }) => {
66
- const isRtlDirection = dir === _uiI18n.DIRECTION.rtl;
67
- const blockStart = {
68
- top: insetBlockStart,
69
- insetBlockStart
70
- };
71
- const blockEnd = {
72
- bottom: insetBlockEnd,
73
- insetBlockEnd
74
- };
75
- const horizontalOffsets = {
76
- left: isRtlDirection ? insetInlineEnd : insetInlineStart,
77
- right: isRtlDirection ? insetInlineStart : insetInlineEnd
78
- };
79
- return {
80
- ...blockStart,
81
- ...blockEnd,
82
- ...horizontalOffsets
83
- };
84
- };
85
- const getStyleProps = ({
86
- cursor,
87
- style
88
- }) => {
89
- const whitelisted = (0, _pickProps.pickProps)(style || {}, {}, [
90
- // Position/calculateElementPosition:
91
- 'top', 'left', 'position', 'display', 'transform', 'overflow', 'minWidth', 'minHeight',
92
- // Img:
93
- 'filter',
94
- // Flex.Item:
95
- 'flexBasis',
96
- // Avatar:
97
- 'backgroundImage',
98
- // Popover:
99
- 'pointerEvents']);
100
- if (cursor) {
101
- whitelisted.cursor = cursor;
102
- }
103
- return whitelisted;
104
- };
105
- const withBorder = props => {
106
- const {
107
- borderWidth
108
- } = props;
109
- return borderWidth && borderWidth !== '0' && borderWidth !== 'none';
110
- };
111
- const getFocusStyles = (props, componentTheme) => {
112
- const {
113
- focusColor,
114
- focusPosition,
115
- shouldAnimateFocus,
116
- withFocusOutline,
117
- focusWithin
118
- } = props;
119
- const focusPos = focusPosition == 'offset' || focusPosition == 'inset' ? focusPosition : 'offset';
120
- const focusPositionVariants = {
121
- offset: {
122
- outlineOffset: `calc(${componentTheme.focusOutlineOffset} - ${componentTheme.focusOutlineWidth})`
123
- },
124
- inset: {
125
- outlineOffset: `calc(${componentTheme.focusOutlineInset} - ${componentTheme.focusOutlineWidth})`
126
- }
127
- };
128
- const focusColorVariants = {
129
- info: componentTheme.focusColorInfo,
130
- inverse: componentTheme.focusColorInverse,
131
- success: componentTheme.focusColorSuccess,
132
- danger: componentTheme.focusColorDanger
133
- };
134
- const visibleFocusStyle = {
135
- ...focusPositionVariants[focusPos],
136
- outlineColor: focusColorVariants[focusColor]
137
- };
138
- const outlineStyle = {
139
- outlineOffset: '-0.8rem',
140
- // value when not in focus, its invisible
141
- outlineColor: (0, _alpha.alpha)(focusColorVariants[focusColor], 0),
142
- outlineStyle: componentTheme.focusOutlineStyle,
143
- outlineWidth: componentTheme.focusOutlineWidth,
144
- ...(withFocusOutline && visibleFocusStyle)
145
- };
146
- return {
147
- ...(shouldAnimateFocus && {
148
- transition: 'outline-color 0.2s, outline-offset 0.25s'
149
- }),
150
- ...outlineStyle,
151
- '&:hover, &:active': {
152
- // apply the same style so it's not overridden by some global style
153
- ...outlineStyle
154
- },
155
- ...(typeof withFocusOutline === 'undefined' && {
156
- // user focuses the element
157
- '&:focus': visibleFocusStyle
158
- }),
159
- ...(focusWithin && {
160
- '&:focus-within': visibleFocusStyle
161
- })
162
- };
163
- };
164
-
165
- /**
166
- * Generates the style object from the theme and provided additional information
167
- * @param {Object} componentTheme The theme variable object.
168
- * @param {Object} props the props of the component, the style is applied to
169
- * @return {Object} The final style object, which will be used in the component
170
- */
171
- const generateStyle = (componentTheme, props) => {
172
- const {
173
- borderRadius,
174
- borderWidth,
175
- margin,
176
- padding,
177
- position,
178
- display,
179
- textAlign,
180
- borderColor,
181
- background,
182
- stacking,
183
- shadow,
184
- overflowY,
185
- overflowX,
186
- overscrollBehavior,
187
- insetBlockEnd,
188
- insetBlockStart,
189
- insetInlineEnd,
190
- insetInlineStart,
191
- width,
192
- height,
193
- minWidth,
194
- minHeight,
195
- maxWidth,
196
- maxHeight,
197
- withVisualDebug,
198
- dir
199
- } = props;
200
- const borderStyle = getBorderStyle({
201
- theme: componentTheme,
202
- borderRadius,
203
- borderWidth,
204
- dir
205
- });
206
- const spacingStyle = getSpacingStyle({
207
- margin,
208
- padding,
209
- theme: componentTheme,
210
- dir
211
- });
212
- const offsetStyle = getOffsetStyle({
213
- dir,
214
- insetBlockEnd,
215
- insetBlockStart,
216
- insetInlineEnd,
217
- insetInlineStart
218
- });
219
- const displayVariants = {
220
- inline: {
221
- label: 'view--inline',
222
- display: 'inline'
223
- },
224
- block: {
225
- label: 'view--block',
226
- display: 'block'
227
- },
228
- 'inline-block': {
229
- label: 'view--inlineBlock',
230
- display: 'inline-block',
231
- verticalAlign: 'middle'
232
- },
233
- flex: {
234
- label: 'view--flex',
235
- display: 'flex'
236
- },
237
- 'inline-flex': {
238
- label: 'view--inlineFlex',
239
- display: 'inline-flex',
240
- verticalAlign: 'middle'
241
- },
242
- contents: {
243
- label: 'view--contents',
244
- display: 'contents'
245
- },
246
- inherit: {
247
- label: 'view--inherit',
248
- display: 'inherit'
249
- },
250
- initial: {
251
- label: 'view--initial',
252
- display: 'initial'
253
- },
254
- revert: {
255
- label: 'view--revert',
256
- display: 'revert'
257
- },
258
- 'revert-layer': {
259
- label: 'view--revertLayer',
260
- display: 'revert-layer'
261
- },
262
- unset: {
263
- label: 'view--unset',
264
- display: 'unset'
265
- },
266
- auto: {}
267
- };
268
- const textAlignVariants = {
269
- start: {
270
- textAlign: 'start'
271
- },
272
- center: {
273
- textAlign: 'center'
274
- },
275
- end: {
276
- textAlign: 'end'
277
- }
278
- };
279
- const borderColorVariants = {
280
- transparent: {
281
- borderColor: componentTheme.borderColorTransparent
282
- },
283
- primary: {
284
- borderColor: componentTheme.borderColorPrimary
285
- },
286
- secondary: {
287
- borderColor: componentTheme.borderColorSecondary
288
- },
289
- brand: {
290
- borderColor: componentTheme.borderColorBrand
291
- },
292
- info: {
293
- borderColor: componentTheme.borderColorInfo
294
- },
295
- success: {
296
- borderColor: componentTheme.borderColorSuccess
297
- },
298
- warning: {
299
- borderColor: componentTheme.borderColorWarning
300
- },
301
- alert: {
302
- borderColor: componentTheme.borderColorAlert
303
- },
304
- danger: {
305
- borderColor: componentTheme.borderColorDanger
306
- }
307
- };
308
- const backgroundColorVariants = {
309
- transparent: {
310
- color: componentTheme.color,
311
- background: 'none'
312
- },
313
- primary: {
314
- color: componentTheme.color,
315
- background: componentTheme.backgroundPrimary
316
- },
317
- secondary: {
318
- color: componentTheme.color,
319
- background: componentTheme.backgroundSecondary
320
- },
321
- ['primary-inverse']: {
322
- color: componentTheme.colorPrimaryInverse,
323
- background: componentTheme.backgroundPrimaryInverse
324
- },
325
- brand: {
326
- color: componentTheme.colorPrimaryInverse,
327
- background: componentTheme.backgroundBrand
328
- },
329
- info: {
330
- color: componentTheme.colorPrimaryInverse,
331
- background: componentTheme.backgroundInfo
332
- },
333
- alert: {
334
- color: componentTheme.colorPrimaryInverse,
335
- background: componentTheme.backgroundAlert
336
- },
337
- success: {
338
- color: componentTheme.colorPrimaryInverse,
339
- background: componentTheme.backgroundSuccess
340
- },
341
- danger: {
342
- color: componentTheme.colorPrimaryInverse,
343
- background: componentTheme.backgroundDanger
344
- },
345
- warning: {
346
- color: componentTheme.colorPrimaryInverse,
347
- background: componentTheme.backgroundWarning
348
- }
349
- };
350
- const stackingVariants = {
351
- topmost: {
352
- zIndex: componentTheme.stackingTopmost
353
- },
354
- above: {
355
- zIndex: componentTheme.stackingAbove
356
- },
357
- resting: {},
358
- below: {
359
- zIndex: componentTheme.stackingBelow
360
- },
361
- deepest: {
362
- zIndex: componentTheme.stackingDeepest
363
- }
364
- };
365
- const shadowVariants = {
366
- topmost: {
367
- boxShadow: componentTheme.shadowTopmost
368
- },
369
- resting: {
370
- boxShadow: componentTheme.shadowResting
371
- },
372
- above: {
373
- boxShadow: componentTheme.shadowAbove
374
- },
375
- none: {}
376
- };
377
- const focusStyles = getFocusStyles(props, componentTheme);
378
- return {
379
- view: {
380
- label: 'view',
381
- boxSizing: 'border-box',
382
- fontFamily: componentTheme.fontFamily,
383
- maxWidth: '100%',
384
- overflow: 'visible',
385
- ...displayVariants[display],
386
- ...(background && backgroundColorVariants[background]),
387
- ...(stacking && stackingVariants[stacking]),
388
- ...(shadow && shadowVariants[shadow]),
389
- ...(textAlign && textAlignVariants[textAlign]),
390
- overflowX: overflowX && overflowX !== 'visible' ? overflowX : '',
391
- overflowY: overflowY && overflowY !== 'visible' ? overflowY : '',
392
- position: position !== 'static' ? position : '',
393
- overscrollBehavior: overscrollBehavior ? overscrollBehavior : 'auto',
394
- ...(withVisualDebug ? {
395
- boxShadow: `0 0 0 1px ${componentTheme.debugOutlineColor}`
396
- } : {}),
397
- ...(withBorder(props) ? {
398
- borderStyle: componentTheme.borderStyle,
399
- ...(borderColorVariants[borderColor] || {
400
- borderColor: borderColor
401
- })
402
- } : {}),
403
- ...borderStyle
404
- },
405
- inlineStyles: {
406
- //every '&' symbol will add another class to the rule, so it will be stronger
407
- //making an accidental override less likely
408
- '&&&&&&&&&&': {
409
- ...spacingStyle,
410
- ...offsetStyle,
411
- ...focusStyles,
412
- width,
413
- height,
414
- minWidth,
415
- minHeight,
416
- maxWidth,
417
- maxHeight,
418
- ...getStyleProps(props)
419
- }
420
- }
421
- };
422
- };
423
- var _default = exports.default = generateStyle;
@@ -1,109 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _emotion = require("@instructure/emotion");
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- /* Global variables (colors, typography, spacing, etc.) are defined in lib/themes */
33
-
34
- /**
35
- * Generates the theme object for the component from the theme and provided additional information
36
- * @param {Object} theme The actual theme object.
37
- * @return {Object} The final theme object with the overrides and component variables
38
- */
39
- const generateComponentTheme = theme => {
40
- const {
41
- colors,
42
- typography,
43
- borders,
44
- breakpoints,
45
- spacing,
46
- shadows,
47
- stacking,
48
- key: themeName
49
- } = theme;
50
- const themeSpecificStyle = {
51
- canvas: {
52
- color: theme['ic-brand-font-color-dark'],
53
- focusColorInfo: theme['ic-brand-primary'],
54
- backgroundBrand: theme['ic-brand-primary'],
55
- backgroundInfo: theme['ic-brand-primary'],
56
- borderColorBrand: theme['ic-brand-primary'],
57
- borderColorInfo: theme['ic-brand-primary']
58
- }
59
- };
60
- const componentVariables = {
61
- fontFamily: typography?.fontFamily,
62
- color: colors?.contrasts?.grey125125,
63
- colorPrimaryInverse: colors?.contrasts?.white1010,
64
- borderColorPrimary: colors?.contrasts?.grey1424,
65
- borderColorSecondary: colors?.contrasts?.grey3045,
66
- borderColorSuccess: colors?.contrasts?.green4570,
67
- borderColorBrand: colors?.contrasts?.blue4570,
68
- borderColorInfo: colors?.contrasts?.blue4570,
69
- borderColorAlert: colors?.contrasts?.blue4570,
70
- borderColorWarning: colors?.contrasts?.orange4570,
71
- borderColorDanger: colors?.contrasts?.red4570,
72
- borderColorTransparent: 'transparent',
73
- debugOutlineColor: colors?.contrasts?.red4570,
74
- backgroundPrimary: colors?.contrasts?.white1010,
75
- backgroundSecondary: colors?.contrasts?.grey1111,
76
- backgroundPrimaryInverse: colors?.contrasts?.grey125125,
77
- backgroundBrand: colors?.contrasts?.blue4570,
78
- backgroundInfo: colors?.contrasts?.blue4570,
79
- backgroundAlert: colors?.contrasts?.blue4570,
80
- backgroundSuccess: colors?.contrasts?.green4570,
81
- backgroundDanger: colors?.contrasts?.red4570,
82
- backgroundWarning: colors?.contrasts?.orange4570,
83
- arrowSize: '0.5rem',
84
- focusOutlineStyle: borders?.style,
85
- focusOutlineWidth: borders?.widthMedium,
86
- focusOutlineOffset: '0.3125rem',
87
- focusOutlineInset: '0rem',
88
- // do not use unitless zero (for CSS calc())
89
-
90
- focusColorInfo: colors?.contrasts?.blue4570,
91
- focusColorDanger: colors?.contrasts?.red4570,
92
- focusColorSuccess: colors?.contrasts?.green4570,
93
- focusColorInverse: colors?.contrasts?.white1010,
94
- xSmallMaxWidth: breakpoints?.xSmall,
95
- smallMaxWidth: breakpoints?.small,
96
- mediumMaxWidth: breakpoints?.medium,
97
- largeMaxWidth: breakpoints?.large,
98
- ...(0, _emotion.makeThemeVars)('margin', spacing),
99
- ...(0, _emotion.makeThemeVars)('padding', spacing),
100
- ...(0, _emotion.makeThemeVars)('shadow', shadows),
101
- ...(0, _emotion.makeThemeVars)('stacking', stacking),
102
- ...(0, _emotion.makeThemeVars)('border', borders)
103
- };
104
- return {
105
- ...componentVariables,
106
- ...themeSpecificStyle[themeName]
107
- };
108
- };
109
- var _default = exports.default = generateComponentTheme;
@@ -1,181 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.View = void 0;
8
- var _react = require("react");
9
- var _getCSSStyleDeclaration = require("@instructure/ui-dom-utils/lib/getCSSStyleDeclaration.js");
10
- var _textDirectionContextConsumer = require("@instructure/ui-i18n/lib/textDirectionContextConsumer.js");
11
- var _console = require("@instructure/console");
12
- var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
13
- var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
14
- var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
15
- var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
16
- var _emotion = require("@instructure/emotion");
17
- var _styles = _interopRequireDefault(require("./styles"));
18
- var _props = require("./props");
19
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
20
- var _dec, _dec2, _class;
21
- /*
22
- * The MIT License (MIT)
23
- *
24
- * Copyright (c) 2015 - present Instructure, Inc.
25
- *
26
- * Permission is hereby granted, free of charge, to any person obtaining a copy
27
- * of this software and associated documentation files (the "Software"), to deal
28
- * in the Software without restriction, including without limitation the rights
29
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30
- * copies of the Software, and to permit persons to whom the Software is
31
- * furnished to do so, subject to the following conditions:
32
- *
33
- * The above copyright notice and this permission notice shall be included in all
34
- * copies or substantial portions of the Software.
35
- *
36
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42
- * SOFTWARE.
43
- */
44
- /**
45
- ---
46
- category: components
47
- ---
48
- @module View
49
- **/
50
- let View = exports.View = (_dec = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec2 = (0, _emotion.withStyleNew)(_styles.default), _dec(_class = _dec2(_class = class View extends _react.Component {
51
- static displayName = "View";
52
- static componentId = 'View';
53
- static allowedProps = _props.allowedProps;
54
- static defaultProps = {
55
- display: 'auto',
56
- overflowX: 'visible',
57
- overflowY: 'visible',
58
- withVisualDebug: false,
59
- borderColor: 'primary',
60
- position: 'static',
61
- focusPosition: 'offset',
62
- focusColor: 'info',
63
- shouldAnimateFocus: true,
64
- overscrollBehavior: 'auto'
65
- };
66
-
67
- // TODO: Remove this code once all components are using passthroughProps in place
68
- // of omitProps and have removed this function
69
-
70
- // omitViewProps needs to be called on the composed View component so that the
71
- // View.allowedProps in the method matches the View.allowedProps that will be called in
72
- // the consumers. Otherwise the discrepancy could cause unexpected props being
73
- // allowed through.
74
-
75
- // Removes View's own props from the given object. Automatically excludes the
76
- // following props: 'theme', 'children', 'className', 'style', 'styles',
77
- // 'makeStyles', 'themeOverride'
78
- // @param props the object to process
79
- // @param Component The component whose props are processed.
80
- // Only needed for debug logging in non-production builds.
81
- static omitViewProps = (props, Component) => {
82
- // We don't want the theming and styling props to pass
83
- // (these are added and handled by the `@withStyleNew` decorator)
84
- const propsToOmit = [...View.allowedProps, 'styles', 'makeStyles', 'themeOverride'];
85
- if (typeof process !== 'undefined' && (process?.env?.GITHUB_PULL_REQUEST_PREVIEW === 'true' || process?.env?.NODE_ENV !== 'production')) {
86
- Object.keys((0, _pickProps.pickProps)(props, propsToOmit)).forEach(prop => {
87
- (0, _console.logError)(false, `[${Component.name}] prop '${prop}' is not allowed.`);
88
- });
89
- }
90
- return (0, _omitProps.omitProps)(props, propsToOmit);
91
- };
92
- spanMarginVerified;
93
- get _element() {
94
- return this.ref;
95
- }
96
- constructor(props) {
97
- super(props);
98
- this.spanMarginVerified = false;
99
- }
100
- componentDidMount() {
101
- this.props.makeStyles?.();
102
- }
103
- componentDidUpdate() {
104
- this.props.makeStyles?.();
105
-
106
- // Not calling getCSSStyleDeclaration can save hundreds of ms in tests and production
107
- if (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development' && !this.spanMarginVerified) {
108
- // We have to verify margins in the first 'componentDidUpdate',
109
- // because that is when all styles are calculated,
110
- // but we only want to check once, using a flag
111
- this.spanMarginVerified = true;
112
- (0, _console.logError)(!function verifySpanMargin(element, margin) {
113
- if (!element) {
114
- return;
115
- }
116
- const display = (0, _getCSSStyleDeclaration.getCSSStyleDeclaration)(element)?.display;
117
- if (display !== 'inline') {
118
- return;
119
- }
120
- const marginValues = margin ? margin.split(' ') : null;
121
- let verticalMargin = false;
122
-
123
- // either top or bottom margin are set
124
- if (margin) {
125
- if (marginValues && marginValues[0] && marginValues[0] !== 'none' && marginValues[0] !== '0') {
126
- verticalMargin = true;
127
- }
128
- if (marginValues && marginValues[2] && marginValues[2] !== 'none' && marginValues[2] !== '0') {
129
- verticalMargin = true;
130
- }
131
- }
132
- return verticalMargin;
133
- }(this.ref, this.props.margin), `[View] display style is set to 'inline' and will allow for horizontal margins only.`);
134
- }
135
- }
136
- ref = null;
137
- handleElementRef = el => {
138
- if (typeof this.props.elementRef === 'function') {
139
- this.props.elementRef(el);
140
- }
141
- this.ref = el;
142
- };
143
- render() {
144
- const {
145
- children,
146
- textAlign,
147
- background,
148
- display,
149
- withVisualDebug,
150
- width,
151
- height,
152
- minWidth,
153
- minHeight,
154
- maxWidth,
155
- maxHeight,
156
- overflowX,
157
- overflowY,
158
- stacking,
159
- shadow,
160
- position,
161
- focusPosition,
162
- focusColor,
163
- shouldAnimateFocus,
164
- borderColor,
165
- className,
166
- overscrollBehavior,
167
- styles,
168
- makeStyles,
169
- ...props
170
- } = this.props;
171
- const ElementType = (0, _getElementType.getElementType)(View, this.props);
172
- return (0, _jsxRuntime.jsx)(ElementType, {
173
- ...(0, _passthroughProps.passthroughProps)(props),
174
- className: className,
175
- css: [styles?.view, styles?.inlineStyles],
176
- ref: this.handleElementRef,
177
- children: children
178
- });
179
- }
180
- }) || _class) || _class);
181
- var _default = exports.default = View;