Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(footer): ensure IBM logo icon is visible #4226

Merged
merged 4 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/styles/icons/svg/IBM-8bar-logo--h65-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 10 additions & 4 deletions packages/web-components/src/components/footer/footer-logo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { html, property, customElement, LitElement } from 'lit-element';
import { html, svg, property, customElement, LitElement } from 'lit-element';
import settings from 'carbon-components/es/globals/js/settings';
import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/settings.js';
import FocusMixin from 'carbon-web-components/es/globals/mixins/focus.js';
Expand Down Expand Up @@ -48,9 +48,15 @@ class DDSFooterLogo extends StableSelectorMixin(FocusMixin(LitElement)) {
render() {
const { href } = this;
return html`
<a class="${prefix}--footer-logo__link" aria-label="IBM logo" href="${ifNonNull(href)}"
>${IBM8BarLogoH65White()}<slot></slot
></a>
<a class="${prefix}--footer-logo__link" aria-label="IBM logo" href="${ifNonNull(href)}">
${IBM8BarLogoH65White({
class: `${prefix}--footer-logo__logo`,
role: 'img',
'aria-labelledby': 'footer-logo',
children: svg`<title id="footer-logo">IBM Logo</title>`,
})}
<slot></slot>
</a>
`;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/web-components/tools/descriptor-from-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ function svg2JSAsync(data) {
* @param {string} svg A `<svg>` string.
* @returns {object} The JSON version of the given `<svg>` string.
*/
async function svgResultCarbonIconLoader(svg) {
async function descriptorFromSVG(svg) {
const svgNode = findRootNode(await svg2JSAsync(svg));
if (!svgNode) {
throw new Error(`Wrong SVG2JS result found in: ${svg}`);
}
return convertAttrs(svgNode);
}

module.exports = svgResultCarbonIconLoader;
module.exports = descriptorFromSVG;
30 changes: 28 additions & 2 deletions packages/web-components/tools/svg-result-from-icon-descriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

const { getAttributes, formatAttributes } = require('@carbon/icon-helpers');

// For `@carbon/ibmdotcom-web-components`, we let our consumers set those attributes
const omitAttrs = {
class: true,
role: true,
'aria-labelledby': true,
};

/**
* @param {object} descriptor Object representation of an SVG icon as generated by @carbon/icons
* @returns {string} The `lit-html` template string version of the given SVG icon descriptor.
Expand All @@ -33,12 +40,31 @@ const toString = descriptor => {
* @param {object} descriptor Object representation of an SVG icon as generated by @carbon/icons
*/
const icon = descriptor => {
descriptor.attrs = getAttributes(
const attrs = getAttributes(
Object.assign(descriptor.attrs, {
'...': '${spread(attrs)}', // eslint-disable-line no-template-curly-in-string
})
);
descriptor.content.unshift('${children}'); // eslint-disable-line no-template-curly-in-string
descriptor.attrs = Object.keys(attrs).reduce(
(acc, attr) =>
typeof attrs[attr] === 'undefined' || omitAttrs[attr]
? acc
: {
...acc,
[attr]: attrs[attr],
},
{}
);
descriptor.content = descriptor.content.reduce(
(acc, item) => {
// For `@carbon/ibmdotcom-web-components`, we let our consumers set the `<title>`
if (item.elem !== 'title') {
acc.push(item);
}
return acc;
},
['${children}'] // eslint-disable-line no-template-curly-in-string
);
return `({ children, ...attrs } = {}) => svg\`${toString(descriptor)}\``;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

const svg2js = require('svgo/lib/svgo/svg2js');
const createSVGResultFromCarbonIcon = require('./svg-result-carbon-icon');
const createSVGResultFromIconDescriptor = require('./svg-result-from-icon-descriptor');

/**
* @param {object} node The node in SVG2JS result.
Expand Down Expand Up @@ -68,7 +68,7 @@ function svgResultIBMDotcomIconLoader(content) {
`
import { svg } from 'lit-html';
import spread from 'carbon-web-components/es/globals/directives/spread';
const svgResultCarbonIcon = ${createSVGResultFromCarbonIcon(convertAttrs(svgNode))};
const svgResultCarbonIcon = ${createSVGResultFromIconDescriptor(convertAttrs(svgNode))};
export default svgResultCarbonIcon;
`
);
Expand Down