Skip to content

Commit cb82810

Browse files
committed
Updated
1 parent e76d140 commit cb82810

28 files changed

+81
-5
lines changed

src/button/ButtonElement.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { EventType } from '../core/Event';
1313
* @property {String} textTransform - If the button text should be transformed
1414
* (uppercase, lowercase, capitalize)
1515
* @property {Boolean} disabled - Whether the button is disabled
16+
* @property {String} popup - The associated popup to show when the button is clicked
1617
*
1718
* @example
1819
* <wc-button type="control">Close</wc-button>
@@ -30,6 +31,7 @@ export class ButtonElement extends LitElement {
3031
this.type = '';
3132
this.textTransform = '';
3233
this.disabled = false;
34+
this.popup = '';
3335
}
3436

3537
static get properties() {
@@ -38,6 +40,7 @@ export class ButtonElement extends LitElement {
3840
type: { type: String },
3941
textTransform: { type: String },
4042
disabled: { type: Boolean },
43+
popup: { type: String },
4144
};
4245
}
4346

@@ -103,25 +106,48 @@ export class ButtonElement extends LitElement {
103106
}
104107
}
105108

109+
firstUpdated() {
110+
if (this.popup) {
111+
// Attach the popover target element
112+
const buttonNode = this.shadowRoot.querySelector('button');
113+
const targetNode = document.getElementById(this.popup);
114+
if (buttonNode && targetNode) {
115+
buttonNode.popoverTargetElement = targetNode;
116+
}
117+
}
118+
}
119+
106120
renderButton() {
107121
return html`
108-
<button class=${this.classes.join(' ') || nothing} ?disabled=${this.disabled} name=${this.name || nothing} value=${this.buttonTitle || nothing} @click=${this.onClick}>
122+
<button class=${this.classes.join(' ') || nothing}
123+
name=${this.name || nothing} value=${this.buttonTitle || nothing}
124+
?disabled=${this.disabled}
125+
@click=${this.onClick}>
109126
<slot></slot>
110127
</button>
111128
`;
112129
}
113130

114131
renderSubmit() {
115132
return html`
116-
<button class=${this.classes.join(' ') || nothing} type="submit" ?disabled=${this.disabled} name=${this.name || nothing} value=${this.buttonTitle || nothing} @click=${this.onClick}><slot></slot></button>
133+
<button class=${this.classes.join(' ') || nothing}
134+
type="submit" ?disabled=${this.disabled}
135+
name=${this.name || nothing} value=${this.buttonTitle || nothing}
136+
?disabled=${this.disabled}
137+
@click=${this.onClick}>
138+
<slot></slot>
139+
</button>
117140
`;
118141
}
119142

120143
renderControl() {
121144
const icon = this.controlButtonIcon;
122145
if (icon) {
123146
return html`
124-
<button class=${this.classes.join(' ') || nothing} ?disabled=${this.disabled} name=${this.name || nothing} value=${this.buttonTitle || nothing} @click=${this.onClick}>
147+
<button class=${this.classes.join(' ') || nothing}
148+
name=${this.name || nothing} value=${this.buttonTitle || nothing}
149+
?disabled=${this.disabled}
150+
@click=${this.onClick}>
125151
<wc-icon name=${icon}></wc-icon>
126152
</button>
127153
`;

src/index.html

+15-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,23 @@ <h4>Card</h4>
8484
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
8585
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
8686
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
87+
88+
<wc-button popup="poop">Toggle</wc-button>
89+
<wc-popup id="poop">
90+
<h4>Card</h4>
91+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
92+
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
93+
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
94+
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
95+
cupidatat
96+
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
97+
Popover content
98+
</wc-popup>
8799
</wc-card>
88100
<wc-card id="card" backgroundColor="secondary" width="2">
89101
<h4>Card</h4>
90-
<wc-form-select id="backgroundColor" options='[ "primary", "secondary", "light", "dark", "black", "white", "success", "warning", "error" ]'>Background
102+
<wc-form-select id="backgroundColor"
103+
options='[ "primary", "secondary", "light", "dark", "black", "white", "success", "warning", "error" ]'>Background
91104
Colour</wc-form-select>
92105
<script>
93106
document.querySelector('wc-form-select#backgroundColor').addEventListener('wc-change', (e) => {
@@ -116,7 +129,7 @@ <h2>Subtitle</h2>
116129
<script>
117130
document.querySelector('wc-control-button-group#controls').addEventListener('wc-click', (e) => {
118131
var card = e.target.closest('wc-card');
119-
if(card) {
132+
if (card) {
120133
card.setAttribute('hidden', true);
121134
}
122135
});

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import './app/app';
99
import './layout/layout';
1010
import './form/form';
1111
import './button/button';
12+
import './popup/popup';
1213

1314
// Other
1415
import './esbuild';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/popup/PopupElement.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { LitElement, html, nothing } from 'lit';
2+
3+
/**
4+
* @class PopupElement
5+
*
6+
* This class is used as a popup, which is initially hidden but can be shown indefinitely
7+
* or for a specific duration.
8+
*
9+
* @example
10+
* <wc-popup id="popup">Suprise!</wc-popup>
11+
*/
12+
export class PopupElement extends LitElement {
13+
static get localName() {
14+
return 'wc-popup';
15+
}
16+
17+
// eslint-disable-next-line class-methods-use-this
18+
get classes() {
19+
const classes = [];
20+
return classes;
21+
}
22+
23+
render() {
24+
return html`
25+
<div class=${this.classes.join(' ') || nothing} popover><slot></slot></div>
26+
`;
27+
}
28+
}

src/popup/popup.css

Whitespace-only changes.

src/popup/popup.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// CSS
2+
import './popup.css';
3+
4+
// Classes
5+
import { PopupElement } from './PopupElement';
6+
7+
// Web Components
8+
customElements.define(PopupElement.localName, PopupElement); // wc-popup

0 commit comments

Comments
 (0)