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