@instructure/ui-view 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.View = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
8
  var _react = require("react");
10
9
  var _getCSSStyleDeclaration = require("@instructure/ui-dom-utils/lib/getCSSStyleDeclaration.js");
11
10
  var _textDirectionContextConsumer = require("@instructure/ui-i18n/lib/textDirectionContextConsumer.js");
@@ -19,8 +18,7 @@ var _styles = _interopRequireDefault(require("./styles"));
19
18
  var _theme = _interopRequireDefault(require("./theme"));
20
19
  var _props = require("./props");
21
20
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
22
- const _excluded = ["children", "textAlign", "background", "display", "withVisualDebug", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "overflowX", "overflowY", "stacking", "shadow", "position", "focusPosition", "focusColor", "shouldAnimateFocus", "borderColor", "className", "overscrollBehavior", "styles", "makeStyles"];
23
- var _dec, _dec2, _class, _View;
21
+ var _dec, _dec2, _class;
24
22
  /*
25
23
  * The MIT License (MIT)
26
24
  *
@@ -50,42 +48,73 @@ category: components
50
48
  ---
51
49
  @module View
52
50
  **/
53
- let View = exports.View = (_dec = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_View = class View extends _react.Component {
51
+ let View = exports.View = (_dec = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = class View extends _react.Component {
52
+ static displayName = "View";
53
+ static componentId = 'View';
54
+ static allowedProps = _props.allowedProps;
55
+ static defaultProps = {
56
+ display: 'auto',
57
+ overflowX: 'visible',
58
+ overflowY: 'visible',
59
+ withVisualDebug: false,
60
+ borderColor: 'primary',
61
+ position: 'static',
62
+ focusPosition: 'offset',
63
+ focusColor: 'info',
64
+ shouldAnimateFocus: true,
65
+ overscrollBehavior: 'auto'
66
+ };
67
+
68
+ // TODO: Remove this code once all components are using passthroughProps in place
69
+ // of omitProps and have removed this function
70
+
71
+ // omitViewProps needs to be called on the composed View component so that the
72
+ // View.allowedProps in the method matches the View.allowedProps that will be called in
73
+ // the consumers. Otherwise the discrepancy could cause unexpected props being
74
+ // allowed through.
75
+
76
+ // Removes View's own props from the given object. Automatically excludes the
77
+ // following props: 'theme', 'children', 'className', 'style', 'styles',
78
+ // 'makeStyles', 'themeOverride'
79
+ // @param props the object to process
80
+ // @param Component The component whose props are processed.
81
+ // Only needed for debug logging in non-production builds.
82
+ static omitViewProps = (props, Component) => {
83
+ // We don't want the theming and styling props to pass
84
+ // (these are added and handled by the `@withStyle` decorator)
85
+ const propsToOmit = [...View.allowedProps, 'styles', 'makeStyles', 'themeOverride'];
86
+ if (typeof process !== 'undefined' && process?.env?.NODE_ENV !== 'production') {
87
+ Object.keys((0, _pickProps.pickProps)(props, propsToOmit)).forEach(prop => {
88
+ (0, _console.logError)(false, `[${Component.name}] prop '${prop}' is not allowed.`);
89
+ });
90
+ }
91
+ return (0, _omitProps.omitProps)(props, propsToOmit);
92
+ };
93
+ spanMarginVerified;
54
94
  get _element() {
55
95
  return this.ref;
56
96
  }
57
97
  constructor(props) {
58
98
  super(props);
59
- this.spanMarginVerified = void 0;
60
- this.ref = null;
61
- this.handleElementRef = el => {
62
- if (typeof this.props.elementRef === 'function') {
63
- this.props.elementRef(el);
64
- }
65
- this.ref = el;
66
- };
67
99
  this.spanMarginVerified = false;
68
100
  }
69
101
  componentDidMount() {
70
- var _this$props$makeStyle, _this$props;
71
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
102
+ this.props.makeStyles?.();
72
103
  }
73
104
  componentDidUpdate() {
74
- var _this$props$makeStyle2, _this$props2, _process, _process$env;
75
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
105
+ this.props.makeStyles?.();
76
106
 
77
107
  // Not calling getCSSStyleDeclaration can save hundreds of ms in tests and production
78
- if (typeof process !== 'undefined' && ((_process = process) === null || _process === void 0 ? void 0 : (_process$env = _process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'development' && !this.spanMarginVerified) {
108
+ if (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development' && !this.spanMarginVerified) {
79
109
  // We have to verify margins in the first 'componentDidUpdate',
80
110
  // because that is when all styles are calculated,
81
111
  // but we only want to check once, using a flag
82
112
  this.spanMarginVerified = true;
83
113
  (0, _console.logError)(!function verifySpanMargin(element, margin) {
84
- var _getCSSStyleDeclarati;
85
114
  if (!element) {
86
115
  return;
87
116
  }
88
- const display = (_getCSSStyleDeclarati = (0, _getCSSStyleDeclaration.getCSSStyleDeclaration)(element)) === null || _getCSSStyleDeclarati === void 0 ? void 0 : _getCSSStyleDeclarati.display;
117
+ const display = (0, _getCSSStyleDeclaration.getCSSStyleDeclaration)(element)?.display;
89
118
  if (display !== 'inline') {
90
119
  return;
91
120
  }
@@ -105,63 +134,49 @@ let View = exports.View = (_dec = (0, _textDirectionContextConsumer.textDirectio
105
134
  }(this.ref, this.props.margin), `[View] display style is set to 'inline' and will allow for horizontal margins only.`);
106
135
  }
107
136
  }
137
+ ref = null;
138
+ handleElementRef = el => {
139
+ if (typeof this.props.elementRef === 'function') {
140
+ this.props.elementRef(el);
141
+ }
142
+ this.ref = el;
143
+ };
108
144
  render() {
109
- const _this$props3 = this.props,
110
- children = _this$props3.children,
111
- textAlign = _this$props3.textAlign,
112
- background = _this$props3.background,
113
- display = _this$props3.display,
114
- withVisualDebug = _this$props3.withVisualDebug,
115
- width = _this$props3.width,
116
- height = _this$props3.height,
117
- minWidth = _this$props3.minWidth,
118
- minHeight = _this$props3.minHeight,
119
- maxWidth = _this$props3.maxWidth,
120
- maxHeight = _this$props3.maxHeight,
121
- overflowX = _this$props3.overflowX,
122
- overflowY = _this$props3.overflowY,
123
- stacking = _this$props3.stacking,
124
- shadow = _this$props3.shadow,
125
- position = _this$props3.position,
126
- focusPosition = _this$props3.focusPosition,
127
- focusColor = _this$props3.focusColor,
128
- shouldAnimateFocus = _this$props3.shouldAnimateFocus,
129
- borderColor = _this$props3.borderColor,
130
- className = _this$props3.className,
131
- overscrollBehavior = _this$props3.overscrollBehavior,
132
- styles = _this$props3.styles,
133
- makeStyles = _this$props3.makeStyles,
134
- props = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
145
+ const {
146
+ children,
147
+ textAlign,
148
+ background,
149
+ display,
150
+ withVisualDebug,
151
+ width,
152
+ height,
153
+ minWidth,
154
+ minHeight,
155
+ maxWidth,
156
+ maxHeight,
157
+ overflowX,
158
+ overflowY,
159
+ stacking,
160
+ shadow,
161
+ position,
162
+ focusPosition,
163
+ focusColor,
164
+ shouldAnimateFocus,
165
+ borderColor,
166
+ className,
167
+ overscrollBehavior,
168
+ styles,
169
+ makeStyles,
170
+ ...props
171
+ } = this.props;
135
172
  const ElementType = (0, _getElementType.getElementType)(View, this.props);
136
173
  return (0, _jsxRuntime.jsx)(ElementType, {
137
174
  ...(0, _passthroughProps.passthroughProps)(props),
138
175
  className: className,
139
- css: [styles === null || styles === void 0 ? void 0 : styles.view, styles === null || styles === void 0 ? void 0 : styles.inlineStyles],
176
+ css: [styles?.view, styles?.inlineStyles],
140
177
  ref: this.handleElementRef,
141
178
  children: children
142
179
  });
143
180
  }
144
- }, _View.displayName = "View", _View.componentId = 'View', _View.allowedProps = _props.allowedProps, _View.defaultProps = {
145
- display: 'auto',
146
- overflowX: 'visible',
147
- overflowY: 'visible',
148
- withVisualDebug: false,
149
- borderColor: 'primary',
150
- position: 'static',
151
- focusPosition: 'offset',
152
- focusColor: 'info',
153
- shouldAnimateFocus: true,
154
- overscrollBehavior: 'auto'
155
- }, _View.omitViewProps = (props, Component) => {
156
- var _process2, _process2$env;
157
- // We don't want the theming and styling props to pass
158
- // (these are added and handled by the `@withStyle` decorator)
159
- const propsToOmit = [..._View.allowedProps, 'styles', 'makeStyles', 'themeOverride'];
160
- if (typeof process !== 'undefined' && ((_process2 = process) === null || _process2 === void 0 ? void 0 : (_process2$env = _process2.env) === null || _process2$env === void 0 ? void 0 : _process2$env.NODE_ENV) !== 'production') {
161
- Object.keys((0, _pickProps.pickProps)(props, propsToOmit)).forEach(prop => {
162
- (0, _console.logError)(false, `[${Component.name}] prop '${prop}' is not allowed.`);
163
- });
164
- }
165
- return (0, _omitProps.omitProps)(props, propsToOmit);
166
- }, _View)) || _class) || _class);
181
+ }) || _class) || _class);
167
182
  var _default = exports.default = View;
@@ -103,15 +103,19 @@ const getStyleProps = ({
103
103
  return whitelisted;
104
104
  };
105
105
  const withBorder = props => {
106
- const borderWidth = props.borderWidth;
106
+ const {
107
+ borderWidth
108
+ } = props;
107
109
  return borderWidth && borderWidth !== '0' && borderWidth !== 'none';
108
110
  };
109
111
  const getFocusStyles = (props, componentTheme) => {
110
- const focusColor = props.focusColor,
111
- focusPosition = props.focusPosition,
112
- shouldAnimateFocus = props.shouldAnimateFocus,
113
- withFocusOutline = props.withFocusOutline,
114
- focusWithin = props.focusWithin;
112
+ const {
113
+ focusColor,
114
+ focusPosition,
115
+ shouldAnimateFocus,
116
+ withFocusOutline,
117
+ focusWithin
118
+ } = props;
115
119
  const focusPos = focusPosition == 'offset' || focusPosition == 'inset' ? focusPosition : 'offset';
116
120
  const focusPositionVariants = {
117
121
  offset: {
@@ -165,32 +169,34 @@ const getFocusStyles = (props, componentTheme) => {
165
169
  * @return {Object} The final style object, which will be used in the component
166
170
  */
167
171
  const generateStyle = (componentTheme, props) => {
168
- const borderRadius = props.borderRadius,
169
- borderWidth = props.borderWidth,
170
- margin = props.margin,
171
- padding = props.padding,
172
- position = props.position,
173
- display = props.display,
174
- textAlign = props.textAlign,
175
- borderColor = props.borderColor,
176
- background = props.background,
177
- stacking = props.stacking,
178
- shadow = props.shadow,
179
- overflowY = props.overflowY,
180
- overflowX = props.overflowX,
181
- overscrollBehavior = props.overscrollBehavior,
182
- insetBlockEnd = props.insetBlockEnd,
183
- insetBlockStart = props.insetBlockStart,
184
- insetInlineEnd = props.insetInlineEnd,
185
- insetInlineStart = props.insetInlineStart,
186
- width = props.width,
187
- height = props.height,
188
- minWidth = props.minWidth,
189
- minHeight = props.minHeight,
190
- maxWidth = props.maxWidth,
191
- maxHeight = props.maxHeight,
192
- withVisualDebug = props.withVisualDebug,
193
- dir = props.dir;
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;
194
200
  const borderStyle = getBorderStyle({
195
201
  theme: componentTheme,
196
202
  borderRadius,
@@ -37,15 +37,16 @@ var _emotion = require("@instructure/emotion");
37
37
  * @return {Object} The final theme object with the overrides and component variables
38
38
  */
39
39
  const generateComponentTheme = theme => {
40
- var _colors$contrasts, _colors$contrasts2, _colors$contrasts3, _colors$contrasts4, _colors$contrasts5, _colors$contrasts6, _colors$contrasts7, _colors$contrasts8, _colors$contrasts9, _colors$contrasts0, _colors$contrasts1, _colors$contrasts10, _colors$contrasts11, _colors$contrasts12, _colors$contrasts13, _colors$contrasts14, _colors$contrasts15, _colors$contrasts16, _colors$contrasts17, _colors$contrasts18, _colors$contrasts19, _colors$contrasts20, _colors$contrasts21, _colors$contrasts22;
41
- const colors = theme.colors,
42
- typography = theme.typography,
43
- borders = theme.borders,
44
- breakpoints = theme.breakpoints,
45
- spacing = theme.spacing,
46
- shadows = theme.shadows,
47
- stacking = theme.stacking,
48
- themeName = theme.key;
40
+ const {
41
+ colors,
42
+ typography,
43
+ borders,
44
+ breakpoints,
45
+ spacing,
46
+ shadows,
47
+ stacking,
48
+ key: themeName
49
+ } = theme;
49
50
  const themeSpecificStyle = {
50
51
  canvas: {
51
52
  color: theme['ic-brand-font-color-dark'],
@@ -57,43 +58,43 @@ const generateComponentTheme = theme => {
57
58
  }
58
59
  };
59
60
  const componentVariables = {
60
- fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
61
- color: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.grey125125,
62
- colorPrimaryInverse: colors === null || colors === void 0 ? void 0 : (_colors$contrasts2 = colors.contrasts) === null || _colors$contrasts2 === void 0 ? void 0 : _colors$contrasts2.white1010,
63
- borderColorPrimary: colors === null || colors === void 0 ? void 0 : (_colors$contrasts3 = colors.contrasts) === null || _colors$contrasts3 === void 0 ? void 0 : _colors$contrasts3.grey1424,
64
- borderColorSecondary: colors === null || colors === void 0 ? void 0 : (_colors$contrasts4 = colors.contrasts) === null || _colors$contrasts4 === void 0 ? void 0 : _colors$contrasts4.grey3045,
65
- borderColorSuccess: colors === null || colors === void 0 ? void 0 : (_colors$contrasts5 = colors.contrasts) === null || _colors$contrasts5 === void 0 ? void 0 : _colors$contrasts5.green4570,
66
- borderColorBrand: colors === null || colors === void 0 ? void 0 : (_colors$contrasts6 = colors.contrasts) === null || _colors$contrasts6 === void 0 ? void 0 : _colors$contrasts6.blue4570,
67
- borderColorInfo: colors === null || colors === void 0 ? void 0 : (_colors$contrasts7 = colors.contrasts) === null || _colors$contrasts7 === void 0 ? void 0 : _colors$contrasts7.blue4570,
68
- borderColorAlert: colors === null || colors === void 0 ? void 0 : (_colors$contrasts8 = colors.contrasts) === null || _colors$contrasts8 === void 0 ? void 0 : _colors$contrasts8.blue4570,
69
- borderColorWarning: colors === null || colors === void 0 ? void 0 : (_colors$contrasts9 = colors.contrasts) === null || _colors$contrasts9 === void 0 ? void 0 : _colors$contrasts9.orange4570,
70
- borderColorDanger: colors === null || colors === void 0 ? void 0 : (_colors$contrasts0 = colors.contrasts) === null || _colors$contrasts0 === void 0 ? void 0 : _colors$contrasts0.red4570,
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,
71
72
  borderColorTransparent: 'transparent',
72
- debugOutlineColor: colors === null || colors === void 0 ? void 0 : (_colors$contrasts1 = colors.contrasts) === null || _colors$contrasts1 === void 0 ? void 0 : _colors$contrasts1.red4570,
73
- backgroundPrimary: colors === null || colors === void 0 ? void 0 : (_colors$contrasts10 = colors.contrasts) === null || _colors$contrasts10 === void 0 ? void 0 : _colors$contrasts10.white1010,
74
- backgroundSecondary: colors === null || colors === void 0 ? void 0 : (_colors$contrasts11 = colors.contrasts) === null || _colors$contrasts11 === void 0 ? void 0 : _colors$contrasts11.grey1111,
75
- backgroundPrimaryInverse: colors === null || colors === void 0 ? void 0 : (_colors$contrasts12 = colors.contrasts) === null || _colors$contrasts12 === void 0 ? void 0 : _colors$contrasts12.grey125125,
76
- backgroundBrand: colors === null || colors === void 0 ? void 0 : (_colors$contrasts13 = colors.contrasts) === null || _colors$contrasts13 === void 0 ? void 0 : _colors$contrasts13.blue4570,
77
- backgroundInfo: colors === null || colors === void 0 ? void 0 : (_colors$contrasts14 = colors.contrasts) === null || _colors$contrasts14 === void 0 ? void 0 : _colors$contrasts14.blue4570,
78
- backgroundAlert: colors === null || colors === void 0 ? void 0 : (_colors$contrasts15 = colors.contrasts) === null || _colors$contrasts15 === void 0 ? void 0 : _colors$contrasts15.blue4570,
79
- backgroundSuccess: colors === null || colors === void 0 ? void 0 : (_colors$contrasts16 = colors.contrasts) === null || _colors$contrasts16 === void 0 ? void 0 : _colors$contrasts16.green4570,
80
- backgroundDanger: colors === null || colors === void 0 ? void 0 : (_colors$contrasts17 = colors.contrasts) === null || _colors$contrasts17 === void 0 ? void 0 : _colors$contrasts17.red4570,
81
- backgroundWarning: colors === null || colors === void 0 ? void 0 : (_colors$contrasts18 = colors.contrasts) === null || _colors$contrasts18 === void 0 ? void 0 : _colors$contrasts18.orange4570,
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,
82
83
  arrowSize: '0.5rem',
83
- focusOutlineStyle: borders === null || borders === void 0 ? void 0 : borders.style,
84
- focusOutlineWidth: borders === null || borders === void 0 ? void 0 : borders.widthMedium,
84
+ focusOutlineStyle: borders?.style,
85
+ focusOutlineWidth: borders?.widthMedium,
85
86
  focusOutlineOffset: '0.3125rem',
86
87
  focusOutlineInset: '0rem',
87
88
  // do not use unitless zero (for CSS calc())
88
89
 
89
- focusColorInfo: colors === null || colors === void 0 ? void 0 : (_colors$contrasts19 = colors.contrasts) === null || _colors$contrasts19 === void 0 ? void 0 : _colors$contrasts19.blue4570,
90
- focusColorDanger: colors === null || colors === void 0 ? void 0 : (_colors$contrasts20 = colors.contrasts) === null || _colors$contrasts20 === void 0 ? void 0 : _colors$contrasts20.red4570,
91
- focusColorSuccess: colors === null || colors === void 0 ? void 0 : (_colors$contrasts21 = colors.contrasts) === null || _colors$contrasts21 === void 0 ? void 0 : _colors$contrasts21.green4570,
92
- focusColorInverse: colors === null || colors === void 0 ? void 0 : (_colors$contrasts22 = colors.contrasts) === null || _colors$contrasts22 === void 0 ? void 0 : _colors$contrasts22.white1010,
93
- xSmallMaxWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.xSmall,
94
- smallMaxWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.small,
95
- mediumMaxWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.medium,
96
- largeMaxWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.large,
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,
97
98
  ...(0, _emotion.makeThemeVars)('margin', spacing),
98
99
  ...(0, _emotion.makeThemeVars)('padding', spacing),
99
100
  ...(0, _emotion.makeThemeVars)('shadow', shadows),
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.View = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
8
  var _react = require("react");
10
9
  var _getCSSStyleDeclaration = require("@instructure/ui-dom-utils/lib/getCSSStyleDeclaration.js");
11
10
  var _textDirectionContextConsumer = require("@instructure/ui-i18n/lib/textDirectionContextConsumer.js");
@@ -18,8 +17,7 @@ var _emotion = require("@instructure/emotion");
18
17
  var _styles = _interopRequireDefault(require("./styles"));
19
18
  var _props = require("./props");
20
19
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
21
- const _excluded = ["children", "textAlign", "background", "display", "withVisualDebug", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "overflowX", "overflowY", "stacking", "shadow", "position", "focusPosition", "focusColor", "shouldAnimateFocus", "borderColor", "className", "overscrollBehavior", "styles", "makeStyles"];
22
- var _dec, _dec2, _class, _View;
20
+ var _dec, _dec2, _class;
23
21
  /*
24
22
  * The MIT License (MIT)
25
23
  *
@@ -49,42 +47,73 @@ category: components
49
47
  ---
50
48
  @module View
51
49
  **/
52
- let View = exports.View = (_dec = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_View = class View extends _react.Component {
50
+ let View = exports.View = (_dec = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec2 = (0, _emotion.withStyle)(_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 `@withStyle` 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;
53
93
  get _element() {
54
94
  return this.ref;
55
95
  }
56
96
  constructor(props) {
57
97
  super(props);
58
- this.spanMarginVerified = void 0;
59
- this.ref = null;
60
- this.handleElementRef = el => {
61
- if (typeof this.props.elementRef === 'function') {
62
- this.props.elementRef(el);
63
- }
64
- this.ref = el;
65
- };
66
98
  this.spanMarginVerified = false;
67
99
  }
68
100
  componentDidMount() {
69
- var _this$props$makeStyle, _this$props;
70
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
101
+ this.props.makeStyles?.();
71
102
  }
72
103
  componentDidUpdate() {
73
- var _this$props$makeStyle2, _this$props2, _process, _process$env;
74
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
104
+ this.props.makeStyles?.();
75
105
 
76
106
  // Not calling getCSSStyleDeclaration can save hundreds of ms in tests and production
77
- if (typeof process !== 'undefined' && ((_process = process) === null || _process === void 0 ? void 0 : (_process$env = _process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'development' && !this.spanMarginVerified) {
107
+ if (typeof process !== 'undefined' && process?.env?.NODE_ENV === 'development' && !this.spanMarginVerified) {
78
108
  // We have to verify margins in the first 'componentDidUpdate',
79
109
  // because that is when all styles are calculated,
80
110
  // but we only want to check once, using a flag
81
111
  this.spanMarginVerified = true;
82
112
  (0, _console.logError)(!function verifySpanMargin(element, margin) {
83
- var _getCSSStyleDeclarati;
84
113
  if (!element) {
85
114
  return;
86
115
  }
87
- const display = (_getCSSStyleDeclarati = (0, _getCSSStyleDeclaration.getCSSStyleDeclaration)(element)) === null || _getCSSStyleDeclarati === void 0 ? void 0 : _getCSSStyleDeclarati.display;
116
+ const display = (0, _getCSSStyleDeclaration.getCSSStyleDeclaration)(element)?.display;
88
117
  if (display !== 'inline') {
89
118
  return;
90
119
  }
@@ -104,63 +133,49 @@ let View = exports.View = (_dec = (0, _textDirectionContextConsumer.textDirectio
104
133
  }(this.ref, this.props.margin), `[View] display style is set to 'inline' and will allow for horizontal margins only.`);
105
134
  }
106
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
+ };
107
143
  render() {
108
- const _this$props3 = this.props,
109
- children = _this$props3.children,
110
- textAlign = _this$props3.textAlign,
111
- background = _this$props3.background,
112
- display = _this$props3.display,
113
- withVisualDebug = _this$props3.withVisualDebug,
114
- width = _this$props3.width,
115
- height = _this$props3.height,
116
- minWidth = _this$props3.minWidth,
117
- minHeight = _this$props3.minHeight,
118
- maxWidth = _this$props3.maxWidth,
119
- maxHeight = _this$props3.maxHeight,
120
- overflowX = _this$props3.overflowX,
121
- overflowY = _this$props3.overflowY,
122
- stacking = _this$props3.stacking,
123
- shadow = _this$props3.shadow,
124
- position = _this$props3.position,
125
- focusPosition = _this$props3.focusPosition,
126
- focusColor = _this$props3.focusColor,
127
- shouldAnimateFocus = _this$props3.shouldAnimateFocus,
128
- borderColor = _this$props3.borderColor,
129
- className = _this$props3.className,
130
- overscrollBehavior = _this$props3.overscrollBehavior,
131
- styles = _this$props3.styles,
132
- makeStyles = _this$props3.makeStyles,
133
- props = (0, _objectWithoutProperties2.default)(_this$props3, _excluded);
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;
134
171
  const ElementType = (0, _getElementType.getElementType)(View, this.props);
135
172
  return (0, _jsxRuntime.jsx)(ElementType, {
136
173
  ...(0, _passthroughProps.passthroughProps)(props),
137
174
  className: className,
138
- css: [styles === null || styles === void 0 ? void 0 : styles.view, styles === null || styles === void 0 ? void 0 : styles.inlineStyles],
175
+ css: [styles?.view, styles?.inlineStyles],
139
176
  ref: this.handleElementRef,
140
177
  children: children
141
178
  });
142
179
  }
143
- }, _View.displayName = "View", _View.componentId = 'View', _View.allowedProps = _props.allowedProps, _View.defaultProps = {
144
- display: 'auto',
145
- overflowX: 'visible',
146
- overflowY: 'visible',
147
- withVisualDebug: false,
148
- borderColor: 'primary',
149
- position: 'static',
150
- focusPosition: 'offset',
151
- focusColor: 'info',
152
- shouldAnimateFocus: true,
153
- overscrollBehavior: 'auto'
154
- }, _View.omitViewProps = (props, Component) => {
155
- var _process2, _process2$env, _process3, _process3$env;
156
- // We don't want the theming and styling props to pass
157
- // (these are added and handled by the `@withStyle` decorator)
158
- const propsToOmit = [..._View.allowedProps, 'styles', 'makeStyles', 'themeOverride'];
159
- if (typeof process !== 'undefined' && (((_process2 = process) === null || _process2 === void 0 ? void 0 : (_process2$env = _process2.env) === null || _process2$env === void 0 ? void 0 : _process2$env.GITHUB_PULL_REQUEST_PREVIEW) === 'true' || ((_process3 = process) === null || _process3 === void 0 ? void 0 : (_process3$env = _process3.env) === null || _process3$env === void 0 ? void 0 : _process3$env.NODE_ENV) !== 'production')) {
160
- Object.keys((0, _pickProps.pickProps)(props, propsToOmit)).forEach(prop => {
161
- (0, _console.logError)(false, `[${Component.name}] prop '${prop}' is not allowed.`);
162
- });
163
- }
164
- return (0, _omitProps.omitProps)(props, propsToOmit);
165
- }, _View)) || _class) || _class);
180
+ }) || _class) || _class);
166
181
  var _default = exports.default = View;