Skip to content

Commit

Permalink
chore(deps): convert Badge to transient props
Browse files Browse the repository at this point in the history
  • Loading branch information
leeBigCommerce committed Jan 24, 2024
1 parent 8b55ac2 commit fb5f9d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/big-design/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { HTMLAttributes, memo } from 'react';

import { MarginProps } from '../../mixins';
import { withTransients } from '../../utils/withTransients';

import { StyledBadge } from './styled';

Expand All @@ -10,7 +11,7 @@ export interface BadgeProps extends HTMLAttributes<HTMLSpanElement>, MarginProps
}

export const Badge: React.FC<BadgeProps> = memo(({ className, style, label, ...props }) =>
typeof label === 'string' ? <StyledBadge {...props}>{label}</StyledBadge> : null,
typeof label === 'string' ? <StyledBadge {...withTransients(props)}>{label}</StyledBadge> : null,
);

Badge.displayName = 'Badge';
28 changes: 15 additions & 13 deletions packages/big-design/src/components/Badge/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { theme as defaultTheme } from '@bigcommerce/big-design-theme';
import { css, styled } from 'styled-components';

import { withMargins } from '../../mixins';
import { WithTransients } from 'src/utils';

import { MarginProps, withMargins } from '../../mixins';

import { BadgeProps } from './Badge';

export const StyledBadge = styled.span<Omit<BadgeProps, 'label'>>`
export const StyledBadge = styled.span<WithTransients<Omit<BadgeProps, 'label'> & MarginProps>>`
${withMargins()};
color: ${({ theme }) => theme.colors.white};
Expand All @@ -19,39 +21,39 @@ export const StyledBadge = styled.span<Omit<BadgeProps, 'label'>>`
vertical-align: middle;
padding: 0 ${({ theme }) => theme.spacing.xSmall};
${({ theme, variant }) =>
variant === 'secondary' &&
${({ theme, $variant }) =>
$variant === 'secondary' &&
css`
background-color: ${theme.colors.secondary60};
`}
${({ theme, variant }) =>
variant === 'success' &&
${({ theme, $variant }) =>
$variant === 'success' &&
css`
background-color: ${theme.colors.success50};
`}
${({ theme, variant }) =>
variant === 'warning' &&
${({ theme, $variant }) =>
$variant === 'warning' &&
css`
color: ${theme.colors.secondary70};
background-color: ${theme.colors.warning40};
`}
${({ theme, variant }) =>
variant === 'danger' &&
${({ theme, $variant }) =>
$variant === 'danger' &&
css`
background-color: ${theme.colors.danger40};
`}
${({ theme, variant }) =>
variant === 'primary' &&
${({ theme, $variant }) =>
$variant === 'primary' &&
css`
background-color: ${theme.colors.primary40};
`}
`;

StyledBadge.defaultProps = {
theme: defaultTheme,
variant: 'secondary',
$variant: 'secondary',
};
2 changes: 1 addition & 1 deletion packages/big-design/src/mixins/margins/margins.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Spacing } from '@bigcommerce/big-design-theme';
import { css } from 'styled-components';

import { WithTransients } from 'src/utils/withTransients';
import { WithTransients } from 'src/utils';

import { ResponsiveProp } from '../../types';
import { getSpacingStyles } from '../spacings';
Expand Down

0 comments on commit fb5f9d5

Please sign in to comment.