Skip to content

Commit

Permalink
feat: add 'size options' to CvLink
Browse files Browse the repository at this point in the history
Update CvLink prop to include 'size' props and link--${size} on
component. Size options are 'sm', 'md' (default), and 'lg'.
  • Loading branch information
felipebritor committed Mar 25, 2023
1 parent 92de599 commit e1a1781
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/CvLink/CvLink.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../../global/storybook-utils';

import { CvLink } from '.';
import { props as propsCvLink } from '../../use/cvLink';
import { props as propsCvLink, linkSizes } from '../../use/cvLink';

export default {
title: `${sbCompPrefix}/CvLink`,
Expand Down Expand Up @@ -61,6 +61,26 @@ export default {
description:
'Specify whether you want the link to receive visited styles after the link has been clicked.',
},
size: {
type: 'string',
table: {
type: { summary: linkSizes.join(' | ') },
defaultValue: { summary: 'medium (md)' },
category: 'props',
},
options: linkSizes,
control: {
type: 'select',
labels: {
sm: 'small (sm)',
md: 'medium (md)',
lg: 'large (lg)',
},
},
defaultValue: 'md',
description:
'Specify the size of the Link. Currently supports either `sm`, `md` (default) or `lg` as an option.',
},
default: {
type: 'string',
table: {
Expand Down
1 change: 1 addition & 0 deletions src/components/CvLink/CvLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[`${carbonPrefix}--link--disabled`]: disabled,
[`${carbonPrefix}--link--inline`]: inline,
[`${carbonPrefix}--link--visited`]: visited,
[`${carbonPrefix}--link--${size}`]: size,
},
]"
>
Expand Down
34 changes: 34 additions & 0 deletions src/components/CvLink/__tests__/CvLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,38 @@ describe('CvLink', () => {
const element = container.firstElementChild;
expect(element.classList.contains('bx--link--visited')).toBe(true);
});

it("update link size to small when 'size' is sm", () => {
const { container } = render(CvLink, {
props: { size: 'sm' },
});

const element = container.firstElementChild;
expect(element.classList.contains('bx--link--sm')).toBe(true);
});

it("update link size to medium when 'size' is md", () => {
const { container } = render(CvLink, {
props: { size: 'md' },
});

const element = container.firstElementChild;
expect(element.classList.contains('bx--link--md')).toBe(true);
});

it("update link size to large when 'size' is lg", () => {
const { container } = render(CvLink, {
props: { size: 'lg' },
});

const element = container.firstElementChild;
expect(element.classList.contains('bx--link--lg')).toBe(true);
});

it('sets link size to medium when no size is passed', () => {
const { container } = render(CvLink);

const element = container.firstElementChild;
expect(element.classList.contains('bx--link--md')).toBe(true);
});
});
7 changes: 7 additions & 0 deletions src/use/cvLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
*/
import { computed } from 'vue';

export const linkSizes = ['sm', 'md', 'lg'];

export const props = {
disabled: Boolean,
to: { type: [String, Object] },
href: String,
size: {
type: String,
validator: size => linkSizes.includes(size),
default: 'md',
},
};

export const useTagType = props => {
Expand Down

0 comments on commit e1a1781

Please sign in to comment.