blob: 7ac61987cd7a92160932dbc39e0d0f368b83d2de [file] [log] [blame]
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04001/**
2 * @license
Ben Rohlfs94fcbbc2022-05-27 10:45:03 +02003 * Copyright 2016 Google LLC
4 * SPDX-License-Identifier: Apache-2.0
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04005 */
Ben Rohlfs4740bdd2020-08-07 16:13:54 +02006import '../gr-button/gr-button';
Chris Poucet1c713862022-07-25 13:12:24 +02007import '../gr-icon/gr-icon';
Ben Rohlfs4740bdd2020-08-07 16:13:54 +02008import '../gr-limited-text/gr-limited-text';
Ben Rohlfs44f01042023-02-18 13:27:57 +01009import {fire} from '../../../utils/event-util';
Paladox none685819a2021-08-11 00:04:11 +000010import {sharedStyles} from '../../../styles/shared-styles';
Ben Rohlfs0ca140a2021-09-03 10:43:37 +020011import {LitElement, css, html} from 'lit';
Frank Borden42c1a452022-08-11 16:27:20 +020012import {customElement, property} from 'lit/decorators.js';
Kasper Nilsson42b1af42016-11-18 13:49:05 -080013
Ben Rohlfs4740bdd2020-08-07 16:13:54 +020014declare global {
15 interface HTMLElementTagNameMap {
16 'gr-linked-chip': GrLinkedChip;
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010017 }
Ben Rohlfs44f01042023-02-18 13:27:57 +010018 interface HTMLElementEventMap {
19 /** Fired when the 'remove' button was clicked. */
20 // prettier-ignore
21 'remove': CustomEvent<{}>;
22 }
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010023}
24
Ben Rohlfs4740bdd2020-08-07 16:13:54 +020025@customElement('gr-linked-chip')
Ben Rohlfs0ca140a2021-09-03 10:43:37 +020026export class GrLinkedChip extends LitElement {
Ben Rohlfs4740bdd2020-08-07 16:13:54 +020027 @property({type: String})
Paladox none685819a2021-08-11 00:04:11 +000028 href = '';
Ben Rohlfs4740bdd2020-08-07 16:13:54 +020029
Paladox none685819a2021-08-11 00:04:11 +000030 @property({type: Boolean, reflect: true})
Ben Rohlfs4740bdd2020-08-07 16:13:54 +020031 disabled = false;
32
33 @property({type: Boolean})
34 removable = false;
35
36 @property({type: String})
Paladox none685819a2021-08-11 00:04:11 +000037 text = '';
Ben Rohlfs4740bdd2020-08-07 16:13:54 +020038
Ben Rohlfs4740bdd2020-08-07 16:13:54 +020039 /** If provided, sets the maximum length of the content. */
40 @property({type: Number})
41 limit?: number;
42
Gerrit Code Reviewd3f24192021-09-28 10:30:30 +020043 static override get styles() {
Paladox none685819a2021-08-11 00:04:11 +000044 return [
45 sharedStyles,
46 css`
47 :host {
48 display: block;
49 overflow: hidden;
50 }
51 .container {
52 align-items: center;
53 background: var(--chip-background-color);
54 border-radius: 0.75em;
55 display: inline-flex;
56 padding: 0 var(--spacing-m);
57 }
Paladox none685819a2021-08-11 00:04:11 +000058 :host([disabled]) {
59 opacity: 0.6;
60 pointer-events: none;
61 }
62 a {
63 color: var(--linked-chip-text-color);
64 }
Chris Poucet1c713862022-07-25 13:12:24 +020065 gr-icon {
Chris Poucet908d61d2022-07-11 11:19:28 +020066 font-size: 1.2rem;
Paladox none685819a2021-08-11 00:04:11 +000067 }
Paladox nonea0b1e862025-05-26 13:08:09 -070068 gr-button::part(md-text-button),
69 gr-button.remove:hover::part(md-text-button),
70 gr-button.remove:focus::part(md-text-button) {
Milutin Kristofic59ba8682021-08-23 15:13:22 +020071 border-top-width: 0;
72 border-right-width: 0;
73 border-bottom-width: 0;
74 border-left-width: 0;
75 color: var(--deemphasized-text-color);
76 font-weight: var(--font-weight-normal);
77 height: 0.6em;
78 line-height: 10px;
79 margin-left: var(--spacing-xs);
80 padding: 0;
81 text-decoration: none;
Paladox none685819a2021-08-11 00:04:11 +000082 }
Milutin Kristofic7ef311e2022-06-27 11:32:05 +020083 `,
84 ];
85 }
86
87 override render() {
88 return html`<div class="container">
89 <a href=${this.href}>
90 <gr-limited-text
91 .limit=${this.limit}
92 .text=${this.text}
93 ></gr-limited-text>
94 </a>
95 <gr-button
96 id="remove"
97 link=""
98 ?hidden=${!this.removable}
99 class="remove"
100 @click=${this.handleRemoveTap}
101 >
Chris Poucet1c713862022-07-25 13:12:24 +0200102 <gr-icon icon="close"></gr-icon>
Milutin Kristofic7ef311e2022-06-27 11:32:05 +0200103 </gr-button>
104 </div>`;
Paladox none685819a2021-08-11 00:04:11 +0000105 }
106
Milutin Kristofic81ac34c2022-05-24 20:32:17 +0200107 private handleRemoveTap(e: Event) {
Ben Rohlfs4740bdd2020-08-07 16:13:54 +0200108 e.preventDefault();
Ben Rohlfs44f01042023-02-18 13:27:57 +0100109 fire(this, 'remove', {});
Ben Rohlfs4740bdd2020-08-07 16:13:54 +0200110 }
111}