@seed-design/react 2.0.3 → 2.0.4
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/utils/createRecipeContext.cjs +2 -0
- package/lib/utils/createRecipeContext.d.ts.map +1 -1
- package/lib/utils/createRecipeContext.js +2 -0
- package/lib/utils/createRecipeContext.test.d.ts +2 -0
- package/lib/utils/createRecipeContext.test.d.ts.map +1 -0
- package/lib/utils/createSlotRecipeContext.cjs +3 -0
- package/lib/utils/createSlotRecipeContext.d.ts.map +1 -1
- package/lib/utils/createSlotRecipeContext.js +3 -0
- package/lib/utils/createSlotRecipeContext.test.d.ts +2 -0
- package/lib/utils/createSlotRecipeContext.test.d.ts.map +1 -0
- package/lib/utils/restoreDefaultProps.cjs +9 -0
- package/lib/utils/restoreDefaultProps.d.ts +3 -0
- package/lib/utils/restoreDefaultProps.d.ts.map +1 -0
- package/lib/utils/restoreDefaultProps.js +9 -0
- package/package.json +1 -1
- package/src/utils/createRecipeContext.test.tsx +52 -0
- package/src/utils/createRecipeContext.tsx +4 -0
- package/src/utils/createSlotRecipeContext.test.tsx +92 -0
- package/src/utils/createSlotRecipeContext.tsx +7 -0
- package/src/utils/restoreDefaultProps.ts +13 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_restoreDefaultProps = require("./restoreDefaultProps.cjs");
|
|
3
4
|
let clsx = require("clsx");
|
|
4
5
|
clsx = require_runtime.__toESM(clsx);
|
|
5
6
|
let react = require("react");
|
|
@@ -24,6 +25,7 @@ function createRecipeContext(recipe) {
|
|
|
24
25
|
...useProps(),
|
|
25
26
|
...innerProps
|
|
26
27
|
};
|
|
28
|
+
require_restoreDefaultProps.restoreDefaultProps(props, defaultProps);
|
|
27
29
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
28
30
|
const className = recipe(variantProps);
|
|
29
31
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRecipeContext.d.ts","sourceRoot":"","sources":["../../src/utils/createRecipeContext.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createRecipeContext.d.ts","sourceRoot":"","sources":["../../src/utils/createRecipeContext.tsx"],"names":[],"mappings":"AAIA,KAAK,MAAM,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CACzE,KAAK,CAAC,EAAE,KAAK,KACV,MAAM,CAAC,GAAG;IACb,iBAAiB,EAAE,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC;CACjF,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,EAC5F,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;yCAIuB;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE;;kBAQlE,CAAC,EAAE,CAAC,aACZ,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,YACvB;QACR,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;KAC3B,KACA,KAAK,CAAC,yBAAyB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;wBAmB1D,CAAC,OAAK,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;EAU5D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { restoreDefaultProps } from "./restoreDefaultProps.js";
|
|
2
3
|
import clsx$1 from "clsx";
|
|
3
4
|
import { createContext, forwardRef, useContext } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -22,6 +23,7 @@ function createRecipeContext(recipe) {
|
|
|
22
23
|
...useProps(),
|
|
23
24
|
...innerProps
|
|
24
25
|
};
|
|
26
|
+
restoreDefaultProps(props, defaultProps);
|
|
25
27
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
26
28
|
const className = recipe(variantProps);
|
|
27
29
|
return /* @__PURE__ */ jsx(Component, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRecipeContext.test.d.ts","sourceRoot":"","sources":["../../src/utils/createRecipeContext.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_restoreDefaultProps = require("./restoreDefaultProps.cjs");
|
|
3
4
|
let clsx = require("clsx");
|
|
4
5
|
clsx = require_runtime.__toESM(clsx);
|
|
5
6
|
let react = require("react");
|
|
@@ -36,6 +37,7 @@ function createSlotRecipeContext(recipe) {
|
|
|
36
37
|
...useProps(),
|
|
37
38
|
...innerProps
|
|
38
39
|
};
|
|
40
|
+
require_restoreDefaultProps.restoreDefaultProps(props, defaultProps);
|
|
39
41
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
40
42
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClassNamesProvider, {
|
|
41
43
|
value: recipe(variantProps),
|
|
@@ -53,6 +55,7 @@ function createSlotRecipeContext(recipe) {
|
|
|
53
55
|
...useProps(),
|
|
54
56
|
...innerProps
|
|
55
57
|
};
|
|
58
|
+
require_restoreDefaultProps.restoreDefaultProps(props, defaultProps);
|
|
56
59
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
57
60
|
const classNames = recipe(variantProps);
|
|
58
61
|
const className = classNames[slot];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSlotRecipeContext.d.ts","sourceRoot":"","sources":["../../src/utils/createSlotRecipeContext.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createSlotRecipeContext.d.ts","sourceRoot":"","sources":["../../src/utils/createSlotRecipeContext.tsx"],"names":[],"mappings":"AAIA,KAAK,UAAU,CACb,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,EAC1D,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IACvC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,UAAU,CAAC,GAAG;IACpC,iBAAiB,EAAE,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC;CACjF,CAAC;AAEF,wBAAgB,uBAAuB,CACrC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,EAC1D,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC;+CAOlC;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,KAAK,EAAE,UAAU,CAAC;KACnB;yCAI2C;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE;;;uBAmB7D,CAAC,aACd,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,YACvB;QACR,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;KAC3B,KACA,KAAK,CAAC,yBAAyB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;mBAyBtC,CAAC,EAAE,CAAC,aACb,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,QAC3B,MAAM,UAAU,YACZ;QACR,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;KAC3B,KACA,KAAK,CAAC,yBAAyB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;kBA0BhE,CAAC,EAAE,CAAC,aACZ,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,SAC1B,MAAM,UAAU,KACtB,KAAK,CAAC,yBAAyB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;EAsBtF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { restoreDefaultProps } from "./restoreDefaultProps.js";
|
|
2
3
|
import clsx$1 from "clsx";
|
|
3
4
|
import { createContext, forwardRef, useContext } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -34,6 +35,7 @@ function createSlotRecipeContext(recipe) {
|
|
|
34
35
|
...useProps(),
|
|
35
36
|
...innerProps
|
|
36
37
|
};
|
|
38
|
+
restoreDefaultProps(props, defaultProps);
|
|
37
39
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
38
40
|
return /* @__PURE__ */ jsx(ClassNamesProvider, {
|
|
39
41
|
value: recipe(variantProps),
|
|
@@ -51,6 +53,7 @@ function createSlotRecipeContext(recipe) {
|
|
|
51
53
|
...useProps(),
|
|
52
54
|
...innerProps
|
|
53
55
|
};
|
|
56
|
+
restoreDefaultProps(props, defaultProps);
|
|
54
57
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
55
58
|
const classNames = recipe(variantProps);
|
|
56
59
|
const className = classNames[slot];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSlotRecipeContext.test.d.ts","sourceRoot":"","sources":["../../src/utils/createSlotRecipeContext.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/utils/restoreDefaultProps.ts
|
|
3
|
+
/** Restores defaults overwritten by explicitly passed undefined values. */
|
|
4
|
+
function restoreDefaultProps(props, defaultProps) {
|
|
5
|
+
if (!defaultProps) return;
|
|
6
|
+
for (const key of Object.keys(defaultProps)) if (props[key] === void 0) props[key] = defaultProps[key];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.restoreDefaultProps = restoreDefaultProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restoreDefaultProps.d.ts","sourceRoot":"","sources":["../../src/utils/restoreDefaultProps.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,QASrC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/utils/restoreDefaultProps.ts
|
|
3
|
+
/** Restores defaults overwritten by explicitly passed undefined values. */
|
|
4
|
+
function restoreDefaultProps(props, defaultProps) {
|
|
5
|
+
if (!defaultProps) return;
|
|
6
|
+
for (const key of Object.keys(defaultProps)) if (props[key] === void 0) props[key] = defaultProps[key];
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { restoreDefaultProps };
|
package/package.json
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { render } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "bun:test";
|
|
3
|
+
import { createRecipeContext } from "./createRecipeContext";
|
|
4
|
+
|
|
5
|
+
type TestRecipeProps = {
|
|
6
|
+
active?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
let receivedProps: TestRecipeProps | undefined;
|
|
10
|
+
|
|
11
|
+
const testRecipe = Object.assign(
|
|
12
|
+
(props?: TestRecipeProps) => {
|
|
13
|
+
receivedProps = props;
|
|
14
|
+
return "root";
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
splitVariantProps: <T extends TestRecipeProps>(props: T) =>
|
|
18
|
+
[props, {} as Omit<T, keyof TestRecipeProps>] as [
|
|
19
|
+
TestRecipeProps,
|
|
20
|
+
Omit<T, keyof TestRecipeProps>,
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const { PropsProvider, withContext } = createRecipeContext(testRecipe);
|
|
26
|
+
const Root = withContext<unknown, TestRecipeProps>(() => null, {
|
|
27
|
+
defaultProps: { active: true },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("createRecipeContext", () => {
|
|
31
|
+
it("restores default props overwritten with undefined", () => {
|
|
32
|
+
render(<Root active={undefined} />);
|
|
33
|
+
|
|
34
|
+
expect(receivedProps).toMatchObject({ active: true });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("restores default props overwritten with undefined context props", () => {
|
|
38
|
+
render(
|
|
39
|
+
<PropsProvider value={{ active: undefined }}>
|
|
40
|
+
<Root />
|
|
41
|
+
</PropsProvider>,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(receivedProps).toMatchObject({ active: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("preserves explicitly provided false values", () => {
|
|
48
|
+
render(<Root active={false} />);
|
|
49
|
+
|
|
50
|
+
expect(receivedProps).toMatchObject({ active: false });
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import clsx from "clsx";
|
|
2
2
|
import { createContext, forwardRef, useContext } from "react";
|
|
3
|
+
import { restoreDefaultProps } from "./restoreDefaultProps";
|
|
3
4
|
|
|
4
5
|
type Recipe<Props extends Record<string, string | boolean | undefined>> = ((
|
|
5
6
|
props?: Props,
|
|
@@ -31,6 +32,9 @@ export function createRecipeContext<Props extends Record<string, string | boolea
|
|
|
31
32
|
const StyledComponent = forwardRef<any, any>((innerProps, ref) => {
|
|
32
33
|
const props = { ...(defaultProps ?? {}), ...useProps(), ...innerProps } as Props &
|
|
33
34
|
React.HTMLAttributes<HTMLElement>;
|
|
35
|
+
|
|
36
|
+
restoreDefaultProps(props as Record<string, unknown>, defaultProps);
|
|
37
|
+
|
|
34
38
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
35
39
|
const className = recipe(variantProps); // TODO: should we memoize this?
|
|
36
40
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { render } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "bun:test";
|
|
3
|
+
import { createSlotRecipeContext } from "./createSlotRecipeContext";
|
|
4
|
+
|
|
5
|
+
type TestRecipeProps = {
|
|
6
|
+
lazyMount?: boolean;
|
|
7
|
+
unmountOnExit?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type TestClassNames = {
|
|
11
|
+
root: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
let receivedProps: TestRecipeProps | undefined;
|
|
15
|
+
|
|
16
|
+
const testRecipe = Object.assign(
|
|
17
|
+
(props?: TestRecipeProps): TestClassNames => {
|
|
18
|
+
receivedProps = props;
|
|
19
|
+
return { root: "root" };
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
splitVariantProps: <T extends TestRecipeProps>(props: T) =>
|
|
23
|
+
[props, {} as Omit<T, keyof TestRecipeProps>] as [
|
|
24
|
+
TestRecipeProps,
|
|
25
|
+
Omit<T, keyof TestRecipeProps>,
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const { PropsProvider, withProvider, withRootProvider } = createSlotRecipeContext(testRecipe);
|
|
31
|
+
const Root = withRootProvider<TestRecipeProps>(() => null, {
|
|
32
|
+
defaultProps: {
|
|
33
|
+
lazyMount: true,
|
|
34
|
+
unmountOnExit: true,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const Slot = withProvider<unknown, TestRecipeProps>(() => null, "root", {
|
|
38
|
+
defaultProps: {
|
|
39
|
+
lazyMount: true,
|
|
40
|
+
unmountOnExit: true,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("createSlotRecipeContext", () => {
|
|
45
|
+
describe("withRootProvider", () => {
|
|
46
|
+
it("restores default props overwritten with undefined", () => {
|
|
47
|
+
render(<Root lazyMount={undefined} unmountOnExit={undefined} />);
|
|
48
|
+
|
|
49
|
+
expect(receivedProps).toMatchObject({
|
|
50
|
+
lazyMount: true,
|
|
51
|
+
unmountOnExit: true,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("restores default props overwritten with undefined context props", () => {
|
|
56
|
+
render(
|
|
57
|
+
<PropsProvider value={{ lazyMount: undefined, unmountOnExit: undefined }}>
|
|
58
|
+
<Root />
|
|
59
|
+
</PropsProvider>,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(receivedProps).toMatchObject({
|
|
63
|
+
lazyMount: true,
|
|
64
|
+
unmountOnExit: true,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("preserves explicitly provided false values", () => {
|
|
69
|
+
render(<Root lazyMount={false} unmountOnExit={false} />);
|
|
70
|
+
|
|
71
|
+
expect(receivedProps).toMatchObject({
|
|
72
|
+
lazyMount: false,
|
|
73
|
+
unmountOnExit: false,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("withProvider", () => {
|
|
79
|
+
it("restores default props overwritten with undefined context props", () => {
|
|
80
|
+
render(
|
|
81
|
+
<PropsProvider value={{ lazyMount: undefined, unmountOnExit: undefined }}>
|
|
82
|
+
<Slot />
|
|
83
|
+
</PropsProvider>,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(receivedProps).toMatchObject({
|
|
87
|
+
lazyMount: true,
|
|
88
|
+
unmountOnExit: true,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import clsx from "clsx";
|
|
2
2
|
import { createContext, forwardRef, useContext } from "react";
|
|
3
|
+
import { restoreDefaultProps } from "./restoreDefaultProps";
|
|
3
4
|
|
|
4
5
|
type SlotRecipe<
|
|
5
6
|
Props extends Record<string, string | boolean | undefined>,
|
|
@@ -55,6 +56,9 @@ export function createSlotRecipeContext<
|
|
|
55
56
|
const StyledComponent = (innerProps: any) => {
|
|
56
57
|
const props = { ...(defaultProps ?? {}), ...useProps(), ...innerProps } as Props &
|
|
57
58
|
React.HTMLAttributes<HTMLElement>;
|
|
59
|
+
|
|
60
|
+
restoreDefaultProps(props as Record<string, unknown>, defaultProps);
|
|
61
|
+
|
|
58
62
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
59
63
|
const classNames = recipe(variantProps); // TODO: should we memoize this?
|
|
60
64
|
|
|
@@ -83,6 +87,9 @@ export function createSlotRecipeContext<
|
|
|
83
87
|
const StyledComponent = forwardRef<any, any>((innerProps, ref) => {
|
|
84
88
|
const props = { ...(defaultProps ?? {}), ...useProps(), ...innerProps } as Props &
|
|
85
89
|
React.HTMLAttributes<HTMLElement>;
|
|
90
|
+
|
|
91
|
+
restoreDefaultProps(props as Record<string, unknown>, defaultProps);
|
|
92
|
+
|
|
86
93
|
const [variantProps, otherProps] = recipe.splitVariantProps(props);
|
|
87
94
|
const classNames = recipe(variantProps); // TODO: should we memoize this?
|
|
88
95
|
const className = classNames[slot as keyof typeof classNames];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Restores defaults overwritten by explicitly passed undefined values. */
|
|
2
|
+
export function restoreDefaultProps<P>(
|
|
3
|
+
props: Record<string, unknown>,
|
|
4
|
+
defaultProps: Partial<P> | undefined,
|
|
5
|
+
) {
|
|
6
|
+
if (!defaultProps) return;
|
|
7
|
+
|
|
8
|
+
for (const key of Object.keys(defaultProps)) {
|
|
9
|
+
if (props[key] === undefined) {
|
|
10
|
+
props[key] = defaultProps[key as keyof P];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|