Skip to content

Commit

Permalink
Export clsx util to use with the withStyles API
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Feb 1, 2024
1 parent f7566d3 commit b2f3412
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mui/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { tss, makeStyles, useStyles, withStyles } from "./mui";
export { tss, makeStyles, useStyles, withStyles, clsx } from "./mui";
export { useMuiThemeStyleOverridesPlugin } from "./themeStyleOverridesPlugin";
export type { MuiThemeStyleOverridesPluginParams } from "./themeStyleOverridesPlugin";
3 changes: 3 additions & 0 deletions src/mui/mui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { useTheme } from "@mui/material/styles";
import { createMakeAndWithStyles } from "../index";
import { createTss } from "../tss";
import { useMuiThemeStyleOverridesPlugin } from "./themeStyleOverridesPlugin";
import { clsx } from "../tools/clsx";

/** @see <https://docs.tss-react.dev/setup> */
export const { makeStyles, withStyles } = createMakeAndWithStyles({
useTheme
});

export { clsx };

export const { tss } = createTss({
"useContext": function useContext() {
const theme = useTheme();
Expand Down
24 changes: 24 additions & 0 deletions src/tools/clsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { classnames } from "./classnames";

export type ClassValue =
| ClassArray
| ClassDictionary
| string
| null
| boolean
| undefined;

export interface ClassDictionary {
[id: string]: any;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ClassArray extends Array<ClassValue> {}

/**
* Polyfill for cslx.
* This is indended to be used ONLY with the withStyles API.
* Otherwise use `const { cx } = useStyles();` instead.
*/
export const clsx: (...classes: ClassValue[]) => string = (...classes) =>
classnames(classes);

0 comments on commit b2f3412

Please sign in to comment.