Skip to content

Commit

Permalink
feat(component): add ellipsis prop to Link (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
deini authored Jan 3, 2020
1 parent 3aa4c00 commit c2f9b78
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/big-design/src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MarginProps } from '../../mixins';
import { StyledLink } from './styled';

export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>, MarginProps {
ellipsis?: boolean;
external?: boolean;
}

Expand Down
15 changes: 15 additions & 0 deletions packages/big-design/src/components/Link/spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,18 @@ test('forwards styles', () => {
expect(container.firstChild).toHaveClass('test');
expect(container.firstChild).toHaveStyle('background: red');
});

test('render Link with ellipsis', () => {
const { getByTestId } = render(
<Link data-testid="link" ellipsis={true}>
Test with ellipsis
</Link>,
);
const link = getByTestId('link');

expect(link).toHaveStyle(`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`);
});
2 changes: 2 additions & 0 deletions packages/big-design/src/components/Link/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { theme as defaultTheme } from '@bigcommerce/big-design-theme';
import { ellipsis } from 'polished';
import styled, { css } from 'styled-components';

import { withMargins } from '../../mixins';
Expand All @@ -9,6 +10,7 @@ import { LinkProps } from './Link';
export const StyledLink = styled.a<LinkProps & { isExternal?: boolean }>`
${withMargins()};
${withTransition(['color'], '70ms')}
${props => props.ellipsis && ellipsis()};
color: ${({ theme }) => theme.colors.primary};
cursor: pointer;
Expand Down
5 changes: 5 additions & 0 deletions packages/docs/PropTables/LinkPropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const linkProps: Prop[] = [
</>
),
},
{
name: 'ellipsis',
types: 'boolean',
description: 'Controls whether the text will concat and display ellipse... on overflow.',
},
];

export const LinkPropTable: React.FC<PropTableWrapper> = props => (
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/PropTables/TypographyPropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const typographyProps: Prop[] = [
),
},
{
name: 'ellipse',
name: 'ellipsis',
types: 'boolean',
description: 'Controls whether the text will concat and display ellipse... on overflow.',
},
Expand Down

0 comments on commit c2f9b78

Please sign in to comment.