Skip to content

Commit 64cc823

Browse files
authored
refactor!: move button to new package (#2373)
1 parent 2e4003d commit 64cc823

119 files changed

Lines changed: 233 additions & 1241 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/button/README.md‎

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# @vaadin/button
22

3-
> ⚠️ Work in progress, please do not use this component yet.
3+
An accessible and customizable button that allows users to perform actions.
44

5-
The new version of `vaadin-button` component.
5+
[Live Demo ↗](https://vaadin.com/docs/latest/ds/components/button)
6+
7+
```html
8+
<vaadin-button>Press me</vaadin-button>
9+
```
10+
11+
## Installation
12+
13+
Install the component:
14+
15+
```sh
16+
npm i @vaadin/button --save
17+
```
18+
19+
Once installed, import the component in your application:
20+
21+
```js
22+
import '@vaadin/button';
23+
```
24+
25+
## Themes
26+
27+
Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes),
28+
Lumo and Material. The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/button/vaadin-button.js)
29+
of the package uses the Lumo theme.
30+
31+
To use the Material theme, import the component from the `theme/material` folder:
32+
33+
```js
34+
import '@vaadin/button/theme/material/vaadin-button.js';
35+
```
36+
37+
You can also import the Lumo version of the component explicitly:
38+
39+
```js
40+
import '@vaadin/button/theme/lumo/vaadin-button.js';
41+
```
42+
43+
Finally, you can import the un-themed component from the `src` folder to get a minimal starting point:
44+
45+
```js
46+
import '@vaadin/button/src/vaadin-button.js';
47+
```
48+
49+
## License
50+
51+
Apache License 2.0
52+
53+
Vaadin collects development time usage statistics to improve this product.
54+
For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.

‎packages/button/src/vaadin-button.d.ts‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,40 @@ import { ElementMixin } from '@vaadin/vaadin-element-mixin/vaadin-element-mixin.
88
import { ActiveMixin } from '@vaadin/field-base/src/active-mixin.js';
99
import { ControlStateMixin } from '@vaadin/vaadin-control-state-mixin/vaadin-control-state-mixin.js';
1010

11-
declare class Button extends ControlStateMixin(ActiveMixin(ElementMixin(ThemableMixin(HTMLElement)))) {
12-
/**
13-
* A getter that returns the native button as a focusable element for ControlStateMixin.
14-
*/
15-
readonly focusElement: HTMLButtonElement | null;
11+
/**
12+
* `<vaadin-button>` is an accessible and customizable button that allows users to perform actions.
13+
*
14+
* ```html
15+
* <vaadin-button>Press me</vaadin-button>
16+
* ```
17+
*
18+
* ### Styling
19+
*
20+
* The following shadow DOM parts are available for styling:
21+
*
22+
* Part name | Description
23+
* ----------|-------------
24+
* `label` | The label (text) inside the button.
25+
* `prefix` | A slot for content before the label (e.g. an icon).
26+
* `suffix` | A slot for content after the label (e.g. an icon).
27+
*
28+
* The following attributes are available for styling:
29+
*
30+
* Attribute | Description
31+
* -------------|-------------
32+
* `active` | Set when the button is pressed down, either with mouse, touch or the keyboard.
33+
* `disabled` | Set when the button is disabled.
34+
* `focus-ring` | Set when the button is focused using the keyboard.
35+
* `focused` | Set when the button is focused.
36+
*
37+
* See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
38+
*/
39+
declare class Button extends ControlStateMixin(ActiveMixin(ElementMixin(ThemableMixin(HTMLElement)))) {}
40+
41+
declare global {
42+
interface HTMLElementTagNameMap {
43+
'vaadin-button': Button;
44+
}
1645
}
1746

1847
export { Button };

‎packages/button/src/vaadin-button.js‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,41 @@ import { TabindexMixin } from '@vaadin/field-base/src/tabindex-mixin.js';
1010
import { ActiveMixin } from '@vaadin/field-base/src/active-mixin.js';
1111
import { FocusMixin } from '@vaadin/field-base/src/focus-mixin.js';
1212

13+
/**
14+
* `<vaadin-button>` is an accessible and customizable button that allows users to perform actions.
15+
*
16+
* ```html
17+
* <vaadin-button>Press me</vaadin-button>
18+
* ```
19+
*
20+
* ### Styling
21+
*
22+
* The following shadow DOM parts are available for styling:
23+
*
24+
* Part name | Description
25+
* ----------|-------------
26+
* `label` | The label (text) inside the button.
27+
* `prefix` | A slot for content before the label (e.g. an icon).
28+
* `suffix` | A slot for content after the label (e.g. an icon).
29+
*
30+
* The following attributes are available for styling:
31+
*
32+
* Attribute | Description
33+
* -------------|-------------
34+
* `active` | Set when the button is pressed down, either with mouse, touch or the keyboard.
35+
* `disabled` | Set when the button is disabled.
36+
* `focus-ring` | Set when the button is focused using the keyboard.
37+
* `focused` | Set when the button is focused.
38+
*
39+
* See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
40+
*
41+
* @extends HTMLElement
42+
* @mixes ActiveMixin
43+
* @mixes TabindexMixin
44+
* @mixes FocusMixin
45+
* @mixes ElementMixin
46+
* @mixes ThemableMixin
47+
*/
1348
class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableMixin(PolymerElement))))) {
1449
static get is() {
1550
return 'vaadin-button';
@@ -32,7 +67,8 @@ class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableM
3267
display: none !important;
3368
}
3469
35-
/* Ensure the button is always aligned on the baseline */
70+
/* Aligns the button with form fields when placed on the same line.
71+
Note, to make it work, the form fields should have the same "::before" pseudo-element. */
3672
.vaadin-button-container::before {
3773
content: '\\2003';
3874
display: inline-block;
@@ -91,4 +127,6 @@ class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableM
91127
}
92128
}
93129

130+
customElements.define(Button.is, Button);
131+
94132
export { Button };

‎packages/button/test/button.test.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import {
1414
touchstart
1515
} from '@vaadin/testing-helpers';
1616
import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
17-
import { Button } from '../vaadin-button.js';
18-
19-
customElements.define(Button.is, Button);
17+
import '../vaadin-button.js';
2018

2119
describe('vaadin-button', () => {
2220
let element;

‎packages/button/test/visual/lumo/button.test.js‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import { visualDiff } from '@web/test-runner-visual-regression';
33
import { sendKeys } from '@web/test-runner-commands';
44
import '@vaadin/vaadin-icon/theme/lumo/vaadin-icon.js';
55
import '@vaadin/vaadin-lumo-styles/vaadin-iconset.js';
6-
// TODO: Remove in https://github.com/vaadin/web-components/issues/2224.
7-
import './vaadin-button-styles.js';
8-
// TODO: Remove in https://github.com/vaadin/web-components/issues/2224.
9-
import { Button } from '../../../src/vaadin-button.js';
10-
11-
// TODO: Remove in https://github.com/vaadin/web-components/issues/2224.
12-
customElements.define(Button.is, Button);
6+
import '../../../theme/lumo/vaadin-button.js';
137

148
describe('button', () => {
159
let div, element;

‎packages/button/test/visual/lumo/vaadin-button-styles.js‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎packages/button/test/visual/material/button.test.js‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import { visualDiff } from '@web/test-runner-visual-regression';
33
import { sendKeys } from '@web/test-runner-commands';
44
import '@vaadin/vaadin-icon/theme/material/vaadin-icon.js';
55
import '@vaadin/vaadin-lumo-styles/vaadin-iconset.js';
6-
// TODO: Remove in https://github.com/vaadin/web-components/issues/2224.
7-
import './vaadin-button-styles.js';
8-
// TODO: Remove in https://github.com/vaadin/web-components/issues/2224.
9-
import { Button } from '../../../src/vaadin-button.js';
10-
11-
// TODO: Remove in https://github.com/vaadin/web-components/issues/2224.
12-
customElements.define(Button.is, Button);
6+
import '../../../theme/material/vaadin-button.js';
137

148
describe('button', () => {
159
let div, element;

‎packages/button/test/visual/material/vaadin-button-styles.js‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎packages/button/theme/lumo/vaadin-button-styles.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '@vaadin/vaadin-lumo-styles/style.js';
66
import '@vaadin/vaadin-lumo-styles/typography.js';
77

88
registerStyles(
9-
'',
9+
'vaadin-button',
1010
css`
1111
:host {
1212
/* Sizing */
@@ -289,5 +289,5 @@ registerStyles(
289289
margin-right: 0;
290290
}
291291
`,
292-
{ moduleId: 'lumo-button-styles' }
292+
{ moduleId: 'lumo-button' }
293293
);

‎packages/button/theme/material/vaadin-button-styles.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '@vaadin/vaadin-material-styles/shadow.js';
44
import '@vaadin/vaadin-material-styles/typography.js';
55

66
registerStyles(
7-
'',
7+
'vaadin-button',
88
css`
99
:host {
1010
padding: 8px;
@@ -176,5 +176,5 @@ registerStyles(
176176
margin-right: 8px;
177177
}
178178
`,
179-
{ moduleId: 'material-button-styles' }
179+
{ moduleId: 'material-button' }
180180
);

0 commit comments

Comments
 (0)