Skip to content

Commit

Permalink
Add title node inside ClayIcon svg node
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Lancha authored and matuzalemsteles committed Dec 12, 2017
1 parent 8755501 commit aeac244
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/clay-icon/src/ClayIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ ClayIcon.STATE = {
* @default undefined
*/
symbol: Config.string().required(),

/**
* The title of the Clay SVG Icon.
* @instance
* @memberof ClayIcon
* @type {?string|undefined}
* @default undefined
*/
title: Config.string(),
};

defineWebComponent('clay-icon', ClayIcon);
Expand Down
2 changes: 2 additions & 0 deletions packages/clay-icon/src/ClayIcon.soy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{@param symbol: string}
{@param? elementClasses: string}
{@param? id: string}
{@param? title: string}

{let $attributes kind="attributes"}
aria-hidden="true"
Expand All @@ -25,6 +26,7 @@
{/let}

<svg {$attributes}>
<title>{$title ?: $id ?: $symbol}</title>
<use xlink:href="{$spritemap}#{$symbol}" />
</svg>
{/template}
21 changes: 21 additions & 0 deletions packages/clay-icon/src/__tests__/ClayIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,25 @@ describe('ClayIcon', function() {

expect(clayIcon).toMatchSnapshot();
});

it('should render an icon with specified title', () => {
clayIcon = new ClayIcon({
title: 'myTitle',
spritemap: spritemap,
symbol: 'add-cell',
});

expect(clayIcon).toMatchSnapshot();
});

it('should render an icon with specified title when id is passed too', () => {
clayIcon = new ClayIcon({
id: 'myId',
title: 'myTitle',
spritemap: spritemap,
symbol: 'add-cell',
});

expect(clayIcon).toMatchSnapshot();
});
});
17 changes: 17 additions & 0 deletions packages/clay-icon/src/__tests__/__snapshots__/ClayIcon.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,35 @@

exports[`ClayIcon should render an icon with classes 1`] = `
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-add-cell my-custom-class">
<title>add-cell</title>
<use xlink:href="../node_modules/lexicon-ux/build/images/icons/icons.svg#add-cell"></use>
</svg>
`;
exports[`ClayIcon should render an icon with id 1`] = `
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-add-cell" id="myId">
<title>myId</title>
<use xlink:href="../node_modules/lexicon-ux/build/images/icons/icons.svg#add-cell"></use>
</svg>
`;
exports[`ClayIcon should render an icon with specified title 1`] = `
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-add-cell">
<title>myTitle</title>
<use xlink:href="../node_modules/lexicon-ux/build/images/icons/icons.svg#add-cell"></use>
</svg>
`;
exports[`ClayIcon should render an icon with specified title when id is passed too 1`] = `
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-add-cell" id="myId">
<title>myTitle</title>
<use xlink:href="../node_modules/lexicon-ux/build/images/icons/icons.svg#add-cell"></use>
</svg>
`;
exports[`ClayIcon should render markup for icon \`add-cell\` 1`] = `
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-add-cell">
<title>add-cell</title>
<use xlink:href="../node_modules/lexicon-ux/build/images/icons/icons.svg#add-cell"></use>
</svg>
`;

0 comments on commit aeac244

Please sign in to comment.