UNPKG

3.17 kBJavaScriptView Raw
1var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5 return c > 3 && r && Object.defineProperty(target, key, r), r;
6};
7// https://spectrum.adobe.com/page/color-area/
8import { adoptedStyle, customElement, attribute, globalemitter, boolattribute, refobject, } from '@mantou/gem/lib/decorators';
9import { GemElement, html } from '@mantou/gem/lib/element';
10import { createCSSSheet, css, styleMap } from '@mantou/gem/lib/utils';
11import { theme } from '../lib/theme';
12import { commonHandle } from '../lib/hotkeys';
13import { focusStyle } from '../lib/styles';
14import './popover';
15import './color-panel';
16const style = createCSSSheet(css `
17 :host(:where(:not([hidden]))) {
18 cursor: pointer;
19 display: inline-flex;
20 font-size: 0.875em;
21 width: 4em;
22 overflow: hidden;
23 border-radius: ${theme.normalRound};
24 background: conic-gradient(
25 transparent 0.25turn,
26 #d3cfcf 0.25turn 0.5turn,
27 transparent 0.5turn 0.75turn,
28 #d3cfcf 0.75turn
29 )
30 top left / 1.2em 1.2em repeat;
31 }
32 .picker {
33 width: 100%;
34 height: calc(2.2em + 2px);
35 border-radius: ${theme.normalRound};
36 box-shadow: inset 0 0 0 1px #0002;
37 }
38`);
39/**
40 * @customElement dy-color-picker
41 */
42let DuoyunColorPickElement = class DuoyunColorPickElement extends GemElement {
43 constructor() {
44 super({ delegatesFocus: true });
45 this.render = () => {
46 return html `
47 <dy-popover
48 trigger="click"
49 ref=${this.popoverRef.ref}
50 .content=${html `
51 <dy-color-panel
52 style=${styleMap({ marginBlock: '.6em' })}
53 value=${this.value}
54 ?alpha=${this.alpha}
55 @change=${({ detail }) => this.change(detail)}
56 ></dy-color-panel>
57 `}
58 >
59 <div
60 role="combobox"
61 tabindex="0"
62 @keydown=${commonHandle}
63 class="picker"
64 style=${styleMap({ backgroundColor: this.value })}
65 ></div>
66 </dy-popover>
67 `;
68 };
69 }
70 showPicker() {
71 var _a;
72 (_a = this.popoverRef.element) === null || _a === void 0 ? void 0 : _a.click();
73 }
74};
75__decorate([
76 attribute
77], DuoyunColorPickElement.prototype, "value", void 0);
78__decorate([
79 boolattribute
80], DuoyunColorPickElement.prototype, "alpha", void 0);
81__decorate([
82 refobject
83], DuoyunColorPickElement.prototype, "popoverRef", void 0);
84__decorate([
85 globalemitter
86], DuoyunColorPickElement.prototype, "change", void 0);
87DuoyunColorPickElement = __decorate([
88 customElement('dy-color-picker'),
89 adoptedStyle(style),
90 adoptedStyle(focusStyle)
91], DuoyunColorPickElement);
92export { DuoyunColorPickElement };
93//# sourceMappingURL=color-picker.js.map
\No newline at end of file