@telekom/scale-components
Version:
Scale is the digital design system for Telekom products and experiences.
195 lines (194 loc) • 5.86 kB
JavaScript
/**
* @license
* Scale https://github.com/telekom/scale
*
* Copyright (c) 2021 Egor Kirpichev and contributors, Deutsche Telekom AG
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { Component, Prop, h, Host } from '@stencil/core';
import classNames from 'classnames';
export class Icon {
constructor() {
/**
* Will be used for both `width` and `height`, all icons are square.
* Keep in mind the `viewBox` attribute is set to "0 0 24 24".
*/
this.size = 24;
/** The SVG `fill` attribute */
this.fill = 'var(--icon-color, currentColor)';
/** The SVG `stroke` attribute */
this.stroke = 'transparent';
/** (optional) If `true` the icon can receive focus */
this.focusable = false;
/** (optional) If `true` the svg element will get aria-hidden="true" */
this.decorative = false;
}
render() {
const pathAttributes = {
fill: this.fill,
stroke: this.stroke,
};
const ariaHidden = this.decorative ? { 'aria-hidden': 'true' } : {};
const focusable = this.focusable ? { tabindex: 0 } : {};
return (h(Host, null,
h("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", class: this.getCssClassMap(), part: "base", width: this.size, height: this.size, viewBox: "0 0 24 24", role: "img" }, ariaHidden, focusable),
this.accessibilityTitle && h("title", null, this.accessibilityTitle),
this.path ? (h("path", Object.assign({ d: this.path }, pathAttributes, { part: "path" }))) : (h("use", Object.assign({ xlinkHref: `#icon-${this.name}` }, pathAttributes))))));
}
getCssClassMap() {
return classNames('icon');
}
static get is() { return "scale-icon"; }
static get originalStyleUrls() { return {
"$": ["./icon.css"]
}; }
static get styleUrls() { return {
"$": ["icon.css"]
}; }
static get properties() { return {
"name": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "A name that will be used to reference an SVG object defined elsewhere,\nvia `<use xlink:href=\"\">`. `icon-` will be prepended to the name, so if\nyou pass `circle`, it will look for for the `icon-circle` id\ne.g. `<use xlink:href=\"#icon-circle\">`.\nIf there is no element in the document with the id by the name provided,\nthis component will render empty."
},
"attribute": "name",
"reflect": false
},
"path": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "A path shape to be used in the `d` attribute of a path element."
},
"attribute": "path",
"reflect": false
},
"size": {
"type": "number",
"mutable": false,
"complexType": {
"original": "number",
"resolved": "number",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Will be used for both `width` and `height`, all icons are square.\nKeep in mind the `viewBox` attribute is set to \"0 0 24 24\"."
},
"attribute": "size",
"reflect": true,
"defaultValue": "24"
},
"fill": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The SVG `fill` attribute"
},
"attribute": "fill",
"reflect": false,
"defaultValue": "'var(--icon-color, currentColor)'"
},
"stroke": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The SVG `stroke` attribute"
},
"attribute": "stroke",
"reflect": false,
"defaultValue": "'transparent'"
},
"focusable": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "(optional) If `true` the icon can receive focus"
},
"attribute": "focusable",
"reflect": false,
"defaultValue": "false"
},
"decorative": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "(optional) If `true` the svg element will get aria-hidden=\"true\""
},
"attribute": "decorative",
"reflect": false,
"defaultValue": "false"
},
"accessibilityTitle": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "(optional) When using the icon as standalone, make it meaningful for accessibility"
},
"attribute": "accessibility-title",
"reflect": false
}
}; }
}