Skip to content

Commit

Permalink
add webui-notification component
Browse files Browse the repository at this point in the history
  • Loading branch information
basher committed Apr 3, 2024
1 parent 96931b6 commit 6d77af6
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 95 deletions.
4 changes: 2 additions & 2 deletions ui/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "2.3.0",
"version": "2.4.0",
"license": "ISC",
"repository": {
"type": "git",
Expand Down
30 changes: 0 additions & 30 deletions ui/src/javascript/modules/message.ts

This file was deleted.

5 changes: 3 additions & 2 deletions ui/src/javascript/ui-init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Dependencies.
// 1. Modules.
import FormValidate from './modules/form-validate';
import Message from './modules/message';
import Prose from './modules/prose';
import RangeSlider from './modules/range-slider';
import Search from './modules/search';
Expand All @@ -17,11 +16,11 @@ import demoAjaxFetchHTML from './modules/demo-ajax-fetch-html';
import WebUIDisclosure from './web-components/webui-disclosure';
import WebUIMakeClickable from './web-components/webui-make-clickable';
import WebUIModal from './web-components/webui-modal';
import WebUINotification from './web-components/webui-notification';
import WebUIShare from './web-components/webui-share';

export const uiInit = (): void => {
FormValidate.start();
Message.start();
RangeSlider.start();
Search.start();
Slider.start();
Expand All @@ -40,6 +39,8 @@ export const uiInit = (): void => {
customElements.define('webui-make-clickable', WebUIMakeClickable);
!customElements.get('webui-modal') &&
customElements.define('webui-modal', WebUIModal);
!customElements.get('webui-notification') &&
customElements.define('webui-notification', WebUINotification);
!customElements.get('webui-share') &&
customElements.define('webui-share', WebUIShare);
};
2 changes: 0 additions & 2 deletions ui/src/javascript/web-components/webui-make-clickable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ export default class WebUIMakeClickable extends HTMLElement {

constructor() {
super();

this.link = this.querySelector('[data-url]') || this.querySelector('a');

this.addEventListener('click', this);
}

Expand Down
14 changes: 14 additions & 0 deletions ui/src/javascript/web-components/webui-notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default class WebUIMakeNotification extends HTMLElement {
private btnClose: HTMLButtonElement | null;

constructor() {
super();
this.btnClose = this.querySelector('[data-close]');
this.btnClose?.addEventListener('click', this);
}

// Handle web component events from constructor().
handleEvent() {
this.setAttribute('hidden', '');
}
}
1 change: 0 additions & 1 deletion ui/src/stylesheets/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@use 'card';
@use 'image';
@use 'image-gallery';
@use 'message';
@use 'nav';
@use 'pagination';
@use 'prose';
Expand Down
1 change: 1 addition & 0 deletions ui/src/stylesheets/web-components/_index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use 'webui-disclosure';
@use 'webui-make-clickable';
@use 'webui-modal';
@use 'webui-notification';
@use 'webui-share';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Dependencies.
@use '../base' as *;
@use '../mixins' as *;

.message {
webui-notification {
align-items: flex-start;
border: $border-width-s solid;
display: flex;
Expand All @@ -17,22 +17,22 @@ Dependencies.
max-inline-size: none;
}

&--success {
&[data-success] {
background: hsl(var(--color-accent-positive) / 15%);
border-color: $color-success;
}

&--warning {
&[data-warning] {
background: hsl(var(--color-accent-neutral) / 15%);
border-color: $color-notify;
}

&--error {
&[data-error] {
background: hsl(var(--color-accent-negative) / 15%);
border-color: $color-error;
}

&__close {
[data-close] {
font-size: $icon-size-s;
inset-block-start: calc($icon-size-s * -1);
inset-inline-end: calc($icon-size-s * -1);
Expand Down
13 changes: 6 additions & 7 deletions ui/stories/3. Layout/Flex/Flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ const style = `

export const FlexHtml = (args) => `
${style}
<div class="
flex
<div class="flex
${args.growAllFlexItems === true ? 'flex--grow-all' : ''}
flex--${args.direction}
flex--${args.gap}
flex--${args.alignItems}
flex--${args.justifyContent}"
>
${args.direction === undefined ? '' : `flex--${args.direction}`}
${args.gap === undefined ? '' : `flex--${args.gap}`}
${args.alignItems === undefined ? '' : `flex--${args.alignItems}`}
${args.justifyContent === undefined ? '' : `flex--${args.justifyContent}`}
">
<div>Flex item 1 - lots more content<br><br>
to demonstrate (default) equal height columns</div>
<div>Flex item 2</div>
Expand Down
20 changes: 10 additions & 10 deletions ui/stories/3. Layout/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const style = `
export const GridHtml = (args) => `
${style}
<p>Try removing grid items via devtools to see how grid auto-arranges itself.</p>
<div class=" grid grid--${args.gap}">
<div class="grid ${args.gap === undefined ? '' : `${args.gap === undefined ? '' : `grid--${args.gap}`}`}">
<div>Grid item 1 - lots more content<br><br>
to demonstrate (default) equal height columns</div>
<div>Grid item 2</div>
Expand All @@ -32,7 +32,7 @@ ${style}
<p>Use semantic <code>&lt;ul&gt;</code> if it makes sense to have a <strong>list of related items</strong> rendered in a grid.</p>
<p>For example, a gallery of images, or a collection of product cards.</p>
<ul class="grid grid--${args.gap}">
<ul class="grid ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<li>Grid item 1 - lots more content<br><br>
to demonstrate (default) equal height columns</li>
<li>Grid item 2</li>
Expand All @@ -45,22 +45,22 @@ ${style}
export const Grid2EqualColsHtml = (args) => `
${style}
<p>Divide a page (or section of a page) into <strong>equal width</strong> columns, etc.</p>
<div class="grid grid--${args.gap}">
<div class="grid ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>Col 1</div>
<div>Col 2</div>
</div>
<br>
<p>And here's another grid on same page.</p>
<div class="grid grid--${args.gap}">
<div class="grid ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>Col 1</div>
<div>Col 2</div>
</div>
<br>
<p>What if you <em>really</em> want 2 columns on small screens?<br>
Use the <code>grid--2-cols@small</code> classname to override the <code>grid-template-columns</code>.</p>
<div class="grid grid--2-cols@small grid--${args.gap}">
<div class="grid grid--2-cols@small ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>Col 1</div>
<div>Col 2</div>
</div>
Expand All @@ -69,15 +69,15 @@ Use the <code>grid--2-cols@small</code> classname to override the <code>grid-tem
export const Grid3EqualColsHtml = (args) => `
${style}
<p>Divide a page (or section of a page) into <strong>equal width</strong> columns, etc.</p>
<div class="grid grid--${args.gap}">
<div class="grid ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>Col 1</div>
<div>Col 2</div>
<div>Col 3</div>
</div>
<br>
<p>And here's another grid on same page.</p>
<div class="grid grid--${args.gap}">
<div class="grid ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>Col 1</div>
<div>Col 2</div>
<div>Col 3</div>
Expand All @@ -89,7 +89,7 @@ ${style}
<p>All these examples use <code>container queries</code> in supported browsers, rather than <code>media queries</code>.<p>
<div class="grid-container">
<div class="grid--asymmetric grid--${args.gap}">
<div class="grid--asymmetric ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>
Asymmetric col 1<br>
<b>Default width = 66.66%</b>
Expand All @@ -102,7 +102,7 @@ ${style}
</div>
<div class="grid-container">
<div class="grid--75-25 grid--${args.gap}">
<div class="grid--75-25 ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>
Asymmetric col 1<br>
Override width = 75%
Expand All @@ -115,7 +115,7 @@ ${style}
</div>
<div class="grid-container">
<div class="grid--25-75 grid--${args.gap}">
<div class="grid--25-75 ${args.gap === undefined ? '' : `grid--${args.gap}`}">
<div>
Asymmetric col 1<br>
Override width = 25%
Expand Down
8 changes: 0 additions & 8 deletions ui/stories/5. Components/Message/Message.mdx

This file was deleted.

23 changes: 0 additions & 23 deletions ui/stories/5. Components/Message/Message.stories.js

This file was deleted.

6 changes: 6 additions & 0 deletions ui/stories/5. Components/Notification/Notification.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Meta } from '@storybook/blocks';

<Meta title="Components/Notification" />

# Notification
- See the [`<webui-notification>`](/docs/web-components-or-custom-elements-webui-notification--docs) custom element.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export const MessageTemplate = (args) => `
<div class="message message--${args.messageType}" data-module="message">
export const WebUINotificationHtml = (args) => `
<webui-notification
${args.notificationType === 'error' ? 'role="alert"' : 'role="status"'}
${args.notificationType === undefined ? '' : `data-${args.notificationType}`}
>
<div class="stack">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur?</p>
Expand All @@ -9,7 +12,7 @@ export const MessageTemplate = (args) => `
? `<button
type="button"
class="button button--icon message__close"
data-button="message-close"
data-close
>
<svg
aria-hidden="true"
Expand All @@ -22,5 +25,5 @@ export const MessageTemplate = (args) => `
</button>`
: ''
}
</div>
</webui-notification>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Meta, Canvas, Controls } from '@storybook/blocks';
import * as WebUINotification from './WebUINotification.stories';

<Meta of={WebUINotification} />

# `<webui-notification>`

## Accessibility considerations
- Error notifications have an ARIA `role="error"`.
- Other notifications have an ARIA `role="status"`.

<Canvas of={WebUINotification.WebUINotification} />
<Controls of={WebUINotification.WebUINotification} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { WebUINotificationHtml } from './WebUINotification';

export default {
title: 'Web Components Or Custom Elements/<webui-notification>',
parameters: {
status: {
type: 'stable',
},
},
argTypes: {
notificationType: {
control: 'select',
options: ['success', 'warning', 'error'],
},
hasCloseButton: {
control: 'boolean',
},
},
};

export const WebUINotification = {
render: (args) => WebUINotificationHtml(args),
};
WebUINotification.storyName = '<webui-notification>';

0 comments on commit 6d77af6

Please sign in to comment.