Skip to content

Commit

Permalink
custom storybook even for domcontentloaded no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
basher committed Apr 22, 2024
1 parent 128d8c4 commit eccd7c4
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 38 deletions.
10 changes: 0 additions & 10 deletions ui/.storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@

<!-- Overrides for Storybook Docs and UI. -->
<link href="storybook-overrides.css" rel="stylesheet" />

<script>
// Custom event for Parcel UI to listen to in order to instantiate UI component JavaScript when Storybook iframe loads for each story.
const eventStorybook = new Event('StorybookLoaded');

document.addEventListener('DOMContentLoaded', () => {
console.log('Storybook DOMContentLoaded... ');
window.dispatchEvent(eventStorybook);
}, false);
</script>
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "web-ui-boilerplate",
"description": "UI boilerplate for websites/webapps using vanilla HTML/CSS/JavaScript, powered by Storybook, bundled by Parcel.",
"author": "basher",
"version": "3.1.3",
"version": "3.1.4",
"license": "ISC",
"repository": {
"type": "git",
Expand Down
8 changes: 0 additions & 8 deletions ui/src/javascript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ if (browserSupportsAllFeatures()) {
.then(() => uiInit())
.catch((e) => console.error(e));
}

// Run UI module instantition ONCE when each Storybook story has loaded.
const storybookUIinit = (): void => {
console.log('Storybook custom event fired...');
uiInit();
};
// 'StorybookLoaded' is an event that is dispatched from Storybook.
window.addEventListener('StorybookLoaded', storybookUIinit, false);
5 changes: 4 additions & 1 deletion ui/stories/1. Storybook Intro/1-Introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Just plain vanilla code. 😜

## Code authoring guidelines & accessibility
- All UI components are authored with **semantic HTML5** markup.
- Some components are **progressively enhanced** with JavaScript and `WAI-ARIA` as appropriate. <sup>1</sup>
- Some components are **progressively enhanced** with JavaScript and `WAI-ARIA` as appropriate. <sup>1, 2</sup>
- The HTML markup uses the `BEM` methodology to provide CSS namespacing.
- Visual styling is minimal & unopinionated.
- The CSS is authored with as little code as necessary, making full use of the CSS cascade and inheritance.
Expand All @@ -27,6 +27,9 @@ Just plain vanilla code. 😜
> <sup>1</sup>
> The JavaScript-enhanced components have been authored as [HTML Web Components](/docs/web-components-or-custom-elements-using-web-components--docs), also known as `custom elements`.
> <sup>2</sup>
> To test how these enhanced components behave with JavaScript disabled, comment out the call to `uiInit()` in `src/javascript/index.ts`.
### Accessibility testing
Storybook comes with 2 default accessibility testing tools:
- `Accessibility addon`. This is in the Storybook `addons` toolbar, and is built on the same [AxeCore API](https://www.deque.com/axe/) that Lighthouse uses.
Expand Down
15 changes: 0 additions & 15 deletions ui/stories/1. Storybook Intro/2-known-Issues.mdx

This file was deleted.

3 changes: 1 addition & 2 deletions ui/stories/2. Design System/Colours/Colours.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ ${
</div>
${
// Output computed HSL colours when 'StorybookLoaded' custom event has fired.
window.addEventListener('StorybookLoaded',
window.addEventListener('DOMContentLoaded',
() => {
const styledSpan = document.querySelectorAll('.styled');
styledSpan.forEach((span) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Meta } from '@storybook/blocks';
> <sup>1</sup>
> Global CSS is inherited by the Web Components because they contain regular HTML markup. Additional CSS scoping & encapsulation is provided by the custom element names, enabling styles not to "leak" out into the global scope.
> <sup>2</sup> <sup>3</sup>
> <sup>2, 3</sup>
> The [`<webui-ajax-loader>`](/docs/web-components-or-custom-elements-webui-ajax-loader--docs) Web Component is entirely constructed via JavaScript, and uses the shadow DOM.
## Additional reading
Expand Down

0 comments on commit eccd7c4

Please sign in to comment.