Skip to content

Commit 29abe18

Browse files
elizabeth-mooreElizabeth Moore
andauthored
update(Link): Add truncated prop (#397)
* Truncate link * Add story Co-authored-by: Elizabeth Moore <elizabeth.amoore@airbnb.com>
1 parent 1e65b10 commit 29abe18

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

packages/core/src/components/Link/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ export type LinkProps = ButtonOrLinkProps & {
2323
muted?: boolean;
2424
/** Decrease font size to small. */
2525
small?: boolean;
26+
/** Truncate the link text with an ellipsis. */
27+
truncated?: boolean;
2628
/** Bold font. */
2729
bold?: boolean;
2830
/** Custom style sheet. */
2931
styleSheet?: StyleSheet;
3032
/** Pass text props to the underlying text. */
31-
textProps?: Omit<TextProps, 'children' | 'styleSheet'>;
33+
textProps?: Omit<TextProps, 'children' | 'styleSheet' | 'truncated'>;
3234
};
3335

3436
/** A standard link for... linking to things. */
@@ -42,6 +44,7 @@ function Link({
4244
micro,
4345
muted,
4446
small,
47+
truncated,
4548
bold,
4649
styleSheet,
4750
textProps = {},
@@ -61,6 +64,7 @@ function Link({
6164
disabled && styles.link_disabled,
6265
block && styles.link_block,
6366
baseline && styles.link_baseline,
67+
truncated && styles.link_truncated,
6468
)}
6569
>
6670
{children}

packages/core/src/components/Link/story.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,18 @@ export function boldText() {
115115
boldText.story = {
116116
name: 'Bold text.',
117117
};
118+
119+
export function truncatedText() {
120+
return (
121+
<Link block truncated>
122+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam leo erat, lacinia nec porttitor
123+
sed, mollis sed nibh. Nam porta sit amet risus quis interdum. Sed feugiat lorem vitae augue
124+
blandit, sed mollis mi laoreet. Donec auctor, enim eget tempus auctor, est lorem laoreet nisi,
125+
a rutrum dolor quam eget mi.
126+
</Link>
127+
);
128+
}
129+
130+
truncatedText.story = {
131+
name: 'Truncated text.',
132+
};

packages/core/src/components/Link/styles.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@ export const linkStyleSheet: StyleSheet = ({ color, pattern, transition }) => ({
6565
textDecoration: 'none',
6666
},
6767
},
68+
69+
link_truncated: {
70+
overflow: 'hidden',
71+
textOverflow: 'ellipsis',
72+
whiteSpace: 'nowrap',
73+
},
6874
});

packages/core/test/components/Link.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ describe('<Link />', () => {
8585
expect(wrapper.find(ButtonOrLink).prop('className')).toMatch('link_muted');
8686
});
8787

88+
it('renders truncated', () => {
89+
const wrapper = mountUseStyles(
90+
<Link truncated href="/">
91+
Truncated
92+
</Link>,
93+
);
94+
95+
expect(wrapper.find(ButtonOrLink).prop('className')).toMatch('link_truncated');
96+
});
97+
8898
it('renders the child component with an inline=false prop when block prop is passed', () => {
8999
const wrapper = mountUseStyles(
90100
<Link block href="/foo">

0 commit comments

Comments
 (0)