@pictogrammers/components 0.4.8 → 0.5.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 (191) hide show
  1. package/package.json +1 -1
  2. package/pg/annoy/annoy.css +1 -1
  3. package/pg/button/button.css +5 -4
  4. package/pg/buttonLink/buttonLink.css +1 -1
  5. package/pg/buttonMenu/__examples__/basic/basic.ts +2 -2
  6. package/pg/buttonMenu/buttonMenu.ts +4 -1
  7. package/pg/cardUser/cardUser.css +1 -1
  8. package/pg/database/__examples__/basic/basic.ts +0 -1
  9. package/pg/grid/__examples__/basic/basic.ts +1 -4
  10. package/pg/grid/grid.css +1 -1
  11. package/pg/header/header.css +1 -1
  12. package/pg/icon/__examples__/basic/basic.ts +1 -1
  13. package/pg/inputCheck/__examples__/basic/basic.ts +1 -1
  14. package/pg/inputCheck/inputCheck.css +5 -0
  15. package/pg/inputCheck/inputCheck.ts +4 -0
  16. package/pg/inputCheckList/__examples__/basic/basic.ts +1 -1
  17. package/pg/inputFileLocal/inputFileLocal.css +1 -1
  18. package/pg/inputNumber/README.md +27 -0
  19. package/pg/inputNumber/__examples__/basic/basic.html +9 -0
  20. package/pg/inputNumber/__examples__/basic/basic.ts +30 -0
  21. package/pg/inputNumber/inputNumber.css +34 -0
  22. package/pg/inputNumber/inputNumber.html +1 -0
  23. package/pg/inputNumber/inputNumber.spec.ts +59 -0
  24. package/pg/inputNumber/inputNumber.ts +63 -0
  25. package/pg/inputPixelEditor/README.md +211 -29
  26. package/pg/inputPixelEditor/__examples__/basic/basic.css +8 -0
  27. package/pg/inputPixelEditor/__examples__/basic/basic.html +29 -7
  28. package/pg/inputPixelEditor/__examples__/basic/basic.ts +274 -13
  29. package/pg/inputPixelEditor/__examples__/basic/constants.ts +62 -0
  30. package/pg/inputPixelEditor/inputPixelEditor.css +37 -2
  31. package/pg/inputPixelEditor/inputPixelEditor.html +22 -0
  32. package/pg/inputPixelEditor/inputPixelEditor.ts +822 -82
  33. package/pg/inputPixelEditor/utils/bitmapToMask.ts +22 -8
  34. package/pg/inputPixelEditor/utils/blobToImage.ts +11 -0
  35. package/pg/inputPixelEditor/utils/canvasToPngBuffer.ts +12 -0
  36. package/pg/inputPixelEditor/utils/constants.ts +55 -1
  37. package/pg/inputPixelEditor/utils/crc32.ts +116 -0
  38. package/pg/inputPixelEditor/utils/diffMap.ts +32 -0
  39. package/pg/inputPixelEditor/utils/generateGradient.ts +112 -0
  40. package/pg/inputPixelEditor/utils/getEllipsePixels.ts +131 -19
  41. package/pg/inputPixelEditor/utils/getFloodFill.ts +83 -0
  42. package/pg/inputPixelEditor/utils/getGridColorIndexes.ts +13 -0
  43. package/pg/inputPixelEditor/utils/getOutline.ts +92 -0
  44. package/pg/inputPixelEditor/utils/inputMode.ts +7 -1
  45. package/pg/inputPixelEditor/utils/pixelSizes.ts +47 -0
  46. package/pg/inputPixelEditor/utils/pngMetadata.ts +487 -0
  47. package/pg/inputSelect/inputSelect.css +4 -4
  48. package/pg/inputText/inputText.css +14 -7
  49. package/pg/inputText/inputText.ts +5 -1
  50. package/pg/json/README.md +59 -0
  51. package/pg/json/__examples__/basic/basic.html +4 -0
  52. package/pg/json/__examples__/basic/basic.ts +31 -0
  53. package/pg/json/json.css +9 -0
  54. package/pg/json/json.html +1 -0
  55. package/pg/json/json.ts +124 -0
  56. package/pg/jsonArray/README.md +3 -0
  57. package/pg/jsonArray/jsonArray.css +15 -0
  58. package/pg/jsonArray/jsonArray.html +7 -0
  59. package/pg/jsonArray/jsonArray.ts +55 -0
  60. package/pg/jsonBoolean/README.md +3 -0
  61. package/pg/jsonBoolean/jsonBoolean.css +27 -0
  62. package/pg/jsonBoolean/jsonBoolean.html +5 -0
  63. package/pg/jsonBoolean/jsonBoolean.ts +69 -0
  64. package/pg/jsonNumber/README.md +3 -0
  65. package/pg/jsonNumber/jsonNumber.css +21 -0
  66. package/pg/jsonNumber/jsonNumber.html +5 -0
  67. package/pg/jsonNumber/jsonNumber.ts +42 -0
  68. package/pg/jsonObject/README.md +3 -0
  69. package/pg/jsonObject/jsonObject.css +11 -0
  70. package/pg/jsonObject/jsonObject.html +5 -0
  71. package/pg/jsonObject/jsonObject.ts +55 -0
  72. package/pg/jsonString/README.md +3 -0
  73. package/pg/jsonString/jsonString.css +21 -0
  74. package/pg/jsonString/jsonString.html +5 -0
  75. package/pg/jsonString/jsonString.ts +42 -0
  76. package/pg/menu/menu.ts +6 -5
  77. package/pg/menuItem/README.md +13 -2
  78. package/pg/menuItem/menuItem.css +17 -22
  79. package/pg/menuItem/menuItem.ts +8 -3
  80. package/pg/menuItemIcon/__examples__/basic/basic.html +1 -1
  81. package/pg/menuItemIcon/__examples__/basic/basic.ts +7 -0
  82. package/pg/menuItemIcon/menuItemIcon.css +18 -15
  83. package/pg/menuItemIcon/menuItemIcon.ts +8 -4
  84. package/pg/modal/README.md +29 -0
  85. package/pg/modal/__examples__/basic/basic.html +4 -0
  86. package/pg/modal/__examples__/basic/basic.ts +42 -0
  87. package/pg/modal/index.ts +3 -0
  88. package/pg/modal/modal.css +40 -0
  89. package/pg/modal/modal.html +9 -0
  90. package/pg/modal/modal.ts +14 -0
  91. package/pg/modification/__examples__/basic/basic.ts +1 -1
  92. package/pg/overlayMenu/overlayMenu.ts +6 -2
  93. package/pg/overlaySelectMenu/overlaySelectMenu.ts +6 -0
  94. package/pg/overlaySubMenu/overlaySubMenu.ts +6 -2
  95. package/pg/scroll/__examples__/basic/basic.ts +1 -1
  96. package/pg/search/search.css +1 -1
  97. package/pg/table/README.md +108 -0
  98. package/pg/table/__examples__/basic/basic.css +0 -0
  99. package/pg/table/__examples__/basic/basic.html +10 -0
  100. package/pg/table/__examples__/basic/basic.ts +111 -0
  101. package/pg/table/table.css +20 -0
  102. package/pg/table/table.html +6 -0
  103. package/pg/table/table.ts +86 -0
  104. package/pg/tableCellButtonIcon/README.md +3 -0
  105. package/pg/tableCellButtonIcon/tableCellButtonIcon.css +16 -0
  106. package/pg/tableCellButtonIcon/tableCellButtonIcon.html +5 -0
  107. package/pg/tableCellButtonIcon/tableCellButtonIcon.ts +34 -0
  108. package/pg/tableCellCheck/README.md +3 -0
  109. package/pg/tableCellCheck/tableCellCheck.css +15 -0
  110. package/pg/tableCellCheck/tableCellCheck.html +3 -0
  111. package/pg/tableCellCheck/tableCellCheck.ts +43 -0
  112. package/pg/tableCellNumber/README.md +3 -0
  113. package/pg/tableCellNumber/tableCellNumber.css +11 -0
  114. package/pg/tableCellNumber/tableCellNumber.html +3 -0
  115. package/pg/tableCellNumber/tableCellNumber.ts +40 -0
  116. package/pg/tableCellText/README.md +3 -0
  117. package/pg/tableCellText/tableCellText.css +11 -0
  118. package/pg/tableCellText/tableCellText.html +3 -0
  119. package/pg/tableCellText/tableCellText.ts +62 -0
  120. package/pg/tableColumn/README.md +3 -0
  121. package/pg/tableColumn/tableColumn.css +12 -0
  122. package/pg/tableColumn/tableColumn.html +1 -0
  123. package/pg/tableColumn/tableColumn.ts +29 -0
  124. package/pg/tableRow/README.md +3 -0
  125. package/pg/tableRow/tableRow.css +11 -0
  126. package/pg/tableRow/tableRow.html +1 -0
  127. package/pg/tableRow/tableRow.ts +77 -0
  128. package/pg/tabs/tabs.css +1 -1
  129. package/pg/tree/README.md +10 -4
  130. package/pg/tree/__examples__/basic/basic.html +1 -0
  131. package/pg/tree/__examples__/basic/basic.ts +6 -1
  132. package/pg/tree/tree.css +1 -0
  133. package/pg/treeItem/treeItem.css +3 -3
  134. package/favicon.svg +0 -20
  135. package/index.html +0 -321
  136. package/main.js +0 -2
  137. package/main.js.LICENSE.txt +0 -10
  138. package/pgAnnoy.js +0 -1
  139. package/pgApp.js +0 -1
  140. package/pgAvatar.js +0 -1
  141. package/pgButton.js +0 -1
  142. package/pgButtonGroup.js +0 -1
  143. package/pgButtonLink.js +0 -1
  144. package/pgButtonMenu.js +0 -1
  145. package/pgButtonToggle.js +0 -1
  146. package/pgCard.js +0 -1
  147. package/pgCardUser.js +0 -1
  148. package/pgColor.js +0 -1
  149. package/pgDatabase.js +0 -1
  150. package/pgDropdown.js +0 -1
  151. package/pgGrid.js +0 -1
  152. package/pgHeader.js +0 -1
  153. package/pgIcon.js +0 -1
  154. package/pgInputCheck.js +0 -1
  155. package/pgInputCheckList.js +0 -1
  156. package/pgInputFileLocal.js +0 -1
  157. package/pgInputHexRgb.js +0 -1
  158. package/pgInputPixelEditor.js +0 -1
  159. package/pgInputRange.js +0 -1
  160. package/pgInputSelect.js +0 -1
  161. package/pgInputText.js +0 -1
  162. package/pgInputTextIcon.js +0 -1
  163. package/pgInputUserSelect.js +0 -1
  164. package/pgListTag.js +0 -1
  165. package/pgMarkdown.js +0 -2
  166. package/pgMarkdown.js.LICENSE.txt +0 -10
  167. package/pgMenu.js +0 -1
  168. package/pgMenuDivider.js +0 -1
  169. package/pgMenuIcon.js +0 -1
  170. package/pgMenuItem.js +0 -1
  171. package/pgMenuItemIcon.js +0 -1
  172. package/pgModalAlert.js +0 -1
  173. package/pgModification.js +0 -1
  174. package/pgNav.js +0 -1
  175. package/pgOverlay.js +0 -1
  176. package/pgOverlayContextMenu.js +0 -1
  177. package/pgOverlayMenu.js +0 -1
  178. package/pgOverlaySelectMenu.js +0 -1
  179. package/pgOverlaySubMenu.js +0 -1
  180. package/pgPicker.js +0 -1
  181. package/pgPreview.js +0 -1
  182. package/pgScroll.js +0 -1
  183. package/pgSearch.js +0 -1
  184. package/pgTab.js +0 -1
  185. package/pgTabs.js +0 -1
  186. package/pgToast.js +0 -1
  187. package/pgToasts.js +0 -1
  188. package/pgTooltip.js +0 -1
  189. package/pgTree.js +0 -1
  190. package/pgTreeButtonIcon.js +0 -1
  191. package/pgTreeItem.js +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pictogrammers/components",
3
3
  "type": "module",
4
- "version": "0.4.8",
4
+ "version": "0.5.0",
5
5
  "license": "MIT",
6
6
  "author": "Austin Andrews",
7
7
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  :host {
2
2
  display: block;
3
3
  position: var(--pg-annoy-position, fixed);
4
- font-family: var(--pg-font-family);
4
+ font-family: var(--pg-font-family, system-ui);
5
5
  width: var(--pg-annoy-width, 12rem);
6
6
  height: var(--pg-annoy-height, auto);
7
7
  max-height: var(--pg-annoy-max-height, auto);
@@ -1,25 +1,26 @@
1
1
  :host {
2
- display: contents;
2
+ display: inline-flex;
3
3
  }
4
4
 
5
5
  [part="button"] {
6
6
  display: flex;
7
7
  align-items: center;
8
8
  align-content: center;
9
- font-family: var(--pg-font-family);
9
+ font-family: var(--pg-font-family, system-ui);
10
10
  font-size: var(--pg-button-font-size, 1rem);
11
11
  line-height: var(--pg-button-line-height, 1.5rem);
12
- border: 1px solid var(--pg-button-border-color, #453C4F);
12
+ border: var(--pg-button-border-width, 1px) solid var(--pg-button-border-color, #453C4F);
13
13
  background-color: var(--pg-button-background-color, #FFFFFF);
14
14
  color: var(--pg-button-color, #453C4F);
15
15
  padding: var(--pg-button-padding, 0.25rem 0.5rem);
16
16
  border-radius: var(--pg-button-border-radius, 0.25rem);
17
17
  outline: none;
18
18
  --pg-icon-color: var(--pg-button-color, #453C4F);
19
+ cursor: var(--pg-button-cursor, var(--pg-cursor-default, default));
19
20
  }
20
21
 
21
22
  [part="button"]:hover {
22
- border: 1px solid var(--pg-button-hover-border-color, #453C4F);
23
+ --pg-button-border-color: var(--pg-button-hover-border-color, #453C4F);
23
24
  background-color: var(--pg-button-hover-background-color, #453C4F);
24
25
  color: var(--pg-button-hover-color, #FFFFFF);
25
26
  --pg-icon-color: var(--pg-button-hover-color, #FFFFFF);
@@ -6,7 +6,7 @@
6
6
  display: inline-flex;
7
7
  align-items: center;
8
8
  align-content: center;
9
- font-family: var(--pg-font-family);
9
+ font-family: var(--pg-font-family, system-ui);
10
10
  font-size: 1rem;
11
11
  line-height: 1.5rem;
12
12
  text-decoration: none;
@@ -37,7 +37,7 @@ export default class XPgButtonMenuBasic extends HTMLElement {
37
37
  }
38
38
 
39
39
  handleChange(e: any) {
40
- const { active } = e.detail;
41
- this.$value.textContent = `${active}`;
40
+ const { indexes, item } = e.detail;
41
+ this.$value.textContent = `indexes: ${indexes.join(',')}; item: ${JSON.stringify(item)}`;
42
42
  }
43
43
  }
@@ -52,9 +52,12 @@ export default class PgButtonMenu extends HTMLElement {
52
52
  });
53
53
  this.$icon.path = IconExpand;
54
54
  if (result !== undefined) {
55
+ const { indexes, item } = result;
55
56
  this.dispatchEvent(new CustomEvent('change', {
56
57
  detail: {
57
- value: result.value
58
+ indexes,
59
+ item,
60
+ value: item.value
58
61
  }
59
62
  }));
60
63
  }
@@ -1,7 +1,7 @@
1
1
  :host {
2
2
  display: flex;
3
3
  flex-direction: column;
4
- font-family: var(--pg-font-family);
4
+ font-family: var(--pg-font-family, system-ui);
5
5
  }
6
6
 
7
7
  [part="user"] {
@@ -1,5 +1,4 @@
1
1
  import { Component, Part, Prop } from '@pictogrammers/element';
2
- import PgDatabase from 'pg/database/database';
3
2
  import { Icon } from '../../../shared/models/icon';
4
3
 
5
4
  import template from './basic.html';
@@ -1,8 +1,5 @@
1
1
  import { Component, Part, Prop } from '@pictogrammers/element';
2
- import PgDatabase from 'pg/database/database';
3
- import PgTooltip from 'pg/tooltip';
4
- import { Icon } from '../../../shared/models/icon';
5
- import PgGrid from '../../grid';
2
+
6
3
 
7
4
  import template from './basic.html';
8
5
 
package/pg/grid/grid.css CHANGED
@@ -1,5 +1,5 @@
1
1
  * {
2
- font-family: var(--pg-font-family);
2
+ font-family: var(--pg-font-family, system-ui);
3
3
  }
4
4
 
5
5
  :host {
@@ -9,7 +9,7 @@ header {
9
9
  grid-column: 1 / span 2;
10
10
  background: var(--pg-header-background, #fff);
11
11
  color: var(--pg-header-color, #453C4F);
12
- font-family: var(--pg-font-family);
12
+ font-family: var(--pg-font-family, system-ui);
13
13
  height: 3rem;
14
14
  }
15
15
  header > a {
@@ -1,5 +1,5 @@
1
1
  import { Component, Part, Prop } from '@pictogrammers/element';
2
- import PgIcon from 'pg/icon/icon';
2
+ import PgIcon from '../../icon';
3
3
 
4
4
  import template from './basic.html';
5
5
  import { mdiAccount, mdiSquare } from './constants';
@@ -1,5 +1,5 @@
1
1
  import { Component, Part, Prop } from '@pictogrammers/element';
2
- import PgInputCheck from 'pg/inputCheck/inputCheck';
2
+ import PgInputCheck from '../../inputCheck';
3
3
 
4
4
  import template from './basic.html';
5
5
 
@@ -22,6 +22,11 @@
22
22
  background: transparent;
23
23
  }
24
24
 
25
+ [part="button"].readonly {
26
+ display: contents;
27
+ pointer-events: none;
28
+ }
29
+
25
30
  [part="svg"] {
26
31
  width: var(--pg-icon-check-size, 1.5rem);
27
32
  height: var(--pg-icon-check-size, 1.5rem);
@@ -14,6 +14,7 @@ const PATH_CHECKED = 'M19 19L5 19V5H15V3H5C3.89 3 3 3.89 3 5V19C3 20.1 3.89 21 5
14
14
  export default class PgInputCheck extends HTMLElement {
15
15
  @Prop() value: string | boolean = false;
16
16
  @Prop() disabled: boolean = false;
17
+ @Prop() readOnly: boolean = false;
17
18
 
18
19
  @Part() $button: HTMLButtonElement;
19
20
  @Part() $path: SVGPathElement;
@@ -38,5 +39,8 @@ export default class PgInputCheck extends HTMLElement {
38
39
  if (changes.disabled) {
39
40
  this.$button.disabled = ['', true, 'true'].includes(this.disabled);
40
41
  }
42
+ if (changes.readOnly) {
43
+ this.$button.classList.toggle('readonly', this.readOnly);
44
+ }
41
45
  }
42
46
  }
@@ -1,5 +1,5 @@
1
1
  import { Component, Part, Prop } from '@pictogrammers/element';
2
- import PgInputCheckList from 'pg/inputCheckList/inputCheckList';
2
+ import PgInputCheckList from '../../inputCheckList';
3
3
 
4
4
  import template from './basic.html';
5
5
 
@@ -6,7 +6,7 @@
6
6
  display: grid;
7
7
  grid-template-columns: 1.5rem auto;
8
8
  grid-template-rows: auto;
9
- font-family: var(--pg-font-family);
9
+ font-family: var(--pg-font-family, system-ui);
10
10
  font-size: 1rem;
11
11
  line-height: 1.5rem;
12
12
  border: 1px solid var(--pg-button-border-color, #453C4F);
@@ -0,0 +1,27 @@
1
+ # `<pg-input-number>`
2
+
3
+ The `pg-input-number` component creates an input that accepts number input.
4
+
5
+ ```typescript
6
+ import '@pictogrammers/components/pgInputNumber';
7
+ import PgInputNumber from '@pictogrammers/components/pgInputText';
8
+ ```
9
+
10
+ ```html
11
+ <pg-input-number value="50"></pg-input-number>
12
+ ```
13
+
14
+ ## Attributes
15
+
16
+ | Attributes | Tested | Description |
17
+ | ----------- | -------- | ----------- |
18
+ | name | | Unique name in `pg-form` |
19
+ | value | | Field value |
20
+ | placeholder | | Placeholder text |
21
+
22
+ ## Events
23
+
24
+ | Events | Tested | Description |
25
+ | ---------- | -------- | ----------- |
26
+ | change | | `{ detail: { value }` |
27
+ | input | | `{ detail: { value }` |
@@ -0,0 +1,9 @@
1
+ <div class="example">
2
+ <pg-input-number part="input" value="42"></pg-input-number>
3
+ <div>
4
+ <code>onchange: <span part="value1"></span></code>
5
+ </div>
6
+ <div>
7
+ <code>oninput: <span part="value2"></span></code>
8
+ </div>
9
+ </div>
@@ -0,0 +1,30 @@
1
+ import { Component, Part, Prop } from '@pictogrammers/element';
2
+ import PgInputNumber from '../../inputNumber';
3
+
4
+ import template from './basic.html';
5
+
6
+ @Component({
7
+ selector: 'x-pg-input-number-basic',
8
+ template
9
+ })
10
+ export default class XPgInputNumberBasic extends HTMLElement {
11
+
12
+ @Part() $input: PgInputNumber;
13
+ @Part() $value1: HTMLSpanElement;
14
+ @Part() $value2: HTMLSpanElement;
15
+
16
+ connectedCallback() {
17
+ this.$input.addEventListener('change', this.#handleChange.bind(this));
18
+ this.$input.addEventListener('input', this.#handleInput.bind(this));
19
+ }
20
+
21
+ #handleChange(e: CustomEvent) {
22
+ const { value } = e.detail;
23
+ this.$value1.textContent = value;
24
+ }
25
+
26
+ #handleInput(e: CustomEvent) {
27
+ const { value } = e.detail;
28
+ this.$value2.textContent = value;
29
+ }
30
+ }
@@ -0,0 +1,34 @@
1
+ :host {
2
+ display: block;
3
+ font-family: var(--pg-font-family, system-ui);
4
+ }
5
+
6
+ [part=input] {
7
+ border: 1px solid var(--pg-input-text-border-color, #453C4F);
8
+ border-radius: 0.125rem;
9
+ padding: var(--pg-input-text-padding, calc(0.5rem - 1px) 0.75rem);
10
+ font-family: var(--pg-input-number-font-family, var(--pg-font-family));
11
+ font-size: 1rem;
12
+ outline: none;
13
+ field-sizing: content;
14
+ min-width: calc(100% - 0.5rem - 2px);
15
+ max-width: calc(var(--pg-input-text-max-width, 100%) - 0.5rem - 2px);
16
+ background-color: transparent;
17
+ appearance: textfield;
18
+ }
19
+
20
+ [part=input]::-webkit-outer-spin-button,
21
+ [part=input]::-webkit-inner-spin-button {
22
+ -webkit-appearance: none;
23
+ }
24
+
25
+ [part=input]:read-only {
26
+ border-color: transparent;
27
+ }
28
+
29
+ [part=input]:active {
30
+ box-shadow: 0 0 0 3px var(--pg-input-text-active-glow, rgb(79, 143, 249, 0.6));
31
+ }
32
+ [part=input]:focus {
33
+ box-shadow: 0 0 0 3px var(--pg-input-text-focus-glow, rgb(79, 143, 249, 0.5));
34
+ }
@@ -0,0 +1 @@
1
+ <input part="input" type="number" />
@@ -0,0 +1,59 @@
1
+ import { selectComponent, getProps } from '@pictogrammers/element';
2
+
3
+ import './inputNumber';
4
+ import PgInputText from './inputNumber';
5
+
6
+ const PG_INPUT_TEXT = 'pg-input-text';
7
+
8
+ describe('pg-input-text', () => {
9
+
10
+ beforeEach(() => {
11
+ var c = document.createElement(PG_INPUT_TEXT);
12
+ document.body.appendChild(c);
13
+ });
14
+
15
+ afterEach(() => {
16
+ while (document.body.firstChild) {
17
+ document.body.removeChild(document.body.firstChild);
18
+ }
19
+ });
20
+
21
+ it('should be registered', () => {
22
+ expect(customElements.get(PG_INPUT_TEXT)).toBeDefined();
23
+ });
24
+
25
+ it('should only expose known props', () => {
26
+ const props = getProps(PG_INPUT_TEXT);
27
+ expect(props.length).toBe(3);
28
+ expect(props).toContain('name');
29
+ expect(props).toContain('value');
30
+ expect(props).toContain('placeholder');
31
+ });
32
+
33
+ it('should default value to empty', () => {
34
+ const component = selectComponent<PgInputText>(PG_INPUT_TEXT);
35
+ const { $input } = component;
36
+ expect($input.value).toEqual('');
37
+ });
38
+
39
+ it('should set value to "Hello World!"', () => {
40
+ const component = selectComponent<PgInputText>(PG_INPUT_TEXT);
41
+ component.value = 'Hello World!';
42
+ const { $input } = component;
43
+ expect($input.value).toEqual('Hello World!');
44
+ });
45
+
46
+ it('should default placeholder to empty', () => {
47
+ const component = selectComponent<PgInputText>(PG_INPUT_TEXT);
48
+ const { $input } = component;
49
+ expect($input.placeholder).toEqual('');
50
+ });
51
+
52
+ it('should set placeholder to "Hello World!"', () => {
53
+ const component = selectComponent<PgInputText>(PG_INPUT_TEXT);
54
+ component.placeholder = 'Hello World!';
55
+ const { $input } = component;
56
+ expect($input.placeholder).toEqual('Hello World!');
57
+ });
58
+
59
+ });
@@ -0,0 +1,63 @@
1
+ import { Component, Prop, Part } from '@pictogrammers/element';
2
+
3
+ import template from './inputNumber.html';
4
+ import style from './inputNumber.css';
5
+
6
+ @Component({
7
+ selector: 'pg-input-number',
8
+ style,
9
+ template,
10
+ })
11
+ export default class PgInputNumber extends HTMLElement {
12
+ @Prop() name: string = '';
13
+ @Prop() value: string = '';
14
+ @Prop() placeholder: string = '';
15
+ @Prop() readOnly: boolean = false;
16
+
17
+ @Part() $input: HTMLInputElement;
18
+
19
+ connectedCallback() {
20
+ this.$input.addEventListener('input', this.handleInput.bind(this));
21
+ this.$input.addEventListener('change', this.handleChange.bind(this));
22
+ }
23
+
24
+ skipValue = false;
25
+
26
+ render(changes) {
27
+ if (changes.value && !this.skipValue) {
28
+ this.$input.value = this.value;
29
+ }
30
+ if (changes.placeholder) {
31
+ this.$input.placeholder = this.placeholder;
32
+ }
33
+ if (changes.readOnly) {
34
+ this.$input.readOnly = this.readOnly;
35
+ }
36
+ this.skipValue = false;
37
+ }
38
+
39
+ handleInput(e) {
40
+ e.stopPropagation();
41
+ this.skipValue = true;
42
+ this.value = e.target.value;
43
+ this.dispatchEvent(
44
+ new CustomEvent('input', {
45
+ detail: {
46
+ value: e.target.value,
47
+ name: e.name
48
+ }
49
+ })
50
+ );
51
+ }
52
+
53
+ handleChange(e) {
54
+ this.dispatchEvent(
55
+ new CustomEvent('change', {
56
+ detail: {
57
+ value: e.target.value,
58
+ name: e.name
59
+ }
60
+ })
61
+ );
62
+ }
63
+ }