Skip to content

Commit 0770597

Browse files
committed
Added buttons
1 parent 9de499e commit 0770597

File tree

5 files changed

+103
-4
lines changed

5 files changed

+103
-4
lines changed

src/button/ButtonElement.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { LitElement, html, css, nothing } from 'lit';
2+
3+
/**
4+
* @class ButtonElement
5+
*
6+
* This class is used as a button, either a control (close, help, etc), a form submission or
7+
* a normal button.
8+
*
9+
* @property {String} name - The name of the button
10+
* @property {String} type - The type of the button if not standard
11+
* (control, submit)
12+
* @property {String} textTransform - If the button text should be transformed
13+
* (uppercase, lowercase, capitalize)
14+
* @property {Boolean} disabled - Whether the button is disabled
15+
*
16+
* @example
17+
* <wc-button type="control">Close</wc-button>
18+
*/
19+
export class ButtonElement extends LitElement {
20+
static get localName() {
21+
return 'wc-button';
22+
}
23+
24+
constructor() {
25+
super();
26+
27+
// Default properties
28+
this.name = '';
29+
this.type = '';
30+
this.textTransform = '';
31+
this.disabled = false;
32+
}
33+
34+
static get properties() {
35+
return {
36+
name: { type: String },
37+
type: { type: String },
38+
textTransform: { type: String },
39+
disabled: { type: Boolean },
40+
};
41+
}
42+
43+
static get styles() {
44+
return css`
45+
button.control {
46+
background: transparent;
47+
}
48+
`;
49+
}
50+
51+
get classes() {
52+
const classes = [];
53+
if (this.type) {
54+
classes.push(this.type);
55+
}
56+
if (this.textTransform) {
57+
classes.push(`text-transform-${this.textTransform}`);
58+
}
59+
return classes;
60+
}
61+
62+
render() {
63+
return html`
64+
<button class=${this.classes.join(' ') || nothing} ?disabled=${this.disabled}><slot></slot></button>
65+
`;
66+
}
67+
}

src/button/ControlButtonGroupElement.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,31 @@ import { LitElement, html, css, nothing } from 'lit';
66
* This class is used as a group of control buttons, as decoration of a card, located on the
77
* top right corner of the card.
88
*
9+
* @property {String} name - The name of the control group
10+
*
911
* @example
10-
* <wc-control-button-group name="controls"></wc-control-button-group>
12+
* <wc-control-button-group name="controls">
13+
* <wc-button type="control">Close</wc-button>
14+
* </wc-control-button-group>
1115
*/
1216
export class ControlButtonGroupElement extends LitElement {
1317
static get localName() {
1418
return 'wc-control-button-group';
1519
}
1620

21+
constructor() {
22+
super();
23+
24+
// Default properties
25+
this.name = '';
26+
}
27+
28+
static get properties() {
29+
return {
30+
name: { type: String },
31+
};
32+
}
33+
1734
static get styles() {
1835
return css`
1936
div {
@@ -37,8 +54,6 @@ export class ControlButtonGroupElement extends LitElement {
3754
render() {
3855
return html`
3956
<div class=${this.classes.join(' ') || nothing}>
40-
<button class="control-button" title="Close">CLOSE</button>
41-
<button class="control-button" title="Help">HELP</button>
4257
<slot></slot>
4358
</div>
4459
`;

src/button/button.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.text-transform-uppercase {
2+
text-transform: uppercase;
3+
}
4+
5+
.text-transform-lowercase {
6+
text-transform: lowercase;
7+
}
8+
9+
.text-transform-capitalize {
10+
text-transform: capitalize;
11+
}

src/button/button.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import './button.css';
33

44
// Classes
55
import { ControlButtonGroupElement } from './ControlButtonGroupElement';
6+
import { ButtonElement } from './ButtonElement';
67

78
// wc-control-button-group
89
customElements.define(ControlButtonGroupElement.localName, ControlButtonGroupElement);
10+
// wc-button
11+
customElements.define(ButtonElement.localName, ButtonElement);

src/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ <h4>Card</h4>
102102
</script>
103103
</wc-card>
104104
<wc-card>
105-
<wc-control-button-group name="controls"></wc-control-button-group>
105+
<wc-control-button-group name="controls">
106+
<wc-button type="control">Close</wc-button>
107+
<wc-button type="control">Help</wc-button>
108+
</wc-control-button-group>
106109
<h1>Header</h1>
107110
<h2>Subtitle</h2>
108111
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut

0 commit comments

Comments
 (0)