@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.
Files changed (294) hide show
  1. package/README.md +11 -12
  2. package/favicon.svg +20 -0
  3. package/index.html +67 -49
  4. package/main.js +2 -0
  5. package/main.js.LICENSE.txt +10 -0
  6. package/package.json +6 -6
  7. package/pg/annoy/README.md +0 -5
  8. package/pg/annoy/__examples__/basic/basic.css +3 -0
  9. package/pg/annoy/__examples__/basic/basic.html +4 -7
  10. package/pg/annoy/__examples__/basic/basic.ts +3 -1
  11. package/pg/annoy/annoy.css +29 -198
  12. package/pg/annoy/annoy.html +5 -56
  13. package/pg/annoy/annoy.ts +4 -25
  14. package/pg/app/README.md +11 -0
  15. package/pg/app/__examples__/basic/basic.css +8 -0
  16. package/pg/app/__examples__/basic/basic.html +15 -0
  17. package/pg/app/__examples__/basic/basic.ts +13 -0
  18. package/pg/app/app.css +108 -0
  19. package/pg/app/app.html +16 -0
  20. package/pg/app/app.ts +45 -0
  21. package/pg/app/index.ts +3 -0
  22. package/pg/avatar/__examples__/basic/basic.ts +5 -3
  23. package/pg/button/README.md +3 -0
  24. package/pg/button/button.css +13 -12
  25. package/pg/button/button.spec.ts +35 -0
  26. package/pg/button/button.ts +17 -12
  27. package/pg/buttonLink/buttonLink.css +3 -2
  28. package/pg/buttonMenu/README.md +54 -0
  29. package/pg/buttonMenu/__examples__/basic/basic.html +6 -0
  30. package/pg/buttonMenu/__examples__/basic/basic.ts +43 -0
  31. package/pg/buttonMenu/buttonMenu.css +12 -0
  32. package/pg/buttonMenu/buttonMenu.html +4 -0
  33. package/pg/buttonMenu/buttonMenu.ts +63 -0
  34. package/pg/buttonMenu/index.ts +3 -0
  35. package/pg/buttonToggle/__examples__/basic/basic.ts +2 -2
  36. package/pg/buttonToggle/__examples__/persist/persist.html +10 -0
  37. package/pg/buttonToggle/__examples__/persist/persist.ts +35 -0
  38. package/pg/cardUser/__examples__/basic/basic.ts +0 -1
  39. package/pg/cardUser/cardUser.css +2 -10
  40. package/pg/cardUser/cardUser.html +0 -5
  41. package/pg/cardUser/cardUser.ts +0 -6
  42. package/pg/database/README.md +1 -1
  43. package/pg/database/__examples__/basic/basic.html +2 -1
  44. package/pg/database/__examples__/basic/basic.ts +3 -3
  45. package/pg/dropdown/dropdown.ts +0 -19
  46. package/pg/grid/__examples__/basic/basic.html +2 -2
  47. package/pg/grid/__examples__/basic/basic.ts +3 -2
  48. package/pg/grid/grid.ts +0 -1
  49. package/pg/icon/README.md +6 -5
  50. package/pg/icon/__examples__/basic/basic.html +2 -2
  51. package/pg/icon/__examples__/basic/basic.ts +1 -1
  52. package/pg/icon/icon.ts +6 -0
  53. package/pg/inputCheckList/__examples__/basic/basic.ts +5 -5
  54. package/pg/inputCheckList/inputCheckList.ts +2 -0
  55. package/pg/inputFileLocal/inputFileLocal.css +3 -2
  56. package/pg/inputPixelEditor/README.md +132 -0
  57. package/pg/inputPixelEditor/__examples__/basic/basic.css +29 -0
  58. package/pg/inputPixelEditor/__examples__/basic/basic.html +63 -0
  59. package/pg/inputPixelEditor/__examples__/basic/basic.ts +200 -0
  60. package/pg/inputPixelEditor/__examples__/basic/openUtils.ts +41 -0
  61. package/pg/inputPixelEditor/__examples__/basic/saveUtil.ts +35 -0
  62. package/pg/inputPixelEditor/index.ts +3 -0
  63. package/pg/inputPixelEditor/inputPixelEditor.css +27 -0
  64. package/pg/inputPixelEditor/inputPixelEditor.html +3 -0
  65. package/pg/inputPixelEditor/inputPixelEditor.ts +839 -0
  66. package/pg/inputPixelEditor/utils/bitmapToMask.ts +202 -0
  67. package/pg/inputPixelEditor/utils/cloneGrid.ts +17 -0
  68. package/pg/inputPixelEditor/utils/constants.ts +1 -0
  69. package/pg/inputPixelEditor/utils/createLayer.ts +8 -0
  70. package/pg/inputPixelEditor/utils/debounce.ts +5 -0
  71. package/pg/inputPixelEditor/utils/diffGrid.ts +26 -0
  72. package/pg/inputPixelEditor/utils/fillGrid.ts +11 -0
  73. package/pg/inputPixelEditor/utils/getEllipseOutlinePixels.ts +105 -0
  74. package/pg/inputPixelEditor/utils/getEllipsePixels.ts +28 -0
  75. package/pg/inputPixelEditor/utils/getGuides.ts +232 -0
  76. package/pg/inputPixelEditor/utils/getLinePixels.ts +18 -0
  77. package/pg/inputPixelEditor/utils/getRectangleOutlinePixels.ts +20 -0
  78. package/pg/inputPixelEditor/utils/getRectanglePixels.ts +15 -0
  79. package/pg/inputPixelEditor/utils/inputMode.ts +8 -0
  80. package/pg/inputPixelEditor/utils/interateGrid.ts +7 -0
  81. package/pg/inputPixelEditor/utils/isEmptyGrid.ts +3 -0
  82. package/pg/inputPixelEditor/utils/maskToBitmap.ts +66 -0
  83. package/pg/inputRange/__examples__/basic/basic.ts +4 -4
  84. package/pg/inputRange/inputRange.ts +6 -4
  85. package/pg/inputSelect/README.md +1 -1
  86. package/pg/inputSelect/__examples__/basic/basic.ts +7 -5
  87. package/pg/inputSelect/inputSelect.css +15 -12
  88. package/pg/inputSelect/inputSelect.html +3 -3
  89. package/pg/inputSelect/inputSelect.ts +33 -30
  90. package/pg/inputText/__examples__/basic/basic.ts +6 -6
  91. package/pg/inputText/inputText.css +1 -0
  92. package/pg/inputUserSelect/README.md +1 -1
  93. package/pg/inputUserSelect/inputUserSelect.ts +1 -1
  94. package/pg/listTag/__examples__/basic/basic.ts +4 -5
  95. package/pg/markdown/README.md +17 -3
  96. package/pg/markdown/__examples__/basic/basic.ts +2 -2
  97. package/pg/markdown/__examples__/basic/constants.ts +1 -1
  98. package/pg/markdown/markdown.css +11 -0
  99. package/pg/menu/README.md +46 -0
  100. package/pg/menu/__examples__/basic/basic.html +6 -0
  101. package/pg/menu/__examples__/basic/basic.ts +46 -0
  102. package/pg/menu/index.ts +3 -0
  103. package/pg/menu/menu.css +19 -0
  104. package/pg/menu/menu.html +1 -0
  105. package/pg/menu/menu.ts +119 -0
  106. package/pg/menuDivider/README.md +7 -0
  107. package/pg/menuDivider/__examples__/basic/basic.html +3 -0
  108. package/pg/menuDivider/__examples__/basic/basic.ts +28 -0
  109. package/pg/menuDivider/index.ts +3 -0
  110. package/pg/menuDivider/menuDivider.css +9 -0
  111. package/pg/menuDivider/menuDivider.html +1 -0
  112. package/pg/menuDivider/menuDivider.ts +22 -0
  113. package/pg/menuIcon/menuIcon.ts +43 -36
  114. package/pg/menuItem/README.md +32 -0
  115. package/pg/menuItem/__examples__/basic/basic.html +26 -0
  116. package/pg/menuItem/__examples__/basic/basic.ts +41 -0
  117. package/pg/menuItem/index.ts +3 -0
  118. package/pg/menuItem/menuItem.css +97 -0
  119. package/pg/menuItem/menuItem.html +1 -0
  120. package/pg/menuItem/menuItem.ts +77 -0
  121. package/pg/menuItemIcon/README.md +32 -0
  122. package/pg/menuItemIcon/__examples__/basic/basic.html +34 -0
  123. package/pg/menuItemIcon/__examples__/basic/basic.ts +55 -0
  124. package/pg/menuItemIcon/index.ts +3 -0
  125. package/pg/menuItemIcon/menuItemIcon.css +106 -0
  126. package/pg/menuItemIcon/menuItemIcon.html +4 -0
  127. package/pg/menuItemIcon/menuItemIcon.ts +156 -0
  128. package/pg/modalAlert/__examples__/basic/basic.ts +1 -1
  129. package/pg/modalAlert/modalAlert.css +1 -4
  130. package/pg/modalAlert/modalAlert.ts +18 -4
  131. package/pg/modification/__examples__/basic/basic.ts +1 -2
  132. package/pg/modification/__examples__/basic/constants.ts +25 -50
  133. package/pg/modification/modification.ts +1 -1
  134. package/pg/overlay/overlay.ts +13 -12
  135. package/pg/overlayContextMenu/README.md +35 -0
  136. package/pg/overlayContextMenu/__examples__/basic/basic.css +23 -0
  137. package/pg/overlayContextMenu/__examples__/basic/basic.html +7 -0
  138. package/pg/overlayContextMenu/__examples__/basic/basic.ts +87 -0
  139. package/pg/overlayContextMenu/index.ts +3 -0
  140. package/pg/overlayContextMenu/overlayContextMenu.css +16 -0
  141. package/pg/overlayContextMenu/overlayContextMenu.html +3 -0
  142. package/pg/overlayContextMenu/overlayContextMenu.ts +98 -0
  143. package/pg/overlayMenu/README.md +33 -0
  144. package/pg/overlayMenu/__examples__/basic/basic.css +3 -0
  145. package/pg/overlayMenu/__examples__/basic/basic.html +5 -0
  146. package/pg/overlayMenu/__examples__/basic/basic.ts +62 -0
  147. package/pg/overlayMenu/index.ts +3 -0
  148. package/pg/overlayMenu/overlayMenu.css +16 -0
  149. package/pg/overlayMenu/overlayMenu.html +3 -0
  150. package/pg/overlayMenu/overlayMenu.ts +67 -0
  151. package/pg/overlaySelectMenu/README.md +33 -0
  152. package/pg/overlaySelectMenu/__examples__/basic/basic.css +3 -0
  153. package/pg/overlaySelectMenu/__examples__/basic/basic.html +5 -0
  154. package/pg/overlaySelectMenu/__examples__/basic/basic.ts +62 -0
  155. package/pg/overlaySelectMenu/index.ts +3 -0
  156. package/pg/overlaySelectMenu/overlaySelectMenu.css +17 -0
  157. package/pg/overlaySelectMenu/overlaySelectMenu.html +3 -0
  158. package/pg/overlaySelectMenu/overlaySelectMenu.ts +96 -0
  159. package/pg/overlaySubMenu/README.md +35 -0
  160. package/pg/overlaySubMenu/index.ts +3 -0
  161. package/pg/overlaySubMenu/overlaySubMenu.css +27 -0
  162. package/pg/overlaySubMenu/overlaySubMenu.html +3 -0
  163. package/pg/overlaySubMenu/overlaySubMenu.ts +103 -0
  164. package/pg/picker/picker.ts +1 -19
  165. package/pg/scroll/__examples__/basic/basic.ts +1 -1
  166. package/pg/search/__examples__/basic/basic.ts +10 -7
  167. package/pg/search/search.css +2 -2
  168. package/pg/shared/models/user.ts +0 -2
  169. package/pg/tab/tab.ts +0 -10
  170. package/pg/tabs/partials/tab.css +42 -0
  171. package/pg/tabs/partials/tab.ts +70 -0
  172. package/pg/tabs/tabs.css +0 -53
  173. package/pg/tabs/tabs.ts +54 -70
  174. package/pg/toast/README.md +35 -6
  175. package/pg/toast/__examples__/basic/basic.html +7 -0
  176. package/pg/toast/__examples__/basic/basic.ts +76 -0
  177. package/pg/toast/toast.css +3 -0
  178. package/pg/toast/toast.ts +20 -4
  179. package/pg/tooltip/addTooltip.ts +3 -1
  180. package/pg/tooltip/tooltip.ts +1 -1
  181. package/pg/tree/README.md +67 -0
  182. package/pg/tree/__examples__/basic/basic.html +10 -0
  183. package/pg/tree/__examples__/basic/basic.ts +162 -0
  184. package/pg/tree/index.ts +3 -0
  185. package/pg/tree/tree.css +28 -0
  186. package/pg/tree/tree.html +1 -0
  187. package/pg/tree/tree.ts +217 -0
  188. package/pg/treeButtonIcon/README.md +39 -0
  189. package/pg/treeButtonIcon/index.ts +3 -0
  190. package/pg/treeButtonIcon/treeButtonIcon.css +18 -0
  191. package/pg/treeButtonIcon/treeButtonIcon.html +3 -0
  192. package/pg/treeButtonIcon/treeButtonIcon.ts +42 -0
  193. package/pg/treeItem/README.md +3 -0
  194. package/pg/treeItem/index.ts +3 -0
  195. package/pg/treeItem/treeItem.css +263 -0
  196. package/pg/treeItem/treeItem.html +16 -0
  197. package/pg/treeItem/treeItem.ts +558 -0
  198. package/pgAnnoy.js +1 -0
  199. package/pgApp.js +1 -0
  200. package/pgAvatar.js +1 -0
  201. package/pgButton.js +1 -0
  202. package/pgButtonGroup.js +1 -0
  203. package/pgButtonLink.js +1 -0
  204. package/pgButtonMenu.js +1 -0
  205. package/pgButtonToggle.js +1 -0
  206. package/pgCard.js +1 -0
  207. package/pgCardUser.js +1 -0
  208. package/pgColor.js +1 -0
  209. package/pgDatabase.js +1 -0
  210. package/pgDropdown.js +1 -0
  211. package/pgGrid.js +1 -0
  212. package/pgHeader.js +1 -0
  213. package/pgIcon.js +1 -0
  214. package/pgInputCheck.js +1 -0
  215. package/pgInputCheckList.js +1 -0
  216. package/pgInputFileLocal.js +1 -0
  217. package/pgInputHexRgb.js +1 -0
  218. package/pgInputPixelEditor.js +1 -0
  219. package/pgInputRange.js +1 -0
  220. package/pgInputSelect.js +1 -0
  221. package/pgInputText.js +1 -0
  222. package/pgInputTextIcon.js +1 -0
  223. package/pgInputUserSelect.js +1 -0
  224. package/pgListTag.js +1 -0
  225. package/pgMarkdown.js +2 -0
  226. package/pgMarkdown.js.LICENSE.txt +10 -0
  227. package/pgMenu.js +1 -0
  228. package/pgMenuDivider.js +1 -0
  229. package/pgMenuIcon.js +1 -0
  230. package/pgMenuItem.js +1 -0
  231. package/pgMenuItemIcon.js +1 -0
  232. package/pgModalAlert.js +1 -0
  233. package/pgModification.js +1 -0
  234. package/pgNav.js +1 -0
  235. package/pgOverlay.js +1 -0
  236. package/pgOverlayContextMenu.js +1 -0
  237. package/pgOverlayMenu.js +1 -0
  238. package/pgOverlaySelectMenu.js +1 -0
  239. package/pgOverlaySubMenu.js +1 -0
  240. package/pgPicker.js +1 -0
  241. package/pgPreview.js +1 -0
  242. package/pgScroll.js +1 -0
  243. package/pgSearch.js +1 -0
  244. package/pgTab.js +1 -0
  245. package/pgTabs.js +1 -0
  246. package/pgToast.js +1 -0
  247. package/pgToasts.js +1 -0
  248. package/pgTooltip.js +1 -0
  249. package/pgTree.js +1 -0
  250. package/pgTreeButtonIcon.js +1 -0
  251. package/pgTreeItem.js +1 -0
  252. package/theme-ui3.css +31 -0
  253. package/@types/css.d.ts +0 -4
  254. package/@types/html.d.ts +0 -4
  255. package/dist/main.js +0 -3819
  256. package/dist/pgAnnoy.js +0 -116
  257. package/dist/pgAvatar.js +0 -136
  258. package/dist/pgButton.js +0 -116
  259. package/dist/pgButtonGroup.js +0 -116
  260. package/dist/pgButtonLink.js +0 -116
  261. package/dist/pgButtonToggle.js +0 -146
  262. package/dist/pgCard.js +0 -116
  263. package/dist/pgCardUser.js +0 -196
  264. package/dist/pgColor.js +0 -136
  265. package/dist/pgDatabase.js +0 -236
  266. package/dist/pgDropdown.js +0 -686
  267. package/dist/pgGrid.js +0 -126
  268. package/dist/pgHeader.js +0 -116
  269. package/dist/pgIcon.js +0 -116
  270. package/dist/pgInputCheck.js +0 -116
  271. package/dist/pgInputCheckList.js +0 -126
  272. package/dist/pgInputFileLocal.js +0 -116
  273. package/dist/pgInputHexRgb.js +0 -126
  274. package/dist/pgInputRange.js +0 -116
  275. package/dist/pgInputSelect.js +0 -116
  276. package/dist/pgInputText.js +0 -116
  277. package/dist/pgInputTextIcon.js +0 -176
  278. package/dist/pgInputUserSelect.js +0 -116
  279. package/dist/pgListTag.js +0 -136
  280. package/dist/pgMarkdown.js +0 -346
  281. package/dist/pgMenuIcon.js +0 -206
  282. package/dist/pgModalAlert.js +0 -126
  283. package/dist/pgModification.js +0 -396
  284. package/dist/pgNav.js +0 -116
  285. package/dist/pgOverlay.js +0 -96
  286. package/dist/pgPicker.js +0 -116
  287. package/dist/pgPreview.js +0 -116
  288. package/dist/pgScroll.js +0 -266
  289. package/dist/pgSearch.js +0 -146
  290. package/dist/pgTab.js +0 -116
  291. package/dist/pgTabs.js +0 -136
  292. package/dist/pgToast.js +0 -136
  293. package/dist/pgToasts.js +0 -136
  294. package/dist/pgTooltip.js +0 -126
@@ -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,7 @@
1
+ # `<pg-menu-divider>`
2
+
3
+ The `PgMenuDivider` is used as a `type: PgMenuDivider` with the `pg-menu` component items.
4
+
5
+ ```typescript
6
+ import '@pictogrammers/components/pgMenuDivider.js';
7
+ ```
@@ -0,0 +1,3 @@
1
+ <div class="example">
2
+ <pg-menu part="menu"></pg-menu>
3
+ </div>
@@ -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,3 @@
1
+ import PgMenuDivider from './menuDivider';
2
+
3
+ export default PgMenuDivider;
@@ -0,0 +1,9 @@
1
+ :host {
2
+ display: contents;
3
+ }
4
+
5
+ [part=divider] {
6
+ margin-top: 0.25rem;
7
+ border-top: 1px solid var(--pg-menu-divider-color, rgba(69, 60, 79, 0.5));
8
+ margin-bottom: 0.25rem;
9
+ }
@@ -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
+ }
@@ -38,31 +38,33 @@ export default class PgMenuIcon extends HTMLElement {
38
38
  @Part() $colorPicker: any;
39
39
  @Part() $colorHexRgb: any;
40
40
 
41
- @Local('#000000') cachePngColor: string;
42
- @Local('24') cachePngSize: string;
43
- @Local('#000000') cacheSvgColor: string;
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 = '#000000';
55
+ this.store.set('cacheSvgColor', '#000000');
54
56
  this.render();
55
57
  });
56
58
  this.$svgWhite.addEventListener('click', () => {
57
- this.cacheSvgColor = '#FFFFFF';
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 = '#000000';
88
+ this.store.set('cachePngColor', '#000000');
87
89
  this.render();
88
90
  });
89
91
  this.$pngWhite.addEventListener('click', () => {
90
- this.cachePngColor = '#FFFFFF';
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 = '24';
121
+ this.store.set('cachePngSize', 24);
120
122
  this.render();
121
123
  });
122
124
  this.$png36.addEventListener('click', () => {
123
- this.cachePngSize = '36';
125
+ this.store.set('cachePngSize', 36);
124
126
  this.render();
125
127
  });
126
128
  this.$png48.addEventListener('click', () => {
127
- this.cachePngSize = '48';
129
+ this.store.set('cachePngSize', 48);
128
130
  this.render();
129
131
  });
130
132
  this.$png96.addEventListener('click', () => {
131
- this.cachePngSize = '96';
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.$svgBlack.classList.toggle('active', this.cacheSvgColor === '#000000');
218
- this.$svgWhite.classList.toggle('active', this.cacheSvgColor === '#FFFFFF');
219
- this.$svgColor.classList.toggle('active', this.cacheSvgColor !== '#000000' && this.cacheSvgColor !== '#FFFFFF');
220
- this.$pngBlack.classList.toggle('active', this.cachePngColor === '#000000');
221
- this.$pngWhite.classList.toggle('active', this.cachePngColor === '#FFFFFF');
222
- this.$pngColor.classList.toggle('active', this.cachePngColor !== '#000000' && this.cachePngColor !== '#FFFFFF');
223
- this.$png24.classList.toggle('active', this.cachePngSize === '24');
224
- this.$png36.classList.toggle('active', this.cachePngSize === '36');
225
- this.$png48.classList.toggle('active', this.cachePngSize === '48');
226
- this.$png96.classList.toggle('active', this.cachePngSize === '96');
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 = e.detail.hex;
240
+ this.store.set('cacheSvgColor', e.detail.hex);
236
241
  break;
237
242
  case 'png':
238
- this.cachePngColor = e.detail.hex;
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 = e.detail.hex;
253
+ this.store.set('cacheSvgColor', e.detail.hex);
249
254
  break;
250
255
  case 'png':
251
- this.cachePngColor = e.detail.hex;
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
- if (this.cachePngColor !== '#000000' && this.cachePngColor !== '#FFFFFF') {
260
- this.$pngColor.style.color = this.cachePngColor;
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
- if (this.cacheSvgColor !== '#000000' && this.cacheSvgColor !== '#FFFFFF') {
265
- this.$svgColor.style.color = this.cacheSvgColor;
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>&nbsp;</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,3 @@
1
+ import PgMenuItem from './menuItem';
2
+
3
+ export default PgMenuItem;
@@ -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
+ }