Skip to content

Commit

Permalink
add webui-share component another url
Browse files Browse the repository at this point in the history
  • Loading branch information
basher committed Apr 2, 2024
1 parent ae8ec18 commit 446b1a0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ui/src/javascript/web-components/webui-share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export default class WebUIShare extends HTMLElement {
this.shareInput = this.querySelector('[data-input]');

this.canonical = document.querySelector('link[rel=canonical]');
this.shareTitle = this.btnShare?.dataset.shareTitle || document.title;
this.shareTitle = this.btnShare?.dataset.title || document.title;
this.shareUrl =
this.btnShare?.dataset.shareUrl || this.canonical
this.btnShare?.dataset.url || this.canonical
? this.canonical?.href
: document.location.href;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,45 @@ export const WebUIShareHtml = () => `
</webui-disclosure>
</webui-share>
`;

export const WebUIShareAnotherUrlHtml = () => `
<webui-share>
<webui-disclosure>
<button
type="button"
class="button button--text-icon"
data-trigger
data-url="https://www.google.com"
data-title="google"
hidden
>
<svg
aria-hidden="true"
focusable="false"
class="icon"
>
<use href="sprite.svg#share" />
</svg>
<span>Share</span>
</button>
<div data-content>
<label for="share-input" class="label">Share page</label>
<input
type="text"
id="share-input"
class="input"
value=""
data-input
/>
<button
type="button"
class="button button--text button--secondary"
data-copy
>
Copy
</button>
</div>
</webui-disclosure>
</webui-share>
`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Meta, Canvas, Controls } from '@storybook/blocks';
import { Meta, Canvas } from '@storybook/blocks';
import * as WebUIShare from './WebUIShare.stories';

<Meta of={WebUIShare} />
Expand All @@ -8,4 +8,6 @@ import * as WebUIShare from './WebUIShare.stories';
- It is a simple `wrapper` around the [webui-disclosure](/story/web-components-or-custom-elements-webui-disclosure--web-ui-disclosure) custom element.

<Canvas of={WebUIShare.WebUIShare} />
<Controls of={WebUIShare.WebUIShare} />

## Share a different URL
<Canvas of={WebUIShare.WebUIShareAnotherUrl} />
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WebUIShareHtml } from './WebUIShare';
import { WebUIShareHtml, WebUIShareAnotherUrlHtml } from './WebUIShare';

export default {
title: 'Web Components Or Custom Elements/<webui-share>',
Expand All @@ -13,3 +13,8 @@ export const WebUIShare = {
render: () => WebUIShareHtml(),
};
WebUIShare.storyName = '<webui-share>';

export const WebUIShareAnotherUrl = {
render: () => WebUIShareAnotherUrlHtml(),
};
WebUIShareAnotherUrl.storyName = '<webui-share> Another URL';

0 comments on commit 446b1a0

Please sign in to comment.