-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathct-button.ts
More file actions
executable file
·232 lines (195 loc) · 7.23 KB
/
ct-button.ts
File metadata and controls
executable file
·232 lines (195 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/**
@license
Copyright (c) 2020 Herberth Obregón. All rights reserved.
This code may only be used under the BSD style license found at
https://open.grupoconectate.com/LICENSE.txt The complete set of authors may be found at
https://open.grupoconectate.com/AUTHORS.txt The complete set of contributors may be
found at https://open.grupoconectate.com/CONTRIBUTORS.txt Code distributed by Herberth Obregón as
part of the Conectate Open Source Project is also subject to an additional IP rights grant
found at https://open.grupoconectate.com/PATENTS.txt
*/
import { LitElement, css, html } from "lit";
import { customElement, property, query } from "lit/decorators.js";
/**
## Example usage
### Standard
<img src="images/standard.png" width="84px" height="48px">
```html
<ct-button value="value1"></ct-button>
<ct-button shadow value="value2"></ct-button>
<ct-button raised value="value3"></ct-button>
<ct-button flat value="value4"></ct-button>
<ct-button light value="value5"></ct-button>
<ct-button disabled value="value5"></ct-button>
<script type="module">
import "./ct-button.js";
</script>
```
## API
### Slots
_None_
### Properties/Attributes
| Name | Type | Default | Description |
| ---------- | --------- | ------- | ----------------------------------- |
| `raised` | `boolean` | `false` | Raised Style (primary color) |
| `shadow` | `boolean` | `false` | Shown with opaque black background. |
| `flat` | `boolean` | `false` | Shown with a primary color border |
| `light` | `boolean` | `false` | Shown with a primary color border |
| `disabled` | `boolean` | `false` | If `true`, Disable clicks |
### Methods
_None_
### Events
| Name | Detail | Description |
| ------- | ------------------ | ------------------------------------------------------------------------------------------------------- |
| `value` | `{value : string}` | Fired when the user modifies the ct-input `value` state from an input device interaction on this radio. |
### CSS Custom Properties
| Custom property | Description | Default |
| -------------------------- | -------------------- | ----------------------------------------- |
| `--color-primary` | Primary color | `#00aeff` |
| `--dark-primary-color` | Dark Primary color | `#00aeff` |
| `--ct-button-box-shadow` | Box-Shadow for hover | `0 2px 16px 4px rgba(99, 188, 240, 0.45)` |
| `--ct-button-shadow-color` | - | `rgba(64, 117, 187, 0.1)` |
| `--ct-button-radius` | - | `26px` |
| `--ct-button-padding` | - | `0.4em 1em` |
* @group ct-elements
* @element ct-button
* @demo demo/index.html
* @homepage open.grupoconectate.com
* @slot prefix - Content placed above the main content
* @slot - Default content placed in the middle
* @slot suffix - Content placed below the main content
* @attr {Boolean} disabled - Disable clicks
* @attr {Boolean} raised - Raised Style (primary color)
* @attr {Boolean} shadow - Shown with opaque black background.
* @attr {Boolean} flat - Shown with a primary color border
* @attr {Boolean} light - Shown with a primary color border
*/
@customElement("ct-button")
export class CtButton extends LitElement {
static styles = [
css`
:host {
display: inline-flex;
align-items: center;
justify-content: center;
/* overflow: hidden; */
position: relative;
font-family: "Google Sans", "Ubuntu", "Roboto", sans-serif;
padding: 0;
background: #00aeff00;
color: var(--color-primary, #00aeff);
outline-color: var(--color-primary, #19ace1);
border: 1px solid rgba(128, 128, 128, 0.31);
border-radius: var(--ct-button-radius, var(--border-radius, 24px));
touch-action: manipulation;
user-select: none;
-webkit-tap-highlight-color: #0000;
transition: all 0.2s ease-in-out;
}
:host([flat]) {
color: inherit;
border: none;
--color-primary-hover: rgba(173, 195, 222, 0.1);
--color-primary-active: rgba(173, 195, 222, 0.2);
--color-on-primary: var(--color-on-background, #535353);
}
:host([raised]) {
background: var(--color-primary, #00aeff);
color: var(--color-on-primary, #fff);
border: none;
}
:host([shadow]) {
background: var(--ct-button-shadow-color, rgba(173, 195, 222, 0.2));
border: none;
}
:host([light]) {
background: transparent;
border: 1px solid var(--color-primary, #00aeff);
}
:host([hidden]) {
display: none !important;
}
:host([disabled]),
:host([disabled]) button {
background: none;
color: var(--color-disable, #a8a8a8);
cursor: not-allowed;
pointer-events: none;
}
:host([gap]) button {
gap: 1ch;
}
:host button {
display: inline-flex;
justify-content: center;
align-items: center;
text-align: center;
padding: var(--ct-button-padding, 0.4em 1em);
width: 100%;
cursor: pointer;
border: none;
white-space: var(--ct-button-white-space, nowrap);
font-family: inherit;
font-size: inherit;
font-weight: 500;
line-height: 1.75;
color: inherit;
outline-color: var(--color-primary, #00aeff);
border-radius: var(--ct-button-radius, 26px);
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: none;
/* transition: background 0.2s ease-in-out; */
outline-offset: 3px;
}
:host(:is([raised]:hover, :focus-visible)) {
background: var(--color-primary-hover, var(--color-primary, #00aeff));
color: var(--color-on-primary, #fff);
}
:host(:hover) {
background: #6b6b6b1a;
}
:host([raised]:active) {
background: var(--color-primary-active, var(--color-primary-hover, var(--color-primary, #00aeff)));
}
:host([raised]:hover) {
box-shadow: var(--ct-button-box-shadow, 0 2px 16px 4px rgba(99, 188, 240, 0.45));
}
`
];
static formAssociated = true;
private readonly internals = this.attachInternals();
@query(".button") private readonly buttonElement!: HTMLElement | null;
@property({ type: Boolean, reflect: true }) raised = false;
@property({ type: Boolean, reflect: true }) shadow = false;
@property({ type: Boolean, reflect: true }) flat = false;
@property({ type: Boolean, reflect: true }) light = false;
@property({ type: String, reflect: true }) role = "button";
@property({ type: String, reflect: true }) type: "button" | "submit" | "reset" = "button";
@property({ type: Boolean, reflect: true }) disabled = false;
@property({ type: Boolean, reflect: true }) gap = false;
render() {
return html` <button ?disabled=${this.disabled} type=${this.type} @click=${this.handleClick}>
<slot name="prefix"></slot>
<slot></slot>
<slot name="suffix"></slot>
</button>`;
}
override focus() {
this.buttonElement?.focus();
}
override blur() {
this.buttonElement?.blur();
}
private handleClick(event: Event) {
if (this.type === "submit") {
this.internals?.form?.requestSubmit();
}
}
}
declare global {
interface HTMLElementTagNameMap {
"ct-button": CtButton;
}
}