From b5622e17362b5ab7f0fcecbafc49ca1ed352dd19 Mon Sep 17 00:00:00 2001 From: Bruno Henriques Date: Mon, 4 Nov 2024 15:48:29 +0000 Subject: [PATCH 1/2] feat(Button): support external icons --- packages/core/src/Button/Button.stories.tsx | 46 ++++++++++++--------- packages/core/src/Button/Button.styles.ts | 19 ++++----- packages/icons/src/IconBase.tsx | 2 +- packages/icons/src/IconContainer.tsx | 6 +-- packages/icons/src/utils.ts | 3 +- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/packages/core/src/Button/Button.stories.tsx b/packages/core/src/Button/Button.stories.tsx index c6f400e82d..5c0d04f54a 100644 --- a/packages/core/src/Button/Button.stories.tsx +++ b/packages/core/src/Button/Button.stories.tsx @@ -1,4 +1,7 @@ +import { Fragment } from "react"; import { css } from "@emotion/css"; +import { faAdd } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { StoryObj } from "@storybook/react"; import { HvButton, HvButtonProps } from "@hitachivantara/uikit-react-core"; import { @@ -310,19 +313,20 @@ export const Test: StoryObj = { Negative Negative Subtle Negative Ghost - + + }> Primary - + }> Primary Subtle Primary Ghost - + }> Warning - + }> Warning Subtle @@ -330,9 +334,14 @@ export const Test: StoryObj = { {(["sm", "md", "lg"] as const).map((size) => ( - - {size} - + + + {size} + + + + + ))} {(["none", "base", "round", "circle", "full"] as const).map((radius) => ( @@ -366,20 +375,10 @@ export const Test: StoryObj = { - - - - - - - - - - - + - + @@ -419,6 +418,15 @@ export const Test: StoryObj = { } color="lightcyan" variant="ghost"> lightcyan + + + + + }>Add + +
+ + }>Add
), }; diff --git a/packages/core/src/Button/Button.styles.ts b/packages/core/src/Button/Button.styles.ts index 007cc29440..8776d1ea58 100644 --- a/packages/core/src/Button/Button.styles.ts +++ b/packages/core/src/Button/Button.styles.ts @@ -34,16 +34,17 @@ export const { staticClasses, useClasses } = createClasses("HvButton", { border: "1px solid transparent", borderRadius: `var(--radius, ${theme.radii.base})`, padding: theme.spacing(0, "sm"), + + // remove icon container spacing + "--icsize": "auto", }, startIcon: { - marginLeft: theme.spacing(-1), - marginTop: -1, - marginBottom: -1, + marginRight: 8, + minWidth: 16, }, endIcon: { - marginRight: theme.spacing(-1), - marginTop: -1, - marginBottom: -1, + marginLeft: 8, + minWidth: 16, }, focusVisible: {}, disabled: { @@ -59,10 +60,8 @@ export const { staticClasses, useClasses } = createClasses("HvButton", { icon: { margin: 0, padding: 0, - height: "fit-content", - "& > *": { - margin: -1, - }, + height: "var(--HvButton-height)", + width: "var(--HvButton-height)", }, contained: { color: theme.colors.atmo1, // `color-contrast(var(--color) vs ${colors.atmo1}, ${colors.base_light}, ${colors.base_dark})`, diff --git a/packages/icons/src/IconBase.tsx b/packages/icons/src/IconBase.tsx index 6a059df71c..9b459b3119 100644 --- a/packages/icons/src/IconBase.tsx +++ b/packages/icons/src/IconBase.tsx @@ -57,7 +57,7 @@ export interface IconBaseProps /** * A color or array of colors to override the default icon colors. * Accepts any valid CSS color or color from the UI Kit palette. - * @example ["brand", "inherit"] + * @example "secondary" "brand" "atmo2" "#FF0000" "purple" "inherit" */ color?: HvColorAny | HvColorAny[]; /** diff --git a/packages/icons/src/IconContainer.tsx b/packages/icons/src/IconContainer.tsx index 416fceaf00..f48eba4507 100644 --- a/packages/icons/src/IconContainer.tsx +++ b/packages/icons/src/IconContainer.tsx @@ -8,9 +8,9 @@ import { getSizeStyles } from "./utils"; export const StyledIconBase = styled("div")({ display: "flex", fontSize: 16, - // box has a minimum size of 32px (`xs` & `sm`) - width: "var(--size, 32px)", - height: "var(--size, 32px)", + // box has a default icon container size of 32px (`xs` & `sm`) + width: "var(--icsize, 32px)", + height: "var(--icsize, 32px)", transition: "rotate 0.2s ease", justifyContent: "center", alignItems: "center", diff --git a/packages/icons/src/utils.ts b/packages/icons/src/utils.ts index 9bea4661e4..58d74abaa9 100644 --- a/packages/icons/src/utils.ts +++ b/packages/icons/src/utils.ts @@ -64,6 +64,7 @@ export const getSizeStyles = ( return { fontSize, - "--size": `${containerSize}px`, + /** icon container size. @private */ + "--icsize": `${containerSize}px`, }; }; From cb37c53522f50364d9bbef05e48e2002c15da5aa Mon Sep 17 00:00:00 2001 From: Bruno Henriques Date: Mon, 4 Nov 2024 17:28:08 +0000 Subject: [PATCH 2/2] chore(Button): icon spacing alignment --- docs/tests/Components.stories.tsx | 2 +- packages/core/src/Badge/Badge.styles.tsx | 14 ++++++++++- .../DotPagination/DotPagination.stories.tsx | 13 ++++------- .../src/InlineEditor/InlineEditor.styles.tsx | 8 +------ .../Actions/Action.styles.tsx | 8 +++---- .../src/VerticalNavigation/Actions/Action.tsx | 3 ++- .../DefaultNavigation/Step/Step.styles.tsx | 3 ++- .../DefaultNavigation/Step/Step.tsx | 23 ++++++++----------- 8 files changed, 35 insertions(+), 39 deletions(-) diff --git a/docs/tests/Components.stories.tsx b/docs/tests/Components.stories.tsx index 3e5099c4a7..f08875ee32 100644 --- a/docs/tests/Components.stories.tsx +++ b/docs/tests/Components.stories.tsx @@ -109,7 +109,7 @@ export const Test: StoryObj = { style={{ alignItems: "start", justifyContent: "start" }} >
-
+
{renderStory(AccordionDisabledStory, context)} {renderStory(DotPaginationMainStory, context)} {renderStory(DropDownMenuMainStory, context)} diff --git a/packages/core/src/Badge/Badge.styles.tsx b/packages/core/src/Badge/Badge.styles.tsx index 4bc43ee7e7..297839cdc7 100644 --- a/packages/core/src/Badge/Badge.styles.tsx +++ b/packages/core/src/Badge/Badge.styles.tsx @@ -2,7 +2,19 @@ import { createClasses } from "@hitachivantara/uikit-react-utils"; import { theme } from "@hitachivantara/uikit-styles"; export const { staticClasses, useClasses } = createClasses("HvBadge", { - root: { position: "relative", "&>*": { float: "left" } }, + root: { + position: "relative", + "&>*": { float: "left" }, + ":has($badgeIcon)": { + width: "fit-content", + height: "fit-content", + "&>div:first-child": { + minWidth: 32, + minHeight: 32, + "--icsize": "100%", + }, + }, + }, /** class applied to the badge container when it has content */ badgeContainer: { width: 0 }, /** class applied to the badge */ diff --git a/packages/core/src/DotPagination/DotPagination.stories.tsx b/packages/core/src/DotPagination/DotPagination.stories.tsx index 898df642c6..5458162d07 100644 --- a/packages/core/src/DotPagination/DotPagination.stories.tsx +++ b/packages/core/src/DotPagination/DotPagination.stories.tsx @@ -21,7 +21,6 @@ const meta: Meta = { export default meta; const styles = { - container: css({ width: "100%", justifyContent: "center" }), page: css({ textAlign: "center" }), }; @@ -42,10 +41,8 @@ export const Main: StoryObj = { ]; return ( -
-
- {pages[page]} -
+
+ {pages[page]}
= { }; return ( -
-
- {pages[page]} -
+
+ {pages[page]}
- {icon} + {!isOpen && icon} {isOpen && label} ); diff --git a/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.styles.tsx b/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.styles.tsx index b9c9503a08..593fada569 100644 --- a/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.styles.tsx +++ b/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.styles.tsx @@ -1,8 +1,9 @@ -import { createClasses } from "@hitachivantara/uikit-react-core"; +import { createClasses, theme } from "@hitachivantara/uikit-react-core"; export const { staticClasses, useClasses } = createClasses("HvStep", { root: {}, ghost: { + fontWeight: theme.fontWeights.semibold, "&:hover": { backgroundColor: "transparent", }, diff --git a/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.tsx b/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.tsx index a526e1fecb..b8a6fefed9 100644 --- a/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.tsx +++ b/packages/lab/src/StepNavigation/DefaultNavigation/Step/Step.tsx @@ -2,8 +2,8 @@ import { ExtractNames, HvAvatar, HvBaseProps, - HvButton, - HvButtonProps, + HvButtonBase, + HvButtonBaseProps, HvSize, } from "@hitachivantara/uikit-react-core"; import { @@ -20,7 +20,7 @@ import { useClasses } from "./Step.styles"; type HvStepClasses = ExtractNames; export interface HvStepProps - extends Pick, + extends Pick, Omit { /** A Jss Object used to override or extend the styles applied to the empty state StepNavigation. */ classes?: HvStepClasses; @@ -92,8 +92,7 @@ export const HvStep = ({ const backgroundColor = getColor(state); - const color = state === "Pending" ? "atmo2" : undefined; - const semantic = state !== "Pending" ? getSemantic(state) : undefined; + const color = state === "Pending" ? "atmo2" : getSemantic(state); const status = state === "Current" ? "secondary_60" : undefined; const IconComponent = iconStateObject[state]; @@ -107,13 +106,11 @@ export const HvStep = ({ className, )} > - @@ -126,16 +123,14 @@ export const HvStep = ({ {IconComponent ? ( ) : ( number )} - +
); };