@xplortech/apollo-core 0.5.3 → 1.0.0-beta.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 (202) hide show
  1. package/build/style.css +758 -383
  2. package/dist/apollo-core/apollo-core.css +9 -5468
  3. package/dist/apollo-core/apollo-core.esm.js +1 -125
  4. package/dist/apollo-core/index.esm.js +0 -1
  5. package/dist/apollo-core/p-09b2f746.entry.js +1 -0
  6. package/dist/apollo-core/p-0bc956c6.entry.js +1 -0
  7. package/dist/apollo-core/p-1b1e7207.entry.js +1 -0
  8. package/dist/apollo-core/p-20389bb6.entry.js +1 -0
  9. package/dist/apollo-core/p-25983fde.entry.js +1 -0
  10. package/dist/apollo-core/p-2f90296c.js +10 -0
  11. package/dist/apollo-core/p-4a348764.entry.js +1 -0
  12. package/dist/apollo-core/p-4e2b69e8.entry.js +1 -0
  13. package/dist/apollo-core/p-84bf6b2d.entry.js +1 -0
  14. package/dist/apollo-core/p-880c0359.entry.js +1 -0
  15. package/dist/apollo-core/p-8e47a5be.entry.js +1 -0
  16. package/dist/apollo-core/p-93958292.entry.js +1 -0
  17. package/dist/apollo-core/p-93c27db5.entry.js +1 -0
  18. package/dist/apollo-core/p-ad90fe4d.js +1 -0
  19. package/dist/apollo-core/p-b2327e2c.entry.js +1 -0
  20. package/dist/apollo-core/p-c55b5d9c.entry.js +1 -0
  21. package/dist/apollo-core/p-e369d7af.entry.js +1 -0
  22. package/dist/apollo-core/p-e60ecaef.entry.js +1 -0
  23. package/dist/apollo-core/p-f929c958.js +1 -0
  24. package/dist/cjs/apollo-core.cjs.js +19 -0
  25. package/dist/cjs/index-54ba5804.js +1623 -0
  26. package/dist/cjs/index.cjs.js +2 -0
  27. package/dist/cjs/loader.cjs.js +21 -0
  28. package/dist/{apollo-core/regular-133c23b5.js → cjs/regular-872f5226.js} +3 -12
  29. package/dist/cjs/v4-14140ff3.js +77 -0
  30. package/dist/cjs/xpl-application-shell.cjs.entry.js +58 -0
  31. package/dist/cjs/xpl-avatar_12.cjs.entry.js +299 -0
  32. package/dist/cjs/xpl-backdrop.cjs.entry.js +25 -0
  33. package/dist/cjs/xpl-button-row.cjs.entry.js +22 -0
  34. package/dist/cjs/xpl-choicelist.cjs.entry.js +43 -0
  35. package/dist/cjs/xpl-divider.cjs.entry.js +18 -0
  36. package/dist/cjs/xpl-dropdown-group_3.cjs.entry.js +104 -0
  37. package/dist/cjs/xpl-dropdown_2.cjs.entry.js +123 -0
  38. package/dist/cjs/xpl-grid-item.cjs.entry.js +25 -0
  39. package/dist/cjs/xpl-grid.cjs.entry.js +35 -0
  40. package/dist/cjs/xpl-input.cjs.entry.js +2534 -0
  41. package/dist/cjs/xpl-list.cjs.entry.js +61 -0
  42. package/dist/cjs/xpl-main-nav.cjs.entry.js +30 -0
  43. package/dist/cjs/xpl-pagination.cjs.entry.js +76 -0
  44. package/dist/cjs/xpl-select.cjs.entry.js +625 -0
  45. package/dist/cjs/xpl-toggle.cjs.entry.js +34 -0
  46. package/dist/collection/collection-manifest.json +41 -0
  47. package/dist/collection/components/xpl-application-shell/xpl-application-shell.js +147 -0
  48. package/dist/collection/components/xpl-avatar/xpl-avatar.js +158 -0
  49. package/dist/collection/components/xpl-backdrop/xpl-backdrop.js +41 -0
  50. package/dist/collection/components/xpl-badge/xpl-badge.js +50 -0
  51. package/dist/{apollo-core/xpl-breadcrumb-item.entry.js → collection/components/xpl-breadcrumbs/xpl-breadcrumb-item/xpl-breadcrumb-item.js} +12 -11
  52. package/dist/collection/components/xpl-breadcrumbs/xpl-breadcrumbs/xpl-breadcrumbs.js +13 -0
  53. package/dist/collection/components/xpl-button/xpl-button.js +211 -0
  54. package/dist/collection/components/xpl-button-row/xpl-button-row.js +117 -0
  55. package/dist/collection/components/xpl-checkbox/xpl-checkbox.js +185 -0
  56. package/dist/collection/components/xpl-choicelist/xpl-choicelist.js +150 -0
  57. package/dist/collection/components/xpl-content-area/xpl-content-area.js +39 -0
  58. package/dist/collection/components/xpl-divider/xpl-divider.js +30 -0
  59. package/dist/collection/components/xpl-dropdown/xpl-dropdown-group/xpl-dropdown-group.js +66 -0
  60. package/dist/collection/components/xpl-dropdown/xpl-dropdown-heading/xpl-dropdown-heading.js +27 -0
  61. package/dist/collection/components/xpl-dropdown/xpl-dropdown-option/xpl-dropdown-option.js +110 -0
  62. package/dist/collection/components/xpl-dropdown/xpl-dropdown.js +260 -0
  63. package/dist/collection/components/xpl-grid/xpl-grid.js +26 -0
  64. package/dist/collection/components/xpl-grid-item/xpl-grid-item.js +93 -0
  65. package/dist/collection/components/xpl-input/xpl-input.js +478 -0
  66. package/dist/collection/components/xpl-list/xpl-list.js +91 -0
  67. package/dist/collection/components/xpl-main-nav/xpl-main-nav.js +72 -0
  68. package/dist/collection/components/xpl-nav-item/xpl-nav-item.js +67 -0
  69. package/dist/collection/components/xpl-pagination/xpl-pagination.js +190 -0
  70. package/dist/collection/components/xpl-radio/xpl-radio.js +168 -0
  71. package/dist/collection/components/xpl-secondary-nav/xpl-secondary-nav.js +9 -0
  72. package/dist/collection/components/xpl-select/xpl-select.js +344 -0
  73. package/dist/collection/components/xpl-table/xpl-table.js +200 -0
  74. package/dist/collection/components/xpl-tag/xpl-tag.js +30 -0
  75. package/dist/collection/components/xpl-toggle/xpl-toggle.js +157 -0
  76. package/dist/collection/components/xpl-utility-bar/xpl-utility-bar.js +66 -0
  77. package/dist/custom-elements/index.d.ts +24 -0
  78. package/dist/custom-elements/index.js +20201 -0
  79. package/dist/esm/apollo-core.js +17 -0
  80. package/dist/esm/index-3df6db84.js +1594 -0
  81. package/dist/esm/index.js +1 -0
  82. package/dist/esm/loader.js +17 -0
  83. package/dist/esm/polyfills/core-js.js +11 -0
  84. package/dist/esm/polyfills/css-shim.js +1 -0
  85. package/dist/esm/polyfills/dom.js +79 -0
  86. package/dist/esm/polyfills/es5-html-element.js +1 -0
  87. package/dist/esm/polyfills/index.js +34 -0
  88. package/dist/esm/polyfills/system.js +6 -0
  89. package/dist/esm/regular-86225e9d.js +16041 -0
  90. package/dist/esm/v4-929670b7.js +75 -0
  91. package/dist/{apollo-core → esm}/xpl-application-shell.entry.js +12 -8
  92. package/dist/esm/xpl-avatar_12.entry.js +284 -0
  93. package/dist/{apollo-core → esm}/xpl-backdrop.entry.js +2 -2
  94. package/dist/{apollo-core → esm}/xpl-button-row.entry.js +2 -4
  95. package/dist/esm/xpl-choicelist.entry.js +39 -0
  96. package/dist/{apollo-core → esm}/xpl-divider.entry.js +2 -2
  97. package/dist/esm/xpl-dropdown-group_3.entry.js +98 -0
  98. package/dist/esm/xpl-dropdown_2.entry.js +118 -0
  99. package/dist/{apollo-core → esm}/xpl-grid-item.entry.js +2 -2
  100. package/dist/esm/xpl-grid.entry.js +31 -0
  101. package/dist/{apollo-core → esm}/xpl-input.entry.js +35 -45
  102. package/dist/{apollo-core → esm}/xpl-list.entry.js +18 -20
  103. package/dist/{apollo-core → esm}/xpl-main-nav.entry.js +2 -2
  104. package/dist/{apollo-core → esm}/xpl-pagination.entry.js +8 -8
  105. package/dist/{apollo-core → esm}/xpl-select.entry.js +88 -126
  106. package/dist/esm/xpl-toggle.entry.js +30 -0
  107. package/dist/index.cjs.js +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/stories/application-shell.stories.js +767 -0
  110. package/dist/stories/avatar.stories.js +173 -0
  111. package/dist/stories/backdrop.stories.js +18 -0
  112. package/dist/stories/badge.stories.js +48 -0
  113. package/dist/stories/breadcrumbs.stories.js +117 -0
  114. package/dist/stories/button-row.stories.js +68 -0
  115. package/dist/stories/button.stories.js +110 -0
  116. package/dist/stories/checkbox.stories.js +78 -0
  117. package/dist/stories/choicelist.stories.js +112 -0
  118. package/dist/stories/content-area.stories.js +53 -0
  119. package/dist/stories/divider.stories.js +34 -0
  120. package/dist/stories/dropdown.stories.js +377 -0
  121. package/dist/stories/grid.stories.js +100 -0
  122. package/dist/stories/input.stories.js +268 -0
  123. package/dist/stories/list.stories.js +154 -0
  124. package/dist/stories/main-nav.stories.js +308 -0
  125. package/dist/stories/pagination.stories.js +84 -0
  126. package/dist/stories/radio.stories.js +68 -0
  127. package/dist/stories/secondary-nav.stories.js +76 -0
  128. package/dist/stories/select.stories.js +119 -0
  129. package/dist/stories/table.stories.js +107 -0
  130. package/dist/stories/tabs.stories.js +24 -0
  131. package/dist/stories/toggle.stories.js +84 -0
  132. package/dist/stories/utility-bar.stories.js +94 -0
  133. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/application-shell.stories.d.ts +4 -4
  134. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/avatar.stories.d.ts +1 -1
  135. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/backdrop.stories.d.ts +1 -1
  136. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/badge.stories.d.ts +1 -1
  137. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/breadcrumbs.stories.d.ts +1 -1
  138. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/button-row.stories.d.ts +1 -1
  139. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/button.stories.d.ts +19 -10
  140. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/checkbox.stories.d.ts +2 -2
  141. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/choicelist.stories.d.ts +1 -1
  142. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/content-area.stories.d.ts +1 -1
  143. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/divider.stories.d.ts +1 -1
  144. package/dist/types/Users/fernandogelin/Projects/apollo/.stencil/stories/dropdown.stories.d.ts +134 -0
  145. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/grid.stories.d.ts +1 -1
  146. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/input.stories.d.ts +5 -5
  147. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/list.stories.d.ts +1 -1
  148. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/main-nav.stories.d.ts +1 -1
  149. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/radio.stories.d.ts +1 -1
  150. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/secondary-nav.stories.d.ts +1 -1
  151. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/select.stories.d.ts +2 -2
  152. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/table.stories.d.ts +1 -1
  153. package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/toggle.stories.d.ts +2 -2
  154. package/dist/types/components/xpl-application-shell/xpl-application-shell.d.ts +2 -2
  155. package/dist/types/components/xpl-avatar/xpl-avatar.d.ts +3 -3
  156. package/dist/types/components/xpl-badge/xpl-badge.d.ts +1 -1
  157. package/dist/types/components/xpl-button/xpl-button.d.ts +32 -8
  158. package/dist/types/components/xpl-button-row/xpl-button-row.d.ts +3 -3
  159. package/dist/types/components/xpl-checkbox/xpl-checkbox.d.ts +1 -1
  160. package/dist/types/components/xpl-choicelist/xpl-choicelist.d.ts +0 -1
  161. package/dist/types/components/xpl-content-area/xpl-content-area.d.ts +3 -3
  162. package/dist/types/components/xpl-dropdown/xpl-dropdown-group/xpl-dropdown-group.d.ts +7 -0
  163. package/dist/types/components/xpl-dropdown/xpl-dropdown-heading/xpl-dropdown-heading.d.ts +5 -0
  164. package/dist/types/components/xpl-input/xpl-input.d.ts +4 -4
  165. package/dist/types/components/xpl-list/xpl-list.d.ts +2 -3
  166. package/dist/types/components/xpl-main-nav/xpl-main-nav.d.ts +1 -1
  167. package/dist/types/components/xpl-nav-item/xpl-nav-item.d.ts +10 -0
  168. package/dist/types/components/xpl-pagination/xpl-pagination.d.ts +1 -1
  169. package/dist/types/components/xpl-radio/xpl-radio.d.ts +1 -1
  170. package/dist/types/components/xpl-select/xpl-select.d.ts +6 -3
  171. package/dist/types/components/xpl-table/xpl-table.d.ts +1 -1
  172. package/dist/types/components/xpl-toggle/xpl-toggle.d.ts +1 -1
  173. package/dist/types/components.d.ts +264 -43
  174. package/package.json +10 -4
  175. package/dist/apollo-core/app-globals-0f993ce5.js +0 -3
  176. package/dist/apollo-core/css-shim-bbdf0cc6.js +0 -4
  177. package/dist/apollo-core/dom-1f98a75f.js +0 -73
  178. package/dist/apollo-core/index-3c9f25ef.js +0 -2938
  179. package/dist/apollo-core/index-912d1a21.js +0 -584
  180. package/dist/apollo-core/shadow-css-67b66845.js +0 -389
  181. package/dist/apollo-core/xpl-avatar.entry.js +0 -19
  182. package/dist/apollo-core/xpl-badge.entry.js +0 -17
  183. package/dist/apollo-core/xpl-breadcrumbs.entry.js +0 -14
  184. package/dist/apollo-core/xpl-button.entry.js +0 -34
  185. package/dist/apollo-core/xpl-checkbox.entry.js +0 -25
  186. package/dist/apollo-core/xpl-choicelist.entry.js +0 -32
  187. package/dist/apollo-core/xpl-content-area.entry.js +0 -16
  188. package/dist/apollo-core/xpl-grid.entry.js +0 -31
  189. package/dist/apollo-core/xpl-nav-item.entry.js +0 -12
  190. package/dist/apollo-core/xpl-radio.entry.js +0 -25
  191. package/dist/apollo-core/xpl-secondary-nav.entry.js +0 -12
  192. package/dist/apollo-core/xpl-table.entry.js +0 -85
  193. package/dist/apollo-core/xpl-tag.entry.js +0 -17
  194. package/dist/apollo-core/xpl-toggle.entry.js +0 -30
  195. package/dist/apollo-core/xpl-utility-bar.entry.js +0 -25
  196. package/dist/types/components/xpl-choicelist/choice.d.ts +0 -6
  197. package/dist/types/components/xpl-dropdown/dropdownchoice.d.ts +0 -6
  198. package/dist/types/components/xpl-dropdown/xpl-dropdown.d.ts +0 -11
  199. package/dist/types/components/xpl-list/listitem.d.ts +0 -16
  200. /package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/pagination.stories.d.ts +0 -0
  201. /package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/tabs.stories.d.ts +0 -0
  202. /package/dist/types/Users/{roc/Sites → fernandogelin/Projects}/apollo/.stencil/stories/utility-bar.stories.d.ts +0 -0
@@ -0,0 +1,344 @@
1
+ import { v4 as uuid } from 'uuid';
2
+ import { Component, Host, h, Prop, State } from '@stencil/core';
3
+ import throttle from 'lodash.throttle';
4
+ function tagWidth(text) {
5
+ const context = document.createElement('canvas').getContext('2d');
6
+ context.font =
7
+ "14px apple-system, system-ui, 'Segoe UI', Arial, Helvetica, Roboto, sans-serif";
8
+ return context.measureText(text).width + 44; // = text + l/r padding + margin-right
9
+ }
10
+ export class XplSelect {
11
+ constructor() {
12
+ /**
13
+ * An array of choices for the user to choose from.
14
+ * Each choice should be of the form:
15
+ * {
16
+ * label: string;
17
+ * href?: string;
18
+ * value?: string;
19
+ * isGroupHeading?: boolean;
20
+ * }
21
+ */
22
+ this.choices = [];
23
+ /**
24
+ * Whether to allow a single choice or multiple choices.
25
+ */
26
+ this.mode = 'single';
27
+ /**
28
+ * Only used in multi-choice selects. If `true`,
29
+ * badges representing selections that would overflow the
30
+ * container are replaced with "+x more" (where x is the
31
+ * number not shown). If `false`, the container's height will
32
+ * adjust to show all badges representing selections.
33
+ */
34
+ this.truncate = true;
35
+ this.active = false;
36
+ this.id = uuid();
37
+ this.keepFocus = false;
38
+ this.value = '';
39
+ this.displayValue = '';
40
+ // infinity isn't real, it's just a mathematical construct, it can't hurt you
41
+ this.visibleChoices = Infinity;
42
+ }
43
+ componentWillLoad() {
44
+ this.selected =
45
+ this.choices && this.choices.length > 0
46
+ ? this.choices.map(() => false)
47
+ : [];
48
+ window.addEventListener('click', (e) => {
49
+ const el = e.target;
50
+ const select = el.closest('.xpl-select');
51
+ if (select === null || select !== this.container) {
52
+ this.active = false;
53
+ }
54
+ });
55
+ window.addEventListener('resize', throttle(() => {
56
+ this.maybeTruncateChoices();
57
+ }, 250));
58
+ }
59
+ componentDidLoad() {
60
+ this.dropdown = this.container.querySelector('xpl-dropdown');
61
+ }
62
+ maybeTruncateChoices() {
63
+ if (this.mode === 'single' || !this.truncate)
64
+ return;
65
+ const containerWidth = this.container.getBoundingClientRect().width;
66
+ let visibleChoices = 0;
67
+ let visibleChoicesWidth = 0;
68
+ const actualNumSelected = this.selected.filter((a) => a).length;
69
+ for (let i = 0; i < actualNumSelected; i++) {
70
+ visibleChoicesWidth += tagWidth(this.getDisplayValue(i));
71
+ if (visibleChoicesWidth > containerWidth - 140)
72
+ break;
73
+ visibleChoices++;
74
+ }
75
+ if (visibleChoices >= actualNumSelected)
76
+ visibleChoices = Infinity;
77
+ if (visibleChoices < 1)
78
+ visibleChoices = 1;
79
+ this.visibleChoices = visibleChoices;
80
+ }
81
+ flattenChoices() {
82
+ return this.choices.reduce((acc, curr) => [
83
+ ...acc,
84
+ ...(curr.groupName ? curr.options : [curr]),
85
+ ], []);
86
+ }
87
+ getDisplayValue(i) {
88
+ return this.flattenChoices()[i].label || this.flattenChoices()[i].value;
89
+ }
90
+ getActualValue(i) {
91
+ return this.flattenChoices()[i].value || this.flattenChoices()[i].label;
92
+ }
93
+ update() {
94
+ this.selected = this.flattenChoices().map(({ isSelected }) => isSelected);
95
+ if (this.mode === 'single') {
96
+ const selected = this.selected.findIndex((v) => v);
97
+ this.value = selected >= 0 ? this.getActualValue(selected) : '';
98
+ this.displayValue =
99
+ selected >= 0 ? this.getDisplayValue(selected) : '';
100
+ }
101
+ else if (this.mode === 'multi') {
102
+ this.value = this.selected
103
+ .map((v, i) => {
104
+ return v ? this.getActualValue(i) : '';
105
+ })
106
+ .filter((v) => v.length > 0)
107
+ .join('|');
108
+ }
109
+ }
110
+ render() {
111
+ let visibleChoices = 0;
112
+ return (h(Host, { class: {
113
+ 'xpl-select': true,
114
+ 'xpl-select--disabled': this.disabled,
115
+ 'xpl-select--no-truncate': !this.truncate,
116
+ }, onKeyDown: (e) => {
117
+ if (e.key === 'Escape')
118
+ this.active = false;
119
+ }, ref: (el) => (this.container = el) },
120
+ this.label || this.description ? (h("label", { class: {
121
+ 'xpl-label': true,
122
+ 'xpl-label--disabled': this.disabled,
123
+ }, htmlFor: this.id },
124
+ this.label,
125
+ this.description && (h("small", { class: {
126
+ 'xpl-description': true,
127
+ 'xpl-description--disabled': this.disabled,
128
+ } }, this.description)))) : null,
129
+ h("div", { class: {
130
+ 'xpl-input': true,
131
+ 'xpl-input--disabled': this.disabled,
132
+ 'xpl-input--error': this.error !== undefined,
133
+ } },
134
+ h("div", { class: "xpl-input-wrapper" },
135
+ h("div", { class: {
136
+ 'xpl-select-value': true,
137
+ 'xpl-select-value--active': this.mode === 'multi' &&
138
+ this.value.length > 0,
139
+ 'has-value': this.value.length > 0,
140
+ } },
141
+ this.mode === 'single'
142
+ ? this.displayValue || this.placeholder
143
+ : this.value.length > 0
144
+ ? this.selected.map((v, i) => {
145
+ if (!v)
146
+ return null;
147
+ if (visibleChoices >= this.visibleChoices)
148
+ return null;
149
+ visibleChoices++;
150
+ return (h("xpl-tag", { onClose: () => {
151
+ this.flattenChoices().forEach((v, j) => {
152
+ if (i === j)
153
+ v.isSelected =
154
+ false;
155
+ });
156
+ const mapOptions = (option) => {
157
+ option.options =
158
+ option.groupName
159
+ ? option.options.map(mapOptions)
160
+ : undefined;
161
+ return option;
162
+ };
163
+ this.choices =
164
+ this.choices.map(mapOptions);
165
+ this.update();
166
+ this.maybeTruncateChoices();
167
+ } }, this.getDisplayValue(i)));
168
+ })
169
+ : this.placeholder,
170
+ this.visibleChoices < Infinity &&
171
+ `+ ${this.selected.filter((a) => a).length -
172
+ this.visibleChoices} more`),
173
+ h("button", { disabled: this.disabled, id: this.id, onKeyDown: (e) => {
174
+ if (e.key === 'Tab')
175
+ this.keepFocus = true;
176
+ }, onClick: () => {
177
+ const { dropdown } = this;
178
+ if (!this.disabled)
179
+ dropdown.isOpen = !dropdown.isOpen;
180
+ } })),
181
+ !this.disabled && (h("xpl-dropdown", { options: this.choices, mode: this.mode, triggerId: this.id, update: () => {
182
+ this.update();
183
+ this.maybeTruncateChoices();
184
+ } })),
185
+ this.error !== undefined && this.error.length > 0 && (h("label", { class: "xpl-input-error", htmlFor: this.id },
186
+ h("svg", { width: "10", height: "11", viewBox: "0 0 10 11", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
187
+ h("path", { d: "M9.84375 5.25C9.84375 2.59375 7.65625 0.40625 5 0.40625C2.32422 0.40625 0.15625 2.59375 0.15625 5.25C0.15625 7.92578 2.32422 10.0938 5 10.0938C7.65625 10.0938 9.84375 7.92578 9.84375 5.25ZM5 6.22656C5.48828 6.22656 5.89844 6.63672 5.89844 7.125C5.89844 7.63281 5.48828 8.02344 5 8.02344C4.49219 8.02344 4.10156 7.63281 4.10156 7.125C4.10156 6.63672 4.49219 6.22656 5 6.22656ZM4.14062 3.00391C4.12109 2.86719 4.23828 2.75 4.375 2.75H5.60547C5.74219 2.75 5.85938 2.86719 5.83984 3.00391L5.70312 5.66016C5.68359 5.79688 5.58594 5.875 5.46875 5.875H4.51172C4.39453 5.875 4.29688 5.79688 4.27734 5.66016L4.14062 3.00391Z" })),
188
+ this.error))),
189
+ h("input", { type: "hidden", value: this.value })));
190
+ }
191
+ static get is() { return "xpl-select"; }
192
+ static get properties() { return {
193
+ "choices": {
194
+ "type": "unknown",
195
+ "mutable": false,
196
+ "complexType": {
197
+ "original": "SelectChoice[]",
198
+ "resolved": "SelectChoice[]",
199
+ "references": {
200
+ "SelectChoice": {
201
+ "location": "global"
202
+ }
203
+ }
204
+ },
205
+ "required": false,
206
+ "optional": true,
207
+ "docs": {
208
+ "tags": [],
209
+ "text": "An array of choices for the user to choose from.\nEach choice should be of the form:\n{\n label: string;\n href?: string;\n value?: string;\n isGroupHeading?: boolean;\n}"
210
+ },
211
+ "defaultValue": "[]"
212
+ },
213
+ "description": {
214
+ "type": "string",
215
+ "mutable": false,
216
+ "complexType": {
217
+ "original": "string",
218
+ "resolved": "string",
219
+ "references": {}
220
+ },
221
+ "required": false,
222
+ "optional": true,
223
+ "docs": {
224
+ "tags": [],
225
+ "text": "Optional text that appears below the input label."
226
+ },
227
+ "attribute": "description",
228
+ "reflect": false
229
+ },
230
+ "disabled": {
231
+ "type": "boolean",
232
+ "mutable": false,
233
+ "complexType": {
234
+ "original": "boolean",
235
+ "resolved": "boolean",
236
+ "references": {}
237
+ },
238
+ "required": false,
239
+ "optional": true,
240
+ "docs": {
241
+ "tags": [],
242
+ "text": ""
243
+ },
244
+ "attribute": "disabled",
245
+ "reflect": false
246
+ },
247
+ "error": {
248
+ "type": "string",
249
+ "mutable": false,
250
+ "complexType": {
251
+ "original": "string",
252
+ "resolved": "string",
253
+ "references": {}
254
+ },
255
+ "required": false,
256
+ "optional": true,
257
+ "docs": {
258
+ "tags": [],
259
+ "text": "If an empty string (attribute present with no value),\nwill display visually as an error. If a string is\nincluded, will display visually as an error and include\nthe value as an error message."
260
+ },
261
+ "attribute": "error",
262
+ "reflect": false
263
+ },
264
+ "label": {
265
+ "type": "string",
266
+ "mutable": false,
267
+ "complexType": {
268
+ "original": "string",
269
+ "resolved": "string",
270
+ "references": {}
271
+ },
272
+ "required": false,
273
+ "optional": true,
274
+ "docs": {
275
+ "tags": [],
276
+ "text": ""
277
+ },
278
+ "attribute": "label",
279
+ "reflect": false
280
+ },
281
+ "mode": {
282
+ "type": "string",
283
+ "mutable": false,
284
+ "complexType": {
285
+ "original": "'single' | 'multi'",
286
+ "resolved": "\"multi\" | \"single\"",
287
+ "references": {}
288
+ },
289
+ "required": false,
290
+ "optional": true,
291
+ "docs": {
292
+ "tags": [],
293
+ "text": "Whether to allow a single choice or multiple choices."
294
+ },
295
+ "attribute": "mode",
296
+ "reflect": false,
297
+ "defaultValue": "'single'"
298
+ },
299
+ "placeholder": {
300
+ "type": "string",
301
+ "mutable": false,
302
+ "complexType": {
303
+ "original": "string",
304
+ "resolved": "string",
305
+ "references": {}
306
+ },
307
+ "required": false,
308
+ "optional": false,
309
+ "docs": {
310
+ "tags": [],
311
+ "text": ""
312
+ },
313
+ "attribute": "placeholder",
314
+ "reflect": false
315
+ },
316
+ "truncate": {
317
+ "type": "boolean",
318
+ "mutable": false,
319
+ "complexType": {
320
+ "original": "boolean",
321
+ "resolved": "boolean",
322
+ "references": {}
323
+ },
324
+ "required": false,
325
+ "optional": true,
326
+ "docs": {
327
+ "tags": [],
328
+ "text": "Only used in multi-choice selects. If `true`,\nbadges representing selections that would overflow the\ncontainer are replaced with \"+x more\" (where x is the\nnumber not shown). If `false`, the container's height will\nadjust to show all badges representing selections."
329
+ },
330
+ "attribute": "truncate",
331
+ "reflect": false,
332
+ "defaultValue": "true"
333
+ }
334
+ }; }
335
+ static get states() { return {
336
+ "active": {},
337
+ "id": {},
338
+ "keepFocus": {},
339
+ "selected": {},
340
+ "value": {},
341
+ "displayValue": {},
342
+ "visibleChoices": {}
343
+ }; }
344
+ }
@@ -0,0 +1,200 @@
1
+ import { Component, Host, Prop, State, Event, h, } from '@stencil/core';
2
+ export class XplTable {
3
+ constructor() {
4
+ this.areAllSelected = false;
5
+ this.hasScrolled = false;
6
+ this.selectAll = (e) => {
7
+ const { target } = e;
8
+ if (!(target instanceof HTMLInputElement))
9
+ return;
10
+ const { checked } = target;
11
+ this.areAllSelected = checked;
12
+ this.selected = this.selected.map(() => checked);
13
+ this.onChange();
14
+ };
15
+ this.selectOne = (e, i) => {
16
+ const { target } = e;
17
+ if (!(target instanceof HTMLInputElement))
18
+ return;
19
+ const { checked } = target;
20
+ this.areAllSelected = false;
21
+ this.selected = this.selected.map((v, _i) => (_i === i ? checked : v));
22
+ this.onChange();
23
+ };
24
+ this.onChange = () => {
25
+ this.tableSelect.emit({
26
+ selected: this.selected,
27
+ areAllSelected: this.areAllSelected,
28
+ });
29
+ };
30
+ this.onScroll = () => {
31
+ this.hasScrolled = this.container.scrollLeft > 0;
32
+ };
33
+ /**
34
+ * TODO: Need to figure out how this interplays with data
35
+ * received from an API/server
36
+ */
37
+ this.sortBy = (col, ascending = true) => {
38
+ this.rowData.sort((a, b) => {
39
+ const A = a[col];
40
+ const B = b[col];
41
+ if (typeof A === 'number' && typeof B === 'number') {
42
+ const f = ascending ? 1 : -1;
43
+ return A > B ? f : -f;
44
+ }
45
+ return -1;
46
+ });
47
+ this.rowData = Array.from(this.rowData);
48
+ this.render();
49
+ };
50
+ }
51
+ componentWillLoad() {
52
+ this.areAllSelected = false;
53
+ this.rowData = this.data !== undefined ? Array.from(this.data) : [];
54
+ this.selected = new Array(this.rowData.length).fill(false);
55
+ }
56
+ render() {
57
+ let className = 'xpl-table';
58
+ if (this.striped)
59
+ className += ' xpl-table--striped';
60
+ if (this.freeze)
61
+ className += ' xpl-table--freeze';
62
+ if (this.hasScrolled)
63
+ className += ' xpl-table--has-scrolled';
64
+ return (h(Host, null,
65
+ h("div", { class: "xpl-table-container", onScroll: this.onScroll, ref: (el) => (this.container = el) },
66
+ h("table", { class: className },
67
+ this.columns && (h("thead", null, this.columns.map((column, i) => {
68
+ return (h("th", null, this.multiselect && i === 0 ? (h("label", { htmlFor: "__xpl-table-th" },
69
+ h("input", { checked: this.areAllSelected, id: "__xpl-table-th",
70
+ // appear indeterminate when at least one but not all
71
+ // are selected
72
+ indeterminate: !this
73
+ .areAllSelected &&
74
+ this.selected.some((a) => a), onChange: (e) => {
75
+ this.selectAll(e);
76
+ }, type: "checkbox" }),
77
+ column)) : (column)));
78
+ }))),
79
+ h("tbody", null, this.rowData.map((row, rowNum) => {
80
+ return (h("tr", { class: this.selected &&
81
+ this.selected[rowNum]
82
+ ? 'xpl-table-row-selected'
83
+ : '' }, row.map((cell, i) => {
84
+ return (h("td", null, this.multiselect &&
85
+ i === 0 ? (h("label", { htmlFor: '__xpl-table-row-' +
86
+ rowNum },
87
+ h("input", { id: '__xpl-table-row-' +
88
+ rowNum, checked: this
89
+ .selected[rowNum], type: "checkbox", onChange: (e) => this.selectOne(e, rowNum) }),
90
+ h("div", { innerHTML: cell }))) : (h("div", { innerHTML: cell }))));
91
+ })));
92
+ }))))));
93
+ }
94
+ static get is() { return "xpl-table"; }
95
+ static get properties() { return {
96
+ "columns": {
97
+ "type": "unknown",
98
+ "mutable": false,
99
+ "complexType": {
100
+ "original": "string[]",
101
+ "resolved": "string[]",
102
+ "references": {}
103
+ },
104
+ "required": false,
105
+ "optional": true,
106
+ "docs": {
107
+ "tags": [],
108
+ "text": ""
109
+ }
110
+ },
111
+ "data": {
112
+ "type": "unknown",
113
+ "mutable": false,
114
+ "complexType": {
115
+ "original": "string[][]",
116
+ "resolved": "string[][]",
117
+ "references": {}
118
+ },
119
+ "required": false,
120
+ "optional": true,
121
+ "docs": {
122
+ "tags": [],
123
+ "text": ""
124
+ }
125
+ },
126
+ "freeze": {
127
+ "type": "boolean",
128
+ "mutable": false,
129
+ "complexType": {
130
+ "original": "boolean",
131
+ "resolved": "boolean",
132
+ "references": {}
133
+ },
134
+ "required": false,
135
+ "optional": true,
136
+ "docs": {
137
+ "tags": [],
138
+ "text": ""
139
+ },
140
+ "attribute": "freeze",
141
+ "reflect": false
142
+ },
143
+ "multiselect": {
144
+ "type": "boolean",
145
+ "mutable": false,
146
+ "complexType": {
147
+ "original": "boolean",
148
+ "resolved": "boolean",
149
+ "references": {}
150
+ },
151
+ "required": false,
152
+ "optional": true,
153
+ "docs": {
154
+ "tags": [],
155
+ "text": ""
156
+ },
157
+ "attribute": "multiselect",
158
+ "reflect": false
159
+ },
160
+ "striped": {
161
+ "type": "boolean",
162
+ "mutable": false,
163
+ "complexType": {
164
+ "original": "boolean",
165
+ "resolved": "boolean",
166
+ "references": {}
167
+ },
168
+ "required": false,
169
+ "optional": true,
170
+ "docs": {
171
+ "tags": [],
172
+ "text": ""
173
+ },
174
+ "attribute": "striped",
175
+ "reflect": false
176
+ }
177
+ }; }
178
+ static get states() { return {
179
+ "areAllSelected": {},
180
+ "rowData": {},
181
+ "hasScrolled": {},
182
+ "selected": {}
183
+ }; }
184
+ static get events() { return [{
185
+ "method": "tableSelect",
186
+ "name": "tableSelect",
187
+ "bubbles": true,
188
+ "cancelable": true,
189
+ "composed": true,
190
+ "docs": {
191
+ "tags": [],
192
+ "text": ""
193
+ },
194
+ "complexType": {
195
+ "original": "any",
196
+ "resolved": "any",
197
+ "references": {}
198
+ }
199
+ }]; }
200
+ }
@@ -0,0 +1,30 @@
1
+ import { Component, Host, h, Event } from '@stencil/core';
2
+ export class XplTag {
3
+ render() {
4
+ return (h(Host, { class: "xpl-tag-container" },
5
+ h("button", { class: "xpl-tag", onClick: () => {
6
+ this.close.emit();
7
+ } },
8
+ h("slot", null)),
9
+ h("button", { class: "xpl-tag__close", onClick: () => {
10
+ this.close.emit();
11
+ } }, "\u00D7")));
12
+ }
13
+ static get is() { return "xpl-tag"; }
14
+ static get events() { return [{
15
+ "method": "close",
16
+ "name": "close",
17
+ "bubbles": true,
18
+ "cancelable": true,
19
+ "composed": true,
20
+ "docs": {
21
+ "tags": [],
22
+ "text": ""
23
+ },
24
+ "complexType": {
25
+ "original": "any",
26
+ "resolved": "any",
27
+ "references": {}
28
+ }
29
+ }]; }
30
+ }