@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.
- package/CHANGELOG.md +203 -0
- package/README.md +119 -85
- package/dist/declarations/src/{Box.d.ts → box.d.ts} +11 -5
- package/dist/declarations/src/context.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +4 -4
- package/dist/declarations/src/{useBoxProps.d.ts → use-box-props.d.ts} +1 -1
- package/dist/declarations/src/{useBoxStyles.d.ts → use-box-styles.d.ts} +9 -1
- package/dist/spark-web-box.cjs.dev.js +144 -116
- package/dist/spark-web-box.cjs.prod.js +144 -116
- package/dist/spark-web-box.esm.js +144 -116
- package/package.json +15 -8
- /package/dist/declarations/src/{BackgroundProvider.d.ts → background-provider.d.ts} +0 -0
|
@@ -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
|
-
};
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
} :
|
|
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
|
-
};
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
297
|
-
|
|
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
|
|