From 7ffab29a2f801193e1821d5ba0be293f2e358afb Mon Sep 17 00:00:00 2001 From: Bruno Henriques Date: Fri, 16 Jun 2023 15:45:24 +0100 Subject: [PATCH] fix(BaseDropdown): border styles & dedupe (#3404) * refactor(BaseDropdown): improve & dedupe styles in components using it * chore: remove unused theme keys * chore: pr review --- .../BaseDropdown/BaseDropdown.styles.tsx | 32 +-- .../components/BaseDropdown/BaseDropdown.tsx | 31 +- .../__snapshots__/BaseDropdown.test.tsx.snap | 42 +-- .../__snapshots__/BulkActions.test.tsx.snap | 4 +- .../ColorPicker/ColorPicker.styles.tsx | 19 +- .../components/ColorPicker/ColorPicker.tsx | 16 +- .../__snapshots__/ColorPicker.test.tsx.snap | 269 ++++++++++-------- .../__snapshots__/Controls.test.tsx.snap | 80 +++--- .../DatePicker/DatePicker.styles.tsx | 18 +- .../__snapshots__/DatePicker.test.tsx.snap | 200 +++++++------ .../DropDownMenu/DropDownMenu.styles.tsx | 5 +- .../__snapshots__/DropDownMenu.test.tsx.snap | 4 +- .../components/Dropdown/Dropdown.styles.tsx | 13 +- .../components/Dropdown/List/List.styles.tsx | 7 +- .../__snapshots__/Dropdown.test.tsx.snap | 40 +-- .../FilterGroup/Counter/Counter.styles.tsx | 6 +- .../FilterContent/FilterContent.styles.tsx | 10 +- .../__snapshots__/FilterGroup.test.tsx.snap | 24 +- .../src/components/Pagination/Pagination.tsx | 1 - .../components/Pagination/Select.styles.tsx | 33 +-- .../core/src/components/Pagination/Select.tsx | 59 ++-- .../__snapshots__/Pagination.test.tsx.snap | 36 ++- packages/styles/src/theme.ts | 18 +- packages/styles/src/themes/ds3.ts | 20 +- packages/styles/src/themes/ds5.ts | 20 +- packages/styles/src/types.ts | 18 +- 26 files changed, 463 insertions(+), 562 deletions(-) diff --git a/packages/core/src/components/BaseDropdown/BaseDropdown.styles.tsx b/packages/core/src/components/BaseDropdown/BaseDropdown.styles.tsx index 7737b3503d..993200a2d9 100644 --- a/packages/core/src/components/BaseDropdown/BaseDropdown.styles.tsx +++ b/packages/core/src/components/BaseDropdown/BaseDropdown.styles.tsx @@ -1,6 +1,5 @@ import { CSSProperties } from "@emotion/serialize"; import styled from "@emotion/styled"; -import { DropDownXS, DropUpXS } from "@hitachivantara/uikit-react-icons"; import { theme } from "@hitachivantara/uikit-styles"; import { HvTypography } from "@core/components"; import { outlineStyles } from "@core/utils"; @@ -107,7 +106,7 @@ export const StyledSelection = styled("div")({ alignItems: "center", height: "30px", boxSizing: "border-box", - padding: `0px ${theme.space.md} 0px ${theme.space.xs}`, + paddingLeft: theme.space.xs, }); export const StyledPlaceholder = styled( @@ -126,32 +125,13 @@ export const StyledPlaceholder = styled( }), })); -const iconsStyles: CSSProperties = { +export const StyledAdornment = styled("div")({ position: "absolute", pointerEvents: "none", top: -1, right: -1, -}; - -export const StyledDropUpXS = styled(DropUpXS)({ - ...iconsStyles, }); -export const StyledDropDownXS = styled( - DropDownXS, - transientOptions -)(({ $disabled }: { $disabled: boolean }) => ({ - ...iconsStyles, - - ...($disabled && { - "& svg": { - "& path": { - fill: theme.colors.secondary_60, - }, - }, - }), -})); - export const StyledContainer = styled("div")({ zIndex: theme.zIndices.popover, width: "auto", @@ -203,10 +183,14 @@ export const StyledPanel = styled( )(({ $popperPlacement }: { $popperPlacement: string }) => ({ position: "relative", boxShadow: theme.baseDropdown.shadow, + backgroundColor: theme.colors.atmo1, + border: `1px solid ${theme.baseDropdown.openBorderColor}`, ...($popperPlacement === "top" && { - top: "1px", + top: 1, + borderRadius: `${theme.radii.base} ${theme.radii.base} 0 0`, }), ...($popperPlacement === "bottom" && { - top: "-1px", + top: -1, + borderRadius: `0 0 ${theme.radii.base} ${theme.radii.base}`, }), })); diff --git a/packages/core/src/components/BaseDropdown/BaseDropdown.tsx b/packages/core/src/components/BaseDropdown/BaseDropdown.tsx index d881e62b44..4ce0460516 100644 --- a/packages/core/src/components/BaseDropdown/BaseDropdown.tsx +++ b/packages/core/src/components/BaseDropdown/BaseDropdown.tsx @@ -6,6 +6,8 @@ import { PopperPlacementType, PopperProps, } from "@mui/material"; +import { theme } from "@hitachivantara/uikit-styles"; +import { DropDownXS, DropUpXS } from "@hitachivantara/uikit-react-icons"; import { useControlled, useForkRef, useTheme, useUniqueId } from "@core/hooks"; import { isKeypress, keyboardCodes, setId } from "@core/utils"; import { getFirstAndLastFocus } from "@core/utils/focusableElementFinder"; @@ -13,10 +15,9 @@ import { HvBaseProps } from "@core/types"; import { usePopper } from "react-popper"; import { detectOverflow, ModifierArguments, Options } from "@popperjs/core"; import { + StyledAdornment, StyledAnchor, StyledContainer, - StyledDropDownXS, - StyledDropUpXS, StyledExtension, StyledHeaderRoot, StyledPanel, @@ -236,7 +237,7 @@ export const HvBaseDropdown = ({ [] ); - const modifiers: any = useMemo( + const modifiers: PopperProps["modifiers"] = useMemo( () => [ { name: "variableWidth", @@ -283,10 +284,8 @@ export const HvBaseDropdown = ({ } ); - let popperPlacement = "bottom"; - if (attributes.popper) { - popperPlacement = attributes.popper["data-popper-placement"]; - } + const popperPlacement = + attributes.popper?.["data-popper-placement"] ?? "bottom"; const handleToggle = useCallback( (event) => { @@ -332,6 +331,8 @@ export const HvBaseDropdown = ({ }); } + const ExpanderComponent = isOpen ? DropUpXS : DropDownXS; + return ( - {adornment || - (isOpen ? ( - + {adornment || ( + - ) : ( - - ))} + )} + ); })(); diff --git a/packages/core/src/components/BaseDropdown/__snapshots__/BaseDropdown.test.tsx.snap b/packages/core/src/components/BaseDropdown/__snapshots__/BaseDropdown.test.tsx.snap index 20b5139950..4f460e120d 100644 --- a/packages/core/src/components/BaseDropdown/__snapshots__/BaseDropdown.test.tsx.snap +++ b/packages/core/src/components/BaseDropdown/__snapshots__/BaseDropdown.test.tsx.snap @@ -6,47 +6,51 @@ exports[`BaseDropDown > should render correctly 1`] = ` style="width: 121px;" >
diff --git a/packages/core/src/components/BulkActions/__snapshots__/BulkActions.test.tsx.snap b/packages/core/src/components/BulkActions/__snapshots__/BulkActions.test.tsx.snap index 5b1e130fed..7424180083 100644 --- a/packages/core/src/components/BulkActions/__snapshots__/BulkActions.test.tsx.snap +++ b/packages/core/src/components/BulkActions/__snapshots__/BulkActions.test.tsx.snap @@ -150,12 +150,12 @@ exports[`BulkActions > With actions > should render correctly 1`] = `
)} ) : dropdownIcon === "colorPicker" ? ( should render correctly full color icon picker 1`] = ` class="HvColorPicker-labelContainer css-1yp4ln" >
@@ -75,56 +79,60 @@ exports[`ColorPicker > should render correctly full color picker 1`] = ` class="HvColorPicker-labelContainer css-1yp4ln" >

Select color...

- - - + + + +
@@ -146,35 +154,35 @@ exports[`ColorPicker > should render correctly recommended colors only color pic class="HvColorPicker-labelContainer css-1yp4ln" >
should render correctly recommended colors only color pic
@@ -202,22 +211,26 @@ exports[`ColorPicker > should render correctly recommended colors only color pic

- - - + + + +
@@ -239,52 +252,57 @@ exports[`ColorPicker > should render correctly recommended colors only icon colo class="HvColorPicker-labelContainer css-1yp4ln" >
@@ -306,35 +324,35 @@ exports[`ColorPicker > should render correctly without saved colors color picker class="HvColorPicker-labelContainer css-1yp4ln" >
should render correctly without saved colors color picker
@@ -362,22 +381,26 @@ exports[`ColorPicker > should render correctly without saved colors color picker

- - - + + + +
@@ -399,48 +422,52 @@ exports[`ColorPicker > should render correctly without saved colors icon color p class="HvColorPicker-labelContainer css-1yp4ln" >
diff --git a/packages/core/src/components/Controls/__snapshots__/Controls.test.tsx.snap b/packages/core/src/components/Controls/__snapshots__/Controls.test.tsx.snap index ecc2733577..6b272f2cc6 100644 --- a/packages/core/src/components/Controls/__snapshots__/Controls.test.tsx.snap +++ b/packages/core/src/components/Controls/__snapshots__/Controls.test.tsx.snap @@ -84,21 +84,21 @@ exports[` > sample snapshot testing > Controls 1`] = ` class=" e16dy5r70 HvDropdown-root css-u5677i-StyledHvFormElement-StyledDropdown etta2py4 HvFormElement-root" >
@@ -700,21 +704,21 @@ exports[` > sample snapshot testing > Controls Controlled 1`] = ` class=" e16dy5r70 HvDropdown-root css-u5677i-StyledHvFormElement-StyledDropdown etta2py4 HvFormElement-root" >
diff --git a/packages/core/src/components/DatePicker/DatePicker.styles.tsx b/packages/core/src/components/DatePicker/DatePicker.styles.tsx index e60d1849ba..b57a72b2fe 100644 --- a/packages/core/src/components/DatePicker/DatePicker.styles.tsx +++ b/packages/core/src/components/DatePicker/DatePicker.styles.tsx @@ -28,10 +28,7 @@ export const styles: Partial< dropdown: { display: "block", }, - panel: { - border: theme.datePicker.panelBorder, - backgroundColor: theme.datePicker.panelBackgroundColor, - }, + panel: {}, dropdownHeaderInvalid: { border: `1px solid ${theme.colors.negative}`, @@ -39,17 +36,8 @@ export const styles: Partial< border: `1px solid ${theme.colors.negative}`, }, }, - dropdownHeaderOpen: { - border: theme.datePicker.dropdownHeaderOpenBorder, - "&:hover": { - border: theme.datePicker.dropdownHeaderOpenBorder, - }, - }, - icon: { - position: "absolute", - right: -1, - bottom: -1, - }, + dropdownHeaderOpen: {}, + icon: {}, action: { "&:first-of-type": { marginRight: theme.space.xs, diff --git a/packages/core/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap b/packages/core/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap index a6d537c9bf..fc05281aa9 100644 --- a/packages/core/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +++ b/packages/core/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap @@ -7,22 +7,22 @@ exports[`HvDatepicker > calendar custom properties > should render correctly 1`] id="testingDatePicker" >
@@ -61,22 +65,22 @@ exports[`HvDatepicker > ranged calendar > should render correctly 1`] = ` class="HvDatePicker-root css-79elbk HvFormElement-root" >
@@ -116,24 +124,24 @@ exports[`HvDatepicker > sample snapshot testing > Main 1`] = ` id="DatePicker" >
@@ -172,22 +184,22 @@ exports[`HvDatepicker > single calendar > should render correctly 1`] = ` class="HvDatePicker-root css-79elbk HvFormElement-root" >
@@ -226,44 +242,48 @@ exports[`HvDatepicker > with minimum configuration > should render correctly 1`] class="HvDatePicker-root css-79elbk HvFormElement-root" >
diff --git a/packages/core/src/components/DropDownMenu/DropDownMenu.styles.tsx b/packages/core/src/components/DropDownMenu/DropDownMenu.styles.tsx index 88ce5219a2..18cb1a91d3 100644 --- a/packages/core/src/components/DropDownMenu/DropDownMenu.styles.tsx +++ b/packages/core/src/components/DropDownMenu/DropDownMenu.styles.tsx @@ -41,8 +41,5 @@ export const styles: Partial< borderRadius: `${theme.radii.base} ${theme.radii.base} 0px 0px`, border: theme.dropDownMenu.borderOpened, }, - menuListRoot: { - border: theme.dropDownMenu.borderOpened, - borderRadius: theme.dropDownMenu.borderRadius, - }, + menuListRoot: {}, }; diff --git a/packages/core/src/components/DropDownMenu/__snapshots__/DropDownMenu.test.tsx.snap b/packages/core/src/components/DropDownMenu/__snapshots__/DropDownMenu.test.tsx.snap index 2813cbffa6..9a8e9f06c0 100644 --- a/packages/core/src/components/DropDownMenu/__snapshots__/DropDownMenu.test.tsx.snap +++ b/packages/core/src/components/DropDownMenu/__snapshots__/DropDownMenu.test.tsx.snap @@ -3,12 +3,12 @@ exports[`DropDownMenu > should render correctly 1`] = `