@stackoverflow/stacks 1.0.0-beta.0 → 1.1.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 (74) hide show
  1. package/README.md +47 -47
  2. package/dist/controllers/s-popover.d.ts +11 -2
  3. package/dist/css/stacks.css +214 -3
  4. package/dist/css/stacks.min.css +1 -1
  5. package/dist/js/stacks.js +18 -2
  6. package/dist/js/stacks.min.js +1 -1
  7. package/lib/css/atomic/borders.less +378 -378
  8. package/lib/css/atomic/colors.less +209 -209
  9. package/lib/css/atomic/flex.less +375 -375
  10. package/lib/css/atomic/grid.less +174 -174
  11. package/lib/css/atomic/misc.less +343 -343
  12. package/lib/css/atomic/spacing.less +342 -314
  13. package/lib/css/atomic/typography.less +273 -273
  14. package/lib/css/atomic/width-height.less +194 -194
  15. package/lib/css/base/body.less +44 -44
  16. package/lib/css/base/configuration-static.less +61 -61
  17. package/lib/css/base/icons.less +20 -20
  18. package/lib/css/base/internals.less +220 -220
  19. package/lib/css/base/reset-meyer.less +64 -64
  20. package/lib/css/base/reset-normalize.less +449 -449
  21. package/lib/css/base/reset.less +20 -20
  22. package/lib/css/components/activity-indicator.less +44 -45
  23. package/lib/css/components/avatars.less +189 -189
  24. package/lib/css/components/badges.less +209 -209
  25. package/lib/css/components/banners.less +80 -80
  26. package/lib/css/components/blank-states.less +26 -26
  27. package/lib/css/components/breadcrumbs.less +44 -44
  28. package/lib/css/components/button-groups.less +104 -104
  29. package/lib/css/components/buttons.less +665 -665
  30. package/lib/css/components/cards.less +44 -44
  31. package/lib/css/components/code-blocks.less +130 -130
  32. package/lib/css/components/collapsible.less +104 -104
  33. package/lib/css/components/inputs.less +728 -728
  34. package/lib/css/components/link-previews.less +136 -136
  35. package/lib/css/components/links.less +218 -218
  36. package/lib/css/components/menu.less +47 -47
  37. package/lib/css/components/modals.less +133 -133
  38. package/lib/css/components/navigation.less +146 -146
  39. package/lib/css/components/notices.less +233 -233
  40. package/lib/css/components/page-titles.less +60 -60
  41. package/lib/css/components/pagination.less +55 -55
  42. package/lib/css/components/popovers.less +197 -197
  43. package/lib/css/components/post-summary.less +425 -425
  44. package/lib/css/components/progress-bars.less +330 -330
  45. package/lib/css/components/prose.less +503 -503
  46. package/lib/css/components/spinner.less +107 -107
  47. package/lib/css/components/tables.less +341 -341
  48. package/lib/css/components/tags.less +236 -236
  49. package/lib/css/components/toggle-switches.less +144 -144
  50. package/lib/css/components/topbar.less +427 -427
  51. package/lib/css/components/uploader.less +210 -210
  52. package/lib/css/components/user-cards.less +169 -169
  53. package/lib/css/components/widget-dynamic.less +33 -33
  54. package/lib/css/components/widget-static.less +273 -273
  55. package/lib/css/exports/constants-colors.less +1092 -1092
  56. package/lib/css/exports/constants-helpers.less +108 -108
  57. package/lib/css/exports/constants-type.less +153 -153
  58. package/lib/css/exports/exports.less +15 -15
  59. package/lib/css/exports/mixins.less +237 -237
  60. package/lib/css/stacks-dynamic.less +35 -35
  61. package/lib/css/stacks-static.less +86 -86
  62. package/lib/css/stacks.less +13 -13
  63. package/lib/ts/controllers/index.ts +7 -7
  64. package/lib/ts/controllers/s-expandable-control.ts +188 -188
  65. package/lib/ts/controllers/s-modal.ts +321 -321
  66. package/lib/ts/controllers/s-navigation-tablist.ts +117 -117
  67. package/lib/ts/controllers/s-popover.ts +567 -547
  68. package/lib/ts/controllers/s-table.ts +220 -220
  69. package/lib/ts/controllers/s-tooltip.ts +246 -246
  70. package/lib/ts/controllers/s-uploader.ts +172 -172
  71. package/lib/ts/index.ts +20 -20
  72. package/lib/ts/stacks.ts +88 -88
  73. package/lib/tsconfig.json +13 -13
  74. package/package.json +86 -87
@@ -1,246 +1,246 @@
1
- import * as Stacks from "../stacks";
2
- import { BasePopoverController, PopoverController } from "./s-popover";
3
-
4
- export interface TooltipOptions {
5
- placement: string;
6
- }
7
-
8
- export class TooltipController extends BasePopoverController {
9
- static targets = [];
10
-
11
- protected popoverSelectorAttribute = "aria-describedby";
12
-
13
- private boundScheduleShow!: any;
14
- private boundHide!: any;
15
- private boundHideIfWithin!: any;
16
- private activeTimeout!: any;
17
-
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();
29
- }
30
- }
31
-
32
- /**
33
- * Unbinds mouse events in addition to BasePopoverController.disconnect
34
- */
35
- disconnect() {
36
- this.unbindMouseEvents();
37
- super.disconnect();
38
- }
39
-
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");
47
-
48
- // if the controller exists and already has a visible popover, don't show the tooltip
49
- if (controller && (<PopoverController>controller).isVisible) {
50
- return;
51
- }
52
-
53
- super.show(dispatcher);
54
- }
55
-
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
- }
63
-
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;
70
-
71
- super.hide(dispatcher);
72
- }
73
-
74
- /**
75
- * Applies data-s-tooltip-html-title and title attributes.
76
- */
77
- applyTitleAttributes() {
78
-
79
- var content: Node;
80
-
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;
90
- }
91
- }
92
-
93
- this.data.delete("html-title");
94
- this.element.removeAttribute("title");
95
-
96
- var popoverId = this.element.getAttribute("aria-describedby");
97
- if (!popoverId) {
98
- popoverId = TooltipController.generateId();
99
- this.element.setAttribute("aria-describedby", popoverId);
100
- }
101
-
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);
114
- } else {
115
- document.body.appendChild(popover);
116
- }
117
- }
118
-
119
- const arrow = popover.querySelector(".s-popover--arrow");
120
-
121
- // clear and set the content of the popover
122
- popover.innerHTML = "";
123
- popover.appendChild(content);
124
-
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>`);
130
- }
131
-
132
- this.scheduleUpdate();
133
-
134
- return popover;
135
- }
136
-
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);
143
-
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
- }
161
-
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();
169
- }
170
- }
171
-
172
- /**
173
- * Binds mouse events to show/hide on reference element hover
174
- */
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);
183
- }
184
-
185
- /**
186
- * Unbinds all mouse events
187
- */
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);
193
- }
194
-
195
- /**
196
- * Generates an ID for tooltips created with setTooltip.
197
- */
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
- }
203
-
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
- }
215
-
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
- }
227
-
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);
237
- }
238
-
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
- }
1
+ import * as Stacks from "../stacks";
2
+ import { BasePopoverController, PopoverController } from "./s-popover";
3
+
4
+ export interface TooltipOptions {
5
+ placement: string;
6
+ }
7
+
8
+ export class TooltipController extends BasePopoverController {
9
+ static targets = [];
10
+
11
+ protected popoverSelectorAttribute = "aria-describedby";
12
+
13
+ private boundScheduleShow!: any;
14
+ private boundHide!: any;
15
+ private boundHideIfWithin!: any;
16
+ private activeTimeout!: any;
17
+
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();
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Unbinds mouse events in addition to BasePopoverController.disconnect
34
+ */
35
+ disconnect() {
36
+ this.unbindMouseEvents();
37
+ super.disconnect();
38
+ }
39
+
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");
47
+
48
+ // if the controller exists and already has a visible popover, don't show the tooltip
49
+ if (controller && (<PopoverController>controller).isVisible) {
50
+ return;
51
+ }
52
+
53
+ super.show(dispatcher);
54
+ }
55
+
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
+ }
63
+
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;
70
+
71
+ super.hide(dispatcher);
72
+ }
73
+
74
+ /**
75
+ * Applies data-s-tooltip-html-title and title attributes.
76
+ */
77
+ applyTitleAttributes() {
78
+
79
+ var content: Node;
80
+
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;
90
+ }
91
+ }
92
+
93
+ this.data.delete("html-title");
94
+ this.element.removeAttribute("title");
95
+
96
+ var popoverId = this.element.getAttribute("aria-describedby");
97
+ if (!popoverId) {
98
+ popoverId = TooltipController.generateId();
99
+ this.element.setAttribute("aria-describedby", popoverId);
100
+ }
101
+
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);
114
+ } else {
115
+ document.body.appendChild(popover);
116
+ }
117
+ }
118
+
119
+ const arrow = popover.querySelector(".s-popover--arrow");
120
+
121
+ // clear and set the content of the popover
122
+ popover.innerHTML = "";
123
+ popover.appendChild(content);
124
+
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>`);
130
+ }
131
+
132
+ this.scheduleUpdate();
133
+
134
+ return popover;
135
+ }
136
+
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);
143
+
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
+ }
161
+
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();
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Binds mouse events to show/hide on reference element hover
174
+ */
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);
183
+ }
184
+
185
+ /**
186
+ * Unbinds all mouse events
187
+ */
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);
193
+ }
194
+
195
+ /**
196
+ * Generates an ID for tooltips created with setTooltip.
197
+ */
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
+ }
203
+
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
+ }
215
+
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
+ }
227
+
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);
237
+ }
238
+
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
+ }