@oxyhq/bloom 0.6.18 → 0.6.20
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/lib/commonjs/theme/color-scope/index.js +21 -4
- package/lib/commonjs/theme/color-scope/index.js.map +1 -1
- package/lib/commonjs/theme/color-scope/index.web.js +30 -8
- package/lib/commonjs/theme/color-scope/index.web.js.map +1 -1
- package/lib/module/theme/color-scope/index.js +23 -6
- package/lib/module/theme/color-scope/index.js.map +1 -1
- package/lib/module/theme/color-scope/index.web.js +32 -10
- package/lib/module/theme/color-scope/index.web.js.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts +8 -5
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts +8 -5
- package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/index.d.ts +8 -5
- package/lib/typescript/module/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/index.web.d.ts +8 -5
- package/lib/typescript/module/theme/color-scope/index.web.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/BloomColorScope.test.tsx +39 -3
- package/src/theme/color-scope/index.tsx +31 -11
- package/src/theme/color-scope/index.web.tsx +34 -13
|
@@ -22,6 +22,9 @@ function BloomColorScope({
|
|
|
22
22
|
if (!parent) {
|
|
23
23
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
24
24
|
}
|
|
25
|
+
if (!colorPreset) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
26
|
+
children: children
|
|
27
|
+
});
|
|
25
28
|
const resolvedMode = parent.theme.mode;
|
|
26
29
|
const contextValue = (0, _react.useMemo)(() => {
|
|
27
30
|
const theme = (0, _buildTheme.buildTheme)(colorPreset, resolvedMode);
|
|
@@ -32,14 +35,28 @@ function BloomColorScope({
|
|
|
32
35
|
};
|
|
33
36
|
}, [colorPreset, resolvedMode, parent]);
|
|
34
37
|
const varsStyle = (0, _react.useMemo)(() => (0, _styleBuilder.buildNativePresetStyle)(colorPreset, resolvedMode), [colorPreset, resolvedMode]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
let content;
|
|
39
|
+
if (asChild) {
|
|
40
|
+
const child = _react.Children.only(children);
|
|
41
|
+
if (! /*#__PURE__*/(0, _react.isValidElement)(child)) {
|
|
42
|
+
throw new Error('BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.');
|
|
43
|
+
}
|
|
44
|
+
const childStyle = child.props.style;
|
|
45
|
+
const mergedStyle = [varsStyle, style, childStyle];
|
|
46
|
+
content = /*#__PURE__*/(0, _react.cloneElement)(child, {
|
|
47
|
+
style: mergedStyle
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
content = /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
38
51
|
style: [{
|
|
39
52
|
flex: 1
|
|
40
53
|
}, varsStyle, style],
|
|
41
54
|
children: children
|
|
42
|
-
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BloomThemeProvider.BloomThemeContext.Provider, {
|
|
58
|
+
value: contextValue,
|
|
59
|
+
children: content
|
|
43
60
|
});
|
|
44
61
|
}
|
|
45
62
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildNativePresetStyle","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","jsx","Fragment","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildNativePresetStyle","content","child","Children","only","isValidElement","childStyle","props","mergedStyle","cloneElement","View","flex","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAEA,IAAAI,aAAA,GAAAJ,OAAA;AAAyD,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAD,wBAAAO,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAO,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,O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|
22
22
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
23
23
|
}
|
|
24
|
+
if (!colorPreset) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
25
|
+
children: children
|
|
26
|
+
});
|
|
24
27
|
const resolvedMode = parent.theme.mode;
|
|
25
28
|
const contextValue = (0, _react.useMemo)(() => {
|
|
26
29
|
const theme = (0, _buildTheme.buildTheme)(colorPreset, resolvedMode);
|
|
@@ -30,16 +33,35 @@ function BloomColorScope({
|
|
|
30
33
|
colorPreset
|
|
31
34
|
};
|
|
32
35
|
}, [colorPreset, resolvedMode, parent]);
|
|
33
|
-
const varsStyle = (0, _react.useMemo)(() => (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const varsStyle = (0, _react.useMemo)(() => (0, _styleBuilder.buildScopeVars)(colorPreset, resolvedMode), [colorPreset, resolvedMode]);
|
|
37
|
+
let content;
|
|
38
|
+
if (asChild) {
|
|
39
|
+
const child = _react.Children.only(children);
|
|
40
|
+
if (! /*#__PURE__*/(0, _react.isValidElement)(child)) {
|
|
41
|
+
throw new Error('BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.');
|
|
42
|
+
}
|
|
43
|
+
const childStyle = child.props.style;
|
|
44
|
+
const mergedStyle = {
|
|
45
|
+
...varsStyle,
|
|
46
|
+
...style,
|
|
47
|
+
...childStyle
|
|
48
|
+
};
|
|
49
|
+
content = /*#__PURE__*/(0, _react.cloneElement)(child, {
|
|
50
|
+
style: mergedStyle
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
const mergedStyle = {
|
|
54
|
+
...varsStyle,
|
|
55
|
+
...style
|
|
56
|
+
};
|
|
57
|
+
content = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
58
|
+
style: mergedStyle,
|
|
59
|
+
children: children
|
|
60
|
+
});
|
|
61
|
+
}
|
|
37
62
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BloomThemeProvider.BloomThemeContext.Provider, {
|
|
38
63
|
value: contextValue,
|
|
39
|
-
children:
|
|
40
|
-
style: varsStyle,
|
|
41
|
-
children: children
|
|
42
|
-
})
|
|
64
|
+
children: content
|
|
43
65
|
});
|
|
44
66
|
}
|
|
45
67
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildScopeVars","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_BloomThemeProvider","_buildTheme","_styleBuilder","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","BloomColorScope","colorPreset","asChild","style","children","parent","useContext","BloomThemeContext","Error","jsx","Fragment","resolvedMode","theme","mode","contextValue","useMemo","buildTheme","varsStyle","buildScopeVars","content","child","Children","only","isValidElement","childStyle","props","mergedStyle","cloneElement","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.web.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAAiD,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAD,wBAAAM,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,CAAAM,CAAA,EAAAC,CAAA,SAAAA,CAAA,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EA;AACA;AACA;AACA;AACO,SAASW,kBAAkBA,CAAC7B,WAAyB,EAAuB;EACjF,MAAMI,MAAM,GAAG,IAAAC,iBAAU,EAACC,qCAAiB,CAAC;EAC5C,IAAI,CAACF,MAAM,EAAE;IACX,MAAM,IAAIG,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,MAAMG,YAAY,GAAGN,MAAM,CAACO,KAAK,CAACC,IAAI;EACtC,OAAO,IAAAE,cAAO,EACZ,MAAM,IAAAG,4BAAc,EAACjB,WAAW,EAAEU,YAAY,CAAwB,EACtE,CAACV,WAAW,EAAEU,YAAY,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React, { useContext, useMemo } from 'react';
|
|
3
|
+
import React, { Children, cloneElement, isValidElement, useContext, useMemo } from 'react';
|
|
4
4
|
import { View } from 'react-native';
|
|
5
5
|
import { BloomThemeContext } from "../BloomThemeProvider.js";
|
|
6
6
|
import { buildTheme } from "../build-theme.js";
|
|
7
7
|
import { buildNativePresetStyle } from "./style-builder.js";
|
|
8
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
export function BloomColorScope({
|
|
10
10
|
colorPreset,
|
|
11
11
|
asChild = false,
|
|
@@ -16,6 +16,9 @@ export function BloomColorScope({
|
|
|
16
16
|
if (!parent) {
|
|
17
17
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
18
18
|
}
|
|
19
|
+
if (!colorPreset) return /*#__PURE__*/_jsx(_Fragment, {
|
|
20
|
+
children: children
|
|
21
|
+
});
|
|
19
22
|
const resolvedMode = parent.theme.mode;
|
|
20
23
|
const contextValue = useMemo(() => {
|
|
21
24
|
const theme = buildTheme(colorPreset, resolvedMode);
|
|
@@ -26,14 +29,28 @@ export function BloomColorScope({
|
|
|
26
29
|
};
|
|
27
30
|
}, [colorPreset, resolvedMode, parent]);
|
|
28
31
|
const varsStyle = useMemo(() => buildNativePresetStyle(colorPreset, resolvedMode), [colorPreset, resolvedMode]);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
let content;
|
|
33
|
+
if (asChild) {
|
|
34
|
+
const child = Children.only(children);
|
|
35
|
+
if (! /*#__PURE__*/isValidElement(child)) {
|
|
36
|
+
throw new Error('BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.');
|
|
37
|
+
}
|
|
38
|
+
const childStyle = child.props.style;
|
|
39
|
+
const mergedStyle = [varsStyle, style, childStyle];
|
|
40
|
+
content = /*#__PURE__*/cloneElement(child, {
|
|
41
|
+
style: mergedStyle
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
content = /*#__PURE__*/_jsx(View, {
|
|
32
45
|
style: [{
|
|
33
46
|
flex: 1
|
|
34
47
|
}, varsStyle, style],
|
|
35
48
|
children: children
|
|
36
|
-
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return /*#__PURE__*/_jsx(BloomThemeContext.Provider, {
|
|
52
|
+
value: contextValue,
|
|
53
|
+
children: content
|
|
37
54
|
});
|
|
38
55
|
}
|
|
39
56
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useContext","useMemo","View","BloomThemeContext","buildTheme","buildNativePresetStyle","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","
|
|
1
|
+
{"version":3,"names":["React","Children","cloneElement","isValidElement","useContext","useMemo","View","BloomThemeContext","buildTheme","buildNativePresetStyle","Fragment","_Fragment","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","content","child","only","childStyle","props","mergedStyle","flex","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,I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M,IAAIP,KAAK,CACb,mGACF,CAAC;IACH;IACA,MAAMS,UAAU,GAAGF,KAAK,CAACG,KAAK,CAACb,KAAK;IACpC,MAAMc,WAAiC,GAAG,CAACN,SAAS,EAAER,KAAK,EAAEY,UAAU,CAAC;IACxEH,OAAO,gBAAGxB,YAAY,CAACyB,KAAK,EAAE;MAAEV,KAAK,EAAEc;IAAY,CAAC,CAAC;EACvD,CAAC,MAAM;IACLL,OAAO,gBAAGb,IAAA,CAACP,IAAI;MAACW,KAAK,EAAE,CAAC;QAAEe,IAAI,EAAE;MAAE,CAAC,EAAEP,SAAS,EAAER,KAAK,CAAE;MAAAC,QAAA,EAAEA;IAAQ,CAAO,CAAC;EAC3E;EAEA,oBAAOL,IAAA,CAACN,iBAAiB,CAAC0B,QAAQ;IAACC,KAAK,EAAEV,YAAa;IAAAN,QAAA,EAAEQ;EAAO,CAA6B,CAAC;AAChG;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,kBAAkBA,CAACpB,WAAyB,EAAwB;EAClF,MAAMI,MAAM,GAAGf,UAAU,CAACG,iBAAiB,CAAC;EAC5C,IAAI,CAACY,MAAM,EAAE;IACX,MAAM,IAAIC,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,MAAMC,YAAY,GAAGF,MAAM,CAACG,KAAK,CAACC,IAAI;EACtC,OAAOlB,OAAO,CACZ,MAAMI,sBAAsB,CAACM,WAAW,EAAEM,YAAY,CAAC,EACvD,CAACN,WAAW,EAAEM,YAAY,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React, { useContext, useMemo } from 'react';
|
|
3
|
+
import React, { Children, cloneElement, isValidElement, useContext, useMemo } from 'react';
|
|
4
4
|
import { BloomThemeContext } from "../BloomThemeProvider.js";
|
|
5
5
|
import { buildTheme } from "../build-theme.js";
|
|
6
6
|
import { buildScopeVars } from "./style-builder.js";
|
|
7
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
8
8
|
export function BloomColorScope({
|
|
9
9
|
colorPreset,
|
|
10
10
|
asChild = false,
|
|
@@ -15,6 +15,9 @@ export function BloomColorScope({
|
|
|
15
15
|
if (!parent) {
|
|
16
16
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
17
17
|
}
|
|
18
|
+
if (!colorPreset) return /*#__PURE__*/_jsx(_Fragment, {
|
|
19
|
+
children: children
|
|
20
|
+
});
|
|
18
21
|
const resolvedMode = parent.theme.mode;
|
|
19
22
|
const contextValue = useMemo(() => {
|
|
20
23
|
const theme = buildTheme(colorPreset, resolvedMode);
|
|
@@ -24,16 +27,35 @@ export function BloomColorScope({
|
|
|
24
27
|
colorPreset
|
|
25
28
|
};
|
|
26
29
|
}, [colorPreset, resolvedMode, parent]);
|
|
27
|
-
const varsStyle = useMemo(() => (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const varsStyle = useMemo(() => buildScopeVars(colorPreset, resolvedMode), [colorPreset, resolvedMode]);
|
|
31
|
+
let content;
|
|
32
|
+
if (asChild) {
|
|
33
|
+
const child = Children.only(children);
|
|
34
|
+
if (! /*#__PURE__*/isValidElement(child)) {
|
|
35
|
+
throw new Error('BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.');
|
|
36
|
+
}
|
|
37
|
+
const childStyle = child.props.style;
|
|
38
|
+
const mergedStyle = {
|
|
39
|
+
...varsStyle,
|
|
40
|
+
...style,
|
|
41
|
+
...childStyle
|
|
42
|
+
};
|
|
43
|
+
content = /*#__PURE__*/cloneElement(child, {
|
|
44
|
+
style: mergedStyle
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
const mergedStyle = {
|
|
48
|
+
...varsStyle,
|
|
49
|
+
...style
|
|
50
|
+
};
|
|
51
|
+
content = /*#__PURE__*/_jsx("div", {
|
|
52
|
+
style: mergedStyle,
|
|
53
|
+
children: children
|
|
54
|
+
});
|
|
55
|
+
}
|
|
31
56
|
return /*#__PURE__*/_jsx(BloomThemeContext.Provider, {
|
|
32
57
|
value: contextValue,
|
|
33
|
-
children:
|
|
34
|
-
style: varsStyle,
|
|
35
|
-
children: children
|
|
36
|
-
})
|
|
58
|
+
children: content
|
|
37
59
|
});
|
|
38
60
|
}
|
|
39
61
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useContext","useMemo","BloomThemeContext","buildTheme","buildScopeVars","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.web.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,QAAQ,OAAO;
|
|
1
|
+
{"version":3,"names":["React","Children","cloneElement","isValidElement","useContext","useMemo","BloomThemeContext","buildTheme","buildScopeVars","Fragment","_Fragment","jsx","_jsx","BloomColorScope","colorPreset","asChild","style","children","parent","Error","resolvedMode","theme","mode","contextValue","varsStyle","content","child","only","childStyle","props","mergedStyle","Provider","value","useColorScopeStyle"],"sourceRoot":"../../../../src","sources":["theme/color-scope/index.web.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAE1F,SAASC,iBAAiB,QAAqC,0BAAuB;AACtF,SAASC,UAAU,QAAQ,mBAAgB;AAE3C,SAASC,cAAc,QAAQ,oBAAiB;AAAC,SAAAC,QAAA,IAAAC,SAAA,EAAAC,GAAA,IAAAC,IAAA;AAsBjD,OAAO,SAASC,eAAeA,CAAC;EAC9BC,WAAW;EACXC,OAAO,GAAG,KAAK;EACfC,KAAK;EACLC;AACoB,CAAC,EAAE;EACvB,MAAMC,MAAM,GAAGd,UAAU,CAACE,i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A;IAAQ,CAAM,CAAC;EACrD;EAEA,oBAAOL,IAAA,CAACN,iBAAiB,CAACyB,QAAQ;IAACC,KAAK,EAAET,YAAa;IAAAN,QAAA,EAAEQ;EAAO,CAA6B,CAAC;AAChG;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASQ,kBAAkBA,CAACnB,WAAyB,EAAuB;EACjF,MAAMI,MAAM,GAAGd,UAAU,CAACE,iBAAiB,CAAC;EAC5C,IAAI,CAACY,MAAM,EAAE;IACX,MAAM,IAAIC,KAAK,CAAC,+DAA+D,CAAC;EAClF;EACA,MAAMC,YAAY,GAAGF,MAAM,CAACG,KAAK,CAACC,IAAI;EACtC,OAAOjB,OAAO,CACZ,MAAMG,cAAc,CAACM,WAAW,EAAEM,YAAY,CAAwB,EACtE,CAACN,WAAW,EAAEM,YAAY,CAC5B,CAAC;AACH","ignoreList":[]}
|
|
@@ -2,14 +2,17 @@ import React from 'react';
|
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
import type { AppColorName } from '../color-presets';
|
|
4
4
|
export interface BloomColorScopeProps {
|
|
5
|
-
/** Preset to apply within this subtree. */
|
|
6
|
-
colorPreset: AppColorName;
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
7
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
8
|
+
*/
|
|
9
|
+
colorPreset: AppColorName | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
12
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
10
13
|
*/
|
|
11
14
|
asChild?: boolean;
|
|
12
|
-
/** Additional style applied to the wrapping `<View
|
|
15
|
+
/** Additional style applied to the wrapping `<View>` (or merged into the cloned child with `asChild`). */
|
|
13
16
|
style?: StyleProp<ViewStyle>;
|
|
14
17
|
children: React.ReactNode;
|
|
15
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAoCtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAUlF"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { AppColorName } from '../color-presets';
|
|
3
3
|
export interface BloomColorScopeProps {
|
|
4
|
-
/** Preset to apply within this subtree. */
|
|
5
|
-
colorPreset: AppColorName;
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
6
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
7
|
+
*/
|
|
8
|
+
colorPreset: AppColorName | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
11
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
9
12
|
*/
|
|
10
13
|
asChild?: boolean;
|
|
11
|
-
/** Additional style applied to the wrapping `<div
|
|
14
|
+
/** Additional style applied to the wrapping `<div>` (or merged into the cloned child with `asChild`). */
|
|
12
15
|
style?: React.CSSProperties;
|
|
13
16
|
children: React.ReactNode;
|
|
14
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yGAAyG;IACzG,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAqCtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAUjF"}
|
|
@@ -2,14 +2,17 @@ import React from 'react';
|
|
|
2
2
|
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
import type { AppColorName } from '../color-presets';
|
|
4
4
|
export interface BloomColorScopeProps {
|
|
5
|
-
/** Preset to apply within this subtree. */
|
|
6
|
-
colorPreset: AppColorName;
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
7
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
8
|
+
*/
|
|
9
|
+
colorPreset: AppColorName | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
12
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
10
13
|
*/
|
|
11
14
|
asChild?: boolean;
|
|
12
|
-
/** Additional style applied to the wrapping `<View
|
|
15
|
+
/** Additional style applied to the wrapping `<View>` (or merged into the cloned child with `asChild`). */
|
|
13
16
|
style?: StyleProp<ViewStyle>;
|
|
14
17
|
children: React.ReactNode;
|
|
15
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAC3F,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0GAA0G;IAC1G,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAoCtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAUlF"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { AppColorName } from '../color-presets';
|
|
3
3
|
export interface BloomColorScopeProps {
|
|
4
|
-
/** Preset to apply within this subtree. */
|
|
5
|
-
colorPreset: AppColorName;
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
6
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
7
|
+
*/
|
|
8
|
+
colorPreset: AppColorName | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
11
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
9
12
|
*/
|
|
10
13
|
asChild?: boolean;
|
|
11
|
-
/** Additional style applied to the wrapping `<div
|
|
14
|
+
/** Additional style applied to the wrapping `<div>` (or merged into the cloned child with `asChild`). */
|
|
12
15
|
style?: React.CSSProperties;
|
|
13
16
|
children: React.ReactNode;
|
|
14
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsE,MAAM,OAAO,CAAC;AAI3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yGAAyG;IACzG,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAMD,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAqCtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAUjF"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Text } from 'react-native';
|
|
2
|
+
import { Text, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
import { render } from '@testing-library/react-native';
|
|
4
4
|
|
|
5
5
|
import { BloomThemeProvider } from '../theme/BloomThemeProvider';
|
|
@@ -11,6 +11,10 @@ function CurrentPreset() {
|
|
|
11
11
|
return <Text testID="preset">{colorPreset}</Text>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
function StyledChild({ style }: { style?: StyleProp<ViewStyle> }) {
|
|
15
|
+
return <View testID="styled-child" style={style}><CurrentPreset /></View>;
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
describe('BloomColorScope', () => {
|
|
15
19
|
it('overrides the colorPreset of its subtree without affecting the parent', () => {
|
|
16
20
|
const { getAllByTestId } = render(
|
|
@@ -27,16 +31,48 @@ describe('BloomColorScope', () => {
|
|
|
27
31
|
expect(presets[1]).toBe('green');
|
|
28
32
|
});
|
|
29
33
|
|
|
30
|
-
it('
|
|
34
|
+
it('clones the single child and merges scope vars into its style (asChild)', () => {
|
|
31
35
|
const { getByTestId } = render(
|
|
32
36
|
<BloomThemeProvider defaultColorPreset="blue" fonts={false}>
|
|
33
37
|
<BloomColorScope colorPreset="purple" asChild>
|
|
34
|
-
<
|
|
38
|
+
<StyledChild style={{ padding: 8 }} />
|
|
35
39
|
</BloomColorScope>
|
|
36
40
|
</BloomThemeProvider>,
|
|
37
41
|
);
|
|
38
42
|
|
|
39
43
|
expect(getByTestId('preset').props.children).toBe('purple');
|
|
44
|
+
const mergedStyle = getByTestId('styled-child').props.style;
|
|
45
|
+
expect(Array.isArray(mergedStyle)).toBe(true);
|
|
46
|
+
expect(mergedStyle).toEqual(
|
|
47
|
+
expect.arrayContaining([expect.objectContaining({ padding: 8 })]),
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('is a no-op when colorPreset is undefined (children inherit parent scope)', () => {
|
|
52
|
+
const { getByTestId } = render(
|
|
53
|
+
<BloomThemeProvider defaultColorPreset="blue" fonts={false}>
|
|
54
|
+
<BloomColorScope colorPreset={undefined}>
|
|
55
|
+
<CurrentPreset />
|
|
56
|
+
</BloomColorScope>
|
|
57
|
+
</BloomThemeProvider>,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect(getByTestId('preset').props.children).toBe('blue');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('throws when asChild has multiple children', () => {
|
|
64
|
+
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
65
|
+
expect(() =>
|
|
66
|
+
render(
|
|
67
|
+
<BloomThemeProvider defaultColorPreset="blue" fonts={false}>
|
|
68
|
+
<BloomColorScope colorPreset="purple" asChild>
|
|
69
|
+
<CurrentPreset />
|
|
70
|
+
<CurrentPreset />
|
|
71
|
+
</BloomColorScope>
|
|
72
|
+
</BloomThemeProvider>,
|
|
73
|
+
),
|
|
74
|
+
).toThrow();
|
|
75
|
+
consoleError.mockRestore();
|
|
40
76
|
});
|
|
41
77
|
|
|
42
78
|
it('throws when used outside BloomThemeProvider', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useMemo } from 'react';
|
|
1
|
+
import React, { Children, cloneElement, isValidElement, useContext, useMemo } from 'react';
|
|
2
2
|
import { View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemeProvider';
|
|
@@ -7,18 +7,25 @@ import type { AppColorName } from '../color-presets';
|
|
|
7
7
|
import { buildNativePresetStyle } from './style-builder';
|
|
8
8
|
|
|
9
9
|
export interface BloomColorScopeProps {
|
|
10
|
-
/** Preset to apply within this subtree. */
|
|
11
|
-
colorPreset: AppColorName;
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
12
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
13
|
+
*/
|
|
14
|
+
colorPreset: AppColorName | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, do not render a wrapping `<View>`. The single child is cloned
|
|
17
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
15
18
|
*/
|
|
16
19
|
asChild?: boolean;
|
|
17
|
-
/** Additional style applied to the wrapping `<View
|
|
20
|
+
/** Additional style applied to the wrapping `<View>` (or merged into the cloned child with `asChild`). */
|
|
18
21
|
style?: StyleProp<ViewStyle>;
|
|
19
22
|
children: React.ReactNode;
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
interface StyleableProps {
|
|
26
|
+
style?: StyleProp<ViewStyle>;
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
export function BloomColorScope({
|
|
23
30
|
colorPreset,
|
|
24
31
|
asChild = false,
|
|
@@ -30,6 +37,8 @@ export function BloomColorScope({
|
|
|
30
37
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
31
38
|
}
|
|
32
39
|
|
|
40
|
+
if (!colorPreset) return <>{children}</>;
|
|
41
|
+
|
|
33
42
|
const resolvedMode = parent.theme.mode;
|
|
34
43
|
|
|
35
44
|
const contextValue = useMemo<BloomThemeContextValue>(() => {
|
|
@@ -42,11 +51,22 @@ export function BloomColorScope({
|
|
|
42
51
|
[colorPreset, resolvedMode],
|
|
43
52
|
);
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
let content: React.ReactNode;
|
|
55
|
+
if (asChild) {
|
|
56
|
+
const child = Children.only(children);
|
|
57
|
+
if (!isValidElement<StyleableProps>(child)) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
'BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const childStyle = child.props.style;
|
|
63
|
+
const mergedStyle: StyleProp<ViewStyle> = [varsStyle, style, childStyle];
|
|
64
|
+
content = cloneElement(child, { style: mergedStyle });
|
|
65
|
+
} else {
|
|
66
|
+
content = <View style={[{ flex: 1 }, varsStyle, style]}>{children}</View>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return <BloomThemeContext.Provider value={contextValue}>{content}</BloomThemeContext.Provider>;
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useMemo } from 'react';
|
|
1
|
+
import React, { Children, cloneElement, isValidElement, useContext, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemeProvider';
|
|
4
4
|
import { buildTheme } from '../build-theme';
|
|
@@ -6,18 +6,25 @@ import type { AppColorName } from '../color-presets';
|
|
|
6
6
|
import { buildScopeVars } from './style-builder';
|
|
7
7
|
|
|
8
8
|
export interface BloomColorScopeProps {
|
|
9
|
-
/** Preset to apply within this subtree. */
|
|
10
|
-
colorPreset: AppColorName;
|
|
11
9
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Preset to apply within this subtree. When `undefined`, the scope is a
|
|
11
|
+
* no-op and children inherit the parent scope's preset unchanged.
|
|
12
|
+
*/
|
|
13
|
+
colorPreset: AppColorName | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* When `true`, do not render a wrapping `<div>`. The single child is cloned
|
|
16
|
+
* with the scope's CSS vars merged into its `style` prop (Radix-style).
|
|
14
17
|
*/
|
|
15
18
|
asChild?: boolean;
|
|
16
|
-
/** Additional style applied to the wrapping `<div
|
|
19
|
+
/** Additional style applied to the wrapping `<div>` (or merged into the cloned child with `asChild`). */
|
|
17
20
|
style?: React.CSSProperties;
|
|
18
21
|
children: React.ReactNode;
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
interface StyleableProps {
|
|
25
|
+
style?: React.CSSProperties;
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
export function BloomColorScope({
|
|
22
29
|
colorPreset,
|
|
23
30
|
asChild = false,
|
|
@@ -29,6 +36,8 @@ export function BloomColorScope({
|
|
|
29
36
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
30
37
|
}
|
|
31
38
|
|
|
39
|
+
if (!colorPreset) return <>{children}</>;
|
|
40
|
+
|
|
32
41
|
const resolvedMode = parent.theme.mode;
|
|
33
42
|
|
|
34
43
|
const contextValue = useMemo<BloomThemeContextValue>(() => {
|
|
@@ -37,15 +46,27 @@ export function BloomColorScope({
|
|
|
37
46
|
}, [colorPreset, resolvedMode, parent]);
|
|
38
47
|
|
|
39
48
|
const varsStyle = useMemo(
|
|
40
|
-
() =>
|
|
41
|
-
[colorPreset, resolvedMode
|
|
49
|
+
() => buildScopeVars(colorPreset, resolvedMode) as React.CSSProperties,
|
|
50
|
+
[colorPreset, resolvedMode],
|
|
42
51
|
);
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
let content: React.ReactNode;
|
|
54
|
+
if (asChild) {
|
|
55
|
+
const child = Children.only(children);
|
|
56
|
+
if (!isValidElement<StyleableProps>(child)) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
'BloomColorScope with `asChild` requires a single React element child that accepts a `style` prop.',
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const childStyle = child.props.style;
|
|
62
|
+
const mergedStyle: React.CSSProperties = { ...varsStyle, ...style, ...childStyle };
|
|
63
|
+
content = cloneElement(child, { style: mergedStyle });
|
|
64
|
+
} else {
|
|
65
|
+
const mergedStyle: React.CSSProperties = { ...varsStyle, ...style };
|
|
66
|
+
content = <div style={mergedStyle}>{children}</div>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return <BloomThemeContext.Provider value={contextValue}>{content}</BloomThemeContext.Provider>;
|
|
49
70
|
}
|
|
50
71
|
|
|
51
72
|
/**
|