@stackoverflow/stacks 1.0.0 → 1.0.1

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 (71) hide show
  1. package/README.md +47 -47
  2. package/dist/css/stacks.css +108 -0
  3. package/dist/css/stacks.min.css +1 -1
  4. package/lib/css/atomic/borders.less +378 -378
  5. package/lib/css/atomic/colors.less +209 -209
  6. package/lib/css/atomic/flex.less +375 -375
  7. package/lib/css/atomic/grid.less +174 -174
  8. package/lib/css/atomic/misc.less +343 -343
  9. package/lib/css/atomic/spacing.less +332 -314
  10. package/lib/css/atomic/typography.less +273 -273
  11. package/lib/css/atomic/width-height.less +194 -194
  12. package/lib/css/base/body.less +44 -44
  13. package/lib/css/base/configuration-static.less +61 -61
  14. package/lib/css/base/icons.less +20 -20
  15. package/lib/css/base/internals.less +220 -220
  16. package/lib/css/base/reset-meyer.less +64 -64
  17. package/lib/css/base/reset-normalize.less +449 -449
  18. package/lib/css/base/reset.less +20 -20
  19. package/lib/css/components/activity-indicator.less +45 -45
  20. package/lib/css/components/avatars.less +189 -189
  21. package/lib/css/components/badges.less +209 -209
  22. package/lib/css/components/banners.less +80 -80
  23. package/lib/css/components/blank-states.less +26 -26
  24. package/lib/css/components/breadcrumbs.less +44 -44
  25. package/lib/css/components/button-groups.less +104 -104
  26. package/lib/css/components/buttons.less +665 -665
  27. package/lib/css/components/cards.less +44 -44
  28. package/lib/css/components/code-blocks.less +130 -130
  29. package/lib/css/components/collapsible.less +104 -104
  30. package/lib/css/components/inputs.less +728 -728
  31. package/lib/css/components/link-previews.less +136 -136
  32. package/lib/css/components/links.less +218 -218
  33. package/lib/css/components/menu.less +47 -47
  34. package/lib/css/components/modals.less +133 -133
  35. package/lib/css/components/navigation.less +146 -146
  36. package/lib/css/components/notices.less +233 -233
  37. package/lib/css/components/page-titles.less +60 -60
  38. package/lib/css/components/pagination.less +55 -55
  39. package/lib/css/components/popovers.less +197 -197
  40. package/lib/css/components/post-summary.less +425 -425
  41. package/lib/css/components/progress-bars.less +330 -330
  42. package/lib/css/components/prose.less +503 -503
  43. package/lib/css/components/spinner.less +107 -107
  44. package/lib/css/components/tables.less +341 -341
  45. package/lib/css/components/tags.less +236 -236
  46. package/lib/css/components/toggle-switches.less +144 -144
  47. package/lib/css/components/topbar.less +427 -427
  48. package/lib/css/components/uploader.less +210 -210
  49. package/lib/css/components/user-cards.less +169 -169
  50. package/lib/css/components/widget-dynamic.less +33 -33
  51. package/lib/css/components/widget-static.less +273 -273
  52. package/lib/css/exports/constants-colors.less +1092 -1092
  53. package/lib/css/exports/constants-helpers.less +108 -108
  54. package/lib/css/exports/constants-type.less +153 -153
  55. package/lib/css/exports/exports.less +15 -15
  56. package/lib/css/exports/mixins.less +237 -237
  57. package/lib/css/stacks-dynamic.less +35 -35
  58. package/lib/css/stacks-static.less +86 -86
  59. package/lib/css/stacks.less +13 -13
  60. package/lib/ts/controllers/index.ts +7 -7
  61. package/lib/ts/controllers/s-expandable-control.ts +188 -188
  62. package/lib/ts/controllers/s-modal.ts +321 -321
  63. package/lib/ts/controllers/s-navigation-tablist.ts +117 -117
  64. package/lib/ts/controllers/s-popover.ts +547 -547
  65. package/lib/ts/controllers/s-table.ts +220 -220
  66. package/lib/ts/controllers/s-tooltip.ts +246 -246
  67. package/lib/ts/controllers/s-uploader.ts +172 -172
  68. package/lib/ts/index.ts +20 -20
  69. package/lib/ts/stacks.ts +88 -88
  70. package/lib/tsconfig.json +13 -13
  71. package/package.json +87 -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
+ }