Skip to content

Commit 678ecb0

Browse files
authored
feat(icon): implement new icon system (#557)
1 parent 9a47a81 commit 678ecb0

File tree

3 files changed

+99
-36
lines changed

3 files changed

+99
-36
lines changed

public/components/expandable/expandable.css

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
span.expandable {
2-
display: flex;
3-
align-items: center !important;
4-
justify-content: center !important;
5-
height: 35px;
6-
font-size: 13px;
7-
font-family: mononoki;
8-
background: none;
9-
color: #00B0FF;
10-
text-shadow: 1px 1px 1px rgb(20 20 20 / 50%);
11-
transition: all 0.2s linear;
12-
margin-top: 5px;
13-
}
14-
15-
span.expandable[data-value="opened"] {
16-
color: #F44336 !important;
17-
}
18-
19-
span.expandable:hover {
20-
cursor: pointer;
21-
}
22-
23-
span.expandable i {
24-
margin-right: 4px;
25-
margin-top: 1px;
26-
}
27-
281
/**
292
* CUSTOM CSS
303
*/
31-
.package-scripts>.expandable {
4+
.package-scripts> expandable-span {
325
margin-top: 10px;
336
}
347

public/components/expandable/expandable.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
11
// Import Third-party Dependencies
2-
import { LitElement, html } from "lit";
2+
import { LitElement, html, css } from "lit";
33
import { when } from "lit/directives/when.js";
44

55
// Import Internal Dependencies
66
import { currentLang } from "../../common/utils";
7+
import "../icon/icon.js";
78

89
class Expandable extends LitElement {
10+
static styles = css`
11+
span.expandable {
12+
display: flex;
13+
align-items: center !important;
14+
justify-content: center !important;
15+
height: 35px;
16+
font-size: 13px;
17+
font-family: mononoki;
18+
background: none;
19+
color: #00B0FF;
20+
text-shadow: 1px 1px 1px rgb(20 20 20 / 50%);
21+
transition: all 0.2s linear;
22+
margin-top: 5px;
23+
}
24+
25+
span.expandable[data-value="opened"] {
26+
color: #F44336 !important;
27+
}
28+
29+
span.expandable:hover {
30+
cursor: pointer;
31+
}
32+
33+
span.expandable nsecure-icon {
34+
margin-right: 4px;
35+
margin-top: 1px;
36+
}
37+
`;
938
static properties = {
1039
onToggle: { type: Function },
1140
isClosed: { type: Boolean }
@@ -17,20 +46,15 @@ class Expandable extends LitElement {
1746
this.onToggle = () => void 0;
1847
}
1948

20-
// FIXME: must opt out from the shadow DOM for now because of to be able to apply CSS from fontello
21-
createRenderRoot() {
22-
return this;
23-
}
24-
2549
render() {
2650
const lang = currentLang();
2751

2852
return html`
2953
<span data-value=${this.isClosed ? "opened" : "closed"} @click=${this.#handleClick} class="expandable">
3054
${when(this.isClosed,
31-
() => html`<i class="icon-minus-squared-alt"></i>
55+
() => html`<nsecure-icon name="minus"></nsecure-icon>
3256
<p>${window.i18n[lang].home.showLess}</p>`,
33-
() => html`<i class="icon-plus-squared-alt"></i>
57+
() => html`<nsecure-icon name="plus"></nsecure-icon>
3458
<p>${window.i18n[lang].home.showMore}</p>`
3559
)}
3660
</span>

public/components/icon/icon.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Import Third-party Dependencies
2+
import { LitElement, html, css, nothing } from "lit";
3+
4+
// Constants
5+
const kIcons = {
6+
plus: html`
7+
<svg viewBox="0 0 804 1024" aria-hidden="true">
8+
<path
9+
fill="currentColor"
10+
d="M658.432 456.704v36.864q0 8.192-5.12 13.312t-13.312 5.12h-200.704v200.704q0 8.192-5.12
11+
13.312t-13.312 5.12h-36.864q-8.192 0-13.312-5.12t-5.12-13.312v-200.704h-200.704q-8.192
12+
0-13.312-5.12t-5.12-13.312v-36.864q0-7.168 5.12-12.288t13.312-5.12h200.704v-201.728q0-8.192
13+
5.12-13.312t13.312-5.12h36.864q8.192 0 13.312 5.12t5.12 13.312v201.728h200.704q8.192 0
14+
13.312 5.12t5.12 12.288zM731.136 712.704v-475.136q0-37.888-26.624-64.512t-64.512-26.624h-475.136q-37.888
15+
0-64.512 26.624t-27.648 64.512v475.136q0 37.888 27.648 64.512t64.512 27.648h475.136q37.888
16+
0 64.512-27.648t26.624-64.512zM804.864 237.568v475.136q0 68.608-48.128 116.736t-116.736
17+
48.128h-475.136q-68.608 0-116.736-48.128t-48.128-116.736v-475.136q0-67.584 48.128-115.712t116.736-49.152h475.136q67.584
18+
0 116.736 49.152t48.128 115.712z"/>
19+
</svg>
20+
`,
21+
minus: html`
22+
<svg viewBox="0 0 804 1024" aria-hidden="true">
23+
<path
24+
fill="currentColor"
25+
d="M658.432 456.704v36.864q0 8.192-5.12 13.312t-13.312 5.12h-475.136q-8.192 0-13.312-5.12t-5.12-13.312v-36.864q0-7.168
26+
5.12-12.288t13.312-5.12h475.136q8.192 0 13.312 5.12t5.12 12.288zM731.136
27+
712.704v-475.136q0-37.888-26.624-64.512t-64.512-26.624h-475.136q-37.888
28+
0-64.512 26.624t-27.648 64.512v475.136q0 37.888 27.648 64.512t64.512 27.648h475.136q37.888
29+
0 64.512-27.648t26.624-64.512zM804.864 237.568v475.136q0 68.608-48.128 116.736t-116.736
30+
48.128h-475.136q-68.608 0-116.736-48.128t-48.128-116.736v-475.136q0-67.584 48.128-115.712t116.736-49.152h475.136q67.584
31+
0 116.736 49.152t48.128 115.712z"/>
32+
</svg>
33+
`
34+
};
35+
36+
export class Icon extends LitElement {
37+
static styles = css`
38+
:host {
39+
width: 1em;
40+
height: 1em;
41+
margin-right: 0.2em;
42+
margin-right: 0.2em;
43+
display: inline-block;
44+
}
45+
svg {
46+
width: 100%;
47+
height: 100%;
48+
fill: currentColor;
49+
}
50+
`;
51+
52+
static properties = {
53+
name: { type: String },
54+
size: { type: String }
55+
};
56+
57+
render() {
58+
if (!(this.name in kIcons)) {
59+
return nothing;
60+
}
61+
62+
return kIcons[this.name];
63+
}
64+
}
65+
66+
customElements.define("nsecure-icon", Icon);

0 commit comments

Comments
 (0)