Skip to content

Commit

Permalink
fix(tablekit-banner): fix icon alignment
Browse files Browse the repository at this point in the history
closes #39
  • Loading branch information
irmir committed Aug 25, 2021
1 parent 46ed549 commit 44e1353
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"react-dom": ">=16.2.0 <18"
},
"devDependencies": {
"@storybook/react": "6.3.7",
"@tablecheck/tablekit-enzyme": "^1.0.0",
"@tablecheck/tablekit-free-icon-config": "^1.0.0"
},
Expand Down
9 changes: 8 additions & 1 deletion packages/banner/src/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ButtonAppearance, ButtonSize } from '@tablecheck/tablekit-button';
import { Icon, getIcon } from '@tablecheck/tablekit-icon';
import { Size } from '@tablecheck/tablekit-theme';
import { MutableRefObject, useRef, useState, useEffect } from 'react';

import {
adjustedIconSizes,
Expand All @@ -21,15 +22,21 @@ export const Banner = ({
size = Size.Regular,
...restProps
}: BannerProps): JSX.Element => {
const [height, setHeight] = useState(0);
const ref = useRef() as MutableRefObject<HTMLDivElement>;
useEffect(() => {
setHeight(ref.current.clientHeight);
}, []);
const displayedIcon = customIcon || getIcon(appearance);
return (
<BannerContainer
ref={ref}
{...restProps}
className={className}
appearance={appearance}
size={size}
>
<BannerMessageContainer>
<BannerMessageContainer height={height && height} size={size}>
{displayedIcon && (
<AlertIcon
className="bannerIcon"
Expand Down
26 changes: 22 additions & 4 deletions packages/banner/src/__tests__/__snapshots__/index.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ exports[`Banner should allow passing of custom className 1`] = `
-webkit-justify-content: center;
justify-content: center;
padding: 6px 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.emotion-2:only-child {
0 .emotion-2:only-child {
padding: 6px 8px 6px 0;
}
Expand All @@ -58,9 +62,14 @@ exports[`Banner should allow passing of custom className 1`] = `
className="test-class emotion-0 emotion-1"
size="regular"
>
<BannerMessageContainer>
<BannerMessageContainer
height={0}
size="regular"
>
<div
className="emotion-2 emotion-3"
height={0}
size="regular"
>
<AlertIcon
className="bannerIcon"
Expand Down Expand Up @@ -120,9 +129,13 @@ exports[`Banner should correctly apply styling 1`] = `
-webkit-justify-content: center;
justify-content: center;
padding: 6px 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.emotion-2:only-child {
0 .emotion-2:only-child {
padding: 6px 8px 6px 0;
}
Expand All @@ -141,9 +154,14 @@ exports[`Banner should correctly apply styling 1`] = `
className="emotion-0 emotion-1"
size="regular"
>
<BannerMessageContainer>
<BannerMessageContainer
height={0}
size="regular"
>
<div
className="emotion-2 emotion-3"
height={0}
size="regular"
>
<AlertIcon
className="bannerIcon"
Expand Down
12 changes: 10 additions & 2 deletions packages/banner/src/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getThemeValue } from '@tablecheck/tablekit-utils';
import type { ThemeOnlyProps } from '@tablecheck/tablekit-utils';

import { bannerClassicTheme, bannerThemeNamespace } from './themes';
import { Appearance, BannerProps } from './types';
import { Appearance, BannerProps, BannerSizes } from './types';

const sizedTypography = {
[Size.Small]: Typography.Heading4,
Expand Down Expand Up @@ -62,11 +62,19 @@ export const BannerContainer = styled.div<
${getBannerAppearance}
`;

export const BannerMessageContainer = styled.div`
export const BannerMessageContainer = styled.div<{
height: number;
size: BannerSizes;
}>`
display: flex;
flex: 1;
justify-content: center;
padding: 6px 0;
display: flex;
${({ height, size }) =>
height &&
height <= parseFloat(sizedTypography[size].lineHeight) + 12 &&
'align-items: center;'}
&:only-child {
padding: 6px ${Spacing.L2} 6px 0;
Expand Down

0 comments on commit 44e1353

Please sign in to comment.