Skip to content

Commit eaa561a

Browse files
committed
Feat(web-react): Refactor Footer to set padding via style props #DS-1580
1 parent 8fafcb0 commit eaa561a

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

packages/web-react/src/components/Footer/Footer.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import classNames from 'classnames';
44
import React from 'react';
5-
import { BackgroundColors } from '../../constants';
5+
import { BackgroundColors, PaddingStyleProps } from '../../constants';
66
import { useStyleProps } from '../../hooks';
77
import { SpiritFooterProps } from '../../types';
88
import { PADDING_BOTTOM, PADDING_TOP } from './constants';
@@ -16,12 +16,15 @@ const defaultStyleProps: Partial<SpiritFooterProps> = {
1616

1717
const Footer = (props: SpiritFooterProps) => {
1818
const propsWithDefaults = { ...defaultStyleProps, ...props };
19-
const { children, backgroundColor, paddingBottom, paddingTop, ...restProps } = propsWithDefaults;
20-
const { classProps } = useFooterStyleProps({ backgroundColor, paddingBottom, paddingTop });
21-
const { styleProps, props: otherProps } = useStyleProps(restProps);
19+
const { children, backgroundColor, ...restProps } = propsWithDefaults;
20+
const { classProps } = useFooterStyleProps({ backgroundColor });
21+
const { styleProps, props: otherProps } = useStyleProps(restProps, {
22+
paddingBottom: PaddingStyleProps.paddingBottom,
23+
paddingTop: PaddingStyleProps.paddingTop,
24+
});
2225

2326
return (
24-
<footer {...styleProps} {...otherProps} className={classNames(classProps, styleProps.className)}>
27+
<footer {...otherProps} {...styleProps} className={classNames(classProps, styleProps.className)}>
2528
{children}
2629
</footer>
2730
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { renderHook } from '@testing-library/react';
2+
import { SpiritFooterProps } from '../../../types';
3+
import { useFooterStyleProps } from '../useFooterStyleProps';
4+
5+
describe('useFooterStyleProps', () => {
6+
it('should return defaults', () => {
7+
const props: SpiritFooterProps = {};
8+
const { result } = renderHook(() => useFooterStyleProps(props));
9+
10+
expect(result.current.classProps).toBe('');
11+
});
12+
13+
it('should return background classProps', () => {
14+
const props: SpiritFooterProps = {
15+
backgroundColor: 'secondary',
16+
};
17+
const { result } = renderHook(() => useFooterStyleProps(props));
18+
19+
expect(result.current.classProps).toBe('bg-secondary');
20+
});
21+
});

packages/web-react/src/components/Footer/useFooterStyleProps.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ export interface UseFooterStyleProps {
66
}
77

88
export function useFooterStyleProps(props: Partial<SpiritFooterProps>): UseFooterStyleProps {
9-
const { backgroundColor, paddingBottom, paddingTop } = props;
10-
9+
const { backgroundColor } = props;
1110
const footerBackgroundColor = backgroundColor ? `bg-${backgroundColor}` : '';
12-
const footerPaddingBottom = paddingBottom ? paddingBottom.replace('space-', 'pb-') : '';
13-
const footerPaddingTop = paddingTop ? paddingTop.replace('space-', 'pt-') : '';
1411

1512
const classProps = classNames({
1613
[footerBackgroundColor]: backgroundColor,
17-
[footerPaddingBottom]: paddingBottom,
18-
[footerPaddingTop]: paddingTop,
1914
});
2015

2116
return {

0 commit comments

Comments
 (0)