Skip to content

Commit 985972c

Browse files
committed
Add documentation to functions
1 parent 7594e39 commit 985972c

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

packages/mui-material/src/styles/useThemeProps.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ export type ThemedProps<Theme, Name extends keyof any> = Theme extends {
1111
? Props
1212
: {};
1313

14+
/**
15+
* Merges input `props` with the `defaultProps` for a component that were defined in the theme.
16+
*
17+
* The `defaultProps` are defined in the theme under `theme.components[componentName].defaultProps`.
18+
*
19+
* @example
20+
*
21+
* ```tsx
22+
* const createTheme = () => ({
23+
* components: {
24+
* MuiStat: {
25+
* defaultProps: {
26+
* variant: 'outlined',
27+
* },
28+
* },
29+
* },
30+
* });
31+
*
32+
* function Stat(props) {
33+
* const themeProps = useThemeProps({ props, name: 'MuiStat' });
34+
* return <div {...themeProps} />;
35+
* }
36+
* ```
37+
*
38+
* @param params.props The input props
39+
* @param params.name The name of the component as defined in the theme
40+
*/
1441
export default function useThemeProps<
1542
Theme extends ThemeWithProps,
1643
Props,

packages/mui-utils/src/composeClasses/composeClasses.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
These rules are preventing the performance optimizations below.
44
*/
55

6+
/**
7+
* Compose classes from multiple sources.
8+
*
9+
* @example
10+
* ```tsx
11+
* const slots = {
12+
* root: ['root', 'primary'],
13+
* label: ['label'],
14+
* };
15+
*
16+
* const getUtilityClass = (slot) => `MuiButton-${slot}`;
17+
*
18+
* const classes = {
19+
* root: 'my-root-class',
20+
* };
21+
*
22+
* const output = composeClasses(slots, getUtilityClass, classes);
23+
* // {
24+
* // root: 'MuiButton-root MuiButton-primary my-root-class',
25+
* // label: 'MuiButton-label',
26+
* // }
27+
* ```
28+
*
29+
* @param slots a list of classes for each possible slot
30+
* @param getUtilityClass a function to resolve the class based on the slot name
31+
* @param classes the input classes from props
32+
* @returns the resolved classes for all slots
33+
*/
634
export default function composeClasses<ClassKey extends string>(
735
slots: Record<ClassKey, ReadonlyArray<string | false | undefined | null>>,
836
getUtilityClass: (slot: string) => string,

packages/mui-utils/src/deepmerge/deepmerge.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@ describe('deepmerge', () => {
131131

132132
expect(result.element).to.equal(element2);
133133
});
134+
135+
it('should deep clone example correctly', () => {
136+
const result = deepmerge({ a: { b: 1 }, d: 2 }, { a: { c: 2 }, d: 4 });
137+
138+
expect(result).to.deep.equal({ a: { b: 1, c: 2 }, d: 4 });
139+
});
134140
});

packages/mui-utils/src/deepmerge/deepmerge.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ function deepClone<T>(source: T): T | Record<keyof any, unknown> {
3434
return output;
3535
}
3636

37+
/**
38+
* Merge objects deeply.
39+
* It will shallow copy React elements.
40+
*
41+
* If `options.clone` is set to `false` the source object will be merged directly into the target object.
42+
*
43+
* @example
44+
* ```ts
45+
* deepmerge({ a: { b: 1 }, d: 2 }, { a: { c: 2 }, d: 4 });
46+
* // => { a: { b: 1, c: 2 }, d: 4 }
47+
* ````
48+
*
49+
* @param target The target object.
50+
* @param source The source object.
51+
* @param options The merge options.
52+
* @param options.clone Set to `false` to merge the source object directly into the target object.
53+
* @returns The merged object.
54+
*/
3755
export default function deepmerge<T>(
3856
target: T,
3957
source: unknown,

0 commit comments

Comments
 (0)