diff --git a/packages/web-react/src/components/Box/Box.tsx b/packages/web-react/src/components/Box/Box.tsx index d9144502da..22988bd24f 100644 --- a/packages/web-react/src/components/Box/Box.tsx +++ b/packages/web-react/src/components/Box/Box.tsx @@ -2,7 +2,7 @@ import classNames from 'classnames'; import React, { ElementType } from 'react'; -import { BorderStyles } from '../../constants'; +import { BorderStyles, PaddingStyleProps } from '../../constants'; import { useStyleProps } from '../../hooks'; import { SpiritBoxProps } from '../../types'; import { useBoxStyleProps } from './useBoxStyleProps'; @@ -17,7 +17,7 @@ const Box = (props: SpiritBoxProps) => { const { elementType: ElementTag = 'div', children, ...restProps } = propsWithDefaults; const { classProps, props: modifiedProps } = useBoxStyleProps(restProps); - const { styleProps, props: otherProps } = useStyleProps(modifiedProps); + const { styleProps, props: otherProps } = useStyleProps(modifiedProps, PaddingStyleProps); return ( diff --git a/packages/web-react/src/components/Box/__tests__/useBoxStyleProps.test.ts b/packages/web-react/src/components/Box/__tests__/useBoxStyleProps.test.ts index cf64e4815a..3e9426cae0 100644 --- a/packages/web-react/src/components/Box/__tests__/useBoxStyleProps.test.ts +++ b/packages/web-react/src/components/Box/__tests__/useBoxStyleProps.test.ts @@ -19,78 +19,6 @@ describe('useBoxStyleProps', () => { expect(result.current.classProps).toBe('bg-secondary'); }); - it('should return padding classProps', () => { - const props: SpiritBoxProps = { - padding: 'space-400', - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('p-400'); - }); - - it('should return paddingX classProps', () => { - const props: SpiritBoxProps = { - paddingX: 'space-400', - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('px-400'); - }); - - it('should return paddingY classProps', () => { - const props: SpiritBoxProps = { - paddingY: 'space-400', - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('py-400'); - }); - - it('should return paddingTop classProps', () => { - const props: SpiritBoxProps = { - paddingTop: 'space-400', - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('pt-400'); - }); - - it('should return paddingBottom classProps', () => { - const props: SpiritBoxProps = { - paddingBottom: 'space-400', - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('pb-400'); - }); - - it('should return paddingLeft classProps', () => { - const props: SpiritBoxProps = { - paddingLeft: 'space-400', - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('pl-400'); - }); - - it('should return paddingRight classProps', () => { - const props: SpiritBoxProps = { - paddingRight: 'space-400', - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('pr-400'); - }); - - it('should return responsive padding classProps', () => { - const props: SpiritBoxProps = { - padding: { mobile: 'space-400', tablet: 'space-500', desktop: 'space-600' }, - }; - const { result } = renderHook(() => useBoxStyleProps(props)); - - expect(result.current.classProps).toBe('p-400 p-tablet-500 p-desktop-600'); - }); - it('should return border radius classProps', () => { const props: SpiritBoxProps = { borderRadius: '200', @@ -99,7 +27,7 @@ describe('useBoxStyleProps', () => { }; const { result } = renderHook(() => useBoxStyleProps(props)); - expect(result.current.classProps).toBe('border-basic rounded-200 border-100 border-solid'); + expect(result.current.classProps).toBe('border-basic rounded-200 border-solid border-100'); }); it('should not return border radius classProps if border with is not set', () => { @@ -119,7 +47,7 @@ describe('useBoxStyleProps', () => { }; const { result } = renderHook(() => useBoxStyleProps(props)); - expect(result.current.classProps).toBe('border-basic border-100 border-solid'); + expect(result.current.classProps).toBe('border-basic border-solid border-100'); }); it('should return border style classProps', () => { @@ -129,6 +57,6 @@ describe('useBoxStyleProps', () => { }; const { result } = renderHook(() => useBoxStyleProps(props)); - expect(result.current.classProps).toBe('border-basic border-100 border-dashed'); + expect(result.current.classProps).toBe('border-basic border-dashed border-100'); }); }); diff --git a/packages/web-react/src/components/Box/useBoxStyleProps.ts b/packages/web-react/src/components/Box/useBoxStyleProps.ts index ae135eb67f..b36a07a445 100644 --- a/packages/web-react/src/components/Box/useBoxStyleProps.ts +++ b/packages/web-react/src/components/Box/useBoxStyleProps.ts @@ -1,7 +1,7 @@ import classNames from 'classnames'; import { ElementType } from 'react'; import { BorderColors } from '../../constants'; -import { BreakpointToken, SpaceToken, SpiritBoxProps } from '../../types'; +import { SpiritBoxProps } from '../../types'; export interface UseBoxStyleProps { /** className props */ @@ -10,43 +10,10 @@ export interface UseBoxStyleProps { props: T; } -export const generateResponsiveUtilityClasses = ( - prefix: string, - propValue: SpaceToken | Partial> | undefined, -): string[] => { - if (propValue && typeof propValue === 'object') { - return Object.entries(propValue).map(([breakpoint, value]) => { - const classValue = value?.replace('space-', ''); - - return breakpoint === 'mobile' ? `${prefix}-${classValue}` : `${prefix}-${breakpoint}-${classValue}`; - }); - } - - if (propValue && typeof propValue !== 'object') { - return [`${prefix}-${propValue.replace('space-', '')}`]; - } - - return []; -}; - export const useBoxStyleProps = ( props: Partial>, ): UseBoxStyleProps>> => { - const { - backgroundColor, - borderColor, - borderRadius, - borderStyle, - borderWidth, - padding, - paddingBottom, - paddingLeft, - paddingRight, - paddingTop, - paddingX, - paddingY, - ...restProps - } = props || {}; + const { backgroundColor, borderColor, borderRadius, borderStyle, borderWidth, ...restProps } = props || {}; const boxBackgroundColor = backgroundColor ? `bg-${backgroundColor}` : ''; let boxBorderColor = borderColor ? borderColor.replace('', 'border-') : ''; let boxBorderRadius = ''; @@ -61,24 +28,7 @@ export const useBoxStyleProps = ( } } - const paddingClasses = [ - ...generateResponsiveUtilityClasses('p', padding), - ...generateResponsiveUtilityClasses('pb', paddingBottom), - ...generateResponsiveUtilityClasses('pl', paddingLeft), - ...generateResponsiveUtilityClasses('pr', paddingRight), - ...generateResponsiveUtilityClasses('pt', paddingTop), - ...generateResponsiveUtilityClasses('px', paddingX), - ...generateResponsiveUtilityClasses('py', paddingY), - ]; - - const boxClasses = classNames( - boxBackgroundColor, - boxBorderColor, - boxBorderRadius, - boxBorderWidth, - boxBorderStyle, - ...paddingClasses, - ); + const boxClasses = classNames(boxBackgroundColor, boxBorderColor, boxBorderRadius, boxBorderStyle, boxBorderWidth); return { classProps: boxClasses, diff --git a/packages/web-react/src/components/Footer/Footer.tsx b/packages/web-react/src/components/Footer/Footer.tsx index 3cc45a0ff0..ef358c9754 100644 --- a/packages/web-react/src/components/Footer/Footer.tsx +++ b/packages/web-react/src/components/Footer/Footer.tsx @@ -2,7 +2,7 @@ import classNames from 'classnames'; import React from 'react'; -import { BackgroundColors } from '../../constants'; +import { BackgroundColors, PaddingStyleProps } from '../../constants'; import { useStyleProps } from '../../hooks'; import { SpiritFooterProps } from '../../types'; import { PADDING_BOTTOM, PADDING_TOP } from './constants'; @@ -16,12 +16,15 @@ const defaultStyleProps: Partial = { const Footer = (props: SpiritFooterProps) => { const propsWithDefaults = { ...defaultStyleProps, ...props }; - const { children, backgroundColor, paddingBottom, paddingTop, ...restProps } = propsWithDefaults; - const { classProps } = useFooterStyleProps({ backgroundColor, paddingBottom, paddingTop }); - const { styleProps, props: otherProps } = useStyleProps(restProps); + const { children, backgroundColor, ...restProps } = propsWithDefaults; + const { classProps } = useFooterStyleProps({ backgroundColor }); + const { styleProps, props: otherProps } = useStyleProps(restProps, { + paddingBottom: PaddingStyleProps.paddingBottom, + paddingTop: PaddingStyleProps.paddingTop, + }); return ( -