-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
101 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default class WebUIMakeClickable extends HTMLElement { | ||
private link: HTMLAnchorElement | null; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.link = this.querySelector('[data-url]') || this.querySelector('a'); | ||
|
||
this.addEventListener('click', this); | ||
} | ||
|
||
// Handle web component events from constructor(). | ||
handleEvent(e: MouseEvent) { | ||
if (e.target !== this.link) { | ||
this.link?.click(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@use 'webui-disclosure'; | ||
@use 'webui-make-clickable'; | ||
@use 'webui-share'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import { Meta, Canvas } from '@storybook/blocks'; | ||
import * as MakeClickable from './MakeClickable.stories'; | ||
import { Meta } from '@storybook/blocks'; | ||
|
||
<Meta of={MakeClickable} /> | ||
<Meta title='Components/Make Clickable' /> | ||
|
||
# Make clickable | ||
- Utilises CSS `focus-within` to add a focus indicator to a component (e.g. card) when it, or any of its descendents, receives keyboard `focus`. | ||
- The entire component can be made clickable via JavaScript by adding a `data-module="make-clickable"` attribute to the component's HTML. | ||
|
||
<Canvas of={MakeClickable.MakeClickable} /> | ||
- See the [`<webui-make-clickable>`](/docs/web-components-or-custom-elements-webui-make-clickable--docs) custom element. |
14 changes: 0 additions & 14 deletions
14
ui/stories/5. Components/MakeClickable/MakeClickable.stories.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
ui/stories/6. Web Components Or Custom Elements/WebUIMakeClickable/WebUIMakeClickable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export const WebUIMakeClickableHtml = () => ` | ||
<webui-make-clickable> | ||
<article class="card"> | ||
<figure class="card__media"> | ||
<picture> | ||
<source | ||
srcset="https://dummyimage.com/400x300" | ||
type="image/webp" | ||
> | ||
<img | ||
class="image" | ||
src="https://dummyimage.com/400x300" | ||
alt="[alt]" | ||
loading="lazy" | ||
height="300" | ||
width="400" | ||
/> | ||
</picture> | ||
</figure> | ||
<div class="card__content stack"> | ||
<h3 class="card__title"> | ||
<a | ||
href="#" | ||
data-url | ||
> | ||
Title is the primary link | ||
</a> | ||
</h3> | ||
<p>This whole component is clickable.</p> | ||
<p>This is a <a href="https://www.google.com">secondary link</a>.</p> | ||
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugiat, totam molestiae. Soluta voluptatem deleniti excepturi laudantium. Officia at repudiandae quo nulla reiciendis optio modi nemo.</p> | ||
</div> | ||
</article> | ||
</webui-make-clickable> | ||
`; |
11 changes: 11 additions & 0 deletions
11
.../6. Web Components Or Custom Elements/WebUIMakeClickable/WebUIMakeClickable.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Meta, Canvas } from '@storybook/blocks'; | ||
import * as WebUIMakeClickable from './WebUIMakeClickable.stories'; | ||
|
||
<Meta of={WebUIMakeClickable} /> | ||
|
||
# `<webui-make-clickable>` | ||
- The entire custom element is made clickable via JavaScript. | ||
- The primary URL is mapped to either a `data-url` attribute on any link, or by the first link, inside the custom element. | ||
- CSS `focus-within` is utilised to add a focus indicator when the custom element, or any of its descendents, receives keyboard `focus`. | ||
|
||
<Canvas of={WebUIMakeClickable.WebUIMakeClickable} /> |
15 changes: 15 additions & 0 deletions
15
...ies/6. Web Components Or Custom Elements/WebUIMakeClickable/WebUIMakeClickable.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { WebUIMakeClickableHtml } from './WebUIMakeClickable'; | ||
|
||
export default { | ||
title: 'Web Components Or Custom Elements/<webui-make-clickable>', | ||
parameters: { | ||
status: { | ||
type: 'stable', | ||
}, | ||
}, | ||
}; | ||
|
||
export const WebUIMakeClickable = { | ||
render: () => WebUIMakeClickableHtml(), | ||
}; | ||
WebUIMakeClickable.storyName = '<webui-make-clickable>'; |