@stackoverflow/stacks 0.74.0 → 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 (89) hide show
  1. package/dist/controllers/index.d.ts +7 -0
  2. package/dist/controllers/s-expandable-control.d.ts +17 -0
  3. package/dist/controllers/s-modal.d.ts +97 -0
  4. package/dist/controllers/s-navigation-tablist.d.ts +36 -0
  5. package/dist/controllers/s-popover.d.ts +155 -0
  6. package/dist/controllers/s-table.d.ts +8 -0
  7. package/dist/controllers/s-tooltip.d.ts +82 -0
  8. package/dist/controllers/s-uploader.d.ts +48 -0
  9. package/dist/css/stacks.css +4633 -2703
  10. package/dist/css/stacks.min.css +1 -1
  11. package/dist/index.d.ts +3 -0
  12. package/dist/js/stacks.js +6026 -5403
  13. package/dist/js/stacks.min.js +1 -1
  14. package/dist/stacks.d.ts +21 -0
  15. package/lib/css/atomic/{_stacks-borders.less → borders.less} +30 -30
  16. package/lib/css/atomic/{_stacks-colors.less → colors.less} +0 -0
  17. package/lib/css/atomic/{_stacks-flex.less → flex.less} +14 -13
  18. package/lib/css/atomic/{_stacks-grid.less → grid.less} +12 -11
  19. package/lib/css/atomic/{_stacks-misc.less → misc.less} +23 -22
  20. package/lib/css/atomic/spacing.less +314 -0
  21. package/lib/css/atomic/{_stacks-typography.less → typography.less} +29 -29
  22. package/lib/css/atomic/width-height.less +194 -0
  23. package/lib/css/base/{_stacks-body.less → body.less} +3 -5
  24. package/lib/css/base/{_stacks-configuration-static.less → configuration-static.less} +3 -1
  25. package/lib/css/base/{_stacks-icons.less → icons.less} +0 -0
  26. package/lib/css/base/{_stacks-internals.less → internals.less} +0 -10
  27. package/lib/css/base/{_stacks-reset-meyer.less → reset-meyer.less} +0 -0
  28. package/lib/css/base/{_stacks-reset-normalize.less → reset-normalize.less} +0 -0
  29. package/lib/css/base/{_stacks-reset.less → reset.less} +2 -2
  30. package/lib/css/components/{_stacks-activity-indicator.less → activity-indicator.less} +9 -9
  31. package/lib/css/components/{_stacks-avatars.less → avatars.less} +40 -40
  32. package/lib/css/components/{_stacks-badges.less → badges.less} +11 -11
  33. package/lib/css/components/{_stacks-banners.less → banners.less} +5 -6
  34. package/lib/css/components/{_stacks-blank-states.less → blank-states.less} +2 -2
  35. package/lib/css/components/{_stacks-breadcrumbs.less → breadcrumbs.less} +7 -7
  36. package/lib/css/components/{_stacks-button-groups.less → button-groups.less} +2 -2
  37. package/lib/css/components/{_stacks-buttons.less → buttons.less} +77 -72
  38. package/lib/css/components/{_stacks-cards.less → cards.less} +2 -2
  39. package/lib/css/components/{_stacks-code-blocks.less → code-blocks.less} +8 -8
  40. package/lib/css/components/{_stacks-collapsible.less → collapsible.less} +0 -0
  41. package/lib/css/components/{_stacks-inputs.less → inputs.less} +41 -41
  42. package/lib/css/components/{_stacks-link-previews.less → link-previews.less} +17 -17
  43. package/lib/css/components/{_stacks-links.less → links.less} +4 -4
  44. package/lib/css/components/{_stacks-menu.less → menu.less} +5 -5
  45. package/lib/css/components/{_stacks-modals.less → modals.less} +20 -20
  46. package/lib/css/components/{_stacks-navigation.less → navigation.less} +12 -12
  47. package/lib/css/components/{_stacks-notices.less → notices.less} +12 -12
  48. package/lib/css/components/{_stacks-page-titles.less → page-titles.less} +9 -9
  49. package/lib/css/components/{_stacks-pagination.less → pagination.less} +8 -8
  50. package/lib/css/components/{_stacks-popovers.less → popovers.less} +17 -17
  51. package/lib/css/components/{_stacks-post-summary.less → post-summary.less} +155 -60
  52. package/lib/css/components/{_stacks-progress-bars.less → progress-bars.less} +29 -30
  53. package/lib/css/components/{_stacks-prose.less → prose.less} +31 -31
  54. package/lib/css/components/{_stacks-spinner.less → spinner.less} +14 -14
  55. package/lib/css/components/{_stacks-tables.less → tables.less} +10 -10
  56. package/lib/css/components/{_stacks-tags.less → tags.less} +33 -41
  57. package/lib/css/components/{_stacks-toggle-switches.less → toggle-switches.less} +5 -5
  58. package/lib/css/components/{_stacks-topbar.less → topbar.less} +27 -40
  59. package/lib/css/components/{_stacks-uploader.less → uploader.less} +18 -18
  60. package/lib/css/components/{_stacks-user-cards.less → user-cards.less} +14 -14
  61. package/lib/css/components/{_stacks-widget-dynamic.less → widget-dynamic.less} +1 -1
  62. package/lib/css/components/{_stacks-widget-static.less → widget-static.less} +39 -38
  63. package/lib/css/exports/{_stacks-constants-colors.less → constants-colors.less} +21 -29
  64. package/lib/css/exports/constants-helpers.less +108 -0
  65. package/lib/css/exports/constants-type.less +153 -0
  66. package/lib/css/exports/{_stacks-exports.less → exports.less} +4 -4
  67. package/lib/css/exports/{_stacks-mixins.less → mixins.less} +18 -1
  68. package/lib/css/stacks-dynamic.less +12 -13
  69. package/lib/css/stacks-static.less +38 -38
  70. package/lib/ts/controllers/index.ts +8 -0
  71. package/lib/ts/controllers/s-expandable-control.ts +163 -164
  72. package/lib/ts/controllers/s-modal.ts +259 -261
  73. package/lib/ts/controllers/s-navigation-tablist.ts +96 -97
  74. package/lib/ts/controllers/s-popover.ts +438 -440
  75. package/lib/ts/controllers/s-table.ts +203 -203
  76. package/lib/ts/controllers/s-tooltip.ts +195 -196
  77. package/lib/ts/controllers/s-uploader.ts +162 -164
  78. package/lib/ts/index.ts +20 -0
  79. package/lib/ts/stacks.ts +73 -68
  80. package/lib/tsconfig.json +8 -6
  81. package/package.json +43 -27
  82. package/dist/css/stacks-flexgrid-shim.min.css +0 -1
  83. package/lib/css/atomic/_stacks-spacing.less +0 -162
  84. package/lib/css/atomic/_stacks-width-height.less +0 -189
  85. package/lib/css/base/_stacks-configuration-dynamic.less +0 -106
  86. package/lib/css/exports/_stacks-constants-helpers.less +0 -139
  87. package/lib/css/exports/_stacks-constants-type.less +0 -91
  88. package/lib/ts/finalize.ts +0 -1
  89. package/lib/ts/stimulus.d.ts +0 -4
@@ -1,247 +1,246 @@
1
- namespace Stacks {
2
- export interface TooltipOptions {
3
- placement: string;
4
- }
5
-
6
- export class TooltipController extends BasePopoverController {
7
- static targets = [];
1
+ import * as Stacks from "../stacks";
2
+ import { BasePopoverController, PopoverController } from "./s-popover";
8
3
 
9
- protected popoverSelectorAttribute = "aria-describedby";
4
+ export interface TooltipOptions {
5
+ placement: string;
6
+ }
10
7
 
11
- private boundScheduleShow!: any;
12
- private boundHide!: any;
13
- private boundHideIfWithin!: any;
14
- private activeTimeout!: any;
8
+ export class TooltipController extends BasePopoverController {
9
+ static targets = [];
15
10
 
16
- /**
17
- * Binds mouseover and mouseout events in addition to BasePopoverController.connect
18
- */
19
- connect() {
20
- super.connect();
11
+ protected popoverSelectorAttribute = "aria-describedby";
21
12
 
22
- // Only bind to mouse events if the pointer device supports hover behavior.
23
- // Otherwise we run into issues with mobile browser showing popovers for
24
- // click events and not being able to hide them.
25
- if (window.matchMedia("(hover: hover)").matches) {
26
- this.bindMouseEvents();
27
- }
28
- }
13
+ private boundScheduleShow!: any;
14
+ private boundHide!: any;
15
+ private boundHideIfWithin!: any;
16
+ private activeTimeout!: any;
29
17
 
30
- /**
31
- * Unbinds mouse events in addition to BasePopoverController.disconnect
32
- */
33
- disconnect() {
34
- this.unbindMouseEvents();
35
- super.disconnect();
18
+ /**
19
+ * Binds mouseover and mouseout events in addition to BasePopoverController.connect
20
+ */
21
+ connect() {
22
+ super.connect();
23
+
24
+ // Only bind to mouse events if the pointer device supports hover behavior.
25
+ // Otherwise we run into issues with mobile browser showing popovers for
26
+ // click events and not being able to hide them.
27
+ if (window.matchMedia("(hover: hover)").matches) {
28
+ this.bindMouseEvents();
36
29
  }
30
+ }
37
31
 
38
- /**
39
- * Attempts to show the tooltip popover so long as no other Stacks-managed popover is
40
- * present on the page.
41
- */
42
- show(dispatcher: Event|Element|null = null) {
43
- // check and see if this controller coexists with a popover
44
- var controller = Stacks.application.getControllerForElementAndIdentifier(this.element, "s-popover");
45
-
46
- // if the controller exists and already has a visible popover, don't show the tooltip
47
- if (controller && (<PopoverController>controller).isVisible) {
48
- return;
49
- }
32
+ /**
33
+ * Unbinds mouse events in addition to BasePopoverController.disconnect
34
+ */
35
+ disconnect() {
36
+ this.unbindMouseEvents();
37
+ super.disconnect();
38
+ }
50
39
 
51
- super.show(dispatcher);
52
- }
40
+ /**
41
+ * Attempts to show the tooltip popover so long as no other Stacks-managed popover is
42
+ * present on the page.
43
+ */
44
+ show(dispatcher: Event|Element|null = null) {
45
+ // check and see if this controller coexists with a popover
46
+ var controller = Stacks.application.getControllerForElementAndIdentifier(this.element, "s-popover");
53
47
 
54
- /**
55
- * Sets up a tooltip popover show after a delay.
56
- */
57
- scheduleShow(dispatcher: Event | Element | null = null) {
58
- window.clearTimeout(this.activeTimeout);
59
- this.activeTimeout = window.setTimeout(() => this.show(dispatcher), 300);
48
+ // if the controller exists and already has a visible popover, don't show the tooltip
49
+ if (controller && (<PopoverController>controller).isVisible) {
50
+ return;
60
51
  }
61
52
 
62
- /**
63
- * Cancels the scheduled tooltip popover display and hides it if already displayed
64
- */
65
- hide(dispatcher: Event | Element | null = null) {
66
- window.clearTimeout(this.activeTimeout);
67
- this.activeTimeout = null;
68
-
69
- super.hide(dispatcher);
70
- }
53
+ super.show(dispatcher);
54
+ }
71
55
 
72
- /**
73
- * Applies data-s-tooltip-html-title and title attributes.
74
- */
75
- applyTitleAttributes() {
56
+ /**
57
+ * Sets up a tooltip popover show after a delay.
58
+ */
59
+ scheduleShow(dispatcher: Event | Element | null = null) {
60
+ window.clearTimeout(this.activeTimeout);
61
+ this.activeTimeout = window.setTimeout(() => this.show(dispatcher), 300);
62
+ }
76
63
 
77
- var content: Node;
64
+ /**
65
+ * Cancels the scheduled tooltip popover display and hides it if already displayed
66
+ */
67
+ hide(dispatcher: Event | Element | null = null) {
68
+ window.clearTimeout(this.activeTimeout);
69
+ this.activeTimeout = null;
78
70
 
79
- var htmlTitle = this.data.get("html-title");
80
- if (htmlTitle) {
81
- content = document.createRange().createContextualFragment(htmlTitle);
82
- } else {
83
- var plainTitle = this.element.getAttribute("title");
84
- if (plainTitle) {
85
- content = document.createTextNode(plainTitle);
86
- } else {
87
- return null;
88
- }
89
- }
71
+ super.hide(dispatcher);
72
+ }
90
73
 
91
- this.data.delete("html-title");
92
- this.element.removeAttribute("title");
74
+ /**
75
+ * Applies data-s-tooltip-html-title and title attributes.
76
+ */
77
+ applyTitleAttributes() {
93
78
 
94
- var popoverId = this.element.getAttribute("aria-describedby");
95
- if (!popoverId) {
96
- popoverId = TooltipController.generateId();
97
- this.element.setAttribute("aria-describedby", popoverId);
98
- }
79
+ var content: Node;
99
80
 
100
- var popover = document.getElementById(popoverId);
101
- if (!popover) {
102
- popover = document.createElement("div");
103
- popover.id = popoverId;
104
- popover.className = "s-popover s-popover__tooltip pe-none";
105
- popover.setAttribute("aria-hidden", "true");
106
- popover.setAttribute("role", "tooltip");
107
-
108
- var parentNode = this.element.parentNode;
109
- if (parentNode) {
110
- // insertBefore inserts at end if element.nextSibling is null.
111
- parentNode.insertBefore(popover, this.element.nextSibling);
112
- } else {
113
- document.body.appendChild(popover);
114
- }
81
+ var htmlTitle = this.data.get("html-title");
82
+ if (htmlTitle) {
83
+ content = document.createRange().createContextualFragment(htmlTitle);
84
+ } else {
85
+ var plainTitle = this.element.getAttribute("title");
86
+ if (plainTitle) {
87
+ content = document.createTextNode(plainTitle);
88
+ } else {
89
+ return null;
115
90
  }
91
+ }
116
92
 
117
- const arrow = popover.querySelector(".s-popover--arrow");
93
+ this.data.delete("html-title");
94
+ this.element.removeAttribute("title");
118
95
 
119
- // clear and set the content of the popover
120
- popover.innerHTML = "";
121
- popover.appendChild(content);
96
+ var popoverId = this.element.getAttribute("aria-describedby");
97
+ if (!popoverId) {
98
+ popoverId = TooltipController.generateId();
99
+ this.element.setAttribute("aria-describedby", popoverId);
100
+ }
122
101
 
123
- // create the arrow if necessary
124
- if (arrow) {
125
- popover.appendChild(arrow);
102
+ var popover = document.getElementById(popoverId);
103
+ if (!popover) {
104
+ popover = document.createElement("div");
105
+ popover.id = popoverId;
106
+ popover.className = "s-popover s-popover__tooltip pe-none";
107
+ popover.setAttribute("aria-hidden", "true");
108
+ popover.setAttribute("role", "tooltip");
109
+
110
+ var parentNode = this.element.parentNode;
111
+ if (parentNode) {
112
+ // insertBefore inserts at end if element.nextSibling is null.
113
+ parentNode.insertBefore(popover, this.element.nextSibling);
126
114
  } else {
127
- popover.insertAdjacentHTML("beforeend", `<div class="s-popover--arrow"></div>`);
115
+ document.body.appendChild(popover);
128
116
  }
129
-
130
- this.scheduleUpdate();
131
-
132
- return popover;
133
117
  }
134
118
 
135
- /**
136
- * Automatically hides the tooltip popover when a Stacks popover is shown anywhere on
137
- * the page.
138
- */
139
- protected bindDocumentEvents() {
140
- this.boundHideIfWithin = this.boundHideIfWithin || this.hideIfWithin.bind(this);
119
+ const arrow = popover.querySelector(".s-popover--arrow");
141
120
 
142
- document.addEventListener("s-popover:shown", this.boundHideIfWithin);
143
- }
121
+ // clear and set the content of the popover
122
+ popover.innerHTML = "";
123
+ popover.appendChild(content);
144
124
 
145
- /**
146
- * Unbinds all document events
147
- */
148
- protected unbindDocumentEvents() {
149
- document.removeEventListener("s-popover:shown", this.boundHideIfWithin);
125
+ // create the arrow if necessary
126
+ if (arrow) {
127
+ popover.appendChild(arrow);
128
+ } else {
129
+ popover.insertAdjacentHTML("beforeend", `<div class="s-popover--arrow"></div>`);
150
130
  }
151
131
 
152
- /**
153
- * Attempts to generate a new tooltip popover from the title attribute if no popover
154
- * was present when requested, otherwise throws an error.
155
- */
156
- protected generatePopover(): HTMLElement | null {
157
- return this.applyTitleAttributes();
158
- }
132
+ this.scheduleUpdate();
159
133
 
160
- /**
161
- * Hides the tooltip if is or is within the event's target.
162
- * @param event An event object from s-popover:shown
163
- */
164
- private hideIfWithin(event: Event) {
165
- if ((<Element>event.target!).contains(this.referenceElement)) {
166
- this.hide();
167
- }
168
- }
134
+ return popover;
135
+ }
169
136
 
170
- /**
171
- * Binds mouse events to show/hide on reference element hover
172
- */
173
- private bindMouseEvents() {
174
- this.boundScheduleShow = this.boundScheduleShow || this.scheduleShow.bind(this);
175
- this.boundHide = this.boundHide || this.hide.bind(this);
176
-
177
- this.referenceElement.addEventListener("mouseover", this.boundScheduleShow);
178
- this.referenceElement.addEventListener("mouseout", this.boundHide);
179
- this.referenceElement.addEventListener("focus", this.boundScheduleShow);
180
- this.referenceElement.addEventListener("blur", this.boundHide);
181
- }
137
+ /**
138
+ * Automatically hides the tooltip popover when a Stacks popover is shown anywhere on
139
+ * the page.
140
+ */
141
+ protected bindDocumentEvents() {
142
+ this.boundHideIfWithin = this.boundHideIfWithin || this.hideIfWithin.bind(this);
182
143
 
183
- /**
184
- * Unbinds all mouse events
185
- */
186
- private unbindMouseEvents() {
187
- this.referenceElement.removeEventListener("mouseover", this.boundScheduleShow);
188
- this.referenceElement.removeEventListener("mouseout", this.boundHide);
189
- this.referenceElement.removeEventListener("focus", this.boundScheduleShow);
190
- this.referenceElement.removeEventListener("blur", this.boundHide);
191
- }
144
+ document.addEventListener("s-popover:shown", this.boundHideIfWithin);
145
+ }
146
+
147
+ /**
148
+ * Unbinds all mouse events
149
+ */
150
+ protected unbindDocumentEvents() {
151
+ document.removeEventListener("s-popover:shown", this.boundHideIfWithin);
152
+ }
153
+
154
+ /**
155
+ * Attempts to generate a new tooltip popover from the title attribute if no popover
156
+ * was present when requested, otherwise throws an error.
157
+ */
158
+ protected generatePopover(): HTMLElement | null {
159
+ return this.applyTitleAttributes();
160
+ }
192
161
 
193
- /**
194
- * Generates an ID for tooltips created with setTooltip.
195
- */
196
- private static generateId() {
197
- // generate a random number, then convert to a well formatted string
198
- return "--stacks-s-tooltip-" + Math.random().toString(36).substring(2, 10);
162
+ /**
163
+ * Hides the tooltip if is or is within the event's target.
164
+ * @param event An event object from s-popover:shown
165
+ */
166
+ private hideIfWithin(event: Event) {
167
+ if ((<Element>event.target!).contains(this.referenceElement)) {
168
+ this.hide();
199
169
  }
200
170
  }
201
171
 
202
172
  /**
203
- * Adds or updates a Stacks tooltip on a given element, initializing the controller if necessary
204
- * @param element The element to add a tooltip to.
205
- * @param html An HTML string to populate the tooltip with.
206
- * @param options Options for rendering the tooltip.
173
+ * Binds mouse events to show/hide on reference element hover
207
174
  */
208
- export function setTooltipHtml(element: Element, html: string, options?: TooltipOptions) {
209
- element.setAttribute("data-s-tooltip-html-title", html);
210
- element.removeAttribute("title");
211
- applyOptionsAndTitleAttributes(element, options);
175
+ private bindMouseEvents() {
176
+ this.boundScheduleShow = this.boundScheduleShow || this.scheduleShow.bind(this);
177
+ this.boundHide = this.boundHide || this.hide.bind(this);
178
+
179
+ this.referenceElement.addEventListener("mouseover", this.boundScheduleShow);
180
+ this.referenceElement.addEventListener("mouseout", this.boundHide);
181
+ this.referenceElement.addEventListener("focus", this.boundScheduleShow);
182
+ this.referenceElement.addEventListener("blur", this.boundHide);
212
183
  }
213
184
 
214
185
  /**
215
- * Adds or updates a Stacks tooltip on a given element, initializing the controller if necessary
216
- * @param element The element to add a tooltip to.
217
- * @param text A plain text string to populate the tooltip with.
218
- * @param options Options for rendering the tooltip.
186
+ * Unbinds all mouse events
219
187
  */
220
- export function setTooltipText(element: Element, text: string, options?: TooltipOptions) {
221
- element.setAttribute("title", text);
222
- element.removeAttribute("data-s-tooltip-html-title");
223
- applyOptionsAndTitleAttributes(element, options);
188
+ private unbindMouseEvents() {
189
+ this.referenceElement.removeEventListener("mouseover", this.boundScheduleShow);
190
+ this.referenceElement.removeEventListener("mouseout", this.boundHide);
191
+ this.referenceElement.removeEventListener("focus", this.boundScheduleShow);
192
+ this.referenceElement.removeEventListener("blur", this.boundHide);
224
193
  }
225
194
 
226
195
  /**
227
- * Shared helper for setTooltip* to initialize and set tooltip content
228
- * @param element The element to add a tooltip to.
229
- * @param options Options for rendering the tooltip.
196
+ * Generates an ID for tooltips created with setTooltip.
230
197
  */
231
- function applyOptionsAndTitleAttributes(element: Element, options?: TooltipOptions) {
198
+ private static generateId() {
199
+ // generate a random number, then convert to a well formatted string
200
+ return "--stacks-s-tooltip-" + Math.random().toString(36).substring(2, 10);
201
+ }
202
+ }
232
203
 
233
- if (options && options.placement) {
234
- element.setAttribute("data-s-tooltip-placement", options.placement);
235
- }
204
+ /**
205
+ * Adds or updates a Stacks tooltip on a given element, initializing the controller if necessary
206
+ * @param element The element to add a tooltip to.
207
+ * @param html An HTML string to populate the tooltip with.
208
+ * @param options Options for rendering the tooltip.
209
+ */
210
+ export function setTooltipHtml(element: Element, html: string, options?: TooltipOptions) {
211
+ element.setAttribute("data-s-tooltip-html-title", html);
212
+ element.removeAttribute("title");
213
+ applyOptionsAndTitleAttributes(element, options);
214
+ }
236
215
 
237
- var controller = <TooltipController>Stacks.application.getControllerForElementAndIdentifier(element, "s-tooltip");
216
+ /**
217
+ * Adds or updates a Stacks tooltip on a given element, initializing the controller if necessary
218
+ * @param element The element to add a tooltip to.
219
+ * @param text A plain text string to populate the tooltip with.
220
+ * @param options Options for rendering the tooltip.
221
+ */
222
+ export function setTooltipText(element: Element, text: string, options?: TooltipOptions) {
223
+ element.setAttribute("title", text);
224
+ element.removeAttribute("data-s-tooltip-html-title");
225
+ applyOptionsAndTitleAttributes(element, options);
226
+ }
238
227
 
239
- if (controller) {
240
- controller.applyTitleAttributes();
241
- } else {
242
- element.setAttribute("data-controller", element.getAttribute("data-controller") + " s-tooltip");
243
- }
228
+ /**
229
+ * Shared helper for setTooltip* to initialize and set tooltip content
230
+ * @param element The element to add a tooltip to.
231
+ * @param options Options for rendering the tooltip.
232
+ */
233
+ function applyOptionsAndTitleAttributes(element: Element, options?: TooltipOptions) {
234
+
235
+ if (options && options.placement) {
236
+ element.setAttribute("data-s-tooltip-placement", options.placement);
244
237
  }
245
- }
246
238
 
247
- Stacks.application.register("s-tooltip", Stacks.TooltipController);
239
+ var controller = <TooltipController>Stacks.application.getControllerForElementAndIdentifier(element, "s-tooltip");
240
+
241
+ if (controller) {
242
+ controller.applyTitleAttributes();
243
+ } else {
244
+ element.setAttribute("data-controller", element.getAttribute("data-controller") + " s-tooltip");
245
+ }
246
+ }