@ahriknow/lux 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +127 -0
- package/README_zh-CN.md +127 -0
- package/dist/components/lux-button/index.iife.min.js +292 -0
- package/dist/components/lux-button/index.min.js +292 -0
- package/dist/components/lux-code/index.iife.min.js +290 -0
- package/dist/components/lux-code/index.min.js +290 -0
- package/dist/components/lux-dropdown/index.iife.min.js +162 -0
- package/dist/components/lux-dropdown/index.min.js +162 -0
- package/dist/components/lux-example/index.iife.min.js +88 -0
- package/dist/components/lux-example/index.min.js +88 -0
- package/dist/components/lux-icon/index.iife.min.js +22 -0
- package/dist/components/lux-icon/index.min.js +22 -0
- package/dist/components/lux-input/index.iife.min.js +238 -0
- package/dist/components/lux-input/index.min.js +238 -0
- package/dist/components/lux-layout/index.iife.min.js +90 -0
- package/dist/components/lux-layout/index.min.js +90 -0
- package/dist/components/lux-menu/index.iife.min.js +193 -0
- package/dist/components/lux-menu/index.min.js +193 -0
- package/dist/components/lux-scroll/index.iife.min.js +137 -0
- package/dist/components/lux-scroll/index.min.js +137 -0
- package/dist/components/lux-switch/index.iife.min.js +116 -0
- package/dist/components/lux-switch/index.min.js +116 -0
- package/dist/components/lux-table/index.iife.min.js +67 -0
- package/dist/components/lux-table/index.min.js +67 -0
- package/dist/lux.core.min.js +1 -0
- package/dist/lux.i18n.min.js +1 -0
- package/dist/lux.iife.js +1822 -0
- package/dist/lux.iife.js.map +1 -0
- package/dist/lux.iife.min.js +1 -0
- package/dist/lux.js +1792 -0
- package/dist/lux.js.map +1 -0
- package/dist/lux.min.js +1 -0
- package/dist/lux.router.min.js +1 -0
- package/dist/lux.template.min.js +1 -0
- package/dist/lux.theme.min.js +1 -0
- package/dist/themes/dark.css +130 -0
- package/dist/themes/light.css +128 -0
- package/package.json +64 -0
- package/src/components/lux-button/index.js +319 -0
- package/src/components/lux-code/index.js +382 -0
- package/src/components/lux-dropdown/index.js +256 -0
- package/src/components/lux-example/index.js +117 -0
- package/src/components/lux-icon/index.js +180 -0
- package/src/components/lux-input/index.js +363 -0
- package/src/components/lux-layout/index.js +222 -0
- package/src/components/lux-menu/index.js +283 -0
- package/src/components/lux-scroll/index.js +349 -0
- package/src/components/lux-switch/index.js +203 -0
- package/src/components/lux-table/index.js +105 -0
- package/src/core.js +7 -0
- package/src/element.js +477 -0
- package/src/i18n/format.js +108 -0
- package/src/i18n/index.js +102 -0
- package/src/i18n/locale.js +26 -0
- package/src/index.js +22 -0
- package/src/router.js +330 -0
- package/src/template.js +402 -0
- package/src/theme/color.js +148 -0
- package/src/theme/create.js +97 -0
- package/src/theme/index.js +2 -0
- package/src/theme/tokens.js +128 -0
- package/src/themes/dark.css +130 -0
- package/src/themes/light.css +128 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lux-code — Code display component with optional highlight.js integration
|
|
3
|
+
*
|
|
4
|
+
* Props:
|
|
5
|
+
* code — code content (string)
|
|
6
|
+
* language — language hint for highlight.js (optional)
|
|
7
|
+
* show-header — show mac-style header (boolean)
|
|
8
|
+
* show-language — show language label in header (boolean, default true)
|
|
9
|
+
* show-copy — show copy button (boolean, default true)
|
|
10
|
+
*
|
|
11
|
+
* Events:
|
|
12
|
+
* copy — fired when copy button is clicked, detail: { code }
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { html, css, LuxElement, registerComponent, classMap } from '../../index.js';
|
|
16
|
+
|
|
17
|
+
const styles = css`
|
|
18
|
+
:host {
|
|
19
|
+
display: block;
|
|
20
|
+
position: relative;
|
|
21
|
+
margin: 12px 0;
|
|
22
|
+
border-radius: var(--lux-radius, 6px);
|
|
23
|
+
border: 1px solid rgb(var(--lux-code-border, 226 232 240));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:host(.has-fixed-height) {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
:host(.has-fixed-height) .code-body {
|
|
32
|
+
flex: 1;
|
|
33
|
+
min-height: 0;
|
|
34
|
+
overflow: auto;
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
:host(.has-fixed-height) pre {
|
|
40
|
+
flex: 1;
|
|
41
|
+
min-height: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ── Header ── */
|
|
45
|
+
.header {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: space-between;
|
|
49
|
+
padding: 4px 14px;
|
|
50
|
+
background: rgb(var(--lux-code-header, 241 245 249));
|
|
51
|
+
border-bottom: 1px solid rgb(var(--lux-code-border, 226 232 240));
|
|
52
|
+
font-size: 12px;
|
|
53
|
+
color: rgb(var(--lux-text-muted, 100 116 139));
|
|
54
|
+
}
|
|
55
|
+
.header.hidden {
|
|
56
|
+
display: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.dots {
|
|
60
|
+
display: flex;
|
|
61
|
+
gap: 8px;
|
|
62
|
+
}
|
|
63
|
+
.dot {
|
|
64
|
+
width: 12px;
|
|
65
|
+
height: 12px;
|
|
66
|
+
border-radius: 50%;
|
|
67
|
+
}
|
|
68
|
+
.dot-red {
|
|
69
|
+
background: #ff5f57;
|
|
70
|
+
}
|
|
71
|
+
.dot-yellow {
|
|
72
|
+
background: #ffbd2e;
|
|
73
|
+
}
|
|
74
|
+
.dot-green {
|
|
75
|
+
background: #28c840;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.header-right {
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
gap: 8px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.lang-label {
|
|
85
|
+
font-size: 11px;
|
|
86
|
+
color: rgb(var(--lux-text-muted, 100 116 139));
|
|
87
|
+
opacity: 0.7;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.copy-btn {
|
|
91
|
+
display: inline-flex;
|
|
92
|
+
align-items: center;
|
|
93
|
+
justify-content: center;
|
|
94
|
+
padding: 4px;
|
|
95
|
+
border: none;
|
|
96
|
+
border-radius: 4px;
|
|
97
|
+
background: transparent;
|
|
98
|
+
color: rgb(var(--lux-text-secondary, 148 163 184));
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
transition: all 0.15s;
|
|
101
|
+
}
|
|
102
|
+
.copy-btn:hover {
|
|
103
|
+
background: rgb(var(--lux-hover, 0 0 0 / 5%));
|
|
104
|
+
color: rgb(var(--lux-text, 15 23 42));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* ── Floating copy (no header) ── */
|
|
108
|
+
.copy-float {
|
|
109
|
+
position: absolute;
|
|
110
|
+
top: 8px;
|
|
111
|
+
right: 8px;
|
|
112
|
+
display: none;
|
|
113
|
+
align-items: center;
|
|
114
|
+
justify-content: center;
|
|
115
|
+
width: 32px;
|
|
116
|
+
height: 32px;
|
|
117
|
+
border-radius: 6px;
|
|
118
|
+
background: rgb(var(--lux-code-header, 241 245 249));
|
|
119
|
+
border: 1px solid rgb(var(--lux-code-border, 226 232 240));
|
|
120
|
+
color: rgb(var(--lux-text-secondary, 148 163 184));
|
|
121
|
+
cursor: pointer;
|
|
122
|
+
transition: all 0.15s;
|
|
123
|
+
z-index: 1;
|
|
124
|
+
}
|
|
125
|
+
.copy-float:hover {
|
|
126
|
+
background: rgb(var(--lux-hover, 0 0 0 / 5%));
|
|
127
|
+
color: rgb(var(--lux-text, 15 23 42));
|
|
128
|
+
}
|
|
129
|
+
:host(:not([show-header]):hover) .copy-float {
|
|
130
|
+
display: flex;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* ── Code block ── */
|
|
134
|
+
.code-body {
|
|
135
|
+
padding: 14px 18px;
|
|
136
|
+
position: relative;
|
|
137
|
+
background: rgb(var(--lux-code-bg, 248 250 252));
|
|
138
|
+
border-radius: 0 0 var(--lux-radius, 6px) var(--lux-radius, 6px);
|
|
139
|
+
overflow: auto;
|
|
140
|
+
}
|
|
141
|
+
:host([show-header]) .code-body {
|
|
142
|
+
border-radius: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pre {
|
|
146
|
+
margin: 0;
|
|
147
|
+
padding: 0;
|
|
148
|
+
font-size: 13px;
|
|
149
|
+
line-height: 1.7;
|
|
150
|
+
font-family: var(--lux-font-mono, 'SF Mono', Consolas, monospace);
|
|
151
|
+
color: rgb(var(--lux-code-text, 51 65 85));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
pre code {
|
|
155
|
+
display: block;
|
|
156
|
+
padding: 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.code-body::-webkit-scrollbar {
|
|
160
|
+
width: 8px;
|
|
161
|
+
height: 8px;
|
|
162
|
+
}
|
|
163
|
+
.code-body::-webkit-scrollbar-track {
|
|
164
|
+
background: transparent;
|
|
165
|
+
}
|
|
166
|
+
.code-body::-webkit-scrollbar-thumb {
|
|
167
|
+
background: rgb(var(--lux-scrollbar, 180 196 214));
|
|
168
|
+
border-radius: 4px;
|
|
169
|
+
}
|
|
170
|
+
.code-body::-webkit-scrollbar-thumb:hover {
|
|
171
|
+
background: rgb(var(--lux-text-muted, 100 116 139));
|
|
172
|
+
}
|
|
173
|
+
.code-body {
|
|
174
|
+
scrollbar-width: thin;
|
|
175
|
+
scrollbar-color: rgb(var(--lux-scrollbar, 180 196 214)) transparent;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
pre code {
|
|
179
|
+
display: block;
|
|
180
|
+
font-family: inherit;
|
|
181
|
+
font-size: inherit;
|
|
182
|
+
line-height: inherit;
|
|
183
|
+
background: transparent;
|
|
184
|
+
padding: 0;
|
|
185
|
+
white-space: pre;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* ── highlight.js token styles via CSS variables ── */
|
|
189
|
+
.hljs-keyword,
|
|
190
|
+
.hljs-doctag,
|
|
191
|
+
.hljs-template-tag,
|
|
192
|
+
.hljs-template-variable,
|
|
193
|
+
.hljs-type,
|
|
194
|
+
.hljs-variable.language_ {
|
|
195
|
+
color: rgb(var(--lux-code-keyword));
|
|
196
|
+
}
|
|
197
|
+
.hljs-string,
|
|
198
|
+
.hljs-meta .hljs-string,
|
|
199
|
+
.hljs-regexp {
|
|
200
|
+
color: rgb(var(--lux-code-string));
|
|
201
|
+
}
|
|
202
|
+
.hljs-number,
|
|
203
|
+
.hljs-literal,
|
|
204
|
+
.hljs-attr,
|
|
205
|
+
.hljs-attribute,
|
|
206
|
+
.hljs-selector-attr,
|
|
207
|
+
.hljs-selector-class,
|
|
208
|
+
.hljs-selector-id,
|
|
209
|
+
.hljs-variable {
|
|
210
|
+
color: rgb(var(--lux-code-number));
|
|
211
|
+
}
|
|
212
|
+
.hljs-comment,
|
|
213
|
+
.hljs-quote,
|
|
214
|
+
.hljs-formula,
|
|
215
|
+
.hljs-code {
|
|
216
|
+
color: rgb(var(--lux-code-comment));
|
|
217
|
+
font-style: italic;
|
|
218
|
+
}
|
|
219
|
+
.hljs-title.class_,
|
|
220
|
+
.hljs-title.class_.inherited__ {
|
|
221
|
+
color: rgb(var(--lux-code-class));
|
|
222
|
+
}
|
|
223
|
+
.hljs-title.function_ {
|
|
224
|
+
color: rgb(var(--lux-code-function));
|
|
225
|
+
}
|
|
226
|
+
.hljs-variable {
|
|
227
|
+
color: rgb(var(--lux-code-variable));
|
|
228
|
+
}
|
|
229
|
+
.hljs-tag,
|
|
230
|
+
.hljs-name,
|
|
231
|
+
.hljs-selector-pseudo,
|
|
232
|
+
.hljs-selector-tag {
|
|
233
|
+
color: rgb(var(--lux-code-tag));
|
|
234
|
+
}
|
|
235
|
+
.hljs-attr {
|
|
236
|
+
color: rgb(var(--lux-code-attr));
|
|
237
|
+
}
|
|
238
|
+
.hljs-selector-class {
|
|
239
|
+
color: rgb(var(--lux-code-selector));
|
|
240
|
+
}
|
|
241
|
+
.hljs-literal {
|
|
242
|
+
color: rgb(var(--lux-code-literal));
|
|
243
|
+
}
|
|
244
|
+
.hljs-symbol {
|
|
245
|
+
color: rgb(var(--lux-code-symbol));
|
|
246
|
+
}
|
|
247
|
+
.hljs-built_in {
|
|
248
|
+
color: rgb(var(--lux-code-built-in));
|
|
249
|
+
}
|
|
250
|
+
.hljs-meta {
|
|
251
|
+
color: rgb(var(--lux-code-meta));
|
|
252
|
+
}
|
|
253
|
+
.hljs-section {
|
|
254
|
+
color: rgb(var(--lux-code-section));
|
|
255
|
+
font-weight: 700;
|
|
256
|
+
}
|
|
257
|
+
.hljs-bullet {
|
|
258
|
+
color: rgb(var(--lux-code-bullet));
|
|
259
|
+
}
|
|
260
|
+
.hljs-operator {
|
|
261
|
+
color: rgb(var(--lux-code-operator));
|
|
262
|
+
}
|
|
263
|
+
.hljs-punctuation {
|
|
264
|
+
color: rgb(var(--lux-code-punctuation));
|
|
265
|
+
}
|
|
266
|
+
.hljs-subst {
|
|
267
|
+
color: rgb(var(--lux-code-text));
|
|
268
|
+
}
|
|
269
|
+
.hljs-addition {
|
|
270
|
+
color: rgb(var(--lux-code-addition));
|
|
271
|
+
}
|
|
272
|
+
.hljs-deletion {
|
|
273
|
+
color: rgb(var(--lux-code-deletion));
|
|
274
|
+
}
|
|
275
|
+
.hljs-emphasis {
|
|
276
|
+
font-style: italic;
|
|
277
|
+
}
|
|
278
|
+
.hljs-strong {
|
|
279
|
+
font-weight: 700;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.copied {
|
|
283
|
+
color: rgb(var(--lux-success, 34 197 94)) !important;
|
|
284
|
+
}
|
|
285
|
+
`;
|
|
286
|
+
|
|
287
|
+
const COPY_SVG = html`<span class="icon-svg" style="width:14px;height:14px;fill:currentColor"
|
|
288
|
+
><svg viewBox="0 0 24 24">
|
|
289
|
+
<path
|
|
290
|
+
d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"
|
|
291
|
+
/></svg
|
|
292
|
+
></span>`;
|
|
293
|
+
|
|
294
|
+
class LuxCode extends LuxElement {
|
|
295
|
+
static styles = styles;
|
|
296
|
+
|
|
297
|
+
static properties = {
|
|
298
|
+
code: { type: String },
|
|
299
|
+
language: { type: String, reflect: true },
|
|
300
|
+
showHeader: { type: Boolean, attribute: 'show-header', reflect: true },
|
|
301
|
+
showLanguage: { type: Boolean, attribute: 'show-language', reflect: true },
|
|
302
|
+
showCopy: { type: Boolean, attribute: 'show-copy', reflect: true },
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
constructor() {
|
|
306
|
+
super();
|
|
307
|
+
this.code = this.code || '';
|
|
308
|
+
this.language = this.language || '';
|
|
309
|
+
this.showHeader = this.showHeader ?? false;
|
|
310
|
+
this.showLanguage = this.showLanguage ?? true;
|
|
311
|
+
this.showCopy = this.showCopy ?? true;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
updated() {
|
|
315
|
+
this._highlight();
|
|
316
|
+
this._checkHeight();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
_checkHeight() {
|
|
320
|
+
const host = this.shadowRoot.host;
|
|
321
|
+
const style = host.getAttribute('style') || '';
|
|
322
|
+
const hasHeight = /height\s*:/i.test(style);
|
|
323
|
+
host.classList.toggle('has-fixed-height', hasHeight);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
_highlight() {
|
|
327
|
+
const codeEl = this.renderRoot.querySelector('code');
|
|
328
|
+
if (!codeEl || !this.code) return;
|
|
329
|
+
|
|
330
|
+
codeEl.textContent = this.code;
|
|
331
|
+
|
|
332
|
+
const hljs = window.hljs;
|
|
333
|
+
if (hljs) {
|
|
334
|
+
const lang = String(this.language || '');
|
|
335
|
+
if (lang) {
|
|
336
|
+
codeEl.className = `language-${lang}`;
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
hljs.highlightElement(codeEl);
|
|
340
|
+
} catch (e) {
|
|
341
|
+
// ignore
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async _copy() {
|
|
347
|
+
try {
|
|
348
|
+
await navigator.clipboard.writeText(this.code);
|
|
349
|
+
const btns = this.renderRoot.querySelectorAll('.copy-btn, .copy-float');
|
|
350
|
+
btns.forEach((btn) => {
|
|
351
|
+
btn.classList.add('copied');
|
|
352
|
+
setTimeout(() => btn.classList.remove('copied'), 2000);
|
|
353
|
+
});
|
|
354
|
+
this.emit('copy', { code: this.code });
|
|
355
|
+
} catch {
|
|
356
|
+
// clipboard API not available
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
render() {
|
|
361
|
+
return html`
|
|
362
|
+
<div class=${classMap({ header: true, hidden: !this.showHeader })}>
|
|
363
|
+
<div class="dots">
|
|
364
|
+
<span class="dot dot-red"></span>
|
|
365
|
+
<span class="dot dot-yellow"></span>
|
|
366
|
+
<span class="dot dot-green"></span>
|
|
367
|
+
</div>
|
|
368
|
+
<div class="header-right">
|
|
369
|
+
${this.showLanguage ? html`<span class="lang-label">${this.language || 'text'}</span>` : ''}
|
|
370
|
+
${this.showCopy ? html`<button class="copy-btn" @click=${() => this._copy()}>${COPY_SVG}</button>` : ''}
|
|
371
|
+
</div>
|
|
372
|
+
</div>
|
|
373
|
+
${!this.showHeader && this.showCopy ? html`<button class="copy-float" @click=${() => this._copy()}>${COPY_SVG}</button>` : ''}
|
|
374
|
+
<div class="code-body">
|
|
375
|
+
<pre><code></code></pre>
|
|
376
|
+
</div>
|
|
377
|
+
`;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
registerComponent('lux-code', LuxCode);
|
|
382
|
+
export default LuxCode;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { html, css, LuxElement, registerComponent, classMap, repeat } from '../../index.js';
|
|
2
|
+
|
|
3
|
+
const ARROW_SVG = html`<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor">
|
|
4
|
+
<path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z" />
|
|
5
|
+
</svg>`;
|
|
6
|
+
const CLEAR_SVG = html`<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor">
|
|
7
|
+
<path
|
|
8
|
+
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
|
|
9
|
+
/>
|
|
10
|
+
</svg>`;
|
|
11
|
+
|
|
12
|
+
const styles = css`
|
|
13
|
+
:host {
|
|
14
|
+
display: inline-block;
|
|
15
|
+
position: relative;
|
|
16
|
+
}
|
|
17
|
+
.trigger {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: 6px;
|
|
21
|
+
width: 100%;
|
|
22
|
+
padding: 6px 12px;
|
|
23
|
+
border: 1px solid rgb(var(--lux-border, 51 65 85));
|
|
24
|
+
border-radius: var(--lux-radius, 6px);
|
|
25
|
+
background: rgb(var(--lux-card, 30 41 59));
|
|
26
|
+
color: rgb(var(--lux-text, 241 245 249));
|
|
27
|
+
font-size: 13px;
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
user-select: none;
|
|
30
|
+
white-space: nowrap;
|
|
31
|
+
box-sizing: border-box;
|
|
32
|
+
}
|
|
33
|
+
.trigger:hover {
|
|
34
|
+
border-color: rgb(var(--lux-primary-500, 99 91 218));
|
|
35
|
+
background: rgb(var(--lux-hover, 255 255 255 / 5%));
|
|
36
|
+
}
|
|
37
|
+
.placeholder {
|
|
38
|
+
color: rgb(var(--lux-text-muted, 100 116 139));
|
|
39
|
+
}
|
|
40
|
+
.end-icons {
|
|
41
|
+
display: inline-flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
position: relative;
|
|
45
|
+
width: 18px;
|
|
46
|
+
height: 18px;
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
margin-left: auto;
|
|
49
|
+
}
|
|
50
|
+
.arrow,
|
|
51
|
+
.clear {
|
|
52
|
+
display: inline-flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
position: absolute;
|
|
56
|
+
top: 0;
|
|
57
|
+
left: 0;
|
|
58
|
+
width: 18px;
|
|
59
|
+
height: 18px;
|
|
60
|
+
transition: opacity 150ms ease;
|
|
61
|
+
}
|
|
62
|
+
.arrow {
|
|
63
|
+
color: rgb(var(--lux-text-secondary, 148 163 184));
|
|
64
|
+
transition:
|
|
65
|
+
transform 150ms ease,
|
|
66
|
+
opacity 150ms ease;
|
|
67
|
+
}
|
|
68
|
+
:host([open]) .arrow {
|
|
69
|
+
transform: rotate(180deg);
|
|
70
|
+
}
|
|
71
|
+
.clear {
|
|
72
|
+
display: none;
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
color: rgb(var(--lux-text-secondary, 148 163 184));
|
|
75
|
+
z-index: 1;
|
|
76
|
+
}
|
|
77
|
+
.clear:hover {
|
|
78
|
+
color: rgb(var(--lux-text, 241 245 249));
|
|
79
|
+
}
|
|
80
|
+
:host([clearable][has-value]:hover) .clear {
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
}
|
|
83
|
+
:host([clearable][has-value]:hover) .arrow {
|
|
84
|
+
opacity: 0;
|
|
85
|
+
pointer-events: none;
|
|
86
|
+
}
|
|
87
|
+
.menu {
|
|
88
|
+
position: absolute;
|
|
89
|
+
top: calc(100% + 4px);
|
|
90
|
+
left: 0;
|
|
91
|
+
min-width: 100%;
|
|
92
|
+
max-height: 200px;
|
|
93
|
+
overflow-y: auto;
|
|
94
|
+
background: rgb(var(--lux-card, 30 41 59));
|
|
95
|
+
border: 1px solid rgb(var(--lux-border, 51 65 85));
|
|
96
|
+
border-radius: var(--lux-radius, 6px);
|
|
97
|
+
box-shadow: 0 4px 12px rgb(0 0 0 / 30%);
|
|
98
|
+
z-index: 1000;
|
|
99
|
+
padding: 4px 0;
|
|
100
|
+
display: none;
|
|
101
|
+
}
|
|
102
|
+
:host([open]) .menu {
|
|
103
|
+
display: block;
|
|
104
|
+
}
|
|
105
|
+
.item {
|
|
106
|
+
display: block;
|
|
107
|
+
padding: 7px 12px;
|
|
108
|
+
font-size: 13px;
|
|
109
|
+
color: rgb(var(--lux-text, 241 245 249));
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
white-space: nowrap;
|
|
112
|
+
user-select: none;
|
|
113
|
+
}
|
|
114
|
+
.item:hover {
|
|
115
|
+
background: rgb(var(--lux-hover, 255 255 255 / 5%));
|
|
116
|
+
}
|
|
117
|
+
.item.active {
|
|
118
|
+
color: rgb(var(--lux-primary-400, 129 113 234));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* Size: sm */
|
|
122
|
+
:host([size='sm']) .trigger {
|
|
123
|
+
padding: 4px 8px;
|
|
124
|
+
font-size: 12px;
|
|
125
|
+
gap: 4px;
|
|
126
|
+
}
|
|
127
|
+
:host([size='sm']) .item {
|
|
128
|
+
padding: 5px 10px;
|
|
129
|
+
font-size: 12px;
|
|
130
|
+
}
|
|
131
|
+
:host([size='sm']) .end-icons {
|
|
132
|
+
width: 14px;
|
|
133
|
+
height: 14px;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* Size: lg */
|
|
137
|
+
:host([size='lg']) .trigger {
|
|
138
|
+
padding: 10px 16px;
|
|
139
|
+
font-size: 15px;
|
|
140
|
+
gap: 8px;
|
|
141
|
+
}
|
|
142
|
+
:host([size='lg']) .item {
|
|
143
|
+
padding: 10px 16px;
|
|
144
|
+
font-size: 15px;
|
|
145
|
+
}
|
|
146
|
+
:host([size='lg']) .end-icons {
|
|
147
|
+
width: 22px;
|
|
148
|
+
height: 22px;
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
|
|
152
|
+
class LuxDropdown extends LuxElement {
|
|
153
|
+
static styles = styles;
|
|
154
|
+
|
|
155
|
+
static properties = {
|
|
156
|
+
options: { type: Array, attribute: false },
|
|
157
|
+
value: { type: String, reflect: true },
|
|
158
|
+
placeholder: { type: String, reflect: true },
|
|
159
|
+
open: { type: Boolean, reflect: true },
|
|
160
|
+
clearable: { type: Boolean, reflect: true },
|
|
161
|
+
size: { type: String, reflect: true },
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
constructor() {
|
|
165
|
+
super();
|
|
166
|
+
this.placeholder = '';
|
|
167
|
+
this.value = '';
|
|
168
|
+
this.clearable = false;
|
|
169
|
+
this._onDocClickBound = false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
connectedCallback() {
|
|
173
|
+
super.connectedCallback();
|
|
174
|
+
this._bindDocClick();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_bindDocClick() {
|
|
178
|
+
if (this._onDocClickBound) return;
|
|
179
|
+
this._onDocClick = this._onDocClick.bind(this);
|
|
180
|
+
document.addEventListener('click', this._onDocClick, true);
|
|
181
|
+
this._onDocClickBound = true;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
disconnectedCallback() {
|
|
185
|
+
super.disconnectedCallback();
|
|
186
|
+
document.removeEventListener('click', this._onDocClick, true);
|
|
187
|
+
this._onDocClickBound = false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
updated() {
|
|
191
|
+
if (this.value) {
|
|
192
|
+
this.setAttribute('has-value', '');
|
|
193
|
+
} else {
|
|
194
|
+
this.removeAttribute('has-value');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
_onDocClick(e) {
|
|
199
|
+
if (!this.contains(e.target)) {
|
|
200
|
+
this.open = false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
_toggle() {
|
|
205
|
+
this.open = !this.open;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
_clear() {
|
|
209
|
+
this.value = '';
|
|
210
|
+
this.emit('clear');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
_select(opt) {
|
|
214
|
+
this.value = String(opt.value);
|
|
215
|
+
this.open = false;
|
|
216
|
+
this.emit('change', { value: opt.value, label: opt.label ?? opt.value });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
render() {
|
|
220
|
+
const opts = Array.isArray(this.options) ? this.options : [];
|
|
221
|
+
const matched = opts.find((o) => String(o.value) === String(this.value));
|
|
222
|
+
const text = matched ? (matched.label ?? matched.value) : '';
|
|
223
|
+
const ph = this.placeholder;
|
|
224
|
+
const triggerText = text || ph;
|
|
225
|
+
const isPh = !text && !!ph;
|
|
226
|
+
|
|
227
|
+
return html`
|
|
228
|
+
<div class="trigger" @click=${() => this._toggle()}>
|
|
229
|
+
<span class=${classMap({ placeholder: isPh })}>${triggerText}</span>
|
|
230
|
+
<span class="end-icons">
|
|
231
|
+
<span
|
|
232
|
+
class=${classMap({ clear: true })}
|
|
233
|
+
@click=${(e) => {
|
|
234
|
+
e.stopPropagation();
|
|
235
|
+
this._clear();
|
|
236
|
+
}}
|
|
237
|
+
>${CLEAR_SVG}</span
|
|
238
|
+
>
|
|
239
|
+
<span class="arrow">${ARROW_SVG}</span>
|
|
240
|
+
</span>
|
|
241
|
+
</div>
|
|
242
|
+
<div class="menu">
|
|
243
|
+
${repeat(
|
|
244
|
+
opts,
|
|
245
|
+
(opt) => opt.value,
|
|
246
|
+
(opt) => html`
|
|
247
|
+
<div class="item" @click=${() => this._select(opt)}>${opt.label ?? opt.value}</div>
|
|
248
|
+
`
|
|
249
|
+
)}
|
|
250
|
+
</div>
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
registerComponent('lux-dropdown', LuxDropdown);
|
|
256
|
+
export default LuxDropdown;
|