Skip to content

Commit

Permalink
feat: Adds small size badge (#978)
Browse files Browse the repository at this point in the history
* feat: Adds small size badge

* chore: Deletes package-lock.json

* chore: Updates yarn dependency

* chore: Adds changeset

* fix: Fixes badge padding

* fix: Fixes linting issue
  • Loading branch information
yshakib committed Jun 26, 2024
1 parent ef069b4 commit c4d3c69
Show file tree
Hide file tree
Showing 7 changed files with 2,063 additions and 2,009 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-falcons-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@autoguru/overdrive': minor
---

small size added to badge
4 changes: 4 additions & 0 deletions packages/overdrive/lib/components/Badge/Badge.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const label = style({
});

export const labelSize = styleVariants({
small: {
fontSize: vars.typography.size['1'].fontSize,
lineHeight: vars.typography.size['1'].fontSize,
},
standard: {
fontSize: vars.typography.size['2'].fontSize,
lineHeight: vars.typography.size['2'].fontSize,
Expand Down
27 changes: 27 additions & 0 deletions packages/overdrive/lib/components/Badge/Badge.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ describe('<Badge />', () => {
);
});

it('should apply small size when small size is set', () => {
const { container } = render(
<Badge size="small" colour="neutral" label="Hello World!" />,
);
expect(container.firstChild.firstChild).toHaveClass(
styles.labelSize.small,
);
});

it('should apply standard size when standard size is set', () => {
const { container } = render(
<Badge size="standard" colour="neutral" label="Hello World!" />,
);
expect(container.firstChild.firstChild).toHaveClass(
styles.labelSize.standard,
);
});

it('should apply large size when large size is set', () => {
const { container } = render(
<Badge size="large" colour="neutral" label="Hello World!" />,
);
expect(container.firstChild.firstChild).toHaveClass(
styles.labelSize.large,
);
});

it('should apply minimal style when minimal look is set', () => {
const { container } = render(
<Badge look="standard" colour="neutral" label="Hello World!" />,
Expand Down
19 changes: 15 additions & 4 deletions packages/overdrive/lib/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { invariant } from '@autoguru/utilities';
import * as React from 'react';
import { FunctionComponent } from 'react';
import { FunctionComponent, ComponentProps } from 'react';

import { Box } from '../Box';
import { useTextStyles } from '../Text';
Expand All @@ -15,14 +15,25 @@ export interface Props {
size?: keyof typeof styles.labelSize;
}

const paddingXMap: Record<keyof typeof styles.labelSize , ComponentProps<typeof Box>['padding']> = {
'small': '1',
'standard': '1',
'large': '4'
}

const paddingYMap: Record<keyof typeof styles.labelSize , ComponentProps<typeof Box>['padding']> = {
'small': '1',
'standard': '1',
'large': '4'
}

export const Badge: FunctionComponent<Props> = ({
label,
colour = 'neutral',
look = 'standard',
size = 'standard',
className = '',
}) => {
const isStandardSize = size === 'standard';
const textStyles = useTextStyles({
noWrap: true,
fontWeight: 'semiBold',
Expand All @@ -46,8 +57,8 @@ export const Badge: FunctionComponent<Props> = ({
]}
overflow="hidden"
display="block"
paddingX={isStandardSize ? '1' : '4'}
paddingY={isStandardSize ? '1' : '2'}
paddingX={paddingXMap[size]}
paddingY={paddingYMap[size]}
borderRadius="1"
>
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`<Badge /> should match snapshot with label 1`] = `
class="reset_block__6swfds3 useBoxStyles_display_flex__7o6k06fb"
>
<div
class="reset_block__6swfds3 useBoxStyles_makeResponsiveStyle_key_bp__7o6k060 useBoxStyles_makeResponsiveStyle_key_bp__7o6k0614 useBoxStyles_makeResponsiveStyle_key_bp__7o6k0628 useBoxStyles_makeResponsiveStyle_key_bp__7o6k063c useBoxStyles_display_block__7o6k06fa useBoxStyles_overflow_hidden__7o6k06f5 useBoxStyles_makeResponsiveStyle_key_bp__7o6k06cl Badge_labelSize_standard__19rwmn11 Badge_colours_default_neutral__19rwmn13"
class="reset_block__6swfds3 useBoxStyles_makeResponsiveStyle_key_bp__7o6k060 useBoxStyles_makeResponsiveStyle_key_bp__7o6k0614 useBoxStyles_makeResponsiveStyle_key_bp__7o6k0628 useBoxStyles_makeResponsiveStyle_key_bp__7o6k063c useBoxStyles_display_block__7o6k06fa useBoxStyles_overflow_hidden__7o6k06f5 useBoxStyles_makeResponsiveStyle_key_bp__7o6k06cl Badge_labelSize_standard__19rwmn12 Badge_colours_default_neutral__19rwmn14"
>
<span
class="reset_inlineText__6swfds2 useBoxStyles_display_block__7o6k06fa useBoxStyles_overflow_hidden__7o6k06f5 useTextStyles_root__w6to7i0 reset_block__6swfds3 useTextStyles_fontWeight_semiBold__w6to7io useTextStyles_noWrap__w6to7iq Badge_label__19rwmn10 useTextStyles_root__w6to7i0 reset_block__6swfds3 useTextStyles_colours_white__w6to7if"
Expand Down
18 changes: 13 additions & 5 deletions packages/overdrive/lib/components/Badge/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ standard.args = standardProps;
export const standardAllColours = templateAllColours.bind(standardProps);
standardAllColours.args = standardProps;

const standardLargeProps: ComponentProps<typeof Badge> = {
const largeProps: ComponentProps<typeof Badge> = {
...standardProps,
size: 'large',
};
export const standardLargeAllColours =
templateAllColours.bind(standardLargeProps);
standardLargeAllColours.args = standardLargeProps;
export const largeAllColours =
templateAllColours.bind(largeProps);
largeAllColours.args = largeProps;

const smallProps: ComponentProps<typeof Badge> = {
...standardProps,
size: 'small',
};
export const smallAllColours =
templateAllColours.bind(smallProps);
smallAllColours.args = smallProps;

const invertedProps: ComponentProps<typeof Badge> = {
...standardProps,
Expand All @@ -78,7 +86,7 @@ export const invertedAllColours = templateAllColours.bind(invertedProps);
invertedAllColours.args = invertedProps;

const invertedLargeProps: ComponentProps<typeof Badge> = {
...standardLargeProps,
...largeProps,
look: 'inverted',
};
export const invertedLargeAllColours =
Expand Down
Loading

0 comments on commit c4d3c69

Please sign in to comment.