diff --git a/.changeset/mighty-towns-worry.md b/.changeset/mighty-towns-worry.md new file mode 100644 index 0000000000..4af29a033c --- /dev/null +++ b/.changeset/mighty-towns-worry.md @@ -0,0 +1,5 @@ +--- +"@cloudoperators/juno-ui-components": minor +--- + +Add extra-small (`xs`) size to Button component. Spinner margin adjustment will be addressed in a separate PR. diff --git a/packages/ui-components/src/components/Button/Button.component.tsx b/packages/ui-components/src/components/Button/Button.component.tsx index cffbaca5e3..03338bc55f 100644 --- a/packages/ui-components/src/components/Button/Button.component.tsx +++ b/packages/ui-components/src/components/Button/Button.component.tsx @@ -39,6 +39,11 @@ const btnSmallBase = ` jn:leading-5 ` +const btnXSBase = ` + jn:text-xs + jn:leading-4 +` + // default size typography const btnDefaultBase = ` jn:text-base @@ -55,6 +60,11 @@ const btnSmallSubduedPadding = ` jn:px-1.75 ` +const btnXSDefaultPadding = ` + jn:py-1 + jn:px-1.5 +` + // default size padding const btnDefaultPadding = ` jn:py-1.75 @@ -81,7 +91,7 @@ const primaryButtonColors = ` jn:hover:bg-theme-button-primary-hover jn:hover:text-theme-button-primary-hover jn:active:bg-theme-button-primary-active - jn_active:text-theme-button-primary-active + jn:active:text-theme-button-primary-active ` const primaryDangerButtonColors = ` @@ -101,16 +111,15 @@ const subduedButtonColors = ` jn:active:bg-theme-button-subdued-active jn:active:text-theme-button-subdued-active ` -// jn:border -// jn:border-theme-button-subdued -// jn:hover:border-theme-button-subdued-hover -// jn:active:border-theme-button-subdued-active const getButtonPadding = (size: ButtonSize, variant: ButtonVariant | undefined) => { - if (size === "small") { - return variant === "subdued" ? `${btnSmallSubduedPadding}` : `${btnSmallDefaultPadding}` - } else { - return variant === "subdued" ? `${btnDefaultSubduedPadding}` : `${btnDefaultPadding}` + switch (size) { + case "small": + return variant === "subdued" ? `${btnSmallSubduedPadding}` : `${btnSmallDefaultPadding}` + case "xs": + return `${btnXSDefaultPadding}` + default: + return variant === "subdued" ? `${btnDefaultSubduedPadding}` : `${btnDefaultPadding}` } } @@ -133,15 +142,44 @@ const btnIconSmall = ` jn:mr-2 ` +const btnIconXS = ` + jn:mr-1 +` + const btnIconDefault = ` jn:mr-2 ` +const getButtonBase = (size: ButtonSize) => { + switch (size) { + case "small": + return btnSmallBase + case "xs": + return btnXSBase + default: + return btnDefaultBase + } +} + const iconClasses = (size: ButtonSize) => { - if (size === "small") { - return `${btnIconSmall}` - } else { - return `${btnIconDefault}` + switch (size) { + case "small": + return `${btnIconSmall}` + case "xs": + return `${btnIconXS}` + default: + return `${btnIconDefault}` + } +} + +const iconSize = (size: ButtonSize) => { + switch (size) { + case "small": + return "1.125rem" + case "xs": + return "1rem" + default: + return "1.5rem" } } @@ -192,13 +230,17 @@ export const Button = forwardRef + ) : icon ? ( ) : null @@ -215,7 +257,7 @@ export const Button = forwardRef | HTMLProps, "size"> { /** diff --git a/packages/ui-components/src/components/Button/Button.stories.tsx b/packages/ui-components/src/components/Button/Button.stories.tsx index 75bff670de..dd51588a75 100644 --- a/packages/ui-components/src/components/Button/Button.stories.tsx +++ b/packages/ui-components/src/components/Button/Button.stories.tsx @@ -111,6 +111,13 @@ export const Small: Story = { }, } +export const XS: Story = { + args: { + size: "xs", + label: "XS", + }, +} + export const Disabled: Story = { parameters: { docs: { @@ -215,6 +222,21 @@ export const SmallWithIcon: Story = { }, } +export const XSWithIcon: Story = { + parameters: { + docs: { + description: { + story: "XS Button with Icon", + }, + }, + }, + + args: { + ...XS.args, + icon: "warning", + }, +} + export const IconOnlyButton: Story = { parameters: { docs: { @@ -312,7 +334,7 @@ export const DefaultButtonInProgressWithProgressLabel: Story = { parameters: { docs: { description: { - story: "Default Button with an action in oprogress and an alternate label while in progress", + story: "Default Button with an action in progress and an alternate label while in progress", }, }, }, @@ -426,7 +448,7 @@ export const PrimaryDisabledInProgress: Story = { parameters: { docs: { description: { - story: "Disabled Primnary Button with action in progress", + story: "Disabled Primary Button with action in progress", }, }, }, @@ -469,3 +491,19 @@ export const SmallInProgress: Story = { progressLabel: "Small in Progress…", }, } + +export const XSInProgress: Story = { + parameters: { + docs: { + description: { + story: "XS Button in Progress", + }, + }, + }, + + args: { + ...XS.args, + progress: true, + progressLabel: "XS in Progress…", + }, +} diff --git a/packages/ui-components/src/components/Button/Button.test.tsx b/packages/ui-components/src/components/Button/Button.test.tsx index 46240910c3..afb56895b3 100644 --- a/packages/ui-components/src/components/Button/Button.test.tsx +++ b/packages/ui-components/src/components/Button/Button.test.tsx @@ -147,4 +147,21 @@ describe("Button", () => { expect(screen.getByRole("img")).toBeInTheDocument() expect(screen.getByRole("img")).toContainHTML("customTitle") }) + + test("renders an xs button", () => { + render() + expect(screen.getByRole("button")).toBeInTheDocument() + expect(screen.getByRole("button")).toHaveClass("juno-button-xs-size") + }) + + test("renders an xs in progress button as passed", () => { + render( + + ) + expect(screen.getByRole("button")).toBeInTheDocument() + expect(screen.getByRole("button")).toHaveClass("in-progress") + expect(screen.getByRole("progressbar")).toHaveClass("juno-spinner") + }) }) diff --git a/packages/ui-components/src/components/DataGridToolbar/DataGridToolbar.stories.tsx b/packages/ui-components/src/components/DataGridToolbar/DataGridToolbar.stories.tsx index 437a4f8245..23bd9fbc63 100644 --- a/packages/ui-components/src/components/DataGridToolbar/DataGridToolbar.stories.tsx +++ b/packages/ui-components/src/components/DataGridToolbar/DataGridToolbar.stories.tsx @@ -53,25 +53,23 @@ export const ComplexCustomLayout: Story = { - - - - - - - - - - - - - -