View difference between Paste ID: 1Tute0me and 2nfpYApy
SHOW: | | - or go back to the newest paste.
1
import { __esDecorate, __runInitializers } from '../../node_modules/tslib/tslib.es6.js';
2
import '../../focus/md-focus-ring.js';
3
import '../../ripple/ripple.js';
4
import { isServer, nothing, html as html$1, LitElement } from 'lit';
5
import { property, query, queryAssignedElements } from 'lit/decorators.js';
6
import { classMap } from 'lit/directives/class-map.js';
7
import { literal, html } from 'lit/static-html.js';
8
import { requestUpdateOnAriaChange } from '../../internal/aria/delegate.js';
9
import { internals } from '../../internal/controller/element-internals.js';
10
import { isActivationClick, dispatchActivationClick } from '../../internal/controller/events.js';
11
import { setupFormSubmitter } from '../../internal/controller/form-submitter.js';
12
13
/**
14
 * @license
15
 * Copyright 2019 Google LLC
16
 * SPDX-License-Identifier: Apache-2.0
17
 */
18
/**
19
 * A button component.
20
 */
21
let Button = (() => {
22-
    let _classSuper = LitElement;
22+
23-
    let _instanceExtraInitializers = [];
23+
24-
    let _disabled_decorators;
24+
25-
    let _disabled_initializers = [];
25+
26-
    let _href_decorators;
26+
27-
    let _href_initializers = [];
27+
28-
    let _target_decorators;
28+
29-
    let _target_initializers = [];
29+
30-
    let _trailingIcon_decorators;
30+
31-
    let _trailingIcon_initializers = [];
31+
32-
    let _hasIcon_decorators;
32+
33-
    let _hasIcon_initializers = [];
33+
34-
    let _type_decorators;
34+
35-
    let _type_initializers = [];
35+
36-
    let _value_decorators;
36+
37-
    let _value_initializers = [];
37+
38-
    let _buttonElement_decorators;
38+
39-
    let _buttonElement_initializers = [];
39+
40-
    let _assignedIcons_decorators;
40+
41-
    let _assignedIcons_initializers = [];
41+
42
        set href(value) { this.#href_accessor_storage = value; }
43
        #target_accessor_storage = __runInitializers(this, _target_initializers, '');
44-
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
44+
45-
            __esDecorate(this, null, _disabled_decorators, { kind: "accessor", name: "disabled", static: false, private: false, access: { has: obj => "disabled" in obj, get: obj => obj.disabled, set: (obj, value) => { obj.disabled = value; } }, metadata: _metadata }, _disabled_initializers, _instanceExtraInitializers);
45+
46-
            __esDecorate(this, null, _href_decorators, { kind: "accessor", name: "href", static: false, private: false, access: { has: obj => "href" in obj, get: obj => obj.href, set: (obj, value) => { obj.href = value; } }, metadata: _metadata }, _href_initializers, _instanceExtraInitializers);
46+
47-
            __esDecorate(this, null, _target_decorators, { kind: "accessor", name: "target", static: false, private: false, access: { has: obj => "target" in obj, get: obj => obj.target, set: (obj, value) => { obj.target = value; } }, metadata: _metadata }, _target_initializers, _instanceExtraInitializers);
47+
48-
            __esDecorate(this, null, _trailingIcon_decorators, { kind: "accessor", name: "trailingIcon", static: false, private: false, access: { has: obj => "trailingIcon" in obj, get: obj => obj.trailingIcon, set: (obj, value) => { obj.trailingIcon = value; } }, metadata: _metadata }, _trailingIcon_initializers, _instanceExtraInitializers);
48+
49-
            __esDecorate(this, null, _hasIcon_decorators, { kind: "accessor", name: "hasIcon", static: false, private: false, access: { has: obj => "hasIcon" in obj, get: obj => obj.hasIcon, set: (obj, value) => { obj.hasIcon = value; } }, metadata: _metadata }, _hasIcon_initializers, _instanceExtraInitializers);
49+
50-
            __esDecorate(this, null, _type_decorators, { kind: "accessor", name: "type", static: false, private: false, access: { has: obj => "type" in obj, get: obj => obj.type, set: (obj, value) => { obj.type = value; } }, metadata: _metadata }, _type_initializers, _instanceExtraInitializers);
50+
51-
            __esDecorate(this, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value, set: (obj, value) => { obj.value = value; } }, metadata: _metadata }, _value_initializers, _instanceExtraInitializers);
51+
52-
            __esDecorate(this, null, _buttonElement_decorators, { kind: "accessor", name: "buttonElement", static: false, private: false, access: { has: obj => "buttonElement" in obj, get: obj => obj.buttonElement, set: (obj, value) => { obj.buttonElement = value; } }, metadata: _metadata }, _buttonElement_initializers, _instanceExtraInitializers);
52+
53-
            __esDecorate(this, null, _assignedIcons_decorators, { kind: "accessor", name: "assignedIcons", static: false, private: false, access: { has: obj => "assignedIcons" in obj, get: obj => obj.assignedIcons, set: (obj, value) => { obj.assignedIcons = value; } }, metadata: _metadata }, _assignedIcons_initializers, _instanceExtraInitializers);
53+
54-
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54+
55
         * _Note:_ Link buttons cannot have trailing icons.
56
         */
57
        get trailingIcon() { return this.#trailingIcon_accessor_storage; }
58
        set trailingIcon(value) { this.#trailingIcon_accessor_storage = value; }
59
        #hasIcon_accessor_storage = __runInitializers(this, _hasIcon_initializers, false);
60
        /**
61
         * Whether to display the icon or not.
62
         */
63
        get hasIcon() { return this.#hasIcon_accessor_storage; }
64
        set hasIcon(value) { this.#hasIcon_accessor_storage = value; }
65
        #type_accessor_storage = __runInitializers(this, _type_initializers, 'submit');
66
        get type() { return this.#type_accessor_storage; }
67
        set type(value) { this.#type_accessor_storage = value; }
68
        #value_accessor_storage = __runInitializers(this, _value_initializers, '');
69
        get value() { return this.#value_accessor_storage; }
70
        set value(value) { this.#value_accessor_storage = value; }
71
        get name() {
72
            return this.getAttribute('name') ?? '';
73
        }
74
        set name(name) {
75
            this.setAttribute('name', name);
76
        }
77
        /**
78
         * The associated form element with which this element's value will submit.
79
         */
80
        get form() {
81
            return this[internals].form;
82
        }
83
        #buttonElement_accessor_storage = __runInitializers(this, _buttonElement_initializers, void 0);
84
        get buttonElement() { return this.#buttonElement_accessor_storage; }
85
        set buttonElement(value) { this.#buttonElement_accessor_storage = value; }
86
        #assignedIcons_accessor_storage = __runInitializers(this, _assignedIcons_initializers, void 0);
87
        get assignedIcons() { return this.#assignedIcons_accessor_storage; }
88
        set assignedIcons(value) { this.#assignedIcons_accessor_storage = value; }
89
        /** @private */
90
        [(_disabled_decorators = [property({ type: Boolean, reflect: true })], _href_decorators = [property()], _target_decorators = [property()], _trailingIcon_decorators = [property({ type: Boolean, attribute: 'trailing-icon' })], _hasIcon_decorators = [property({ type: Boolean, attribute: 'has-icon' })], _type_decorators = [property()], _value_decorators = [property()], _buttonElement_decorators = [query('.button')], _assignedIcons_decorators = [queryAssignedElements({ slot: 'icon', flatten: true })], internals)] = this /* needed for closure */.attachInternals();
91
        constructor() {
92
            super();
93
            if (!isServer) {
94
                this.addEventListener('click', this.handleActivationClick);
95
            }
96
        }
97
        focus() {
98
            this.buttonElement?.focus();
99
        }
100
        blur() {
101
            this.buttonElement?.blur();
102
        }
103
        render() {
104
            // Link buttons may not be disabled
105
            const isDisabled = this.disabled && !this.href;
106
            const button = this.href ? literal `a` : literal `button`;
107
            // Needed for closure conformance
108
            const { ariaLabel, ariaHasPopup, ariaExpanded } = this;
109
            return html `
110
      <${button}
111
        class="button ${classMap(this.getRenderClasses())}"
112
        ?disabled=${isDisabled}
113
        aria-label="${ariaLabel || nothing}"
114
        aria-haspopup="${ariaHasPopup || nothing}"
115
        aria-expanded="${ariaExpanded || nothing}"
116
        href=${this.href || nothing}
117
        target=${this.target || nothing}
118
      >${this.renderContent()}</${button}>`;
119
        }
120
        getRenderClasses() {
121
            return {
122
                'button--icon-leading': !this.trailingIcon && this.hasIcon,
123
                'button--icon-trailing': this.trailingIcon && this.hasIcon,
124
            };
125
        }
126
        renderContent() {
127
            // Link buttons may not be disabled
128
            const isDisabled = this.disabled && !this.href;
129
            const icon = html$1 `<slot name="icon" @slotchange="${this.handleSlotChange}"></slot>`;
130
            return html$1 `
131
      ${this.renderElevation?.()}
132
      ${this.renderOutline?.()}
133
      <md-focus-ring part="focus-ring"></md-focus-ring>
134
      <md-ripple class="button__ripple" ?disabled="${isDisabled}"></md-ripple>
135
      <span class="touch"></span>
136
      ${this.trailingIcon ? nothing : icon}
137
      <span class="button__label"><slot></slot></span>
138
      ${this.trailingIcon ? icon : nothing}
139
    `;
140
        }
141
        handleActivationClick = (event) => {
142
            if (!isActivationClick((event)) || !this.buttonElement) {
143
                return;
144
            }
145
            this.focus();
146
            dispatchActivationClick(this.buttonElement);
147
        };
148
        handleSlotChange() {
149
            this.hasIcon = this.assignedIcons.length > 0;
150
        }
151
    };
152
})();
153
154
export { Button };