material-theme-builder 3.1.0 → 3.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/README.md +3 -3
- package/dist/react.d.ts +18 -3
- package/dist/react.js +21 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,11 +116,11 @@ A hook is also provided:
|
|
|
116
116
|
```tsx
|
|
117
117
|
import { useMtb } from "material-theme-builder/react";
|
|
118
118
|
|
|
119
|
-
const { initials,
|
|
119
|
+
const { initials, setMtbConfig, getMtbColor } = useMtb();
|
|
120
120
|
|
|
121
121
|
return (
|
|
122
|
-
<button onClick={() =>
|
|
123
|
-
Change to {
|
|
122
|
+
<button onClick={() => setMtbConfig({ ...initials, source: "#FF5722" })}>
|
|
123
|
+
Change to {getMtbColor("primary", "light")}
|
|
124
124
|
</button>
|
|
125
125
|
);
|
|
126
126
|
```
|
package/dist/react.d.ts
CHANGED
|
@@ -188,12 +188,27 @@ declare const Mcu: typeof Mtb;
|
|
|
188
188
|
|
|
189
189
|
type Api = {
|
|
190
190
|
initials: MtbConfig;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
mtbConfig: MtbConfig;
|
|
192
|
+
setMtbConfig: (config: MtbConfig) => void;
|
|
193
|
+
getMtbColor: (colorName: TokenName, theme?: string) => string;
|
|
194
194
|
allPalettes: Record<string, TonalPalette>;
|
|
195
195
|
figmaTokens: FigmaTokens;
|
|
196
196
|
figmaVariables: FigmaVariable[];
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated Renamed `mtbConfig` — same value. This alias will be removed in
|
|
199
|
+
* the next major.
|
|
200
|
+
*/
|
|
201
|
+
mcuConfig: MtbConfig;
|
|
202
|
+
/**
|
|
203
|
+
* @deprecated Renamed `setMtbConfig` — same setter. This alias will be
|
|
204
|
+
* removed in the next major.
|
|
205
|
+
*/
|
|
206
|
+
setMcuConfig: (config: MtbConfig) => void;
|
|
207
|
+
/**
|
|
208
|
+
* @deprecated Renamed `getMtbColor` — same function. This alias will be
|
|
209
|
+
* removed in the next major.
|
|
210
|
+
*/
|
|
211
|
+
getMcuColor: (colorName: TokenName, theme?: string) => string;
|
|
197
212
|
};
|
|
198
213
|
declare const useMtb: () => Api;
|
|
199
214
|
/**
|
package/dist/react.js
CHANGED
|
@@ -4524,15 +4524,15 @@ var createRequiredContext = () => {
|
|
|
4524
4524
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4525
4525
|
var [useMtb, Provider, MtbContext] = createRequiredContext();
|
|
4526
4526
|
var MtbProvider = ({
|
|
4527
|
-
styleId,
|
|
4527
|
+
styleId: styleId2,
|
|
4528
4528
|
children,
|
|
4529
4529
|
...configProps
|
|
4530
4530
|
}) => {
|
|
4531
4531
|
const [initials] = useState(() => configProps);
|
|
4532
|
-
const [
|
|
4532
|
+
const [mtbConfig, setMtbConfig] = useState(initials);
|
|
4533
4533
|
const configKey = JSON.stringify(configProps);
|
|
4534
4534
|
React.useEffect(() => {
|
|
4535
|
-
|
|
4535
|
+
setMtbConfig(configProps);
|
|
4536
4536
|
}, [configKey]);
|
|
4537
4537
|
const {
|
|
4538
4538
|
css,
|
|
@@ -4543,8 +4543,8 @@ var MtbProvider = ({
|
|
|
4543
4543
|
figmaVariables
|
|
4544
4544
|
} = useMemo(() => {
|
|
4545
4545
|
const { toCss, toFigmaTokens, toFigmaVariables, ...rest } = builder(
|
|
4546
|
-
|
|
4547
|
-
|
|
4546
|
+
mtbConfig.source,
|
|
4547
|
+
mtbConfig
|
|
4548
4548
|
);
|
|
4549
4549
|
return {
|
|
4550
4550
|
css: toCss(),
|
|
@@ -4552,13 +4552,13 @@ var MtbProvider = ({
|
|
|
4552
4552
|
figmaVariables: toFigmaVariables(),
|
|
4553
4553
|
...rest
|
|
4554
4554
|
};
|
|
4555
|
-
}, [
|
|
4556
|
-
const
|
|
4555
|
+
}, [mtbConfig]);
|
|
4556
|
+
const getMtbColor = useCallback(
|
|
4557
4557
|
(colorName, theme) => {
|
|
4558
4558
|
const mergedColors = theme === "light" ? mergedColorsLight : mergedColorsDark;
|
|
4559
4559
|
const colorValue = mergedColors[colorName];
|
|
4560
4560
|
if (colorValue === void 0) {
|
|
4561
|
-
throw new Error(`Unknown
|
|
4561
|
+
throw new Error(`Unknown token '${colorName}'`);
|
|
4562
4562
|
}
|
|
4563
4563
|
return hexFromArgb5(colorValue);
|
|
4564
4564
|
},
|
|
@@ -4567,24 +4567,28 @@ var MtbProvider = ({
|
|
|
4567
4567
|
const value = useMemo(
|
|
4568
4568
|
() => ({
|
|
4569
4569
|
initials,
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4570
|
+
mtbConfig,
|
|
4571
|
+
setMtbConfig,
|
|
4572
|
+
getMtbColor,
|
|
4573
4573
|
allPalettes,
|
|
4574
4574
|
figmaTokens,
|
|
4575
|
-
figmaVariables
|
|
4575
|
+
figmaVariables,
|
|
4576
|
+
// deprecated aliases
|
|
4577
|
+
mcuConfig: mtbConfig,
|
|
4578
|
+
setMcuConfig: setMtbConfig,
|
|
4579
|
+
getMcuColor: getMtbColor
|
|
4576
4580
|
}),
|
|
4577
4581
|
[
|
|
4578
|
-
|
|
4582
|
+
getMtbColor,
|
|
4579
4583
|
initials,
|
|
4580
|
-
|
|
4584
|
+
mtbConfig,
|
|
4581
4585
|
allPalettes,
|
|
4582
4586
|
figmaTokens,
|
|
4583
4587
|
figmaVariables
|
|
4584
4588
|
]
|
|
4585
4589
|
);
|
|
4586
4590
|
return /* @__PURE__ */ jsxs2(Provider, { value, children: [
|
|
4587
|
-
/* @__PURE__ */ jsx3("style", { id:
|
|
4591
|
+
/* @__PURE__ */ jsx3("style", { id: styleId2, dangerouslySetInnerHTML: { __html: css } }),
|
|
4588
4592
|
children
|
|
4589
4593
|
] });
|
|
4590
4594
|
};
|
|
@@ -4592,7 +4596,7 @@ var useMcu = useMtb;
|
|
|
4592
4596
|
|
|
4593
4597
|
// src/Mtb.tsx
|
|
4594
4598
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
4595
|
-
var
|
|
4599
|
+
var styleId = "mcu-styles";
|
|
4596
4600
|
var DEFAULT_COLOR_MATCH = false;
|
|
4597
4601
|
function Mtb({
|
|
4598
4602
|
source,
|
|
@@ -4639,7 +4643,7 @@ function Mtb({
|
|
|
4639
4643
|
prefix
|
|
4640
4644
|
]
|
|
4641
4645
|
);
|
|
4642
|
-
return /* @__PURE__ */ jsx4(MtbProvider, { ...config, styleId
|
|
4646
|
+
return /* @__PURE__ */ jsx4(MtbProvider, { ...config, styleId, children });
|
|
4643
4647
|
}
|
|
4644
4648
|
var Mcu = Mtb;
|
|
4645
4649
|
export {
|