Skip to content

Commit

Permalink
Adds countColor prop to Cardinal
Browse files Browse the repository at this point in the history
  • Loading branch information
elseloop committed May 12, 2023
1 parent f8ace26 commit 42d5cce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/Cardinal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const AllCardinals = () => (
</div>
<Cardinal size="large" count={1} text="Story" />
<Cardinal size="large" count={2} text="Story" />
<Cardinal count="1,234" text="Story" countColor="gold" />
</div>
);

Expand Down Expand Up @@ -193,3 +194,7 @@ Thousands.storyName = 'thousands';
export const Decimals = () => <Cardinal count={123.45} text="Story" />;

Decimals.storyName = 'decimals';

export const WithCountColor = () => <Cardinal count="1,234" text="Story" countColor="gold" />;

WithCountColor.storyName = 'with CountColor';
13 changes: 12 additions & 1 deletion src/components/Cardinal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { inlineGlow } from './shared/animation';
type Status = 'default' | 'positive' | 'negative' | 'warning' | 'neutral' | 'link' | 'inverse';
type Size = 'small' | 'large';
type Alignment = 'left' | 'center' | 'right';
type Color = keyof typeof color;

interface CountProps {
status: Status;
countColor: Color;
}

const Count = styled.div<CountProps>`
Expand Down Expand Up @@ -55,6 +57,12 @@ const Count = styled.div<CountProps>`
css`
color: rgba(255, 255, 255, 0.7);
`};
${(props) =>
props.status === 'default' &&
props.countColor &&
css`
color: ${color[props.countColor]};
`};
span {
display: inline-block;
Expand Down Expand Up @@ -169,6 +177,7 @@ export interface CardinalProps {
countLink?: string;
text: string;
status?: Status;
countColor?: Color;
noPlural?: boolean;
CountWrapper?: React.ElementType;
TextWrapper?: React.ElementType;
Expand All @@ -187,6 +196,7 @@ export const Cardinal: FunctionComponent<CardinalProps> = ({
text,
noPlural,
status,
countColor,
CountWrapper,
TextWrapper,
alignment,
Expand Down Expand Up @@ -220,7 +230,7 @@ export const Cardinal: FunctionComponent<CardinalProps> = ({
{...events}
{...props}
>
<Count status={status}>
<Count status={status} countColor={countColor}>
<CountWrapper>{countValue}</CountWrapper>
</Count>
<Text>
Expand All @@ -242,6 +252,7 @@ Cardinal.defaultProps = {
active: false,
size: 'large' as Size,
status: 'default' as Status,
countColor: null,
count: '000',
countLink: null,
noPlural: false,
Expand Down

0 comments on commit 42d5cce

Please sign in to comment.