Skip to content

Commit 8848e05

Browse files
authored
Merge pull request #418 from storybookjs/cardinal-color-prop
Adds `countColor` prop to Cardinal
2 parents f8ace26 + 42d5cce commit 8848e05

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/components/Cardinal.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const AllCardinals = () => (
7272
</div>
7373
<Cardinal size="large" count={1} text="Story" />
7474
<Cardinal size="large" count={2} text="Story" />
75+
<Cardinal count="1,234" text="Story" countColor="gold" />
7576
</div>
7677
);
7778

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

195196
Decimals.storyName = 'decimals';
197+
198+
export const WithCountColor = () => <Cardinal count="1,234" text="Story" countColor="gold" />;
199+
200+
WithCountColor.storyName = 'with CountColor';

src/components/Cardinal.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import { inlineGlow } from './shared/animation';
99
type Status = 'default' | 'positive' | 'negative' | 'warning' | 'neutral' | 'link' | 'inverse';
1010
type Size = 'small' | 'large';
1111
type Alignment = 'left' | 'center' | 'right';
12+
type Color = keyof typeof color;
1213

1314
interface CountProps {
1415
status: Status;
16+
countColor: Color;
1517
}
1618

1719
const Count = styled.div<CountProps>`
@@ -55,6 +57,12 @@ const Count = styled.div<CountProps>`
5557
css`
5658
color: rgba(255, 255, 255, 0.7);
5759
`};
60+
${(props) =>
61+
props.status === 'default' &&
62+
props.countColor &&
63+
css`
64+
color: ${color[props.countColor]};
65+
`};
5866
5967
span {
6068
display: inline-block;
@@ -169,6 +177,7 @@ export interface CardinalProps {
169177
countLink?: string;
170178
text: string;
171179
status?: Status;
180+
countColor?: Color;
172181
noPlural?: boolean;
173182
CountWrapper?: React.ElementType;
174183
TextWrapper?: React.ElementType;
@@ -187,6 +196,7 @@ export const Cardinal: FunctionComponent<CardinalProps> = ({
187196
text,
188197
noPlural,
189198
status,
199+
countColor,
190200
CountWrapper,
191201
TextWrapper,
192202
alignment,
@@ -220,7 +230,7 @@ export const Cardinal: FunctionComponent<CardinalProps> = ({
220230
{...events}
221231
{...props}
222232
>
223-
<Count status={status}>
233+
<Count status={status} countColor={countColor}>
224234
<CountWrapper>{countValue}</CountWrapper>
225235
</Count>
226236
<Text>
@@ -242,6 +252,7 @@ Cardinal.defaultProps = {
242252
active: false,
243253
size: 'large' as Size,
244254
status: 'default' as Status,
255+
countColor: null,
245256
count: '000',
246257
countLink: null,
247258
noPlural: false,

0 commit comments

Comments
 (0)