From 05f92520299ad3e5da75a8d5c4b5c1da90238958 Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Mon, 16 Jan 2023 11:17:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(react)=20add=20icon=20to=20Button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DS does not offer an icons set yet but it seems important to already provide a support for external icons in Button. --- .../react/src/components/Button/index.scss | 12 +++++ .../src/components/Button/index.spec.tsx | 18 +++++++ .../src/components/Button/index.stories.mdx | 13 +++++ .../src/components/Button/index.stories.tsx | 51 +++++++++++++++++++ .../react/src/components/Button/index.tsx | 20 ++++++-- 5 files changed, 111 insertions(+), 3 deletions(-) diff --git a/packages/react/src/components/Button/index.scss b/packages/react/src/components/Button/index.scss index 5959124..6da857c 100644 --- a/packages/react/src/components/Button/index.scss +++ b/packages/react/src/components/Button/index.scss @@ -12,6 +12,18 @@ font-size: var(--c--components--button--font-size); font-weight: var(--c--components--button--font-weight); + &--with-icon--left, &--with-icon--right { + gap: var(--c--theme--spacings--t); + } + + &--with-icon--left { + padding: 0 var(--c--theme--spacings--s) 0 var(--c--theme--spacings--t); + } + + &--with-icon--right { + padding: 0 var(--c--theme--spacings--t) 0 var(--c--theme--spacings--s); + } + &--primary { background-color: var(--c--theme--colors--primary-500); color: var(--c--theme--colors--primary-text); diff --git a/packages/react/src/components/Button/index.spec.tsx b/packages/react/src/components/Button/index.spec.tsx index 52f02a9..c322f08 100644 --- a/packages/react/src/components/Button/index.spec.tsx +++ b/packages/react/src/components/Button/index.spec.tsx @@ -12,6 +12,24 @@ describe("); + const button = screen.getByText("Test button"); + expect(button.classList.contains("c__button")).toBe(true); + expect(button.classList.contains("c__button--with-icon--left")).toBe(true); + }); + + it("renders with custom class when using right icon", () => { + render( + + ); + const button = screen.getByText("Test button"); + expect(button.classList.contains("c__button")).toBe(true); + expect(button.classList.contains("c__button--with-icon--right")).toBe(true); + }); + it("call onClick when click occurs", async () => { const user = userEvent.setup(); const handleClick = vi.fn(); diff --git a/packages/react/src/components/Button/index.stories.mdx b/packages/react/src/components/Button/index.stories.mdx index 3abe403..12dc759 100644 --- a/packages/react/src/components/Button/index.stories.mdx +++ b/packages/react/src/components/Button/index.stories.mdx @@ -22,6 +22,19 @@ The Cunningham Button behaves the same as the native html ` ); };