@pictogrammers/components 0.3.2 → 0.4.0
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/README.md +11 -12
- package/favicon.svg +20 -0
- package/index.html +67 -49
- package/main.js +2 -0
- package/main.js.LICENSE.txt +10 -0
- package/package.json +6 -6
- package/pg/annoy/README.md +0 -5
- package/pg/annoy/__examples__/basic/basic.css +3 -0
- package/pg/annoy/__examples__/basic/basic.html +4 -7
- package/pg/annoy/__examples__/basic/basic.ts +3 -1
- package/pg/annoy/annoy.css +29 -198
- package/pg/annoy/annoy.html +5 -56
- package/pg/annoy/annoy.ts +4 -25
- package/pg/app/README.md +11 -0
- package/pg/app/__examples__/basic/basic.css +8 -0
- package/pg/app/__examples__/basic/basic.html +15 -0
- package/pg/app/__examples__/basic/basic.ts +13 -0
- package/pg/app/app.css +108 -0
- package/pg/app/app.html +16 -0
- package/pg/app/app.ts +45 -0
- package/pg/app/index.ts +3 -0
- package/pg/avatar/__examples__/basic/basic.ts +5 -3
- package/pg/button/README.md +3 -0
- package/pg/button/button.css +13 -12
- package/pg/button/button.spec.ts +35 -0
- package/pg/button/button.ts +17 -12
- package/pg/buttonLink/buttonLink.css +3 -2
- package/pg/buttonMenu/README.md +54 -0
- package/pg/buttonMenu/__examples__/basic/basic.html +6 -0
- package/pg/buttonMenu/__examples__/basic/basic.ts +43 -0
- package/pg/buttonMenu/buttonMenu.css +12 -0
- package/pg/buttonMenu/buttonMenu.html +4 -0
- package/pg/buttonMenu/buttonMenu.ts +63 -0
- package/pg/buttonMenu/index.ts +3 -0
- package/pg/buttonToggle/__examples__/basic/basic.ts +2 -2
- package/pg/buttonToggle/__examples__/persist/persist.html +10 -0
- package/pg/buttonToggle/__examples__/persist/persist.ts +35 -0
- package/pg/cardUser/__examples__/basic/basic.ts +0 -1
- package/pg/cardUser/cardUser.css +2 -10
- package/pg/cardUser/cardUser.html +0 -5
- package/pg/cardUser/cardUser.ts +0 -6
- package/pg/database/README.md +1 -1
- package/pg/database/__examples__/basic/basic.html +2 -1
- package/pg/database/__examples__/basic/basic.ts +3 -3
- package/pg/dropdown/dropdown.ts +0 -19
- package/pg/grid/__examples__/basic/basic.html +2 -2
- package/pg/grid/__examples__/basic/basic.ts +3 -2
- package/pg/grid/grid.ts +0 -1
- package/pg/icon/README.md +6 -5
- package/pg/icon/__examples__/basic/basic.html +2 -2
- package/pg/icon/__examples__/basic/basic.ts +1 -1
- package/pg/icon/icon.ts +6 -0
- package/pg/inputCheckList/__examples__/basic/basic.ts +5 -5
- package/pg/inputCheckList/inputCheckList.ts +2 -0
- package/pg/inputFileLocal/inputFileLocal.css +3 -2
- package/pg/inputPixelEditor/README.md +132 -0
- package/pg/inputPixelEditor/__examples__/basic/basic.css +29 -0
- package/pg/inputPixelEditor/__examples__/basic/basic.html +63 -0
- package/pg/inputPixelEditor/__examples__/basic/basic.ts +200 -0
- package/pg/inputPixelEditor/__examples__/basic/openUtils.ts +41 -0
- package/pg/inputPixelEditor/__examples__/basic/saveUtil.ts +35 -0
- package/pg/inputPixelEditor/index.ts +3 -0
- package/pg/inputPixelEditor/inputPixelEditor.css +27 -0
- package/pg/inputPixelEditor/inputPixelEditor.html +3 -0
- package/pg/inputPixelEditor/inputPixelEditor.ts +839 -0
- package/pg/inputPixelEditor/utils/bitmapToMask.ts +202 -0
- package/pg/inputPixelEditor/utils/cloneGrid.ts +17 -0
- package/pg/inputPixelEditor/utils/constants.ts +1 -0
- package/pg/inputPixelEditor/utils/createLayer.ts +8 -0
- package/pg/inputPixelEditor/utils/debounce.ts +5 -0
- package/pg/inputPixelEditor/utils/diffGrid.ts +26 -0
- package/pg/inputPixelEditor/utils/fillGrid.ts +11 -0
- package/pg/inputPixelEditor/utils/getEllipseOutlinePixels.ts +105 -0
- package/pg/inputPixelEditor/utils/getEllipsePixels.ts +28 -0
- package/pg/inputPixelEditor/utils/getGuides.ts +232 -0
- package/pg/inputPixelEditor/utils/getLinePixels.ts +18 -0
- package/pg/inputPixelEditor/utils/getRectangleOutlinePixels.ts +20 -0
- package/pg/inputPixelEditor/utils/getRectanglePixels.ts +15 -0
- package/pg/inputPixelEditor/utils/inputMode.ts +8 -0
- package/pg/inputPixelEditor/utils/interateGrid.ts +7 -0
- package/pg/inputPixelEditor/utils/isEmptyGrid.ts +3 -0
- package/pg/inputPixelEditor/utils/maskToBitmap.ts +66 -0
- package/pg/inputRange/__examples__/basic/basic.ts +4 -4
- package/pg/inputRange/inputRange.ts +6 -4
- package/pg/inputSelect/README.md +1 -1
- package/pg/inputSelect/__examples__/basic/basic.ts +7 -5
- package/pg/inputSelect/inputSelect.css +15 -12
- package/pg/inputSelect/inputSelect.html +3 -3
- package/pg/inputSelect/inputSelect.ts +33 -30
- package/pg/inputText/__examples__/basic/basic.ts +6 -6
- package/pg/inputText/inputText.css +1 -0
- package/pg/inputUserSelect/README.md +1 -1
- package/pg/inputUserSelect/inputUserSelect.ts +1 -1
- package/pg/listTag/__examples__/basic/basic.ts +4 -5
- package/pg/markdown/README.md +17 -3
- package/pg/markdown/__examples__/basic/basic.ts +2 -2
- package/pg/markdown/__examples__/basic/constants.ts +1 -1
- package/pg/markdown/markdown.css +11 -0
- package/pg/menu/README.md +46 -0
- package/pg/menu/__examples__/basic/basic.html +6 -0
- package/pg/menu/__examples__/basic/basic.ts +46 -0
- package/pg/menu/index.ts +3 -0
- package/pg/menu/menu.css +19 -0
- package/pg/menu/menu.html +1 -0
- package/pg/menu/menu.ts +119 -0
- package/pg/menuDivider/README.md +7 -0
- package/pg/menuDivider/__examples__/basic/basic.html +3 -0
- package/pg/menuDivider/__examples__/basic/basic.ts +28 -0
- package/pg/menuDivider/index.ts +3 -0
- package/pg/menuDivider/menuDivider.css +9 -0
- package/pg/menuDivider/menuDivider.html +1 -0
- package/pg/menuDivider/menuDivider.ts +22 -0
- package/pg/menuIcon/menuIcon.ts +43 -36
- package/pg/menuItem/README.md +32 -0
- package/pg/menuItem/__examples__/basic/basic.html +26 -0
- package/pg/menuItem/__examples__/basic/basic.ts +41 -0
- package/pg/menuItem/index.ts +3 -0
- package/pg/menuItem/menuItem.css +97 -0
- package/pg/menuItem/menuItem.html +1 -0
- package/pg/menuItem/menuItem.ts +77 -0
- package/pg/menuItemIcon/README.md +32 -0
- package/pg/menuItemIcon/__examples__/basic/basic.html +34 -0
- package/pg/menuItemIcon/__examples__/basic/basic.ts +55 -0
- package/pg/menuItemIcon/index.ts +3 -0
- package/pg/menuItemIcon/menuItemIcon.css +106 -0
- package/pg/menuItemIcon/menuItemIcon.html +4 -0
- package/pg/menuItemIcon/menuItemIcon.ts +156 -0
- package/pg/modalAlert/__examples__/basic/basic.ts +1 -1
- package/pg/modalAlert/modalAlert.css +1 -4
- package/pg/modalAlert/modalAlert.ts +18 -4
- package/pg/modification/__examples__/basic/basic.ts +1 -2
- package/pg/modification/__examples__/basic/constants.ts +25 -50
- package/pg/modification/modification.ts +1 -1
- package/pg/overlay/overlay.ts +13 -12
- package/pg/overlayContextMenu/README.md +35 -0
- package/pg/overlayContextMenu/__examples__/basic/basic.css +23 -0
- package/pg/overlayContextMenu/__examples__/basic/basic.html +7 -0
- package/pg/overlayContextMenu/__examples__/basic/basic.ts +87 -0
- package/pg/overlayContextMenu/index.ts +3 -0
- package/pg/overlayContextMenu/overlayContextMenu.css +16 -0
- package/pg/overlayContextMenu/overlayContextMenu.html +3 -0
- package/pg/overlayContextMenu/overlayContextMenu.ts +98 -0
- package/pg/overlayMenu/README.md +33 -0
- package/pg/overlayMenu/__examples__/basic/basic.css +3 -0
- package/pg/overlayMenu/__examples__/basic/basic.html +5 -0
- package/pg/overlayMenu/__examples__/basic/basic.ts +62 -0
- package/pg/overlayMenu/index.ts +3 -0
- package/pg/overlayMenu/overlayMenu.css +16 -0
- package/pg/overlayMenu/overlayMenu.html +3 -0
- package/pg/overlayMenu/overlayMenu.ts +67 -0
- package/pg/overlaySelectMenu/README.md +33 -0
- package/pg/overlaySelectMenu/__examples__/basic/basic.css +3 -0
- package/pg/overlaySelectMenu/__examples__/basic/basic.html +5 -0
- package/pg/overlaySelectMenu/__examples__/basic/basic.ts +62 -0
- package/pg/overlaySelectMenu/index.ts +3 -0
- package/pg/overlaySelectMenu/overlaySelectMenu.css +17 -0
- package/pg/overlaySelectMenu/overlaySelectMenu.html +3 -0
- package/pg/overlaySelectMenu/overlaySelectMenu.ts +96 -0
- package/pg/overlaySubMenu/README.md +35 -0
- package/pg/overlaySubMenu/index.ts +3 -0
- package/pg/overlaySubMenu/overlaySubMenu.css +27 -0
- package/pg/overlaySubMenu/overlaySubMenu.html +3 -0
- package/pg/overlaySubMenu/overlaySubMenu.ts +103 -0
- package/pg/picker/picker.ts +1 -19
- package/pg/scroll/__examples__/basic/basic.ts +1 -1
- package/pg/search/__examples__/basic/basic.ts +10 -7
- package/pg/search/search.css +2 -2
- package/pg/shared/models/user.ts +0 -2
- package/pg/tab/tab.ts +0 -10
- package/pg/tabs/partials/tab.css +42 -0
- package/pg/tabs/partials/tab.ts +70 -0
- package/pg/tabs/tabs.css +0 -53
- package/pg/tabs/tabs.ts +54 -70
- package/pg/toast/README.md +35 -6
- package/pg/toast/__examples__/basic/basic.html +7 -0
- package/pg/toast/__examples__/basic/basic.ts +76 -0
- package/pg/toast/toast.css +3 -0
- package/pg/toast/toast.ts +20 -4
- package/pg/tooltip/addTooltip.ts +3 -1
- package/pg/tooltip/tooltip.ts +1 -1
- package/pg/tree/README.md +67 -0
- package/pg/tree/__examples__/basic/basic.html +10 -0
- package/pg/tree/__examples__/basic/basic.ts +162 -0
- package/pg/tree/index.ts +3 -0
- package/pg/tree/tree.css +28 -0
- package/pg/tree/tree.html +1 -0
- package/pg/tree/tree.ts +217 -0
- package/pg/treeButtonIcon/README.md +39 -0
- package/pg/treeButtonIcon/index.ts +3 -0
- package/pg/treeButtonIcon/treeButtonIcon.css +18 -0
- package/pg/treeButtonIcon/treeButtonIcon.html +3 -0
- package/pg/treeButtonIcon/treeButtonIcon.ts +42 -0
- package/pg/treeItem/README.md +3 -0
- package/pg/treeItem/index.ts +3 -0
- package/pg/treeItem/treeItem.css +263 -0
- package/pg/treeItem/treeItem.html +16 -0
- package/pg/treeItem/treeItem.ts +558 -0
- package/pgAnnoy.js +1 -0
- package/pgApp.js +1 -0
- package/pgAvatar.js +1 -0
- package/pgButton.js +1 -0
- package/pgButtonGroup.js +1 -0
- package/pgButtonLink.js +1 -0
- package/pgButtonMenu.js +1 -0
- package/pgButtonToggle.js +1 -0
- package/pgCard.js +1 -0
- package/pgCardUser.js +1 -0
- package/pgColor.js +1 -0
- package/pgDatabase.js +1 -0
- package/pgDropdown.js +1 -0
- package/pgGrid.js +1 -0
- package/pgHeader.js +1 -0
- package/pgIcon.js +1 -0
- package/pgInputCheck.js +1 -0
- package/pgInputCheckList.js +1 -0
- package/pgInputFileLocal.js +1 -0
- package/pgInputHexRgb.js +1 -0
- package/pgInputPixelEditor.js +1 -0
- package/pgInputRange.js +1 -0
- package/pgInputSelect.js +1 -0
- package/pgInputText.js +1 -0
- package/pgInputTextIcon.js +1 -0
- package/pgInputUserSelect.js +1 -0
- package/pgListTag.js +1 -0
- package/pgMarkdown.js +2 -0
- package/pgMarkdown.js.LICENSE.txt +10 -0
- package/pgMenu.js +1 -0
- package/pgMenuDivider.js +1 -0
- package/pgMenuIcon.js +1 -0
- package/pgMenuItem.js +1 -0
- package/pgMenuItemIcon.js +1 -0
- package/pgModalAlert.js +1 -0
- package/pgModification.js +1 -0
- package/pgNav.js +1 -0
- package/pgOverlay.js +1 -0
- package/pgOverlayContextMenu.js +1 -0
- package/pgOverlayMenu.js +1 -0
- package/pgOverlaySelectMenu.js +1 -0
- package/pgOverlaySubMenu.js +1 -0
- package/pgPicker.js +1 -0
- package/pgPreview.js +1 -0
- package/pgScroll.js +1 -0
- package/pgSearch.js +1 -0
- package/pgTab.js +1 -0
- package/pgTabs.js +1 -0
- package/pgToast.js +1 -0
- package/pgToasts.js +1 -0
- package/pgTooltip.js +1 -0
- package/pgTree.js +1 -0
- package/pgTreeButtonIcon.js +1 -0
- package/pgTreeItem.js +1 -0
- package/theme-ui3.css +31 -0
- package/@types/css.d.ts +0 -4
- package/@types/html.d.ts +0 -4
- package/dist/main.js +0 -3819
- package/dist/pgAnnoy.js +0 -116
- package/dist/pgAvatar.js +0 -136
- package/dist/pgButton.js +0 -116
- package/dist/pgButtonGroup.js +0 -116
- package/dist/pgButtonLink.js +0 -116
- package/dist/pgButtonToggle.js +0 -146
- package/dist/pgCard.js +0 -116
- package/dist/pgCardUser.js +0 -196
- package/dist/pgColor.js +0 -136
- package/dist/pgDatabase.js +0 -236
- package/dist/pgDropdown.js +0 -686
- package/dist/pgGrid.js +0 -126
- package/dist/pgHeader.js +0 -116
- package/dist/pgIcon.js +0 -116
- package/dist/pgInputCheck.js +0 -116
- package/dist/pgInputCheckList.js +0 -126
- package/dist/pgInputFileLocal.js +0 -116
- package/dist/pgInputHexRgb.js +0 -126
- package/dist/pgInputRange.js +0 -116
- package/dist/pgInputSelect.js +0 -116
- package/dist/pgInputText.js +0 -116
- package/dist/pgInputTextIcon.js +0 -176
- package/dist/pgInputUserSelect.js +0 -116
- package/dist/pgListTag.js +0 -136
- package/dist/pgMarkdown.js +0 -346
- package/dist/pgMenuIcon.js +0 -206
- package/dist/pgModalAlert.js +0 -126
- package/dist/pgModification.js +0 -396
- package/dist/pgNav.js +0 -116
- package/dist/pgOverlay.js +0 -96
- package/dist/pgPicker.js +0 -116
- package/dist/pgPreview.js +0 -116
- package/dist/pgScroll.js +0 -266
- package/dist/pgSearch.js +0 -146
- package/dist/pgTab.js +0 -116
- package/dist/pgTabs.js +0 -136
- package/dist/pgToast.js +0 -136
- package/dist/pgToasts.js +0 -136
- package/dist/pgTooltip.js +0 -126
package/pg/menu/menu.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Component, Prop, Part, forEach } from '@pictogrammers/element';
|
|
2
|
+
import PgMenuItem from '../menuItem/menuItem';
|
|
3
|
+
|
|
4
|
+
import template from './menu.html';
|
|
5
|
+
import style from './menu.css';
|
|
6
|
+
|
|
7
|
+
const noIcon = 'M0 0h24v24H0V0zm2 2v20h20V2H2z';
|
|
8
|
+
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'pg-menu',
|
|
11
|
+
style,
|
|
12
|
+
template
|
|
13
|
+
})
|
|
14
|
+
export default class PgMenu extends HTMLElement {
|
|
15
|
+
|
|
16
|
+
@Prop() items: any[] = [];
|
|
17
|
+
|
|
18
|
+
@Part() $items: HTMLDivElement;
|
|
19
|
+
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
forEach({
|
|
22
|
+
container: this.$items,
|
|
23
|
+
items: this.items,
|
|
24
|
+
type: (item) => {
|
|
25
|
+
return item.type ?? PgMenuItem;
|
|
26
|
+
},
|
|
27
|
+
create: ($item: any, item) => {
|
|
28
|
+
$item.addEventListener('close', (e: any) => {
|
|
29
|
+
const { depth } = e.detail;
|
|
30
|
+
this.dispatchEvent(new CustomEvent('close', {
|
|
31
|
+
detail: {
|
|
32
|
+
depth
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
$item.addEventListener('select', (e: any) => {
|
|
37
|
+
const { index } = e.detail;
|
|
38
|
+
this.dispatchEvent(new CustomEvent('select', {
|
|
39
|
+
detail: {
|
|
40
|
+
indexes: [index],
|
|
41
|
+
item
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
$item.addEventListener('up', (e: any) => {
|
|
46
|
+
const { index } = e.detail;
|
|
47
|
+
this.#focus(index - 1, -1, index);
|
|
48
|
+
});
|
|
49
|
+
$item.addEventListener('down', (e: any) => {
|
|
50
|
+
const { index } = e.detail;
|
|
51
|
+
this.#focus(index + 1, 1, index);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.$items.addEventListener('hasCheck', (e: any) => {
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
this.$items.classList.toggle('check', true);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#focus(index, fallback, initIndex) {
|
|
62
|
+
if (index === initIndex) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (index === -1) {
|
|
66
|
+
return this.#focus(this.items.length - 1, fallback, initIndex);
|
|
67
|
+
}
|
|
68
|
+
if (index >= this.items.length) {
|
|
69
|
+
return this.#focus(0, fallback, initIndex);
|
|
70
|
+
}
|
|
71
|
+
const item = this.$items.children[index] as any;
|
|
72
|
+
if (item.focusable === false || this.items[index].disabled) {
|
|
73
|
+
return this.#focus(index + fallback, fallback, initIndex);
|
|
74
|
+
}
|
|
75
|
+
item?.focus();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
focus(index) {
|
|
79
|
+
if (index === -1) {
|
|
80
|
+
this.#focus(0, 1, this.items.length - 1);
|
|
81
|
+
} else {
|
|
82
|
+
const item = this.$items.children[index] as HTMLElement;
|
|
83
|
+
item?.focus();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Calculate height of items + gap + padding
|
|
89
|
+
* @param startIndex Start index.
|
|
90
|
+
* @param endIndex End index.
|
|
91
|
+
*/
|
|
92
|
+
getItemOffset(startIndex, endIndex): number {
|
|
93
|
+
const computedStyle = getComputedStyle(this.$items);
|
|
94
|
+
let height = parseInt(computedStyle.getPropertyValue('padding-top'), 10);
|
|
95
|
+
const total = this.items.length;
|
|
96
|
+
if (startIndex > total || endIndex > total) {
|
|
97
|
+
throw new Error('startIndex or endIndex not within range of items');
|
|
98
|
+
}
|
|
99
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
100
|
+
const ele = this.$items.children[i] as any;
|
|
101
|
+
height += ele.getHeight();
|
|
102
|
+
}
|
|
103
|
+
return height;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get the height of an individiaual item.
|
|
108
|
+
* @param index Item index
|
|
109
|
+
* @returns {number} Item height
|
|
110
|
+
*/
|
|
111
|
+
getItemHeight(index) {
|
|
112
|
+
if (index > this.items.length) {
|
|
113
|
+
throw new Error('index outside range of items');
|
|
114
|
+
}
|
|
115
|
+
const ele = this.$items.children[index] as any;
|
|
116
|
+
return ele.getHeight();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Component, Part, Prop } from '@pictogrammers/element';
|
|
2
|
+
|
|
3
|
+
import PgMenu from '../../../menu/menu';
|
|
4
|
+
import PgMenuDivider from '../../menuDivider';
|
|
5
|
+
|
|
6
|
+
import template from './basic.html';
|
|
7
|
+
|
|
8
|
+
@Component({
|
|
9
|
+
selector: 'x-pg-menu-divider-basic',
|
|
10
|
+
template
|
|
11
|
+
})
|
|
12
|
+
export default class XPgMenuDividerBasic extends HTMLElement {
|
|
13
|
+
@Part() $menu: PgMenu;
|
|
14
|
+
|
|
15
|
+
connectedCallback() {
|
|
16
|
+
this.$menu.items = [{
|
|
17
|
+
label: 'Item 1',
|
|
18
|
+
value: 'item1'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: PgMenuDivider
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: 'Item 2',
|
|
25
|
+
value: 'item2'
|
|
26
|
+
}];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div part="divider"></div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Component, Prop, Part } from '@pictogrammers/element';
|
|
2
|
+
|
|
3
|
+
import template from './menuDivider.html';
|
|
4
|
+
import style from './menuDivider.css';
|
|
5
|
+
|
|
6
|
+
@Component({
|
|
7
|
+
selector: 'pg-menu-divider',
|
|
8
|
+
style,
|
|
9
|
+
template
|
|
10
|
+
})
|
|
11
|
+
export default class PgMenuDivider extends HTMLElement {
|
|
12
|
+
@Prop() focusable = false;
|
|
13
|
+
|
|
14
|
+
@Part() $divider: HTMLDivElement;
|
|
15
|
+
|
|
16
|
+
getHeight(): number {
|
|
17
|
+
const computedStyle = window.getComputedStyle(this.$divider);
|
|
18
|
+
const marginTop = parseFloat(computedStyle.marginTop);
|
|
19
|
+
const marginBottom = parseFloat(computedStyle.marginBottom);
|
|
20
|
+
return this.$divider.getBoundingClientRect().height + marginTop + marginBottom;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/pg/menuIcon/menuIcon.ts
CHANGED
|
@@ -38,31 +38,33 @@ export default class PgMenuIcon extends HTMLElement {
|
|
|
38
38
|
@Part() $colorPicker: any;
|
|
39
39
|
@Part() $colorHexRgb: any;
|
|
40
40
|
|
|
41
|
-
@Local('
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
@Local('store') store = new Map<string, any>([
|
|
42
|
+
['cachePngColor', '#000000'],
|
|
43
|
+
['cachePngSize', 24],
|
|
44
|
+
['cacheSvgColor', '#000000']
|
|
45
|
+
]);
|
|
44
46
|
|
|
45
47
|
color = 'svg';
|
|
46
|
-
@Prop() currentIndex: 0;
|
|
48
|
+
@Prop() currentIndex: number = 0;
|
|
47
49
|
@Prop() icon: Icon = new Icon();
|
|
48
50
|
|
|
49
51
|
connectedCallback() {
|
|
50
52
|
// Wire Up Context Menu
|
|
51
53
|
this.$copyIconName.addEventListener('click', this.handleCopyIconName.bind(this));
|
|
52
54
|
this.$svgBlack.addEventListener('click', () => {
|
|
53
|
-
this.cacheSvgColor
|
|
55
|
+
this.store.set('cacheSvgColor', '#000000');
|
|
54
56
|
this.render();
|
|
55
57
|
});
|
|
56
58
|
this.$svgWhite.addEventListener('click', () => {
|
|
57
|
-
this.cacheSvgColor
|
|
59
|
+
this.store.set('cacheSvgColor', '#FFFFFF');
|
|
58
60
|
this.render();
|
|
59
61
|
});
|
|
60
62
|
let preventSvgColor = false;
|
|
61
63
|
this.$svgColor.addEventListener('click', () => {
|
|
62
64
|
if (preventSvgColor) { preventSvgColor = false; return; }
|
|
63
65
|
this.color = 'svg';
|
|
64
|
-
this.$colorPicker.value = this.cacheSvgColor;
|
|
65
|
-
this.$colorHexRgb.value = this.cacheSvgColor;
|
|
66
|
+
this.$colorPicker.value = this.store.get('cacheSvgColor');
|
|
67
|
+
this.$colorHexRgb.value = this.store.get('cacheSvgColor');
|
|
66
68
|
const self = this;
|
|
67
69
|
//createPopper(this.$svgColor, this.$color, {
|
|
68
70
|
// placement: 'bottom-start'
|
|
@@ -83,19 +85,19 @@ export default class PgMenuIcon extends HTMLElement {
|
|
|
83
85
|
document.addEventListener('mousedown', handleMouseDown);
|
|
84
86
|
});
|
|
85
87
|
this.$pngBlack.addEventListener('click', () => {
|
|
86
|
-
this.cachePngColor
|
|
88
|
+
this.store.set('cachePngColor', '#000000');
|
|
87
89
|
this.render();
|
|
88
90
|
});
|
|
89
91
|
this.$pngWhite.addEventListener('click', () => {
|
|
90
|
-
this.cachePngColor
|
|
92
|
+
this.store.set('cachePngColor', '#FFFFFF');
|
|
91
93
|
this.render();
|
|
92
94
|
});
|
|
93
95
|
let preventPngColor = false;
|
|
94
96
|
this.$pngColor.addEventListener('click', () => {
|
|
95
97
|
if (preventPngColor) { preventPngColor = false; return; }
|
|
96
98
|
this.color = 'png';
|
|
97
|
-
this.$colorPicker.value = this.cachePngColor;
|
|
98
|
-
this.$colorHexRgb.value = this.cachePngColor;
|
|
99
|
+
this.$colorPicker.value = this.store.get('cachePngColor');
|
|
100
|
+
this.$colorHexRgb.value = this.store.get('cachePngColor');
|
|
99
101
|
const self = this;
|
|
100
102
|
//createPopper(this.$pngColor, this.$color, {
|
|
101
103
|
// placement: 'bottom-start'
|
|
@@ -116,26 +118,26 @@ export default class PgMenuIcon extends HTMLElement {
|
|
|
116
118
|
document.addEventListener('mousedown', handleMouseDown);
|
|
117
119
|
});
|
|
118
120
|
this.$png24.addEventListener('click', () => {
|
|
119
|
-
this.cachePngSize
|
|
121
|
+
this.store.set('cachePngSize', 24);
|
|
120
122
|
this.render();
|
|
121
123
|
});
|
|
122
124
|
this.$png36.addEventListener('click', () => {
|
|
123
|
-
this.cachePngSize
|
|
125
|
+
this.store.set('cachePngSize', 36);
|
|
124
126
|
this.render();
|
|
125
127
|
});
|
|
126
128
|
this.$png48.addEventListener('click', () => {
|
|
127
|
-
this.cachePngSize
|
|
129
|
+
this.store.set('cachePngSize', 48);
|
|
128
130
|
this.render();
|
|
129
131
|
});
|
|
130
132
|
this.$png96.addEventListener('click', () => {
|
|
131
|
-
this.cachePngSize
|
|
133
|
+
this.store.set('cachePngSize', 96);
|
|
132
134
|
this.render();
|
|
133
135
|
});
|
|
134
136
|
this.$svgDownload.addEventListener('click', () => {
|
|
135
|
-
alert(`SVG ${this.cacheSvgColor}`);
|
|
137
|
+
alert(`SVG ${this.store.get('cacheSvgColor')}`);
|
|
136
138
|
});
|
|
137
139
|
this.$pngDownload.addEventListener('click', () => {
|
|
138
|
-
alert(`SVG ${this.cachePngSize} ${this.cachePngColor}`);
|
|
140
|
+
alert(`SVG ${this.store.get('cachePngSize')} ${this.store.get('cachePngColor')}`);
|
|
139
141
|
});
|
|
140
142
|
this.$copySvgInline.addEventListener('click', () => {
|
|
141
143
|
const icon = this.icon;
|
|
@@ -214,16 +216,19 @@ export default class PgMenuIcon extends HTMLElement {
|
|
|
214
216
|
|
|
215
217
|
render() {
|
|
216
218
|
// Context Menu
|
|
217
|
-
this
|
|
218
|
-
this
|
|
219
|
-
|
|
220
|
-
this.$
|
|
221
|
-
this.$
|
|
222
|
-
this.$
|
|
223
|
-
this.$
|
|
224
|
-
this.$
|
|
225
|
-
this.$
|
|
226
|
-
this.$
|
|
219
|
+
const cacheSvgColor = this.store.get('cacheSvgColor');
|
|
220
|
+
const cachePngColor = this.store.get('cachePngColor');
|
|
221
|
+
const cachePngSize = this.store.get('cachePngSize');
|
|
222
|
+
this.$svgBlack.classList.toggle('active', cacheSvgColor === '#000000');
|
|
223
|
+
this.$svgWhite.classList.toggle('active', cacheSvgColor === '#FFFFFF');
|
|
224
|
+
this.$svgColor.classList.toggle('active', cacheSvgColor !== '#000000' && cacheSvgColor !== '#FFFFFF');
|
|
225
|
+
this.$pngBlack.classList.toggle('active', cachePngColor === '#000000');
|
|
226
|
+
this.$pngWhite.classList.toggle('active', cachePngColor === '#FFFFFF');
|
|
227
|
+
this.$pngColor.classList.toggle('active', cachePngColor !== '#000000' && cachePngColor !== '#FFFFFF');
|
|
228
|
+
this.$png24.classList.toggle('active', cachePngSize === 24);
|
|
229
|
+
this.$png36.classList.toggle('active', cachePngSize === 36);
|
|
230
|
+
this.$png48.classList.toggle('active', cachePngSize === 48);
|
|
231
|
+
this.$png96.classList.toggle('active', cachePngSize === 96);
|
|
227
232
|
this.$colorPicker.addEventListener('select', this.handleColorSelect.bind(this));
|
|
228
233
|
this.$colorHexRgb.addEventListener('change', this.handleHexRgbChange.bind(this));
|
|
229
234
|
this.syncEyedropper();
|
|
@@ -232,10 +237,10 @@ export default class PgMenuIcon extends HTMLElement {
|
|
|
232
237
|
handleColorSelect(e) {
|
|
233
238
|
switch(this.color) {
|
|
234
239
|
case 'svg':
|
|
235
|
-
this.cacheSvgColor
|
|
240
|
+
this.store.set('cacheSvgColor', e.detail.hex);
|
|
236
241
|
break;
|
|
237
242
|
case 'png':
|
|
238
|
-
this.cachePngColor
|
|
243
|
+
this.store.set('cachePngColor', e.detail.hex);
|
|
239
244
|
break;
|
|
240
245
|
}
|
|
241
246
|
this.$colorHexRgb.value = e.detail.hex;
|
|
@@ -245,10 +250,10 @@ export default class PgMenuIcon extends HTMLElement {
|
|
|
245
250
|
handleHexRgbChange(e) {
|
|
246
251
|
switch(this.color) {
|
|
247
252
|
case 'svg':
|
|
248
|
-
this.cacheSvgColor
|
|
253
|
+
this.store.set('cacheSvgColor', e.detail.hex);
|
|
249
254
|
break;
|
|
250
255
|
case 'png':
|
|
251
|
-
this.cachePngColor
|
|
256
|
+
this.store.set('cachePngColor', e.detail.hex);
|
|
252
257
|
break;
|
|
253
258
|
}
|
|
254
259
|
this.$colorPicker.value = e.detail.hex;
|
|
@@ -256,13 +261,15 @@ export default class PgMenuIcon extends HTMLElement {
|
|
|
256
261
|
}
|
|
257
262
|
|
|
258
263
|
syncEyedropper() {
|
|
259
|
-
|
|
260
|
-
|
|
264
|
+
const cachePngColor = this.store.get('cachePngColor');
|
|
265
|
+
if (cachePngColor !== '#000000' && cachePngColor !== '#FFFFFF') {
|
|
266
|
+
this.$pngColor.style.color = cachePngColor;
|
|
261
267
|
} else {
|
|
262
268
|
this.$pngColor.style.color = 'transparent';
|
|
263
269
|
}
|
|
264
|
-
|
|
265
|
-
|
|
270
|
+
const cacheSvgColor = this.store.get('cacheSvgColor');
|
|
271
|
+
if (cacheSvgColor !== '#000000' && cacheSvgColor !== '#FFFFFF') {
|
|
272
|
+
this.$svgColor.style.color = cacheSvgColor;
|
|
266
273
|
} else {
|
|
267
274
|
this.$svgColor.style.color = 'transparent';
|
|
268
275
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# `<pg-menu>`
|
|
2
|
+
|
|
3
|
+
The `PgMenuItem` is used with the `pg-menu` as a `type: PgMenuItem`.
|
|
4
|
+
|
|
5
|
+
For icon support use `PgMenuItemIcon`.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import '@pictogrammers/components/pgMenuItem.js';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
this.$items = [{
|
|
15
|
+
type: PgMenuItem,
|
|
16
|
+
label: 'Item 1'
|
|
17
|
+
}];
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
| Attributes | Tested | Description |
|
|
21
|
+
| ---------- | -------- | ----------- |
|
|
22
|
+
| `label` | | Item label. |
|
|
23
|
+
| `checked` | | Item checked. |
|
|
24
|
+
| `disabled` | | Item disabled. |
|
|
25
|
+
|
|
26
|
+
## Events
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
this.$item.addEventListener('select', (e: any) => {
|
|
30
|
+
const { index } = e.detail;
|
|
31
|
+
});
|
|
32
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<div class="example">
|
|
2
|
+
<pg-menu-item part="item"></pg-menu-item>
|
|
3
|
+
</div>
|
|
4
|
+
<div>
|
|
5
|
+
<table style="border: 1px solid #ddd;margin-block-start: 0.5rem;">
|
|
6
|
+
<thead>
|
|
7
|
+
<tr>
|
|
8
|
+
<th>Property</th>
|
|
9
|
+
<th>Value</th>
|
|
10
|
+
<th> </th>
|
|
11
|
+
</tr>
|
|
12
|
+
</thead>
|
|
13
|
+
<tbody>
|
|
14
|
+
<tr>
|
|
15
|
+
<td><code>checked</code></td>
|
|
16
|
+
<td part="checkedValue"></td>
|
|
17
|
+
<td><input part="checkedToggle" type="checkbox"/></td>
|
|
18
|
+
</tr>
|
|
19
|
+
<tr>
|
|
20
|
+
<td><code>disabled</code></td>
|
|
21
|
+
<td part="disabledValue"></td>
|
|
22
|
+
<td><input part="disabledToggle" type="checkbox"/></td>
|
|
23
|
+
</tr>
|
|
24
|
+
</tbody>
|
|
25
|
+
</table>
|
|
26
|
+
</div>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Component, Part } from '@pictogrammers/element';
|
|
2
|
+
|
|
3
|
+
import PgMenuItem from '../../menuItem';
|
|
4
|
+
|
|
5
|
+
import template from './basic.html';
|
|
6
|
+
|
|
7
|
+
@Component({
|
|
8
|
+
selector: 'x-pg-menu-item-basic',
|
|
9
|
+
template
|
|
10
|
+
})
|
|
11
|
+
export default class XPgMenuItemBasic extends HTMLElement {
|
|
12
|
+
@Part() $item: PgMenuItem;
|
|
13
|
+
@Part() $checkedToggle: HTMLInputElement;
|
|
14
|
+
@Part() $disabledToggle: HTMLInputElement;
|
|
15
|
+
@Part() $checkedValue: HTMLDivElement;
|
|
16
|
+
@Part() $disabledValue: HTMLDivElement;
|
|
17
|
+
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
this.$item.label = 'Item 1';
|
|
20
|
+
this.$item.checked = false;
|
|
21
|
+
this.$item.disabled = false;
|
|
22
|
+
|
|
23
|
+
this.$checkedValue.textContent = `${this.$item.checked}`;
|
|
24
|
+
this.$disabledValue.textContent = `${this.$item.disabled}`;
|
|
25
|
+
|
|
26
|
+
this.$item.addEventListener('select', (e: any) => {
|
|
27
|
+
this.$checkedToggle.checked = e.target.checked;
|
|
28
|
+
this.$checkedValue.textContent = `${this.$item.checked}`;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
this.$checkedToggle.addEventListener('change', (e: any) => {
|
|
32
|
+
this.$item.checked = e.target.checked;
|
|
33
|
+
this.$checkedValue.textContent = `${this.$item.checked}`;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
this.$disabledToggle.addEventListener('change', (e: any) => {
|
|
37
|
+
this.$item.disabled = e.target.checked;
|
|
38
|
+
this.$disabledValue.textContent = `${this.$item.disabled}`;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: contents;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
[part=label] {
|
|
6
|
+
outline: none;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
font-family: var(--pg-font-family);
|
|
10
|
+
text-align: var(--pg-menu-item-text-align, left);
|
|
11
|
+
background: var(--pg-menu-item-background, transparent);
|
|
12
|
+
padding: var(--pg-menu-item-padding, 0.25rem 0.5rem 0.25rem 0.5rem);
|
|
13
|
+
border-color: transparent;
|
|
14
|
+
border-width: 0;
|
|
15
|
+
border-style: solid;
|
|
16
|
+
border-top-left-radius: var(--pg-menu-item-border-radius-top, 0.25rem);
|
|
17
|
+
border-top-right-radius: var(--pg-menu-item-border-radius-top, 0.25rem);
|
|
18
|
+
border-bottom-left-radius: var(--pg-menu-item-border-radius-bottom, 0.25rem);
|
|
19
|
+
border-bottom-right-radius: var(--pg-menu-item-border-radius-bottom, 0.25rem);
|
|
20
|
+
color: var(--pg-menu-item-color, #453C4F);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
[part=label]:not(:disabled):active,
|
|
24
|
+
[part=label]:not(:disabled):hover {
|
|
25
|
+
background: var(--pg-menu-item-selected-background, #453C4F);
|
|
26
|
+
color: #FFFFFF;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[part=label]:not(:disabled):active {
|
|
30
|
+
background: var(--pg-menu-item-active-background, #5f516e);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
[part=label]:disabled {
|
|
34
|
+
color: var(--pg-menu-item-disabled-color, rgb(69, 60, 79, 0.75));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@container style(--pg-menu-_has-check: true) {
|
|
38
|
+
[part=label] {
|
|
39
|
+
padding-inline-start: 1.5rem;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
[part=label].checked::before {
|
|
43
|
+
position: absolute;
|
|
44
|
+
translate: -1.5rem 0;
|
|
45
|
+
content: var(--pg-menu-item-check, url("data:image/svg+xml; utf8, <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M 17.5,10.2501L 10.5,17.25L 6.5,13.25L 7.9,11.8L 10.5,14.4L 16.0857,8.8L 17.5,10.25Z' fill='rgb(69, 60, 79)' /></svg>"));
|
|
46
|
+
width: 1.5rem;
|
|
47
|
+
height: 1.5rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
[part=label].checked:active::before,
|
|
51
|
+
[part=label].checked:hover::before {
|
|
52
|
+
content: var(--pg-menu-item-hover-check, url("data:image/svg+xml; utf8, <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M 17.5,10.2501L 10.5,17.25L 6.5,13.25L 7.9,11.8L 10.5,14.4L 16.0857,8.8L 17.5,10.25Z' fill='white' /></svg>"));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
[part=label].checked:disabled::before {
|
|
56
|
+
content: var(--pg-menu-item-disabled-check, url("data:image/svg+xml; utf8, <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M 17.5,10.2501L 10.5,17.25L 6.5,13.25L 7.9,11.8L 10.5,14.4L 16.0857,8.8L 17.5,10.25Z' fill='rgb(69, 60, 79, 0.5)' /></svg>"));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[part=label]:focus-visible {
|
|
61
|
+
position: relative;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
[part=label]:focus-visible::after {
|
|
65
|
+
pointer-events: none;
|
|
66
|
+
content: '';
|
|
67
|
+
position: absolute;
|
|
68
|
+
top: -1px;
|
|
69
|
+
right: -1px;
|
|
70
|
+
bottom: -1px;
|
|
71
|
+
left: -1px;
|
|
72
|
+
border-radius: 0.25rem;
|
|
73
|
+
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
[part=label]:focus-visible:not(:hover)::after {
|
|
77
|
+
background: var(--pg-focus-background-color, rgb(79, 143, 249, 0.1));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
[part=label].more::after {
|
|
82
|
+
position: absolute;
|
|
83
|
+
translate: -0.5rem 0;
|
|
84
|
+
right: 0;
|
|
85
|
+
content: var(--pg-menu-item-check, url("data:image/svg+xml; utf8, <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z' fill='rgb(69, 60, 79)' /></svg>"));
|
|
86
|
+
width: 1.5rem;
|
|
87
|
+
height: 1.5rem;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
[part=label].more:active::after,
|
|
91
|
+
[part=label].more:hover::after {
|
|
92
|
+
content: var(--pg-menu-item-hover-check, url("data:image/svg+xml; utf8, <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z' fill='white' /></svg>"));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
[part=label].more:disabled::after {
|
|
96
|
+
content: var(--pg-menu-item-disabled-check, url("data:image/svg+xml; utf8, <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z' fill='rgb(69, 60, 79, 0.5)' /></svg>"));
|
|
97
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<button part="label"></button>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Component, Prop, Part, forEach } from '@pictogrammers/element';
|
|
2
|
+
|
|
3
|
+
import template from './menuItem.html';
|
|
4
|
+
import style from './menuItem.css';
|
|
5
|
+
|
|
6
|
+
const noIcon = 'M0 0h24v24H0V0zm2 2v20h20V2H2z';
|
|
7
|
+
|
|
8
|
+
@Component({
|
|
9
|
+
selector: 'pg-menu-item',
|
|
10
|
+
style,
|
|
11
|
+
template
|
|
12
|
+
})
|
|
13
|
+
export default class PgMenuItem extends HTMLElement {
|
|
14
|
+
static delegatesFocus = true;
|
|
15
|
+
|
|
16
|
+
@Prop() index: number;
|
|
17
|
+
@Prop() label: string = '';
|
|
18
|
+
@Prop() checked: boolean = false;
|
|
19
|
+
@Prop() disabled: boolean = false;
|
|
20
|
+
@Prop() items: any[] = [];
|
|
21
|
+
|
|
22
|
+
@Part() $label: HTMLButtonElement;
|
|
23
|
+
|
|
24
|
+
render(changes) {
|
|
25
|
+
if (changes.label) {
|
|
26
|
+
this.$label.textContent = this.label;
|
|
27
|
+
}
|
|
28
|
+
if (changes.disabled) {
|
|
29
|
+
this.$label.disabled = this.disabled;
|
|
30
|
+
}
|
|
31
|
+
if (changes.checked) {
|
|
32
|
+
this.$label.classList.toggle('checked', this.checked);
|
|
33
|
+
}
|
|
34
|
+
if (changes.checked) {
|
|
35
|
+
if (this.checked === true) {
|
|
36
|
+
this.dispatchEvent(new CustomEvent('hasCheck', { bubbles: true }));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
connectedCallback() {
|
|
42
|
+
this.$label.addEventListener('click', () => {
|
|
43
|
+
this.dispatchEvent(new CustomEvent('select', {
|
|
44
|
+
detail: { index: this.index }
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
this.$label.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
48
|
+
switch (e.key) {
|
|
49
|
+
case 'ArrowDown':
|
|
50
|
+
this.dispatchEvent(new CustomEvent('down', {
|
|
51
|
+
detail: { index: this.index }
|
|
52
|
+
}));
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
break;
|
|
55
|
+
case 'ArrowUp':
|
|
56
|
+
this.dispatchEvent(new CustomEvent('up', {
|
|
57
|
+
detail: { index: this.index }
|
|
58
|
+
}));
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
break;
|
|
61
|
+
case 'Escape':
|
|
62
|
+
this.dispatchEvent(new CustomEvent('close'));
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
focus() {
|
|
70
|
+
this.$label.focus();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getHeight(): number {
|
|
74
|
+
return this.$label.getBoundingClientRect().height;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|