1 | import '@polymer/iron-flex-layout/iron-flex-layout.js';
|
2 | import '@polymer/marked-element/marked-element.js';
|
3 | import '@polymer/prism-element/prism-highlighter.js';
|
4 | import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
|
5 | import { close } from '@kano/icons/ui.js';
|
6 | import { code } from '@kano/icons/social.js';
|
7 |
|
8 | class KwcCodeDisplay extends PolymerElement {
|
9 | static get template() {
|
10 | return html`
|
11 | <style>
|
12 | :host {
|
13 | position: absolute;
|
14 | top:0;
|
15 | right: 0;
|
16 | left: 0;
|
17 | bottom: 0;
|
18 | @apply --layout-vertical;
|
19 | @apply --layout-center;
|
20 | @apply --layout-start-justified;
|
21 | background-color: rgba(50, 50, 50, 0.8);
|
22 | padding: 50px 16px 0 16px;
|
23 | width: 100%;
|
24 | z-index: 100;
|
25 | }
|
26 | .code {
|
27 | width: 100%;
|
28 | height: 100%;
|
29 | }
|
30 |
|
31 | .code-contents {
|
32 | @apply --layout-vertical;
|
33 | @apply --layout-center;
|
34 | @apply --layout-start-justified;
|
35 | height: 100%;
|
36 | margin: auto;
|
37 | max-width: 880px;
|
38 | width: 100%;
|
39 | }
|
40 |
|
41 | .code-header {
|
42 | @apply --layout-horizontal;
|
43 | @apply --layout-center;
|
44 | @apply --layout-justified;
|
45 | border-bottom: 1px solid var(--color-grey);
|
46 | color: white;
|
47 | padding-bottom: 16px;
|
48 | width: 100%;
|
49 | box-sizing: border-box;
|
50 | }
|
51 |
|
52 | .code-icon {
|
53 | display: inline-block;
|
54 | width: 24px;
|
55 | height: 24px;
|
56 | fill: var(--color-azure);
|
57 | margin-right: 16px;
|
58 | vertical-align: -25%;
|
59 | }
|
60 |
|
61 | .code-title {
|
62 | margin: 0;
|
63 | text-transform: uppercase;
|
64 | }
|
65 |
|
66 | .close-button {
|
67 | -webkit-appearance: none;
|
68 | appearance: none;
|
69 | background-color: var(--color-grey);
|
70 | border: 0;
|
71 | border-radius: 3px;
|
72 | cursor: pointer;
|
73 | padding: 8px;
|
74 | }
|
75 |
|
76 | .close-button:focus {
|
77 | outline: 0;
|
78 | }
|
79 |
|
80 | .close-button-icon {
|
81 | color: white;
|
82 | height: 16px;
|
83 | width: 16px;
|
84 | }
|
85 |
|
86 | .code-main {
|
87 | @apply --layout-horizontal;
|
88 | @apply --layout-start;
|
89 | @apply --layout-justified;
|
90 | overflow-y: scroll;
|
91 | padding: 16px 0;
|
92 | width: 100%;
|
93 | }
|
94 |
|
95 | .line-numbers {
|
96 | @apply --layout-flex-1;
|
97 | color: white;
|
98 | font-family: monospace;
|
99 | font-size: 14px;
|
100 | line-height: 18px;
|
101 | opacity: 0.1;
|
102 | padding: 1em 16px 0 0;
|
103 | position: relative;
|
104 | text-align: center;
|
105 | }
|
106 |
|
107 | marked-element {
|
108 | @apply --layout-flex-12;
|
109 | font-size: 14px;
|
110 | line-height: 18px;
|
111 | width: 100%;
|
112 | }
|
113 |
|
114 | .markdown-html {
|
115 | color: white;
|
116 | }
|
117 |
|
118 | .markdown-html .token.number {
|
119 | color: var(--color-amber);
|
120 | }
|
121 |
|
122 | .markdown-html .token.function,
|
123 | .markdown-html .token.keyword {
|
124 | color: #d356cf;
|
125 | }
|
126 |
|
127 | .markdown-html .token.title {
|
128 | color: var(--color-kano-orange);
|
129 | }
|
130 |
|
131 | .markdown-html .token.string {
|
132 | color: var(--color-grassland);
|
133 | }
|
134 |
|
135 | .markdown-html .token.punctuation,
|
136 | .markdown-html .token.operator {
|
137 | color: white;
|
138 | background: transparent;
|
139 | }
|
140 | </style>
|
141 | <div class="code">
|
142 | <div class="code-contents">
|
143 | <div class="code-header">
|
144 | <h3 class="code-title">
|
145 | <div class="icon code-icon">${code}</div>
|
146 | [[codeType]]
|
147 | </h3>
|
148 | <button type="button" class="close-button" on-tap="_hideCode">
|
149 | <div class="icon close-button-icon">${close}</div>
|
150 | </button>
|
151 | </div>
|
152 | <div class="code-main">
|
153 | <div class="line-numbers">
|
154 | <template is="dom-repeat" items="[[lines]]" as="line">
|
155 | <div class="line-number">[[line]]</div>
|
156 | </template>
|
157 | </div>
|
158 | <prism-highlighter></prism-highlighter>
|
159 | <marked-element id="code" markdown="[[code]]">
|
160 | <div slot="markdown-html" class="markdown-html"></div>
|
161 | </marked-element>
|
162 | </div>
|
163 | </div>
|
164 | </div>
|
165 | `;
|
166 | }
|
167 | static get properties() {
|
168 | return {
|
169 | |
170 |
|
171 |
|
172 |
|
173 | lines: {
|
174 | type: Array,
|
175 | value: null,
|
176 | },
|
177 | |
178 |
|
179 |
|
180 |
|
181 | code: {
|
182 | type: String,
|
183 | value: null,
|
184 | },
|
185 | |
186 |
|
187 |
|
188 |
|
189 | codeType: {
|
190 | type: String,
|
191 | value: 'Code',
|
192 | },
|
193 | };
|
194 | }
|
195 | |
196 |
|
197 |
|
198 | _hideCode() {
|
199 | this.dispatchEvent(new CustomEvent('hide-code'));
|
200 | }
|
201 | }
|
202 |
|
203 | customElements.define('kwc-code-display', KwcCodeDisplay);
|