|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { html, nothing } from "lit"; |
| 17 | +import { html, nothing, css } from "lit"; |
18 | 18 | import { customElement } from "lit/decorators.js"; |
19 | 19 | import { classMap } from "lit/directives/class-map.js"; |
20 | 20 | import { ButtonApi } from "@a2ui/web_core/v0_9/basic_catalog"; |
21 | 21 | import { A2uiLitElement, A2uiController } from "@a2ui/lit/v0_9"; |
| 22 | +import { injectDefaultA2uiTheme } from "@a2ui/web_core/v0_9"; |
22 | 23 |
|
| 24 | +/** |
| 25 | + * A button component that can be used to trigger an action. |
| 26 | + */ |
23 | 27 | @customElement("a2ui-basic-button") |
24 | 28 | export class A2uiBasicButtonElement extends A2uiLitElement<typeof ButtonApi> { |
| 29 | + /** |
| 30 | + * The styles of the button can be customized by redefining the following |
| 31 | + * CSS variables: |
| 32 | + * |
| 33 | + * - Primary variant: |
| 34 | + * - `--a2ui-color-primary`: The color for the primary variant. |
| 35 | + * - `--a2ui-color-on-primary`: The color of the text on the primary variant. |
| 36 | + * - Standard/default variant: |
| 37 | + * - `--a2ui-color-secondary`: The color for the default variant. |
| 38 | + * - `--a2ui-color-on-secondary`: The color of the text on the default variant. |
| 39 | + * - `--a2ui-button-border`: The styling for the button border. Defaults to `--a2ui-border-width` width and `--a2ui-color-border` color. |
| 40 | + * - `--a2ui-button-border-radius`: The border radius of the button. Defaults to `--a2ui-border-radius`. |
| 41 | + * - `--a2ui-button-padding`: The padding of the button. Defaults to `--a2ui-spacing-m`. |
| 42 | + */ |
| 43 | + static styles = css` |
| 44 | + :where(:host) { |
| 45 | + --_color-primary: var(--a2ui-color-primary, #17e); |
| 46 | + --_button-border-radius: var( |
| 47 | + --a2ui-button-border-radius, |
| 48 | + var(--a2ui-spacing-s, 0.25rem) |
| 49 | + ); |
| 50 | + --_button-padding: var( |
| 51 | + --a2ui-button-padding, |
| 52 | + var(--a2ui-spacing-m, 0.5rem) var(--a2ui-spacing-l, 1rem) |
| 53 | + ); |
| 54 | + --_button-border: var( |
| 55 | + --a2ui-button-border, |
| 56 | + var(--a2ui-border-width, 1px) solid var(--a2ui-color-border, #ccc) |
| 57 | + ); |
| 58 | + } |
| 59 | + .a2ui-button { |
| 60 | + --_a2ui-text-margin: 0; |
| 61 | + padding: var(--_button-padding); |
| 62 | + background-color: var(--a2ui-color-secondary, #ddd); |
| 63 | + color: var(--a2ui-color-on-secondary, #333); |
| 64 | + border: var(--_button-border); |
| 65 | + border-radius: var(--_button-border-radius); |
| 66 | + cursor: pointer; |
| 67 | + display: inline-flex; |
| 68 | + align-items: center; |
| 69 | + justify-content: center; |
| 70 | + } |
| 71 | + .a2ui-button.a2ui-button-primary { |
| 72 | + border-color: var(--_color-primary); |
| 73 | + background-color: var(--_color-primary); |
| 74 | + color: var(--a2ui-color-on-primary, #fff); |
| 75 | + } |
| 76 | + .a2ui-button:hover { |
| 77 | + background-color: var(--a2ui-color-secondary-hover, #ddd); |
| 78 | + } |
| 79 | + .a2ui-button.a2ui-button-primary:hover { |
| 80 | + background-color: var(--a2ui-color-primary-hover, #fbd); |
| 81 | + } |
| 82 | + .a2ui-button.a2ui-button-borderless { |
| 83 | + background: none; |
| 84 | + padding: 0; |
| 85 | + color: var(--_color-primary); |
| 86 | + } |
| 87 | + `; |
| 88 | + |
25 | 89 | protected createController() { |
26 | 90 | return new A2uiController(this, ButtonApi); |
27 | 91 | } |
28 | 92 |
|
| 93 | + connectedCallback() { |
| 94 | + super.connectedCallback(); |
| 95 | + injectDefaultA2uiTheme(); |
| 96 | + } |
| 97 | + |
29 | 98 | render() { |
30 | 99 | const props = this.controller.props; |
31 | 100 | if (!props) return nothing; |
|
0 commit comments