Skip to content

Commit 878697a

Browse files
committed
button variants
1 parent ac34fde commit 878697a

12 files changed

Lines changed: 81 additions & 23 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.example-flex {
2+
display: flex;
3+
gap: 0.5rem;
4+
}

src/components/pg/button/__examples__/basic/basic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Component, Part, Prop } from '@pictogrammers/element';
22

3+
import style from './basic.css';
34
import template from './basic.html';
45

56
@Component({
67
selector: 'x-pg-button-basic',
7-
template
8+
style,
9+
template,
810
})
911
export default class XPgButtonBasic extends HTMLElement {
1012

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h4 {
2+
margin-block: 0.25rem;
3+
}

src/components/pg/button/__examples__/states/states.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Component, Part, Prop } from '@pictogrammers/element';
22
import PgButton from '../../button';
33

4+
import style from './states.css';
45
import template from './states.html';
56

67
@Component({
78
selector: 'x-pg-button-states',
8-
template
9+
style,
10+
template,
911
})
1012
export default class XPgButtonStates extends HTMLElement {
1113
@Part() $active: PgButton;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.example-flex {
2+
display: flex;
3+
gap: 0.5rem;
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div class="example">
2+
<div class="example-flex">
3+
<pg-button variant="brand">Example Button</pg-button>
4+
<pg-button variant="brand"><pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon></pg-button>
5+
<pg-button variant="brand">
6+
<pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon>
7+
With Icon
8+
</pg-button>
9+
</div>
10+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Component, Part, Prop } from '@pictogrammers/element';
2+
3+
import style from './variants.css';
4+
import template from './variants.html';
5+
6+
@Component({
7+
selector: 'x-pg-button-variants',
8+
style,
9+
template,
10+
})
11+
export default class XPgVariantsBasic extends HTMLElement {
12+
13+
}

src/components/pg/button/button.css

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
display: inline-flex;
33
}
44

5-
[part="button"] {
5+
[part=button] {
66
display: flex;
77
align-items: center;
88
align-content: center;
@@ -17,25 +17,26 @@
1717
outline: none;
1818
--pg-icon-color: var(--pg-button-color, #453C4F);
1919
cursor: var(--pg-button-cursor, var(--pg-cursor-default, default));
20+
gap: var(--pg-button-gap, 0.325rem);
2021
}
2122

22-
[part="button"]:hover {
23+
[part=button]:hover {
2324
--pg-button-border-color: var(--pg-button-hover-border-color, #453C4F);
2425
background-color: var(--pg-button-hover-background-color, #453C4F);
2526
color: var(--pg-button-hover-color, #FFFFFF);
2627
--pg-icon-color: var(--pg-button-hover-color, #FFFFFF);
2728
}
2829

29-
[part="button"]:active {
30+
[part=button]:active {
3031
box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
3132
position: relative;
3233
}
3334

34-
[part="button"]:focus-visible {
35+
[part=button]:focus-visible {
3536
position: relative;
3637
}
3738

38-
[part="button"]:active::before {
39+
[part=button]:active::before {
3940
content: '';
4041
position: absolute;
4142
top: -1px;
@@ -45,7 +46,7 @@
4546
border-radius: var(--pg-button-border-radius, 0.25rem);
4647
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
4748
}
48-
[part="button"]:focus-visible::before {
49+
[part=button]:focus-visible::before {
4950
pointer-events: none;
5051
content: '';
5152
position: absolute;
@@ -57,37 +58,46 @@
5758
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
5859
}
5960

60-
[part="button"].start {
61+
[part=button].start {
6162
border-top-right-radius: 0;
6263
border-bottom-right-radius: 0;
6364
margin-right: -1px;
6465
}
6566

66-
[part="button"].center {
67+
[part=button].center {
6768
border-radius: 0;
6869
margin-right: -1px;
6970
}
7071

71-
[part="button"].end {
72+
[part=button].end {
7273
border-top-left-radius: 0;
7374
border-bottom-left-radius: 0;
7475
}
7576

76-
[part="button"].active {
77+
[part=button].active {
7778
box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
7879
background-color: rgba(69, 60, 79, 0.1);
7980
color: var(--pg-button-color, #453C4F);
8081
}
81-
[part="button"].active:hover {
82+
[part=button].active:hover {
8283
box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.5) inset;
8384
background-color: var(--pg-button-color, #453C4F);
84-
color: var(--pg-button-hover-color, #fff);
85+
color: var(--pg-button-hover-color, #FFFFFF);
8586
}
8687

87-
[part="button"].block {
88+
[part=button].block {
8889
flex: 1;
8990
}
9091

92+
[part=button].brand {
93+
--pg-button-background-color: #453C4F;
94+
--pg-button-color: #FFFFFF;
95+
}
96+
[part=button].brand:hover {
97+
--pg-button-hover-background-color: color-mix(in oklab, var(--pg-button-background-color), white 10%);
98+
--pg-button-hover-border-color: color-mix(in oklab, var(--pg-button-background-color), white 10%);
99+
}
100+
91101
::slotted {
92102
align-self: center;
93-
}
103+
}

src/components/pg/button/button.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import { Component, Part, Prop, normalizeBoolean } from '@pictogrammers/element';
1+
import { Component, Part, Prop, normalizeBoolean, normalizeString } from '@pictogrammers/element';
22

33
import template from './button.html';
44
import style from './button.css';
55

6+
const variants = ['neutral', 'brand'];
7+
68
@Component({
79
selector: 'pg-button',
810
style,
911
template
1012
})
1113
export default class PgButton extends HTMLElement {
14+
@Prop(normalizeString) variant: string = 'neutral';
1215
@Prop(normalizeBoolean) active: boolean = false;
1316
@Prop(normalizeBoolean) block: boolean = false;
1417
@Prop(normalizeBoolean) start: boolean = false;
@@ -27,6 +30,13 @@ export default class PgButton extends HTMLElement {
2730
}
2831

2932
render(changes) {
33+
if (changes.variant) {
34+
if (!variants.includes(this.variant)) {
35+
throw new Error(`invalid variant ${this.variant}`);
36+
}
37+
this.$button.classList.toggle('neutral', this.variant === 'neutral');
38+
this.$button.classList.toggle('brand', this.variant === 'brand');
39+
}
3040
if (changes.active) {
3141
this.$button.classList.toggle('active', this.active);
3242
}

src/components/pg/inputText/inputText.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
font-size: 1rem;
1212
outline: none;
1313
field-sizing: content;
14-
min-width: calc(100% - 0.5rem - 2px);
15-
max-width: calc(var(--pg-input-text-max-width, 100%) - 0.5rem - 2px);
14+
min-width: calc(100% - 1.5rem - 2px);
15+
max-width: calc(var(--pg-input-text-max-width, 100%) - 1.5rem - 2px);
1616
background-color: transparent;
1717
}
1818

0 commit comments

Comments
 (0)