Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui-system): adding prop "className" to ThemeProvider #465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ui-system/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const FLEXGRID_CLASSNAME = "av-flexgrid";
export const FLEXGRID_ITEM_CLASSNAME = "av-flexgrid-item";
export const THEMEPROVIDER_CLASSNAME = "av-theme-provider";

export const FLEXGRID_GAP_RATIO = 0.25;
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import clsx from "clsx";
import { useEffect, useRef } from "react";

import { THEMEPROVIDER_CLASSNAME } from "../../common/constants";
import { ThemeProviderProps } from "./ThemeProviderTypes";

export const ThemeProvider = ({
customTheme,
children,
global,
className,
}: ThemeProviderProps) => {
const wrapperRef = useRef<HTMLDivElement>(null);
const wrapperClass = clsx(THEMEPROVIDER_CLASSNAME, "contents", className);

useEffect(() => {
const wrapper = global
Expand All @@ -22,7 +26,7 @@ export const ThemeProvider = ({
}, [customTheme, global]);

return customTheme || !global ? (
<div ref={wrapperRef} className="contents">
<div ref={wrapperRef} className={wrapperClass}>
{children}
</div>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export type ThemeProviderProps = {
* The children to render.
*/
children: React.ReactNode;
/**
* CSS class(es) to add to the main component wrapper.
*/
className?: string;
/**
* An object specifying custom properties impacting the base theme.
* Not all custom properties need to be specified.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { act, render, screen } from "@testing-library/react";

import { expectToHaveClasses } from "../../../../../../configuration/tests-helpers";
import { THEMEPROVIDER_CLASSNAME } from "../../../common/constants";
import { ThemeProvider } from "../..";

const customTheme = {
Expand All @@ -13,6 +15,16 @@ describe("ThemeProvider (exceptions)", () => {
});
});

describe("ThemeProvider props tests", () => {
it("should have default and custom classes", async () => {
await act(async () => {
render(<ThemeProvider className="toto">Hello World</ThemeProvider>);
});
const node = await screen.findByText("Hello World");
expectToHaveClasses(node, [THEMEPROVIDER_CLASSNAME, "contents", "toto"]);
});
});

describe("ThemeProvider injection tests", () => {
it("should NOT inject a custom theme locally [no custom theme]", async () => {
await act(async () => {
Expand Down
Loading