Skip to content

Commit

Permalink
feat(vwc-icon): exported style to external scss
Browse files Browse the repository at this point in the history
  • Loading branch information
Tal Weinfeld committed Sep 29, 2020
1 parent 2b44f0f commit a0af301
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
12 changes: 2 additions & 10 deletions components/icon/src/vwc-icon.js
@@ -1,6 +1,7 @@
import '@vonage/vvd-core';
import kefir from "kefir";
import resolveIcon from "./icon-resolve.autogenerated";
import { style } from "../vwc-icon.css";

const [
SYMBOL_CONNECT,
Expand All @@ -9,10 +10,6 @@ const [
SYMBOL_PROPERTY_TYPE_SET
] = ["connect", "disconnect", "property-type", "property-type-set"].map((name) => Symbol(name));

const
SIZES = { small: 16, medium: 24, large: 32 },
DEFAULT_SIZE = "medium";

const noop = ()=> { };

/**
Expand All @@ -34,12 +31,7 @@ class IconElement extends HTMLElement {
rootEl = this.attachShadow({ mode: "open" }),
[styleEl, slotEl] = ["style", "slot"].map((elName) => document.createElement(elName));

styleEl.innerHTML = [
`:host { display: inline-block; fill: currentColor; }`,
`:host > slot { margin: 0; padding: 0; display: block; position: relative; width: 100%; height: 100%; }`,
`:host > slot > svg { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }`,
...[[null, SIZES[DEFAULT_SIZE]], ...Object.entries(SIZES)].map(([sizeId, size])=>`:host${sizeId ? `([size=${sizeId}])` : ''} { width: ${size}px; height: ${size}px; }`)
].join('\n');
styleEl.innerHTML = style.cssText;

[SYMBOL_CONNECT, SYMBOL_DISCONNECT, SYMBOL_PROPERTY_TYPE_SET].forEach((symbol) => this[symbol] = noop);

Expand Down
7 changes: 7 additions & 0 deletions components/icon/src/vwc-icon.scss
@@ -0,0 +1,7 @@
:host { display: inline-block; fill: currentColor; }
:host > slot { margin: 0; padding: 0; display: block; position: relative; width: 100%; height: 100%; }
:host > slot > svg { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
:host { width: 24px; height: 24px; }
:host([size=small]) { width: 16px; height: 16px; }
:host([size=medium]) { width: 24px; height: 24px; }
:host([size=large]) { width: 32px; height: 32px; }
5 changes: 3 additions & 2 deletions components/icon/tsconfig.json
@@ -1,13 +1,14 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"allowJs": true,
"composite": true,
"rootDir": "src",
"outDir": ".",
"tsBuildInfoFile": ".tsbuildinfo"
},
"include": [],
"include": [
"src/*.ts"
],
"references": [
{
"path": "../../common/core"
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -60,6 +60,7 @@
{ "path": "components/textarea" },
{ "path": "components/textfield" },
{ "path": "components/top-app-bar" },
{ "path": "components/top-app-bar-fixed" }
{ "path": "components/top-app-bar-fixed" },
{ "path": "components/icon" }
]
}

0 comments on commit a0af301

Please sign in to comment.