Skip to content

Commit a3ba2e0

Browse files
committed
add variant prop in Brand to support different styles.
- Add `variant` prop to support 'horizontal' and 'square' layouts - Update styles to apply dynamic width based on variant (5em vs 3em) - Update stories to include variant control
1 parent f96b711 commit a3ba2e0

4 files changed

Lines changed: 46 additions & 9 deletions

File tree

src/General/Brand/Brand.stories.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export default {
2727
],
2828
},
2929
},
30+
variant: {
31+
control: {
32+
type: 'radio',
33+
options: ['horizontal', 'square'],
34+
},
35+
},
3036
className: {
3137
control: {
3238
disable: true,
@@ -45,11 +51,12 @@ const Template: Story<BrandProps> = args => <Brand {...args} />;
4551

4652
export const Interactive = Template.bind({});
4753
Interactive.args = {
48-
asset: 'glints-black',
54+
asset: 'glints',
4955
};
5056

5157
export const RedirectToGlintsWhenRightClick = Template.bind({});
5258
RedirectToGlintsWhenRightClick.args = {
5359
asset: 'glints-black',
60+
variant: 'square',
5461
rightClickURL: 'https://glints.com',
5562
};

src/General/Brand/Brand.test.tsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ import Brand from './Brand';
88
describe('<Brand/>', () => {
99
it('should render as expected', () => {
1010
const blackLogoSnapshot = renderer
11-
.create(<Brand asset="glints-black" />)
11+
.create(<Brand asset="glints-black" variant="square" />)
1212
.toJSON();
1313
expect(blackLogoSnapshot).toMatchSnapshot();
14-
const white = renderer.create(<Brand asset="glints-white" />).toJSON();
14+
const white = renderer
15+
.create(<Brand asset="glints-white" variant="square" />)
16+
.toJSON();
1517
expect(white).toMatchSnapshot();
1618
const blackTapLoker = renderer
17-
.create(<Brand asset="glints-taploker-black" />)
19+
.create(<Brand asset="glints-taploker-black" variant="square" />)
1820
.toJSON();
1921
expect(blackTapLoker).toMatchSnapshot();
2022
const whiteTapLoker = renderer
21-
.create(<Brand asset="glints-taploker-white" />)
23+
.create(<Brand asset="glints-taploker-white" variant="square" />)
2224
.toJSON();
2325
expect(whiteTapLoker).toMatchSnapshot();
2426
const cutsom = renderer
25-
.create(<Brand asset="http://example.com/example.jpg" />)
27+
.create(<Brand asset="http://example.com/example.jpg" variant="square" />)
2628
.toJSON();
2729
expect(cutsom).toMatchSnapshot();
2830
});
@@ -33,7 +35,7 @@ describe('<Brand/>', () => {
3335

3436
const url = 'https://glints.com';
3537
const { getByRole } = render(
36-
<Brand asset="glints-black" rightClickURL={url} />
38+
<Brand asset="glints-black" rightClickURL={url} variant="square" />
3739
);
3840
const container = getByRole('presentation');
3941
fireEvent.contextMenu(container);
@@ -51,11 +53,35 @@ describe('<Brand/>', () => {
5153
asset="glints-black"
5254
rightClickURL={url}
5355
onContextMenu={onContextMenu}
56+
variant="square"
5457
/>
5558
);
5659
const container = getByRole('presentation');
5760
expect(onContextMenu).toHaveBeenCalledTimes(0);
5861
fireEvent.contextMenu(container);
5962
expect(onContextMenu).toHaveBeenCalledTimes(1);
6063
});
64+
it('should render with correct styles based on variant', () => {
65+
const { container: defaultContainer } = render(<Brand asset="glints" />);
66+
expect(defaultContainer.querySelector('.brand-image')).toHaveStyleRule(
67+
'width',
68+
'5em'
69+
);
70+
71+
const { container: horizontalContainer } = render(
72+
<Brand asset="glints" variant="horizontal" />
73+
);
74+
expect(horizontalContainer.querySelector('.brand-image')).toHaveStyleRule(
75+
'width',
76+
'5em'
77+
);
78+
79+
const { container: squareContainer } = render(
80+
<Brand asset="glints-black" variant="square" />
81+
);
82+
expect(squareContainer.querySelector('.brand-image')).toHaveStyleRule(
83+
'width',
84+
'3em'
85+
);
86+
});
6187
});

src/General/Brand/Brand.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Brand = ({
2525
className,
2626
rightClickURL,
2727
onContextMenu,
28+
variant = 'horizontal',
2829
...defaultProps
2930
}: Props) => {
3031
const handleRightClick = (
@@ -84,6 +85,7 @@ const Brand = ({
8485
src={srcAsset}
8586
alt={alt}
8687
tabIndex={-1}
88+
$variant={variant}
8789
/>
8890
</BrandContainer>
8991
);
@@ -99,6 +101,8 @@ export type Props = React.ComponentPropsWithoutRef<typeof BrandContainer> & {
99101
rightClickURL?: string;
100102
/** Executes when the user right-clicks on the component */
101103
onContextMenu?(): void;
104+
/** Display mode of the brand image */
105+
variant?: 'square' | 'horizontal';
102106
};
103107

104108
export default Brand;

src/General/Brand/BrandStyle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export const BrandContainer = styled.div`
1414
}
1515
`;
1616

17-
export const BrandImage = styled.img`
17+
export const BrandImage = styled.img<{ $variant?: 'square' | 'horizontal' }>`
1818
object-fit: contain;
19-
width: 3em;
19+
width: ${({ $variant }) => ($variant === 'square' ? '3em' : '5em')};
2020
height: 3em;
2121
outline: none;
2222
`;

0 commit comments

Comments
 (0)