From 748d070bd9f64dcc1f58e71e703c43d1abf41b25 Mon Sep 17 00:00:00 2001 From: Nathan Panchout Date: Thu, 18 Sep 2025 15:19:01 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(react)=20update=20Button=20c?= =?UTF-8?q?omponent=20props=20and=20refactor=20related=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit modifies the Button component to switch the `variant` and `color` props, ensuring consistency across various components that utilize the Button. The changes include updates in the Alert, Modal, Tooltip, and other components to reflect this new prop structure. Additionally, several test and story files have been adjusted to accommodate these changes, enhancing the overall component architecture. --- .../Alert/AlertAdditionalExpandable.tsx | 4 +- packages/react/src/components/Alert/Utils.tsx | 14 ++-- .../react/src/components/Alert/index.spec.tsx | 30 ++++---- .../src/components/Alert/index.stories.tsx | 4 +- .../src/components/Button/index.stories.tsx | 74 +++++++++---------- .../react/src/components/Button/index.tsx | 16 ++-- .../src/components/DataGrid/index.spec.tsx | 32 ++++---- .../src/components/DataGrid/index.stories.tsx | 18 ++--- .../components/Forms/DatePicker/Calendar.tsx | 24 +++--- .../Forms/DatePicker/CalendarCell.tsx | 4 +- .../Forms/DatePicker/DatePickerAux.tsx | 8 +- .../Forms/FileUploader/FileUploaderMulti.tsx | 4 +- .../components/Forms/Input/InputPassword.tsx | 4 +- .../components/Forms/Select/mono-common.tsx | 8 +- .../components/Forms/Select/multi-common.tsx | 8 +- .../Forms/Select/multi-selected-items.tsx | 4 +- .../components/Modal/ConfirmationModal.tsx | 2 +- .../Modal/DeleteConfirmationModal.tsx | 4 +- .../components/Modal/EdgeCases.stories.tsx | 18 ++--- .../src/components/Modal/index.stories.tsx | 26 +++---- packages/react/src/components/Modal/index.tsx | 4 +- .../react/src/components/Pagination/index.tsx | 16 ++-- .../react/src/components/Toast/index.spec.tsx | 2 +- .../src/components/Toast/index.stories.tsx | 4 +- packages/react/src/components/Toast/index.tsx | 4 +- .../src/components/Tooltip/index.spec.tsx | 20 ++--- .../src/components/Tooltip/index.stories.tsx | 16 ++-- 27 files changed, 186 insertions(+), 186 deletions(-) diff --git a/packages/react/src/components/Alert/AlertAdditionalExpandable.tsx b/packages/react/src/components/Alert/AlertAdditionalExpandable.tsx index bc9c341..f9803a0 100644 --- a/packages/react/src/components/Alert/AlertAdditionalExpandable.tsx +++ b/packages/react/src/components/Alert/AlertAdditionalExpandable.tsx @@ -16,8 +16,8 @@ export const AlertAdditionalExpandable = (props: AlertProps) => { const iconButton = ( - + + } > Alert component - , + ); screen.getByRole("button", { name: "Primary Custom" }); screen.getByRole("button", { name: "Secondary Custom" }); @@ -96,7 +96,7 @@ describe("", () => { Alert component - , + ); screen.getByText("Alert component"); @@ -165,14 +165,14 @@ describe("", () => { > Alert component - , + ); const user = userEvent.setup(); screen.getByText("Alert component"); expect( - screen.queryByText("Additional information"), + screen.queryByText("Additional information") ).not.toBeInTheDocument(); const $expandButton = screen.getByRole("button", { name: "Expand alert" }); @@ -184,7 +184,7 @@ describe("", () => { await user.click($shrinkButton); expect( - screen.queryByText("Additional information"), + screen.queryByText("Additional information") ).not.toBeInTheDocument(); }); it("can expand the alert controlled", async () => { @@ -226,7 +226,7 @@ describe("", () => { screen.getByText("Expanded: false"); expect( - screen.queryByText("Additional information"), + screen.queryByText("Additional information") ).not.toBeInTheDocument(); // Expand from alert. @@ -246,14 +246,14 @@ describe("", () => { screen.getByText("Expanded: false"); expect( - screen.queryByText("Additional information"), + screen.queryByText("Additional information") ).not.toBeInTheDocument(); }); it("renders with className", async () => { render(); expect( - document.querySelector(".c__alert.my-custom-class"), + document.querySelector(".c__alert.my-custom-class") ).toBeInTheDocument(); }); }); diff --git a/packages/react/src/components/Alert/index.stories.tsx b/packages/react/src/components/Alert/index.stories.tsx index f21d75c..b520cee 100644 --- a/packages/react/src/components/Alert/index.stories.tsx +++ b/packages/react/src/components/Alert/index.stories.tsx @@ -58,10 +58,10 @@ export const CustomButtons: Story = { canClose: true, buttons: (
- -
diff --git a/packages/react/src/components/Button/index.stories.tsx b/packages/react/src/components/Button/index.stories.tsx index 04eba5b..3544527 100644 --- a/packages/react/src/components/Button/index.stories.tsx +++ b/packages/react/src/components/Button/index.stories.tsx @@ -11,10 +11,10 @@ export default meta; type Story = StoryObj; type AllButtonsProps = ButtonProps & { - variant: ButtonProps["variant"]; + color: ButtonProps["color"]; }; -const AllButtons = ({ variant = "brand" }: AllButtonsProps) => { +const AllButtons = ({ color = "brand" }: AllButtonsProps) => { return (
{ justifyContent: "start", }} > -

Primary

-
-

Secondary

-
-

Tertiary

-
-

Bordered

-
); @@ -58,44 +58,44 @@ const AllButtons = ({ variant = "brand" }: AllButtonsProps) => { export const AllBrands: Story = { render: () => { - return ; + return ; }, }; export const AllNeutrals: Story = { render: () => { - return ; + return ; }, }; export const AllWarnings: Story = { render: () => { - return ; + return ; }, }; export const AllErrors: Story = { render: () => { - return ; + return ; }, }; export const AllSuccesses: Story = { render: () => { - return ; + return ; }, }; export const AllInfos: Story = { render: () => { - return ; + return ; }, }; const Primary: Story = { args: { children: "Primary", - color: "primary", + variant: "primary", icon: bolt, }, }; @@ -103,7 +103,7 @@ const Primary: Story = { const PrimaryDisabled: Story = { args: { children: "Disabled", - color: "primary", + variant: "primary", disabled: true, icon: bolt, }, @@ -112,7 +112,7 @@ const PrimaryDisabled: Story = { const Secondary: Story = { args: { children: "Secondary", - color: "secondary", + variant: "secondary", icon: bolt, }, }; @@ -120,7 +120,7 @@ const Secondary: Story = { const SecondaryDisabled: Story = { args: { children: "Disabled", - color: "secondary", + variant: "secondary", disabled: true, icon: bolt, }, @@ -129,7 +129,7 @@ const SecondaryDisabled: Story = { const BrandTertiary: Story = { args: { children: "Tertiary", - color: "tertiary", + variant: "tertiary", icon: bolt, }, }; @@ -137,7 +137,7 @@ const BrandTertiary: Story = { const TertiaryDisabled: Story = { args: { children: "Disabled", - color: "tertiary", + variant: "tertiary", disabled: true, icon: bolt, }, @@ -146,7 +146,7 @@ const TertiaryDisabled: Story = { const Bordered: Story = { args: { children: "Bordered", - color: "bordered", + variant: "bordered", icon: bolt, }, }; @@ -154,7 +154,7 @@ const Bordered: Story = { const BrandBorderedDisabled: Story = { args: { children: " Disabled", - color: "bordered", + variant: "bordered", disabled: true, icon: bolt, }, @@ -163,14 +163,14 @@ const BrandBorderedDisabled: Story = { export const Medium: Story = { args: { children: "Primary", - color: "primary", + variant: "primary", }, }; export const Small: Story = { args: { children: "Primary", - color: "primary", + variant: "primary", size: "small", }, }; @@ -178,7 +178,7 @@ export const Small: Story = { export const Nano: Story = { args: { children: "Primary", - color: "primary", + variant: "primary", size: "nano", }, }; @@ -186,7 +186,7 @@ export const Nano: Story = { export const FullWidth: Story = { args: { children: "Primary", - color: "primary", + variant: "primary", fullWidth: true, }, }; @@ -194,7 +194,7 @@ export const FullWidth: Story = { export const FullWidthWithIcon: Story = { args: { children: "Primary", - color: "primary", + variant: "primary", fullWidth: true, icon: bolt, }, @@ -204,7 +204,7 @@ export const IconLeft: Story = { args: { children: "Icon", icon: bolt, - color: "primary", + variant: "primary", }, }; @@ -213,7 +213,7 @@ export const IconRight: Story = { children: "Icon", iconPosition: "right", icon: bolt, - color: "primary", + variant: "primary", }, }; @@ -221,7 +221,7 @@ export const IconOnly: Story = { args: { "aria-label": "Button with only an icon", icon: bolt, - color: "primary", + variant: "primary", }, }; @@ -229,7 +229,7 @@ export const AsLink: Story = { args: { children: "Go to fun-mooc.fr", icon: link, - color: "primary", + variant: "primary", href: "https://www.fun-mooc.fr/", target: "_blank", rel: "noopener noreferrer", diff --git a/packages/react/src/components/Button/index.tsx b/packages/react/src/components/Button/index.tsx index c2fc2a5..78ea34c 100644 --- a/packages/react/src/components/Button/index.tsx +++ b/packages/react/src/components/Button/index.tsx @@ -13,7 +13,7 @@ export type ButtonElement = HTMLButtonElement & HTMLAnchorElement; export type ButtonProps = Omit & RefAttributes & { size?: "medium" | "small" | "nano"; - variant?: + color?: | "brand" | "neutral" | "info" @@ -21,7 +21,7 @@ export type ButtonProps = Omit & | "warning" | "error" | "success"; - color?: "primary" | "secondary" | "tertiary" | "bordered"; + variant?: "primary" | "secondary" | "tertiary" | "bordered"; icon?: ReactNode; iconPosition?: "left" | "right"; active?: boolean; @@ -30,10 +30,10 @@ export type ButtonProps = Omit & export const Button = ({ children, - color = "primary", + variant = "primary", size = "medium", iconPosition = "left", - variant = "brand", + color = "brand", icon, active, className, @@ -43,8 +43,8 @@ export const Button = ({ }: ButtonProps) => { const classes = [ "c__button", - "c__button--" + variant, - ["c__button--", variant, "--", color].join(""), + "c__button--" + color, + ["c__button--", color, "--", variant].join(""), "c__button--" + size, className, ]; @@ -60,7 +60,7 @@ export const Button = ({ if (fullWidth) { classes.push("c__button--full-width"); } - if (["primary-text", "tertiary-text"].includes(color)) { + if (["primary-text", "tertiary-text"].includes(variant)) { classes.push("c__button--text"); } if (props.href && props.disabled) { @@ -79,6 +79,6 @@ export const Button = ({ {!!icon && iconPosition === "left" && iconElement} {children} {!!icon && iconPosition === "right" && iconElement} - , + ); }; diff --git a/packages/react/src/components/DataGrid/index.spec.tsx b/packages/react/src/components/DataGrid/index.spec.tsx index 130fbcc..580fda3 100644 --- a/packages/react/src/components/DataGrid/index.spec.tsx +++ b/packages/react/src/components/DataGrid/index.spec.tsx @@ -97,7 +97,7 @@ describe("", () => { fetchMock.mockIf( "https://example.com/?page=1&sort=lastName&sortOrder=desc", - () => deferred.promise, + () => deferred.promise ); render(); @@ -115,8 +115,8 @@ describe("", () => { JSON.stringify({ rows: database.slice(0, 10), count: database.length, - }), - ), + }) + ) ); // Make sure the loader disappears. @@ -124,8 +124,8 @@ describe("", () => { expect( screen.queryByRole("status", { name: "Loading data", - }), - ).toBeNull(), + }) + ).toBeNull() ); // Make sure the rows are rendered. @@ -154,7 +154,7 @@ describe("", () => { deferred = new Deferred(); fetchMock.mockIf( "https://example.com/?page=2&sort=lastName&sortOrder=desc", - () => deferred.promise, + () => deferred.promise ); // Go to page 2. @@ -187,8 +187,8 @@ describe("", () => { JSON.stringify({ rows: database.slice(10, 20), count: database.length, - }), - ), + }) + ) ); // Make sure the loader disappears. @@ -196,8 +196,8 @@ describe("", () => { expect( screen.queryByRole("status", { name: "Loading data", - }), - ).toBeNull(), + }) + ).toBeNull() ); // Make sure the rows are rendered. @@ -248,7 +248,7 @@ describe("", () => { id: "buttonValidator", renderCell: () => ( ); @@ -328,7 +328,7 @@ export const WithColumnWidth = () => { size: 50, renderCell: () => ( diff --git a/packages/react/src/components/Modal/EdgeCases.stories.tsx b/packages/react/src/components/Modal/EdgeCases.stories.tsx index 58367ac..558474d 100644 --- a/packages/react/src/components/Modal/EdgeCases.stories.tsx +++ b/packages/react/src/components/Modal/EdgeCases.stories.tsx @@ -57,11 +57,11 @@ export const StackedModals = { Open Modals Tertiary} + leftActions={} rightActions={ <> - - + + } size={ModalSize.LARGE} @@ -70,11 +70,11 @@ export const StackedModals = { {longLorem.text} Tertiary} + leftActions={} rightActions={ <> - - + + } size={ModalSize.MEDIUM} @@ -83,11 +83,11 @@ export const StackedModals = { {longLorem.text} Tertiary} + leftActions={} rightActions={ <> - - + + } size={ModalSize.SMALL} diff --git a/packages/react/src/components/Modal/index.stories.tsx b/packages/react/src/components/Modal/index.stories.tsx index 405cb57..4fcd868 100644 --- a/packages/react/src/components/Modal/index.stories.tsx +++ b/packages/react/src/components/Modal/index.stories.tsx @@ -97,7 +97,7 @@ export const PrimaryButton: Story = { args: { size: ModalSize.MEDIUM, rightActions: ( - ), @@ -108,7 +108,7 @@ export const SecondaryButton: Story = { args: { size: ModalSize.MEDIUM, rightActions: ( - ), @@ -119,12 +119,12 @@ export const TwoButtons: Story = { args: { size: ModalSize.MEDIUM, leftActions: ( - ), rightActions: ( - ), @@ -135,16 +135,16 @@ export const ThreeButtons: Story = { args: { size: ModalSize.MEDIUM, leftActions: ( - ), rightActions: ( <> - - @@ -157,8 +157,8 @@ export const CenterButtons: Story = { size: ModalSize.MEDIUM, actions: ( <> - - + + ), }, @@ -179,7 +179,7 @@ export const ExampleApplication: Story = { touch. ), - rightActions: , + rightActions: , }, parameters: { docs: { @@ -193,11 +193,11 @@ export const ExampleApplication: Story = { export const FullWithContent: Story = { args: { size: ModalSize.FULL, - leftActions: , + leftActions: , rightActions: ( <> - - + + ), children: longLorem.text, diff --git a/packages/react/src/components/Modal/index.tsx b/packages/react/src/components/Modal/index.tsx index 6537921..e4f9c67 100644 --- a/packages/react/src/components/Modal/index.tsx +++ b/packages/react/src/components/Modal/index.tsx @@ -99,8 +99,8 @@ export const ModalInner = ({ closeOnEsc = true, ...props }: ModalProps) => {
, + actions: , }) } > diff --git a/packages/react/src/components/Toast/index.stories.tsx b/packages/react/src/components/Toast/index.stories.tsx index 4b4cdaa..06807bb 100644 --- a/packages/react/src/components/Toast/index.stories.tsx +++ b/packages/react/src/components/Toast/index.stories.tsx @@ -78,8 +78,8 @@ export const InfoCustom: Story = { type: VariantType.INFO, actions: ( <> - - + + ), }, diff --git a/packages/react/src/components/Toast/index.tsx b/packages/react/src/components/Toast/index.tsx index 5840151..f3a8378 100644 --- a/packages/react/src/components/Toast/index.tsx +++ b/packages/react/src/components/Toast/index.tsx @@ -45,7 +45,7 @@ export const Toast = (props: ToastProps) => { const removeAfterAnimation = async () => { await Promise.allSettled( - container.current!.getAnimations().map((animation) => animation.finished), + container.current!.getAnimations().map((animation) => animation.finished) ); props.onDelete?.(); }; @@ -71,7 +71,7 @@ export const Toast = (props: ToastProps) => { {props.primaryLabel && (
- , + ); const button = screen.getByRole("button"); @@ -33,10 +33,10 @@ describe("", () => { it("appear on button focus and then disappear", async () => { render( - - , + ); expect(screen.queryByText("Hi there")).not.toBeInTheDocument(); @@ -51,10 +51,10 @@ describe("", () => { it("sets entering and exiting class", async () => { render( - - , + ); expect(screen.queryByText("Hi there")).not.toBeInTheDocument(); @@ -102,10 +102,10 @@ describe("", () => { } closeDelay={0} > - - , + ); const button = screen.getByRole("button"); @@ -128,10 +128,10 @@ describe("", () => { closeDelay={0} className="my-custom-class" > - - , + ); const button = screen.getByRole("button"); diff --git a/packages/react/src/components/Tooltip/index.stories.tsx b/packages/react/src/components/Tooltip/index.stories.tsx index dfb50d7..57ca2a7 100644 --- a/packages/react/src/components/Tooltip/index.stories.tsx +++ b/packages/react/src/components/Tooltip/index.stories.tsx @@ -26,8 +26,8 @@ export const Default = { - - - @@ -131,8 +131,8 @@ export const WithHtml = {