Skip to content

Commit 3c1fc43

Browse files
heyMPgithub-actions[bot]kylebuch8
authored
feat: pfe-button | Add large variant #1745 (#1751)
* feat: added size variant. Added font weight hook * feat: update docs * chore: update Changelog-1.x.md * chore: added styling hooks to docs * fix: fixed changlog * feat: updated pfe-button tests to spec.js. Added tests for large size * fix: commenting out denyAttributeElement to supress React errors * updating the button README with the size attribute Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Kyle Buchanan <[email protected]>
1 parent 489c561 commit 3c1fc43

File tree

7 files changed

+210
-3
lines changed

7 files changed

+210
-3
lines changed

CHANGELOG-1.x.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
- [3d3c4f1](https://github.com/patternfly/patternfly-elements/commit/3d3c4f109a7e09adae3f3f01122846354a278787) fix: accordion rendering slotted content in the header
1010
- [519d16a](https://github.com/patternfly/patternfly-elements/commit/519d16af4c714efdc5246f9c0925ca30447b87ea) feat: vertically center pfe-tab content
1111
- [877a1ed](https://github.com/patternfly/patternfly-elements/commit/877a1ed5c6a02cdc5899f8e73007572e831b18a0) feat: modal width attribute
12-
- [](https://github.com/patternfly/patternfly-elements/commit/) feat: add color vars to pfe-progress-indicator for styling
12+
- [3765170](https://github.com/patternfly/patternfly-elements/commit/376517064f3f12a4cc97cb7bcd8f7dd7b375a30c) feat: add color vars to pfe-progress-indicator for styling
13+
- [](https://github.com/patternfly/patternfly-elements/commit/) feat: pfe-button | Add large variant
1314

1415

1516
# 1.10.1 (2021-07-12)

elements/pfe-button/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ the only light DOM child of `pfe-button`.
1414
</pfe-button>
1515
```
1616

17+
### Size
18+
19+
```html
20+
<pfe-button size="large">
21+
<button>Large Button</button>
22+
</pfe-button>
23+
```
24+
1725
### Accessibility
1826
`<pfe-button>` addresses the issues associated with typical implementations of
1927
web component buttons. When using a `<pfe-button>` in a `<form>` element, the
@@ -71,6 +79,10 @@ None
7179
- danger
7280
- control
7381

82+
`size`: Changes the size of the button.
83+
- medium (default)
84+
- large
85+
7486
## Events
7587
### pfe-button:click
7688
This event is fired when `<pfe-button>` is clicked and serves as a way to

elements/pfe-button/demo/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ <h2>&lt;pfe-button&gt;</h2>
100100
</article>
101101
</pfe-band>
102102

103+
<pfe-band color="lightest">
104+
<header slot="pfe-band--header">
105+
<h2>&lt;pfe-button size="large"&gt;</h2>
106+
</header>
107+
<article>
108+
<pfe-button size="large">
109+
<button>Primary</button>
110+
</pfe-button>
111+
<pfe-button variant="secondary" size="large">
112+
<button>Secondary</button>
113+
</pfe-button>
114+
<pfe-button variant="tertiary" size="large">
115+
<button>Tertiary</button>
116+
</pfe-button>
117+
<pfe-button variant="danger" size="large">
118+
<button>Danger</button>
119+
</pfe-button>
120+
<pfe-button variant="control" size="large">
121+
<button>Control</button>
122+
</pfe-button>
123+
</article>
124+
</pfe-band>
125+
103126
<pfe-band>
104127
<header slot="pfe-band--header">
105128
<h2>&lt;pfe-button&gt; in a form</h2>

elements/pfe-button/docs/index.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,34 @@ npm install @patternfly/pfe-button
5353
::: section
5454
## Usage
5555
When using this component, you must provide a standard HTML Button Element as the only light DOM child of `pfe-button`.
56+
57+
<pfe-button>
58+
<button>My Button</button>
59+
</pfe-button>
60+
5661
```html
5762
<pfe-button>
5863
<button>My Button</button>
5964
</pfe-button>
6065
```
6166
:::
6267

68+
::: section
69+
70+
### Size
71+
72+
<pfe-button size="large">
73+
<button>Large Button</button>
74+
</pfe-button>
75+
76+
```html
77+
<pfe-button size="large">
78+
<button>Large Button</button>
79+
</pfe-button>
80+
```
81+
:::
82+
83+
6384
::: section
6485
## Slots
6586
None
@@ -75,6 +96,10 @@ None
7596
- tertiary
7697
- danger
7798
- control
99+
100+
`size`: Changes the size of the button.
101+
- medium (default)
102+
- large
78103
:::
79104

80105
::: section
@@ -91,5 +116,19 @@ capture click events if necessary.
91116

92117
::: section
93118
## Styling hooks
94-
None
119+
120+
| Theme hook | Default value | Region |
121+
| --- | --- | --- |
122+
| `--pfe-button--BackgroundColor` | var(--pfe-theme--color--ui-accent, #06c) | N/A |
123+
| `--pfe-button--Color` | var(--pfe-theme--color--ui-base--text, #fff) | N/A |
124+
| `--pfe-button--FontSize` | var(--pf-global--FontSize--md, 1rem) | N/A |
125+
| `--pfe-button--FontWeight` | var(--pfe-theme--font-weight--normal, 400) | N/A |
126+
| `--pfe-button--Padding` | calc(var(--pfe-theme--container-padding, 1rem) / 2) var(--pfe-theme--container-padding, 1rem) | N/A |
127+
| `--pfe-button--BorderRadius` | var(--pfe-theme--surface--border-radius, 3px) | N/A |
128+
| `--pfe-button--LineHeight` | var(--pfe-theme--line-height, 1.5) | N/A |
129+
| `--pfe-button__after--Border` | var(--pfe-theme--ui--border-width, 1px) var(--pfe-theme--ui--border-style, solid) var(--pfe-button__after--BorderColor, transparent) | `after` |
130+
| `--pfe-button--BackgroundColor--hover` | var(--pfe-theme--color--ui-accent--hover, #004080) | N/A |
131+
| `--pfe-button__after--Border--hover` | var(--pfe-theme--ui--border-width, 1px) var(--pfe-theme--ui--border-style, solid) var(--pfe-button__after--BorderColor--hover, transparent) | `after` |
132+
| `--pfe-button--FontWeight--large` | var(--pfe-theme--font-weight--semi-bold, 600) | N/A |
133+
| `--pfe-button--Padding--large` | 12px 24px | N/A |
95134
:::

elements/pfe-button/src/pfe-button.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class PfeButton extends PFElement {
6969
prefix: false,
7070
observer: "_disabledChanged",
7171
},
72+
size: {
73+
title: "Size",
74+
type: String,
75+
values: ["medium", "large"],
76+
},
7277
};
7378
}
7479

elements/pfe-button/src/pfe-button.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $LOCAL-VARIABLES: (
88
BackgroundColor--hover: pfe-var(ui-accent--hover),
99
Color: pfe-var(ui-base--text),
1010
FontSize: pfe-var(FontSize--md),
11+
FontWeight: pfe-var(font-weight--normal),
1112
Border: 0,
1213
BorderRadius: pfe-var(surface--border-radius),
1314
Padding: calc(#{pfe-var(container-padding)} / 2) pfe-var(container-padding),
@@ -44,6 +45,7 @@ button {
4445
color: pfe-local(Color);
4546
font-size: pfe-local(FontSize);
4647
font-family: pfe-var(font-family, $fallback: inherit);
48+
font-weight: pfe-local(FontWeight);
4749
padding: pfe-local(Padding);
4850
cursor: pointer;
4951
border-radius: pfe-local(BorderRadius);
@@ -113,7 +115,7 @@ button {
113115
&:hover,
114116
&:focus {
115117
--pfe-button__after--BorderColor: #{pfe-local(BorderColor--hover, pfe-var(ui--border--lightest))};
116-
118+
117119
&::after {
118120
border-bottom-width: pfe-var(ui--border-width--md);
119121
border-bottom-color: pfe-var(ui-accent);
@@ -130,6 +132,11 @@ button {
130132
background-color: pfe-local(BackgroundColor, pfe-var(surface--lighter));
131133
}
132134

135+
:host([size="large"]) & {
136+
--pfe-button--FontWeight: #{pfe-local(FontWeight--large, $fallback: pfe-var(font-weight--semi-bold))};
137+
--pfe-button--Padding: #{pfe-local(Padding--large, $fallback: 12px 24px)};
138+
}
139+
133140
:host([disabled]) & {
134141
background-color: pfe-local(BackgroundColor, pfe-var(ui-disabled));
135142
color: pfe-local(Color, pfe-var(ui-disabled--text));
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { expect, elementUpdated } from "@open-wc/testing/index-no-side-effects";
2+
import { spy } from "sinon";
3+
import { createFixture } from "../../../test/utils/create-fixture";
4+
import PfeButton from "../dist/pfe-button.js";
5+
6+
const element = `
7+
<pfe-button>
8+
<button>Button</button>
9+
</pfe-button>
10+
`;
11+
12+
const badElement = `
13+
<pfe-button>
14+
<div>Bad button</div>
15+
</pfe-button>
16+
`;
17+
18+
const attributeElement = `
19+
<pfe-button>
20+
<button id="myBtn" disabled type="reset">Button</button>
21+
</pfe-button>
22+
`;
23+
24+
const denyAttributeElement = `
25+
<pfe-button>
26+
<button style="background: red;">Button</button>
27+
</pfe-button>
28+
`;
29+
30+
const largeSizeElement = `
31+
<pfe-button size="large">
32+
<button>Button</button>
33+
</pfe-button>
34+
`;
35+
36+
describe("<pfe-button>", () => {
37+
it("should upgrade", async () => {
38+
const el = await createFixture(element);
39+
expect(el).to.be.an.instanceOf(customElements.get(PfeButton.tag), "pfe-card should be an instance of PfeButton");
40+
});
41+
42+
it("should log a console warning if the light dom inside pfe-button is not a button", async () => {
43+
const spyConsole = spy(console, 'warn');
44+
const el = await createFixture(badElement);
45+
46+
expect(el).to.exist;
47+
expect(spyConsole.calledWith("[pfe-button]", "The only child in the light DOM must be a button tag")).to.be.true;
48+
spyConsole.restore();
49+
});
50+
51+
it("should copy any attributes from the light dom button to the shadow dom button", async () => {
52+
const el = await createFixture(attributeElement);
53+
const shadowBtn = el.shadowRoot.querySelector("button");
54+
55+
await elementUpdated(el);
56+
57+
expect(shadowBtn.hasAttribute("disabled")).to.be.true;
58+
expect(shadowBtn.getAttribute("type")).to.equal("reset");
59+
expect(shadowBtn.id).to.equal("myBtn");
60+
});
61+
62+
/**
63+
* @todo denyAttributeElement throws errors in React. We should an option to skip running
64+
* tests in certain environments.
65+
*/
66+
// it("should not accept any deny list attributes from the light dom button", async () => {
67+
// const el = await createFixture(denyAttributeElement);
68+
// const shadowBtn = el.shadowRoot.querySelector("button");
69+
// expect(shadowBtn.hasAttribute("style")).to.be.false;
70+
// });
71+
72+
it("should add a disabled attribute to the light DOM button if pfe-button has a disabled attribute", async () => {
73+
const el = await createFixture(element);
74+
let lightDomBtn = el.querySelector("button");
75+
el.setAttribute("disabled", "");
76+
77+
await elementUpdated(el);
78+
expect(lightDomBtn.hasAttribute("disabled")).to.be.true;
79+
80+
el.removeAttribute("disabled");
81+
82+
await elementUpdated(el);
83+
expect(lightDomBtn.hasAttribute("disabled")).to.be.false;
84+
});
85+
86+
it("should update the shadow dom button text if the light dom button text changes", async () => {
87+
const el = await createFixture(element);
88+
const lightDomBtn = el.querySelector("button");
89+
const newText = "New Text";
90+
let shadowBtn = el.shadowRoot.querySelector("button");
91+
92+
expect(lightDomBtn.textContent).to.equal(shadowBtn.textContent);
93+
94+
lightDomBtn.textContent = newText;
95+
96+
await elementUpdated(el);
97+
shadowBtn = el.shadowRoot.querySelector("button");
98+
expect(shadowBtn.textContent).to.equal(newText);
99+
});
100+
101+
it("should send a pfe-button:click event on click", async () => {
102+
const el = await createFixture(element);
103+
const handlerSpy = spy();
104+
105+
document.addEventListener('pfe-button:click', handlerSpy);
106+
el.click();
107+
108+
expect(handlerSpy.calledOnce).to.be.true;
109+
document.removeEventListener("pfe-button:click", handlerSpy);
110+
});
111+
112+
describe("with size=large attribute", () => {
113+
it("should have large size styles", async () => {
114+
const el = await createFixture(largeSizeElement);
115+
const shadowBtn = el.shadowRoot.querySelector("button");
116+
expect(getComputedStyle(shadowBtn).getPropertyValue('padding')).to.equal('12px 24px');
117+
expect(getComputedStyle(shadowBtn).getPropertyValue('font-weight')).to.equal('600');
118+
});
119+
});
120+
});

0 commit comments

Comments
 (0)