@justeattakeaway/pie-button 1.5.1 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -16
- package/custom-elements.json +4 -4
- package/dist/index.js +305 -309
- package/package.json +5 -5
- package/src/index.ts +2 -3
package/README.md
CHANGED
|
@@ -1,38 +1,152 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
</p>
|
|
1
|
+
# @justeattakeaway/pie-button
|
|
2
|
+
[Source Code](https://github.com/justeattakeaway/pie/tree/main/packages/components/pie-button) | [Design Documentation](https://pie.design/components/button) | [NPM](https://www.npmjs.com/package/@justeattakeaway/pie-button)
|
|
4
3
|
|
|
5
|
-
<p
|
|
4
|
+
<p>
|
|
6
5
|
<a href="https://www.npmjs.com/@justeattakeaway/pie-button">
|
|
7
6
|
<img alt="GitHub Workflow Status" src="https://img.shields.io/npm/v/@justeattakeaway/pie-button.svg">
|
|
8
7
|
</a>
|
|
9
8
|
</p>
|
|
10
9
|
|
|
10
|
+
`@justeattakeaway/pie-button` is a Web Component built using the Lit library. It offers a simple and accessible button component for web applications.
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## Table of Contents
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Documentation](#documentation)
|
|
16
|
+
- [Properties](#properties)
|
|
17
|
+
- [Slots](#slots)
|
|
18
|
+
- [CSS Variables](#css-variables)
|
|
19
|
+
- [Events](#events)
|
|
20
|
+
- [Forms Usage](#forms-usage)
|
|
21
|
+
- [Button Attributes](#button-attributes)
|
|
22
|
+
- [Form Integration Example](#form-integration-example)
|
|
23
|
+
- [Usage Examples](#usage-examples)
|
|
24
|
+
- [Questions and Support](#questions-and-support)
|
|
25
|
+
- [Contributing](#contributing)
|
|
15
26
|
|
|
16
|
-
|
|
27
|
+
## Installation
|
|
17
28
|
|
|
29
|
+
> To install any of our web components in your application, we would suggest following the [getting started guide](https://webc.pie.design/?path=/docs/introduction-getting-started--docs) to set up your project.
|
|
18
30
|
|
|
19
|
-
|
|
31
|
+
Ideally, you should install the component using the **`@justeattakeaway/pie-webc`** package, which includes all of the components. Or you can install the individual component package.
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
### Properties
|
|
36
|
+
| Prop | Options | Description | Default |
|
|
37
|
+
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|
|
|
38
|
+
| `size` | `"xsmall"`, `"small-productive"`, `"small-expressive"`, `"medium"`, `"large"` | Sets the size of the button. | `"medium"` |
|
|
39
|
+
| `isResponsive` | `true`, `false` | If true, uses the next larger size on wide viewports. | `false` |
|
|
40
|
+
| `responsiveSize` | `"productive"`, `"expressive"` | Sets which `"small-"` size an xsmall button should grow to when `isResponsive` is true. | `"productive"` |
|
|
41
|
+
| `type` | `"button"`, `"reset"`, `"submit"` | Sets the type of the button. | `"submit"` |
|
|
42
|
+
| `variant` | `"primary"`, `"primary-alternative"`, `"secondary"`, `"outline"`, `"outline-inverse"`, `"ghost"`, `"inverse"`, `"ghost-inverse"`, `"destructive"`, `"destructive-ghost"` | Sets the variant of the button. | `"primary"` |
|
|
43
|
+
| `disabled` | `true`, `false` | If true, disables the button. | `false` |
|
|
44
|
+
| `isFullWidth` | `true`, `false` | If true, sets the button's width to 100% of its container. | `false` |
|
|
45
|
+
| `isLoading` | `true`, `false` | If true, displays a loading indicator inside the button. | `false` |
|
|
46
|
+
| `iconPlacement` | `"leading"`, `"trailing"` | Sets the position of the icon relative to the text. Leading comes before the text and trailing comes after, taking writing direction into account. To use this, you must pass an icon into the [icon slot](#slots). | `"leading"` |
|
|
47
|
+
| `name` | – | The name of the button, submitted as a pair with the button's value as part of the form data, when that button is used to submit the form. | `undefined` |
|
|
48
|
+
| `value` | – | Defines the value associated with the button's name when it's submitted with the form data. This value is passed to the server in params when the form is submitted using this button. | `undefined` |
|
|
49
|
+
| `formaction` | – | The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner. Does nothing if there is no form owner. | `undefined` |
|
|
50
|
+
| `formenctype` | `"application/x-www-form-urlencoded"`, `"multipart/form-data"`, `"text/plain"` | If the button is a submit button, specifies how to encode the form data that is submitted. | `undefined` |
|
|
51
|
+
| `formmethod` | `"post"`, `"get"`, `"dialog"` | If the button is a submit button, this attribute specifies the HTTP method used to submit the form. | `undefined` |
|
|
52
|
+
| `formnovalidate` | `true`, `false` | If the button is a submit button, this Boolean attribute specifies that the form is not to be validated when it is submitted. | `undefined` |
|
|
53
|
+
| `formtarget` | `"_self"`, `"_blank"`, `"_parent"`, `"_top"` | If the button is a submit button, this attribute is an author-defined name or standardized, underscore-prefixed keyword indicating where to display the response from submitting the form. | `undefined` |
|
|
54
|
+
|
|
55
|
+
### Slots
|
|
56
|
+
|
|
57
|
+
| Slot | Description |
|
|
58
|
+
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
59
|
+
| `default`| The default slot is used to pass text into the button component. |
|
|
60
|
+
| `icon` | Used to pass in an icon to the button component. The icon placement can be controlled via the `iconPlacement` prop and we recommend using `pie-icons-webc` for defining this icon, but this can also accept an SVG icon. |
|
|
61
|
+
|
|
62
|
+
### CSS Variables
|
|
63
|
+
This component does not expose any CSS variables for style overrides.
|
|
64
|
+
|
|
65
|
+
### Events
|
|
66
|
+
|
|
67
|
+
This component does not emit any custom events. In order to add event listening to this component, you can treat it like a native HTML element in your application.
|
|
68
|
+
|
|
69
|
+
## Forms Usage
|
|
70
|
+
|
|
71
|
+
The `pie-button` web component is designed to integrate with standard HTML forms just like a native HTML button. When positioned inside a form, the component will automatically associate itself, enabling it to directly interact with the form context.
|
|
72
|
+
|
|
73
|
+
### Button Attributes
|
|
74
|
+
|
|
75
|
+
The `pie-button` provides a set of attributes to customise its behaviour within forms:
|
|
76
|
+
|
|
77
|
+
- `type`: Determines the button's function. Set to `submit` for form submissions or `reset` to clear form fields.
|
|
78
|
+
- `formaction`: Designates an alternative URL for form data submission when this specific button is clicked.
|
|
79
|
+
- `formenctype`: Specifies the form data encoding type during submission via this button.
|
|
80
|
+
- `formmethod`: Sets the HTTP method (e.g., GET or POST) for form data when initiated by this button.
|
|
81
|
+
- `formnovalidate`: If present, ensures the form is submitted without validation checks.
|
|
82
|
+
- `formtarget`: Dictates where to display the response after form submission.
|
|
83
|
+
|
|
84
|
+
### Form Integration Example
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<form action="/default-endpoint" method="post">
|
|
88
|
+
<input type="text" name="username" required>
|
|
89
|
+
<pie-button
|
|
90
|
+
type="submit"
|
|
91
|
+
formaction="/alternate-endpoint"
|
|
92
|
+
formenctype="multipart/form-data"
|
|
93
|
+
formmethod="post"
|
|
94
|
+
formnovalidate
|
|
95
|
+
formtarget="_blank">
|
|
96
|
+
Submit
|
|
97
|
+
</pie-button>
|
|
98
|
+
</form>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
In this example:
|
|
102
|
+
|
|
103
|
+
- The pie-button, when clicked, will send the form data to /alternate-endpoint instead of the form's default /default-endpoint.
|
|
104
|
+
- It uses the multipart/form-data encoding type for form submission.
|
|
105
|
+
- The form will submit using the POST method.
|
|
106
|
+
- No validation will be performed during submission, thanks to formnovalidate.
|
|
107
|
+
- The form's submission response will be opened in a new browser tab/window because of the formtarget="_blank" attribute.
|
|
22
108
|
|
|
23
|
-
|
|
24
|
-
npm i @justeattakeaway/pie-button
|
|
109
|
+
## Usage Examples
|
|
25
110
|
|
|
26
|
-
|
|
111
|
+
**For HTML:**
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
// import as module into a js file e.g. main.js
|
|
115
|
+
import '@justeattakeaway/pie-webc/components/button.js'
|
|
27
116
|
```
|
|
28
117
|
|
|
29
|
-
|
|
118
|
+
```html
|
|
119
|
+
<pie-button type="reset" isFullWidth="true" onclick="e => console.log(e)">
|
|
120
|
+
Click me!
|
|
121
|
+
</pie-button>
|
|
30
122
|
|
|
31
|
-
|
|
123
|
+
<script type="module" src="/main.js"></script>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**For Native JS Applications, Vue, Angular, Svelte etc.:**
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
// Vue templates (using Nuxt 3)
|
|
130
|
+
import '@justeattakeaway/pie-webc/components/button.js';
|
|
131
|
+
|
|
132
|
+
<pie-button @click="handleClick" size="large" type="button" variant="secondary">
|
|
133
|
+
Click me!
|
|
134
|
+
</pie-button>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**For React Applications:**
|
|
138
|
+
|
|
139
|
+
```jsx
|
|
140
|
+
import { PieButton } from '@justeattakeaway/pie-webc/react/button.js';
|
|
141
|
+
|
|
142
|
+
<PieButton onClick={handleClick}>
|
|
143
|
+
increment
|
|
144
|
+
</PieButton>
|
|
145
|
+
```
|
|
32
146
|
|
|
33
|
-
## Questions
|
|
147
|
+
## Questions and Support
|
|
34
148
|
|
|
35
|
-
|
|
149
|
+
If you work at Just Eat Takeaway.com, please contact us on **#help-designsystem**. Otherwise, please raise an issue on [Github](https://github.com/justeattakeaway/pie/issues).
|
|
36
150
|
|
|
37
151
|
## Contributing
|
|
38
152
|
|
package/custom-elements.json
CHANGED
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"kind": "variable",
|
|
49
49
|
"name": "variants",
|
|
50
50
|
"type": {
|
|
51
|
-
"text": "[\n 'primary', 'primary-alternative', 'secondary', 'outline', 'outline-inverse', 'ghost',\n 'inverse', 'ghost-inverse', 'destructive', 'destructive-ghost',\n]"
|
|
51
|
+
"text": "[\r\n 'primary', 'primary-alternative', 'secondary', 'outline', 'outline-inverse', 'ghost',\r\n 'inverse', 'ghost-inverse', 'destructive', 'destructive-ghost',\r\n]"
|
|
52
52
|
},
|
|
53
|
-
"default": "[\n 'primary', 'primary-alternative', 'secondary', 'outline', 'outline-inverse', 'ghost',\n 'inverse', 'ghost-inverse', 'destructive', 'destructive-ghost',\n]"
|
|
53
|
+
"default": "[\r\n 'primary', 'primary-alternative', 'secondary', 'outline', 'outline-inverse', 'ghost',\r\n 'inverse', 'ghost-inverse', 'destructive', 'destructive-ghost',\r\n]"
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
"kind": "variable",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"type": {
|
|
91
91
|
"text": "DefaultProps"
|
|
92
92
|
},
|
|
93
|
-
"default": "{\n tag: 'button',\n size: 'medium',\n type: 'submit',\n variant: 'primary',\n iconPlacement: 'leading',\n disabled: false,\n isLoading: false,\n isFullWidth: false,\n isResponsive: false,\n}"
|
|
93
|
+
"default": "{\r\n tag: 'button',\r\n size: 'medium',\r\n type: 'submit',\r\n variant: 'primary',\r\n iconPlacement: 'leading',\r\n disabled: false,\r\n isLoading: false,\r\n isFullWidth: false,\r\n isResponsive: false,\r\n}"
|
|
94
94
|
}
|
|
95
95
|
],
|
|
96
96
|
"exports": [
|
|
@@ -361,7 +361,7 @@
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
],
|
|
364
|
-
"description": "This method creates an invisible button of the same type as pie-button. It is then clicked, and immediately removed from the DOM.\nThis is done so that we trigger native form actions, such as submit and reset in the browser. The performance impact of adding and removing a single button to the DOM\nshould be neglible, however this should be monitored.\nThis is the only viable way of guaranteeing native button behaviour when using a web component in place of an actual HTML button.\n\nTODO: if we need to repeat this logic elsewhere, then we should consider moving this code to a shared class or mixin."
|
|
364
|
+
"description": "This method creates an invisible button of the same type as pie-button. It is then clicked, and immediately removed from the DOM.\r\nThis is done so that we trigger native form actions, such as submit and reset in the browser. The performance impact of adding and removing a single button to the DOM\r\nshould be neglible, however this should be monitored.\r\nThis is the only viable way of guaranteeing native button behaviour when using a web component in place of an actual HTML button.\r\n\r\nTODO: if we need to repeat this logic elsewhere, then we should consider moving this code to a shared class or mixin."
|
|
365
365
|
},
|
|
366
366
|
{
|
|
367
367
|
"kind": "method",
|