Skip to content

Commit e98145c

Browse files
Merge pull request #384 from storybookjs/cardinal-inverse-link
add inverse styling for link and selectable variants of the cardinal
2 parents c794910 + 700923a commit e98145c

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/components/Cardinal.stories.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,25 @@ export const AllCardinals = () => (
5151
text="Selectable"
5252
noPlural
5353
/>
54+
<div style={{ background: '#171C23', display: 'inline-block' }}>
55+
<Cardinal
56+
selectable
57+
onHover={onHover}
58+
onClick={onClick}
59+
size="small"
60+
count={14}
61+
text="Selectable"
62+
status="inverse"
63+
noPlural
64+
/>
65+
</div>
5466
<br />
5567
<Cardinal isLoading />
5668
<Cardinal count={37} text="Stories" />
5769
<Cardinal count={12} countLink="http://github.com" text="Commits" />
70+
<div style={{ background: '#171C23', display: 'inline-block' }}>
71+
<Cardinal count={12} countLink="http://github.com" text="Commits" status="inverse" />
72+
</div>
5873
<Cardinal size="large" count={1} text="Story" />
5974
<Cardinal size="large" count={2} text="Story" />
6075
</div>

src/components/Cardinal.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,20 @@ const CardinalInner = styled.div<CardinalInnerProps>`
119119
`};
120120
121121
${(props) =>
122-
props.active &&
123-
css`
124-
background: ${background.app};
125-
`};
122+
props.selectable &&
123+
(props.inverse
124+
? css`
125+
&:hover {
126+
background: rgba(255, 255, 255, 0.2);
127+
}
128+
`
129+
: css`
130+
cursor: pointer;
131+
132+
&:hover {
133+
background: ${background.app};
134+
}
135+
`)};
126136
127137
${Count} {
128138
font-weight: ${(props) =>
@@ -138,6 +148,14 @@ const CardinalInner = styled.div<CardinalInnerProps>`
138148
line-height: ${(props) => (props.size === 'small' ? typography.size.s2 : typography.size.m1)}px;
139149
clear: both;
140150
}
151+
152+
${(props) =>
153+
props.inverse &&
154+
css`
155+
a {
156+
color: rgba(255, 255, 255, 0.7);
157+
}
158+
`}
141159
`;
142160

143161
export interface CardinalProps {
@@ -176,7 +194,11 @@ export function Cardinal({
176194
}: CardinalProps) {
177195
let countValue = count;
178196
if (countLink) {
179-
countValue = <Link href={countLink}>{count}</Link>;
197+
countValue = (
198+
<Link href={countLink} inverse={status === 'inverse'}>
199+
{count}
200+
</Link>
201+
);
180202
}
181203
let events = {};
182204
if (selectable) {

0 commit comments

Comments
 (0)