diff --git a/src/components/sidebar/sidebar.style.ts b/src/components/sidebar/sidebar.style.ts index 08c47171f5..4e4cb8f018 100644 --- a/src/components/sidebar/sidebar.style.ts +++ b/src/components/sidebar/sidebar.style.ts @@ -7,7 +7,6 @@ import baseTheme from "../../style/themes/base"; import StyledIconButton from "../icon-button/icon-button.style"; import { SIDEBAR_SIZES_CSS } from "./sidebar.config"; -import resolvePaddingSides from "../../style/utils/resolve-padding-sides"; import { StyledForm, StyledFormContent } from "../form/form.style"; type StyledSidebarProps = Pick< @@ -56,40 +55,28 @@ const StyledSidebar = styled.div` `} `; -const StyledSidebarContent = styled.div((props) => { - const { - paddingTop = "var(--spacing300)", - paddingRight = "var(--spacing400)", - paddingBottom = "var(--spacing400)", - paddingLeft = "var(--spacing400)", - } = resolvePaddingSides(props); +const StyledSidebarContent = styled.div` + box-sizing: border-box; + display: block; + overflow-y: auto; + flex-grow: 1; - return css` - box-sizing: border-box; + padding: var(--spacing300) var(--spacing400) var(--spacing400); + ${paddingFn} + + &:has(${StyledForm}.sticky) { display: flex; flex-direction: column; - overflow-y: auto; - - flex: 1; - - ${StyledForm}.sticky { - margin-top: calc(-1 * ${paddingTop}); - margin-right: calc(-1 * ${paddingRight}); - margin-bottom: calc(-1 * ${paddingBottom}); - margin-left: calc(-1 * ${paddingLeft}); - - ${StyledFormContent} { - padding-top: ${paddingTop}; - padding-right: ${paddingRight}; - padding-bottom: ${paddingBottom}; - padding-left: ${paddingLeft}; - } + overflow-y: hidden; + padding: 0; + } + ${StyledForm}.sticky { + ${StyledFormContent} { + padding: var(--spacing300) var(--spacing400) var(--spacing400); + ${paddingFn} } - - padding: ${paddingTop} ${paddingRight} ${paddingBottom} ${paddingLeft}; - ${paddingFn} - `; -}); + } +`; StyledSidebar.defaultProps = { theme: baseTheme, diff --git a/src/style/utils/resolve-padding-sides.test.ts b/src/style/utils/resolve-padding-sides.test.ts deleted file mode 100644 index f6dd11244b..0000000000 --- a/src/style/utils/resolve-padding-sides.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import resolvePaddingSides from "./resolve-padding-sides"; - -test.each([ - ["10px 20px 30px 40px", "10px", "20px", "30px", "40px"], - ["10px 20px 30px", "10px", "20px", "30px", "20px"], - ["10px 20px", "10px", "20px", "10px", "20px"], - ["10px", "10px", "10px", "10px", "10px"], -] as const)( - "parses shorthand padding prop, with value '%s', into individual padding values", - (padding, expectedTop, expectedRight, expectedBottom, expectedLeft) => { - const result = resolvePaddingSides({ padding }); - expect(result).toMatchObject({ - paddingTop: expectedTop, - paddingRight: expectedRight, - paddingBottom: expectedBottom, - paddingLeft: expectedLeft, - }); - } -); - -test("returns individual padding values, when the shorthand padding prop is not provided", () => { - const result = resolvePaddingSides({ - paddingTop: "1px", - paddingX: "100px", - }); - expect(result).toMatchObject({ - paddingTop: "1px", - paddingRight: "100px", - paddingLeft: "100px", - }); -}); diff --git a/src/style/utils/resolve-padding-sides.ts b/src/style/utils/resolve-padding-sides.ts deleted file mode 100644 index 827a50485b..0000000000 --- a/src/style/utils/resolve-padding-sides.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - padding as convertPaddingPropsToCSS, - PaddingProps, -} from "styled-system"; - -interface PaddingValues { - padding?: string; - paddingTop?: string; - paddingRight?: string; - paddingBottom?: string; - paddingLeft?: string; -} - -function resolvePaddingSides(props: PaddingProps) { - const expandShorthand = (cssValue: string) => { - const sideValues = cssValue.split(/\s+/); - const [ - paddingTop, - paddingRight = paddingTop, - paddingBottom = paddingTop, - paddingLeft = paddingRight, - ] = sideValues; - - return { paddingTop, paddingBottom, paddingLeft, paddingRight }; - }; - - const { - padding, - ...individualSides - }: PaddingValues = convertPaddingPropsToCSS(props); - - if (padding) - return { - ...expandShorthand(padding), - ...individualSides, - }; - - return individualSides; -} - -export default resolvePaddingSides;