@spark-web/box 1.0.9 → 1.2.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.
@@ -12,96 +12,104 @@ var internal = require('@spark-web/utils/internal');
12
12
  var ts = require('@spark-web/utils/ts');
13
13
 
14
14
  // prepare context
15
+
15
16
  var backgroundContext = /*#__PURE__*/react.createContext('body');
16
17
  var InternalBackgroundProvider = backgroundContext.Provider;
17
18
  var useBackground = function useBackground() {
18
19
  return react.useContext(backgroundContext);
19
- }; // conditional provider
20
+ };
21
+
22
+ // conditional provider
20
23
 
21
24
  function renderBackgroundProvider(background, element) {
22
25
  return background ? /*#__PURE__*/jsxRuntime.jsx(InternalBackgroundProvider, {
23
26
  value: background,
24
27
  children: element
25
28
  }) : element;
26
- } // a11y contrast utility
29
+ }
30
+
31
+ // a11y contrast utility
27
32
 
28
33
  var useBackgroundLightness = function useBackgroundLightness(backgroundOverride) {
29
34
  var backgroundFromContext = useBackground();
30
35
  var background = backgroundOverride || backgroundFromContext;
36
+ var theme$1 = theme.useTheme();
37
+ var defaultLightness = theme$1.backgroundLightness.body;
31
38
 
32
- var _useTheme = theme.useTheme(),
33
- backgroundLightness = _useTheme.backgroundLightness;
34
-
35
- var defaultLightness = backgroundLightness.body; // used by the consumer-facing/external BackgroundProvider
36
-
39
+ // used by the consumer-facing/external BackgroundProvider
37
40
  if (background === 'UNKNOWN_DARK') {
38
41
  return 'dark';
39
42
  }
40
-
41
43
  if (background === 'UNKNOWN_LIGHT') {
42
44
  return 'light';
43
45
  }
44
-
45
- return background ? backgroundLightness[background] || defaultLightness : defaultLightness;
46
+ return background ? theme$1.backgroundLightness[background] || defaultLightness : defaultLightness;
46
47
  };
47
48
 
48
49
  /** Enforce background "lightness" without applying a background color. */
49
50
  var BackgroundProvider = function BackgroundProvider(_ref) {
50
51
  var type = _ref.type,
51
- children = _ref.children;
52
+ children = _ref.children;
52
53
  return renderBackgroundProvider(type === 'dark' ? 'UNKNOWN_DARK' : 'UNKNOWN_LIGHT', children);
53
54
  };
54
55
 
56
+ // TODO perf review
55
57
  // TODO: review responsive props! Now that we're using object syntax, un-mapped properties don't behave as expected
58
+
56
59
  // types
57
60
 
58
61
  // Hook
59
62
  // ------------------------------
63
+
60
64
  var useBoxStyles = function useBoxStyles(_ref) {
61
65
  var alignItems = _ref.alignItems,
62
- alignSelf = _ref.alignSelf,
63
- background = _ref.background,
64
- border = _ref.border,
65
- borderRadius = _ref.borderRadius,
66
- _ref$borderWidth = _ref.borderWidth,
67
- borderWidth = _ref$borderWidth === void 0 ? 'standard' : _ref$borderWidth,
68
- bottom = _ref.bottom,
69
- cursor = _ref.cursor,
70
- display = _ref.display,
71
- flex = _ref.flex,
72
- flexDirection = _ref.flexDirection,
73
- flexGrow = _ref.flexGrow,
74
- flexShrink = _ref.flexShrink,
75
- flexWrap = _ref.flexWrap,
76
- gap = _ref.gap,
77
- height = _ref.height,
78
- justifyContent = _ref.justifyContent,
79
- left = _ref.left,
80
- margin = _ref.margin,
81
- marginBottom = _ref.marginBottom,
82
- marginLeft = _ref.marginLeft,
83
- marginRight = _ref.marginRight,
84
- marginTop = _ref.marginTop,
85
- marginX = _ref.marginX,
86
- marginY = _ref.marginY,
87
- minHeight = _ref.minHeight,
88
- minWidth = _ref.minWidth,
89
- opacity = _ref.opacity,
90
- overflow = _ref.overflow,
91
- padding = _ref.padding,
92
- paddingBottom = _ref.paddingBottom,
93
- paddingLeft = _ref.paddingLeft,
94
- paddingRight = _ref.paddingRight,
95
- paddingTop = _ref.paddingTop,
96
- paddingX = _ref.paddingX,
97
- paddingY = _ref.paddingY,
98
- position = _ref.position,
99
- right = _ref.right,
100
- shadow = _ref.shadow,
101
- top = _ref.top,
102
- userSelect = _ref.userSelect,
103
- width = _ref.width,
104
- zIndex = _ref.zIndex;
66
+ alignSelf = _ref.alignSelf,
67
+ background = _ref.background,
68
+ border = _ref.border,
69
+ borderTop = _ref.borderTop,
70
+ borderBottom = _ref.borderBottom,
71
+ borderLeft = _ref.borderLeft,
72
+ borderRight = _ref.borderRight,
73
+ borderRadius = _ref.borderRadius,
74
+ _ref$borderWidth = _ref.borderWidth,
75
+ borderWidth = _ref$borderWidth === void 0 ? 'standard' : _ref$borderWidth,
76
+ bottom = _ref.bottom,
77
+ cursor = _ref.cursor,
78
+ display = _ref.display,
79
+ flex = _ref.flex,
80
+ flexDirection = _ref.flexDirection,
81
+ flexGrow = _ref.flexGrow,
82
+ flexShrink = _ref.flexShrink,
83
+ flexWrap = _ref.flexWrap,
84
+ gap = _ref.gap,
85
+ height = _ref.height,
86
+ justifyContent = _ref.justifyContent,
87
+ left = _ref.left,
88
+ margin = _ref.margin,
89
+ marginBottom = _ref.marginBottom,
90
+ marginLeft = _ref.marginLeft,
91
+ marginRight = _ref.marginRight,
92
+ marginTop = _ref.marginTop,
93
+ marginX = _ref.marginX,
94
+ marginY = _ref.marginY,
95
+ minHeight = _ref.minHeight,
96
+ minWidth = _ref.minWidth,
97
+ opacity = _ref.opacity,
98
+ overflow = _ref.overflow,
99
+ padding = _ref.padding,
100
+ paddingBottom = _ref.paddingBottom,
101
+ paddingLeft = _ref.paddingLeft,
102
+ paddingRight = _ref.paddingRight,
103
+ paddingTop = _ref.paddingTop,
104
+ paddingX = _ref.paddingX,
105
+ paddingY = _ref.paddingY,
106
+ position = _ref.position,
107
+ right = _ref.right,
108
+ shadow = _ref.shadow,
109
+ top = _ref.top,
110
+ userSelect = _ref.userSelect,
111
+ width = _ref.width,
112
+ zIndex = _ref.zIndex;
105
113
  var theme$1 = theme.useTheme();
106
114
  var unresponsiveProps = {
107
115
  background: background ? theme$1.color.background[background] : undefined,
@@ -113,11 +121,27 @@ var useBoxStyles = function useBoxStyles(_ref) {
113
121
  overflow: overflow,
114
122
  userSelect: userSelect
115
123
  };
116
- var conditionalBorderStyles = border ? {
124
+ var conditionalBorderStyles = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, border ? {
117
125
  borderStyle: 'solid',
118
126
  borderColor: theme$1.utils.mapResponsiveScale(border, theme$1.border.color),
119
127
  borderWidth: theme$1.utils.mapResponsiveScale(borderWidth, theme$1.border.width)
120
- } : null;
128
+ } : {}), borderTop ? {
129
+ borderTopStyle: 'solid',
130
+ borderTopColor: theme$1.utils.mapResponsiveScale(borderTop, theme$1.border.color),
131
+ borderTopWidth: theme$1.utils.mapResponsiveScale(borderWidth, theme$1.border.width)
132
+ } : {}), borderBottom ? {
133
+ borderBottomStyle: 'solid',
134
+ borderBottomColor: theme$1.utils.mapResponsiveScale(borderBottom, theme$1.border.color),
135
+ borderBottomWidth: theme$1.utils.mapResponsiveScale(borderWidth, theme$1.border.width)
136
+ } : {}), borderLeft ? {
137
+ borderLeftStyle: 'solid',
138
+ borderLeftColor: theme$1.utils.mapResponsiveScale(borderLeft, theme$1.border.color),
139
+ borderLeftWidth: theme$1.utils.mapResponsiveScale(borderWidth, theme$1.border.width)
140
+ } : {}), borderRight ? {
141
+ borderRightStyle: 'solid',
142
+ borderRightColor: theme$1.utils.mapResponsiveScale(borderRight, theme$1.border.color),
143
+ borderRightWidth: theme$1.utils.mapResponsiveScale(borderWidth, theme$1.border.width)
144
+ } : {});
121
145
  return theme$1.utils.resolveResponsiveProps(_objectSpread(_objectSpread(_objectSpread({}, unresponsiveProps), conditionalBorderStyles), {}, {
122
146
  // allow padding and height/width props to play nice
123
147
  display: theme$1.utils.mapResponsiveProp(display),
@@ -155,7 +179,9 @@ var useBoxStyles = function useBoxStyles(_ref) {
155
179
  top: theme$1.utils.mapResponsiveProp(top),
156
180
  zIndex: theme$1.utils.mapResponsiveScale(zIndex, theme$1.elevation)
157
181
  }));
158
- }; // Flex shorthand / adjustments
182
+ };
183
+
184
+ // Flex shorthand / adjustments
159
185
  // ------------------------------
160
186
 
161
187
  var flexMap = {
@@ -180,55 +206,58 @@ var flexMap = {
180
206
  }
181
207
  };
182
208
 
183
- var _excluded$1 = ["alignItems", "alignSelf", "background", "border", "borderRadius", "borderWidth", "bottom", "cursor", "display", "flex", "flexDirection", "flexGrow", "flexShrink", "flexWrap", "gap", "height", "justifyContent", "left", "margin", "marginBottom", "marginLeft", "marginRight", "marginTop", "marginX", "marginY", "minHeight", "minWidth", "opacity", "overflow", "padding", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "paddingX", "paddingY", "position", "right", "shadow", "top", "userSelect", "width", "zIndex"];
184
- /** Separate the style properties from the element attributes. */
209
+ var _excluded$1 = ["alignItems", "alignSelf", "background", "border", "borderRadius", "borderWidth", "borderTop", "borderBottom", "borderLeft", "borderRight", "bottom", "cursor", "display", "flex", "flexDirection", "flexGrow", "flexShrink", "flexWrap", "gap", "height", "justifyContent", "left", "margin", "marginBottom", "marginLeft", "marginRight", "marginTop", "marginX", "marginY", "minHeight", "minWidth", "opacity", "overflow", "padding", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "paddingX", "paddingY", "position", "right", "shadow", "top", "userSelect", "width", "zIndex"];
185
210
 
211
+ /** Separate the style properties from the element attributes. */
186
212
  function useBoxProps(props) {
187
213
  var alignItems = props.alignItems,
188
- alignSelf = props.alignSelf,
189
- background = props.background,
190
- border = props.border,
191
- borderRadius = props.borderRadius,
192
- borderWidth = props.borderWidth,
193
- bottom = props.bottom,
194
- cursor = props.cursor,
195
- display = props.display,
196
- flex = props.flex,
197
- flexDirection = props.flexDirection,
198
- flexGrow = props.flexGrow,
199
- flexShrink = props.flexShrink,
200
- flexWrap = props.flexWrap,
201
- gap = props.gap,
202
- height = props.height,
203
- justifyContent = props.justifyContent,
204
- left = props.left,
205
- margin = props.margin,
206
- marginBottom = props.marginBottom,
207
- marginLeft = props.marginLeft,
208
- marginRight = props.marginRight,
209
- marginTop = props.marginTop,
210
- marginX = props.marginX,
211
- marginY = props.marginY,
212
- minHeight = props.minHeight,
213
- minWidth = props.minWidth,
214
- opacity = props.opacity,
215
- overflow = props.overflow,
216
- padding = props.padding,
217
- paddingBottom = props.paddingBottom,
218
- paddingLeft = props.paddingLeft,
219
- paddingRight = props.paddingRight,
220
- paddingTop = props.paddingTop,
221
- paddingX = props.paddingX,
222
- paddingY = props.paddingY,
223
- position = props.position,
224
- right = props.right,
225
- shadow = props.shadow,
226
- top = props.top,
227
- userSelect = props.userSelect,
228
- width = props.width,
229
- zIndex = props.zIndex,
230
- attributes = _objectWithoutProperties(props, _excluded$1);
231
-
214
+ alignSelf = props.alignSelf,
215
+ background = props.background,
216
+ border = props.border,
217
+ borderRadius = props.borderRadius,
218
+ borderWidth = props.borderWidth,
219
+ borderTop = props.borderTop,
220
+ borderBottom = props.borderBottom,
221
+ borderLeft = props.borderLeft,
222
+ borderRight = props.borderRight,
223
+ bottom = props.bottom,
224
+ cursor = props.cursor,
225
+ display = props.display,
226
+ flex = props.flex,
227
+ flexDirection = props.flexDirection,
228
+ flexGrow = props.flexGrow,
229
+ flexShrink = props.flexShrink,
230
+ flexWrap = props.flexWrap,
231
+ gap = props.gap,
232
+ height = props.height,
233
+ justifyContent = props.justifyContent,
234
+ left = props.left,
235
+ margin = props.margin,
236
+ marginBottom = props.marginBottom,
237
+ marginLeft = props.marginLeft,
238
+ marginRight = props.marginRight,
239
+ marginTop = props.marginTop,
240
+ marginX = props.marginX,
241
+ marginY = props.marginY,
242
+ minHeight = props.minHeight,
243
+ minWidth = props.minWidth,
244
+ opacity = props.opacity,
245
+ overflow = props.overflow,
246
+ padding = props.padding,
247
+ paddingBottom = props.paddingBottom,
248
+ paddingLeft = props.paddingLeft,
249
+ paddingRight = props.paddingRight,
250
+ paddingTop = props.paddingTop,
251
+ paddingX = props.paddingX,
252
+ paddingY = props.paddingY,
253
+ position = props.position,
254
+ right = props.right,
255
+ shadow = props.shadow,
256
+ top = props.top,
257
+ userSelect = props.userSelect,
258
+ width = props.width,
259
+ zIndex = props.zIndex,
260
+ attributes = _objectWithoutProperties(props, _excluded$1);
232
261
  var styles = useBoxStyles({
233
262
  alignItems: alignItems,
234
263
  alignSelf: alignSelf,
@@ -236,6 +265,10 @@ function useBoxProps(props) {
236
265
  border: border,
237
266
  borderRadius: borderRadius,
238
267
  borderWidth: borderWidth,
268
+ borderBottom: borderBottom,
269
+ borderLeft: borderLeft,
270
+ borderRight: borderRight,
271
+ borderTop: borderTop,
239
272
  bottom: bottom,
240
273
  cursor: cursor,
241
274
  display: display,
@@ -281,29 +314,24 @@ function useBoxProps(props) {
281
314
  }
282
315
 
283
316
  var _excluded = ["as", "asElement", "className", "data", "id"];
284
-
285
317
  /** Exposes a prop-based API for adding styles to a view, within the constraints of the theme. */
286
318
  var Box = ts.forwardRefWithAs(function (_ref, forwardedRef) {
287
319
  var _ref$as = _ref.as,
288
- Tag = _ref$as === void 0 ? 'div' : _ref$as,
289
- asElement = _ref.asElement,
290
- className = _ref.className,
291
- data = _ref.data,
292
- id = _ref.id,
293
- props = _objectWithoutProperties(_ref, _excluded);
294
-
320
+ Tag = _ref$as === void 0 ? 'div' : _ref$as,
321
+ asElement = _ref.asElement,
322
+ className = _ref.className,
323
+ data = _ref.data,
324
+ id = _ref.id,
325
+ props = _objectWithoutProperties(_ref, _excluded);
295
326
  var _useBoxProps = useBoxProps(props),
296
- styles = _useBoxProps.styles,
297
- attributes = _useBoxProps.attributes;
298
-
327
+ styles = _useBoxProps.styles,
328
+ attributes = _useBoxProps.attributes;
299
329
  var resetStyles = internal.resetElementStyles(asElement !== null && asElement !== void 0 ? asElement : Tag);
300
-
301
330
  var element = /*#__PURE__*/jsxRuntime.jsx(Tag, _objectSpread(_objectSpread({}, data ? internal.buildDataAttributes(data) : undefined), {}, {
302
331
  ref: forwardedRef,
303
332
  id: id,
304
333
  className: css.cx(css.css(resetStyles), css.css(styles), className)
305
334
  }, attributes));
306
-
307
335
  return renderBackgroundProvider(props.background, element);
308
336
  });
309
337