@stackoverflow/stacks 1.6.6 → 1.7.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.
- package/README.md +86 -2
- package/dist/controllers/index.d.ts +2 -0
- package/dist/controllers/s-banner.d.ts +41 -0
- package/dist/controllers/s-toast.d.ts +97 -0
- package/dist/css/stacks.css +18884 -18912
- package/dist/css/stacks.min.css +1 -1
- package/dist/js/stacks.js +5252 -5260
- package/dist/js/stacks.min.js +1 -1
- package/dist/stacks.d.ts +1 -1
- package/lib/css/components/anchors.less +61 -0
- package/lib/css/components/block-link.less +80 -0
- package/lib/css/components/buttons.less +20 -4
- package/lib/css/components/expandable.less +1 -1
- package/lib/css/components/inputs.less +4 -0
- package/lib/css/components/link.less +104 -0
- package/lib/css/components/post-summary.less +327 -356
- package/lib/css/components/table.less +297 -0
- package/lib/css/stacks-dynamic.less +0 -8
- package/lib/css/stacks-static.less +9 -1
- package/lib/test/s-banner.test.ts +73 -0
- package/lib/test/s-banner.visual.test.ts +61 -0
- package/lib/test/s-button.visual.test.ts +12 -0
- package/lib/test/s-toast.test.ts +63 -0
- package/lib/test/s-toast.visual.test.ts +48 -0
- package/lib/test/s-tooltip.test.ts +62 -0
- package/lib/test/s-tooltip.visual.test.ts +31 -0
- package/lib/ts/controllers/index.ts +2 -0
- package/lib/ts/controllers/s-banner.ts +149 -0
- package/lib/ts/controllers/s-toast.ts +357 -0
- package/lib/ts/index.ts +4 -0
- package/lib/ts/stacks.ts +1 -1
- package/lib/tsconfig.json +2 -2
- package/package.json +35 -19
- package/lib/css/components/links.less +0 -214
- package/lib/css/components/tables.less +0 -313
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Stacks
|
|
2
2
|
|
|
3
|
+
[![ci status][gh-action-badge]][gh-action-url] [![npm version][npm-badge]][npm-url]
|
|
4
|
+
|
|
3
5
|
Stacks is Stack Overflow’s design system. It includes the resources needed to create consistent, predictable interfaces and workflows that conform to Stack Overflow’s principles, design language, and best practices.
|
|
4
6
|
|
|
5
7
|
Our documentation is built with Stacks itself, using its [immutable, atomic classes](http://johnpolacek.com/rethinking/) and components.
|
|
@@ -22,6 +24,7 @@ Stacks documentation can be found at https://stackoverflow.design/
|
|
|
22
24
|
- [Building Stacks](#building-stacks)
|
|
23
25
|
- [Linting Stacks](#linting-stacks)
|
|
24
26
|
- [Testing Stacks](#testing-stacks)
|
|
27
|
+
- [Releasing Stacks](#release-a-new-version-of-stacks)
|
|
25
28
|
- [Bugs and feature requests](#bugs-and-feature-requests)
|
|
26
29
|
- [Contributing](#contributing)
|
|
27
30
|
- [License](#license)
|
|
@@ -55,9 +58,85 @@ npm run lint:format
|
|
|
55
58
|
```
|
|
56
59
|
|
|
57
60
|
## Testing Stacks
|
|
58
|
-
Stacks has implemented visual regression testing with [Backstop](https://github.com/garris/BackstopJS). To test if your new feature introduces visual regressions, run `npm run test` in a new Terminal window while Stacks is running. After the tests have run, a new browser window with any regressions will show. If the regressions are desired, you can run `npm run approve` to establish the new baseline.
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
Run all test suites by running:
|
|
63
|
+
```sh
|
|
64
|
+
npm test
|
|
65
|
+
```
|
|
66
|
+
### Unit/Component Tests
|
|
67
|
+
|
|
68
|
+
Unit/Component tests are written with [DOM Testing Library](https://testing-library.com/docs/dom-testing-library/intro).
|
|
69
|
+
Please follow the library's principles and documentation to write tests.
|
|
70
|
+
|
|
71
|
+
Stacks uses [Web Test Runner](https://modern-web.dev/docs/test-runner/overview/) and [Playwright](https://modern-web.dev/docs/test-runner/browser-launchers/playwright/) to run tests in a real browser context.
|
|
72
|
+
|
|
73
|
+
Execute the unit/component tests suite by running:
|
|
74
|
+
```sh
|
|
75
|
+
npm run test:unit
|
|
76
|
+
```
|
|
77
|
+
or if you prefer watch mode run:
|
|
78
|
+
```sh
|
|
79
|
+
npm run test:unit:watch
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Visual Regression Tests
|
|
83
|
+
|
|
84
|
+
**Prerequisite:**
|
|
85
|
+
In order to pull and upload baseline images you need to have `git lfs` installed in your local machine. Please follow [this guide](https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage) to install that.
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
This [Web Test Runner plugin](https://www.npmjs.com/package/@web/test-runner-visual-regression) is used to run visual regression tests. [DOM Testing Library](https://testing-library.com/docs/dom-testing-library/intro).
|
|
89
|
+
Visual regression tests end with this suffix `*.visual.test.ts`.
|
|
90
|
+
|
|
91
|
+
Execute the visual regression tests suite by running:
|
|
92
|
+
```sh
|
|
93
|
+
npm run test:visual
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Update the visual baseline via:
|
|
97
|
+
```sh
|
|
98
|
+
npm run test:visual:update
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Failing tests (including diffs) can be found under `screenshots/[browser]/failed/` folders.
|
|
102
|
+
|
|
103
|
+
## Releasing a new version of Stacks
|
|
104
|
+
Stacks uses [Semantic Versioning](https://semver.org/), is distributed via [npm](https://www.npmjs.com/package/@stackoverflow/stacks), and publishes [release notes on Github](https://github.com/StackExchange/Stacks/releases). Follow the steps below to release a new version of Stacks.
|
|
105
|
+
|
|
106
|
+
### Bump the version number
|
|
107
|
+
```sh
|
|
108
|
+
npm version [major | minor | patch]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Push the new tag
|
|
112
|
+
```sh
|
|
113
|
+
git push && git push --tags
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Create release notes [on Github](https://github.com/StackExchange/Stacks/releases/new)
|
|
117
|
+
|
|
118
|
+
1. Visit https://github.com/StackExchange/Stacks/releases/new
|
|
119
|
+
1. Choose your new version from the "Choose a tag" dropdown
|
|
120
|
+
1. Click "Generate release notes"
|
|
121
|
+
1. Cleanup and complete the release notes
|
|
122
|
+
- Prominently mention any breaking changes, if applicable
|
|
123
|
+
- Include a "What's Changed" section in the release notes
|
|
124
|
+
- Mention significant bug fixes
|
|
125
|
+
- Mention new features
|
|
126
|
+
- Mention significant under-the-hood changes that could impact consumers
|
|
127
|
+
|
|
128
|
+
### Ship your newly created version to [npm](https://www.npmjs.com/package/@stackoverflow/stacks)
|
|
129
|
+
```sh
|
|
130
|
+
npm publish
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Merge `develop` into `production` and push
|
|
134
|
+
```sh
|
|
135
|
+
git checkout production && git merge develop && git push
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Push the updated docs site
|
|
139
|
+
Head to [Netlify](https://app.netlify.com), navigate to the Stacks overview, click on "Production deploys", and select "Deploy site" from the "Trigger deploy" dropdown.
|
|
61
140
|
|
|
62
141
|
## Bugs and feature requests
|
|
63
142
|
Have a bug or feature request? First search existing or closed issues to make sure the issue hasn’t been noted yet. If not, review our [issue guidelines](/CONTRIBUTING.md#open-an-issue) for submitting [a bug report](/CONTRIBUTING.md#reporting-bugs) or [feature request](/CONTRIBUTING.md#feature-requests).
|
|
@@ -67,3 +146,8 @@ If you’d like to contribute to Stacks, please read through our [contribution g
|
|
|
67
146
|
|
|
68
147
|
## License
|
|
69
148
|
Code and documentation copyright 2017-2022 Stack Exchange, Inc and released under the [MIT License](/LICENSE.MD).
|
|
149
|
+
|
|
150
|
+
[gh-action-url]: https://github.com/StackExchange/Stacks/actions/workflows/main.yml
|
|
151
|
+
[gh-action-badge]: https://github.com/StackExchange/Stacks/actions/workflows/main.yml/badge.svg?branch=develop
|
|
152
|
+
[npm-url]: https://npmjs.org/package/@stackoverflow/stacks
|
|
153
|
+
[npm-badge]: https://img.shields.io/npm/v/@stackoverflow/stacks.svg
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { ExpandableController } from "./s-expandable-control";
|
|
2
2
|
export { hideModal, ModalController, showModal } from "./s-modal";
|
|
3
|
+
export { hideBanner, BannerController, showBanner } from "./s-banner";
|
|
4
|
+
export { hideToast, ToastController, showToast } from "./s-toast";
|
|
3
5
|
export { TabListController } from "./s-navigation-tablist";
|
|
4
6
|
export { attachPopover, detachPopover, hidePopover, BasePopoverController, PopoverController, showPopover, } from "./s-popover";
|
|
5
7
|
export { TableController } from "./s-table";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Stacks from "../stacks";
|
|
2
|
+
export declare class BannerController extends Stacks.StacksController {
|
|
3
|
+
static targets: string[];
|
|
4
|
+
readonly bannerTarget: HTMLElement;
|
|
5
|
+
/**
|
|
6
|
+
* Toggles the visibility of the banner
|
|
7
|
+
*/
|
|
8
|
+
toggle(dispatcher?: Event | Element | null): void;
|
|
9
|
+
/**
|
|
10
|
+
* Shows the banner
|
|
11
|
+
*/
|
|
12
|
+
show(dispatcher?: Event | Element | null): void;
|
|
13
|
+
/**
|
|
14
|
+
* Hides the banner
|
|
15
|
+
*/
|
|
16
|
+
hide(dispatcher?: Event | Element | null): void;
|
|
17
|
+
/**
|
|
18
|
+
* Toggles the visibility of the banner element
|
|
19
|
+
* @param show Optional parameter that force shows/hides the element or toggles it if left undefined
|
|
20
|
+
*/
|
|
21
|
+
private _toggle;
|
|
22
|
+
/**
|
|
23
|
+
* Remove the element on hide if the `remove-when-hidden` flag is set
|
|
24
|
+
*/
|
|
25
|
+
private removeBannerOnHide;
|
|
26
|
+
/**
|
|
27
|
+
* Determines the correct dispatching element from a potential input
|
|
28
|
+
* @param dispatcher The event or element to get the dispatcher from
|
|
29
|
+
*/
|
|
30
|
+
private getDispatcher;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Helper to manually show an s-banner element via external JS
|
|
34
|
+
* @param element the element the `data-controller="s-banner"` attribute is on
|
|
35
|
+
*/
|
|
36
|
+
export declare function showBanner(element: HTMLElement): void;
|
|
37
|
+
/**
|
|
38
|
+
* Helper to manually hide an s-banner element via external JS
|
|
39
|
+
* @param element the element the `data-controller="s-banner"` attribute is on
|
|
40
|
+
*/
|
|
41
|
+
export declare function hideBanner(element: HTMLElement): void;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as Stacks from "../stacks";
|
|
2
|
+
export declare class ToastController extends Stacks.StacksController {
|
|
3
|
+
static targets: string[];
|
|
4
|
+
readonly toastTarget: HTMLElement;
|
|
5
|
+
readonly initialFocusTargets: HTMLElement[];
|
|
6
|
+
private _boundClickFn;
|
|
7
|
+
private _boundKeypressFn;
|
|
8
|
+
private activeTimeout;
|
|
9
|
+
private returnElement;
|
|
10
|
+
connect(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Disconnects all added event listeners on controller disconnect
|
|
13
|
+
*/
|
|
14
|
+
disconnect(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Toggles the visibility of the toast
|
|
17
|
+
*/
|
|
18
|
+
toggle(dispatcher?: Event | Element | null): void;
|
|
19
|
+
/**
|
|
20
|
+
* Shows the toast
|
|
21
|
+
*/
|
|
22
|
+
show(dispatcher?: Event | Element | null): void;
|
|
23
|
+
/**
|
|
24
|
+
* Hides the toast
|
|
25
|
+
*/
|
|
26
|
+
hide(dispatcher?: Event | Element | null): void;
|
|
27
|
+
/**
|
|
28
|
+
* Validates the toast settings and attempts to set necessary internal variables
|
|
29
|
+
*/
|
|
30
|
+
private validate;
|
|
31
|
+
/**
|
|
32
|
+
* Toggles the visibility of the toast element
|
|
33
|
+
* @param show Optional parameter that force shows/hides the element or toggles it if left undefined
|
|
34
|
+
*/
|
|
35
|
+
private _toggle;
|
|
36
|
+
/**
|
|
37
|
+
* Listens for the s-toast:hidden event and focuses the returnElement when it is fired
|
|
38
|
+
*/
|
|
39
|
+
private focusReturnElement;
|
|
40
|
+
/**
|
|
41
|
+
* Remove the element on hide if the `remove-when-hidden` flag is set
|
|
42
|
+
*/
|
|
43
|
+
private removeToastOnHide;
|
|
44
|
+
/**
|
|
45
|
+
* Hide the element after a delay
|
|
46
|
+
*/
|
|
47
|
+
private hideAfterTimeout;
|
|
48
|
+
/**
|
|
49
|
+
* Cancels the activeTimeout
|
|
50
|
+
*/
|
|
51
|
+
clearActiveTimeout(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Gets all elements within the toast that could receive keyboard focus.
|
|
54
|
+
*/
|
|
55
|
+
private getAllTabbables;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the first visible element in an array or `undefined` if no elements are visible.
|
|
58
|
+
*/
|
|
59
|
+
private firstVisible;
|
|
60
|
+
/**
|
|
61
|
+
* Attempts to shift keyboard focus into the toast.
|
|
62
|
+
* If elements with `data-s-toast-target="initialFocus"` are present and visible, one of those will be selected.
|
|
63
|
+
* Otherwise, the first visible focusable element will receive focus.
|
|
64
|
+
*/
|
|
65
|
+
private focusInsideToast;
|
|
66
|
+
/**
|
|
67
|
+
* Binds global events to the document for hiding toasts on user interaction
|
|
68
|
+
*/
|
|
69
|
+
private bindDocumentEvents;
|
|
70
|
+
/**
|
|
71
|
+
* Unbinds global events to the document for hiding toasts on user interaction
|
|
72
|
+
*/
|
|
73
|
+
private unbindDocumentEvents;
|
|
74
|
+
/**
|
|
75
|
+
* Forces the toast to hide if a user clicks outside of it or its reference element
|
|
76
|
+
*/
|
|
77
|
+
private hideOnOutsideClick;
|
|
78
|
+
/**
|
|
79
|
+
* Forces the toast to hide if the user presses escape while it, one of its childen, or the reference element are focused
|
|
80
|
+
*/
|
|
81
|
+
private hideOnEscapePress;
|
|
82
|
+
/**
|
|
83
|
+
* Determines the correct dispatching element from a potential input
|
|
84
|
+
* @param dispatcher The event or element to get the dispatcher from
|
|
85
|
+
*/
|
|
86
|
+
private getDispatcher;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Helper to manually show an s-toast element via external JS
|
|
90
|
+
* @param element the element the `data-controller="s-toast"` attribute is on
|
|
91
|
+
*/
|
|
92
|
+
export declare function showToast(element: HTMLElement): void;
|
|
93
|
+
/**
|
|
94
|
+
* Helper to manually hide an s-toast element via external JS
|
|
95
|
+
* @param element the element the `data-controller="s-toast"` attribute is on
|
|
96
|
+
*/
|
|
97
|
+
export declare function hideToast(element: HTMLElement): void;
|