@api-client/ui 0.3.3 → 0.3.5
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/build/src/md/button/internals/base.d.ts.map +1 -1
- package/build/src/md/button/internals/base.js +2 -6
- package/build/src/md/button/internals/base.js.map +1 -1
- package/build/src/md/button/internals/button.styles.js +1 -1
- package/build/src/md/button/internals/button.styles.js.map +1 -1
- package/build/src/md/chip/internals/Chip.d.ts +11 -15
- package/build/src/md/chip/internals/Chip.d.ts.map +1 -1
- package/build/src/md/chip/internals/Chip.js +66 -104
- package/build/src/md/chip/internals/Chip.js.map +1 -1
- package/build/src/md/chip/internals/Chip.styles.d.ts.map +1 -1
- package/build/src/md/chip/internals/Chip.styles.js +114 -101
- package/build/src/md/chip/internals/Chip.styles.js.map +1 -1
- package/build/src/md/chip/internals/ChipSet.d.ts +16 -0
- package/build/src/md/chip/internals/ChipSet.d.ts.map +1 -0
- package/build/src/md/chip/internals/ChipSet.js +138 -0
- package/build/src/md/chip/internals/ChipSet.js.map +1 -0
- package/build/src/md/chip/internals/ChipSet.styles.d.ts +3 -0
- package/build/src/md/chip/internals/ChipSet.styles.d.ts.map +1 -0
- package/build/src/md/chip/internals/ChipSet.styles.js +9 -0
- package/build/src/md/chip/internals/ChipSet.styles.js.map +1 -0
- package/build/src/md/chip/ui-chip-set.d.ts +11 -0
- package/build/src/md/chip/ui-chip-set.d.ts.map +1 -0
- package/build/src/md/chip/ui-chip-set.js +27 -0
- package/build/src/md/chip/ui-chip-set.js.map +1 -0
- package/build/src/md/dialog/internals/Dialog.styles.d.ts.map +1 -1
- package/build/src/md/dialog/internals/Dialog.styles.js +5 -11
- package/build/src/md/dialog/internals/Dialog.styles.js.map +1 -1
- package/build/src/md/switch/internals/Switch.styles.js +1 -1
- package/build/src/md/switch/internals/Switch.styles.js.map +1 -1
- package/build/src/md/text-field/internals/outlined.styles.js +2 -2
- package/build/src/md/text-field/internals/outlined.styles.js.map +1 -1
- package/demo/md/chip/chip.html +33 -6
- package/demo/md/chip/chip.ts +111 -56
- package/package.json +2 -2
- package/src/md/button/internals/base.ts +2 -6
- package/src/md/button/internals/button.styles.ts +1 -1
- package/src/md/chip/internals/Chip.styles.ts +114 -101
- package/src/md/chip/internals/Chip.ts +58 -88
- package/src/md/chip/internals/ChipSet.styles.ts +9 -0
- package/src/md/chip/internals/ChipSet.ts +142 -0
- package/src/md/chip/ui-chip-set.ts +15 -0
- package/src/md/dialog/internals/Dialog.styles.ts +5 -11
- package/src/md/switch/internals/Switch.styles.ts +1 -1
- package/src/md/text-field/internals/outlined.styles.ts +2 -2
- package/test/ui/chip/UiChip.test.ts +18 -67
- package/build/src/events/BroadcastUiEvents.d.ts +0 -18
- package/build/src/events/BroadcastUiEvents.d.ts.map +0 -1
- package/build/src/events/BroadcastUiEvents.js +0 -2
- package/build/src/events/BroadcastUiEvents.js.map +0 -1
- package/src/events/BroadcastUiEvents.ts +0 -19
|
@@ -6,166 +6,179 @@ export default css`
|
|
|
6
6
|
vertical-align: middle;
|
|
7
7
|
outline: none;
|
|
8
8
|
-webkit-tap-highlight-color: transparent;
|
|
9
|
-
|
|
9
|
+
position: relative;
|
|
10
|
+
user-select: none;
|
|
10
11
|
|
|
11
12
|
font-family: var(--md-sys-typescale-label-large-font);
|
|
12
13
|
font-size: var(--md-sys-typescale-label-large-size);
|
|
13
14
|
letter-spacing: var(--md-sys-typescale-label-large-tracking);
|
|
14
15
|
line-height: var(--md-sys-typescale-label-large-height);
|
|
15
16
|
|
|
16
|
-
border-radius: var(--md-sys-shape-corner-small);
|
|
17
|
-
color: var(--md-sys-color-on-surface);
|
|
18
|
-
fill: var(--md-sys-color-primary);
|
|
19
|
-
|
|
20
|
-
user-select: none;
|
|
21
|
-
|
|
22
17
|
--md-ripple-hover-state-layer-color: var(--md-sys-color-on-surface);
|
|
23
18
|
--md-ripple-focus-state-layer-color: var(--md-sys-color-on-surface);
|
|
24
19
|
--md-ripple-pressed-state-layer-color: var(--md-sys-color-primary);
|
|
25
|
-
}
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
--_leading-icon-color: currentColor;
|
|
22
|
+
--_trailing-icon-color: currentColor;
|
|
23
|
+
--_background-color: transparent;
|
|
24
|
+
--_color: inherit;
|
|
25
|
+
--_shadow: var(--md-sys-elevation-0);
|
|
26
|
+
--_outline-color: transparent;
|
|
27
|
+
--_outline-size: 0;
|
|
28
|
+
--_inline-padding-start: 16px;
|
|
29
|
+
--_inline-padding-end: 16px;
|
|
30
|
+
--_avatar-size: 24px;
|
|
31
|
+
--_avatar-shape: 24px;
|
|
32
|
+
--_icon-size: 18px;
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
:host([disabled]) .content {
|
|
43
|
-
color: var(--md-sys-color-on-surface);
|
|
44
|
-
opacity: 0.68;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.surface {
|
|
48
|
-
position: relative;
|
|
49
|
-
height: inherit;
|
|
50
|
-
border-radius: inherit;
|
|
34
|
+
height: 32px;
|
|
35
|
+
border-radius: var(--md-sys-shape-corner-small);
|
|
36
|
+
box-shadow: var(--_shadow);
|
|
37
|
+
border: var(--_outline-size) solid var(--_outline-color);
|
|
51
38
|
}
|
|
52
39
|
|
|
53
40
|
.ripple {
|
|
54
|
-
z-index: 0;
|
|
55
41
|
border-radius: inherit;
|
|
42
|
+
transition: border-radius var(--md-sys-motion-duration-medium1) var(--md-sys-motion-easing-standard);
|
|
56
43
|
}
|
|
57
44
|
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
.ripple.activated {
|
|
46
|
+
z-index: 1;
|
|
47
|
+
}
|
|
61
48
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
:host([disabled]) {
|
|
50
|
+
--_background-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
|
|
51
|
+
--_color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
|
|
52
|
+
--_leading-icon-color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
|
|
53
|
+
--_trailing-icon-color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
|
|
54
|
+
--_outline-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
|
|
55
|
+
box-shadow: none;
|
|
56
|
+
cursor: not-allowed;
|
|
57
|
+
pointer-events: none;
|
|
66
58
|
}
|
|
67
59
|
|
|
68
|
-
.
|
|
60
|
+
.surface {
|
|
69
61
|
height: inherit;
|
|
70
62
|
display: flex;
|
|
71
63
|
align-items: center;
|
|
72
64
|
justify-content: start;
|
|
73
65
|
box-sizing: border-box;
|
|
74
|
-
padding: 0
|
|
66
|
+
padding: 0 var(--_inline-padding-end) 0 var(--_inline-padding-start);
|
|
75
67
|
border-radius: inherit;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
background-color: var(--_background-color);
|
|
69
|
+
color: var(--_color);
|
|
70
|
+
gap: 0;
|
|
79
71
|
}
|
|
80
72
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
.leading-icon {
|
|
74
|
+
height: var(--_icon-size);
|
|
75
|
+
width: 0px;
|
|
76
|
+
overflow: hidden;
|
|
77
|
+
transition: width 230ms var(--md-sys-animation-easing-standard);
|
|
78
|
+
color: var(--_leading-icon-color);
|
|
79
|
+
fill: currentColor;
|
|
85
80
|
}
|
|
86
81
|
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
.leading-icon::slotted(*) {
|
|
83
|
+
width: var(--_icon-size);
|
|
84
|
+
height: var(--_icon-size);
|
|
85
|
+
margin-right: 8px;
|
|
90
86
|
}
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
slot[name='avatar']::slotted(*) {
|
|
89
|
+
width: var(--_avatar-size);
|
|
90
|
+
height: var(--_avatar-size);
|
|
91
|
+
border-radius: var(--_avatar-shape);
|
|
92
|
+
flex-shrink: 0;
|
|
93
|
+
flex-grow: 0;
|
|
94
|
+
margin-right: 8px;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
.check-mark.checked {
|
|
98
|
+
width: 18px;
|
|
99
|
+
margin-right: 8px;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
.
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
.trailing-icon {
|
|
103
|
+
margin-left: 8px;
|
|
104
|
+
width: 18px;
|
|
105
|
+
height: 18px;
|
|
106
|
+
color: var(--_trailing-icon-color);
|
|
107
|
+
fill: currentColor;
|
|
104
108
|
}
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
:host([elevated]) {
|
|
111
|
+
--_shadow: var(--md-sys-elevation-1);
|
|
112
|
+
border: none;
|
|
113
|
+
--_background-color: var(--md-sys-color-surface-container-low);
|
|
109
114
|
}
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
height: 24px;
|
|
114
|
-
border-radius: var(--md-sys-shape-corner-medium);
|
|
116
|
+
:host([elevated]:hover:not([disabled])) {
|
|
117
|
+
--_shadow: var(--md-sys-elevation-2);
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
width: 0px;
|
|
120
|
-
overflow: hidden;
|
|
121
|
-
transition: width 230ms var(--md-sys-animation-easing-standard);
|
|
120
|
+
.surface.has-trailing-icon {
|
|
121
|
+
--_inline-padding-end: 8px;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
:host([type='assist']:not([disabled])) {
|
|
125
|
+
--_outline-color: var(--md-sys-color-outline-variant);
|
|
126
|
+
--_outline-size: 1px;
|
|
127
|
+
--_color: var(--md-sys-color-on-surface);
|
|
128
|
+
--_leading-icon-color: var(--md-sys-color-primary);
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
:host .has-icon {
|
|
132
|
+
--_inline-padding-start: 8px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
:host .has-avatar {
|
|
136
|
+
--_inline-padding-start: 4px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
:host([checked]) {
|
|
140
|
+
--_inline-padding-start: 8px;
|
|
141
|
+
--_background-color: var(--md-sys-color-secondary-container);
|
|
134
142
|
}
|
|
135
143
|
|
|
136
|
-
:host([
|
|
137
|
-
|
|
138
|
-
|
|
144
|
+
:host([type='filter']:not([disabled])) {
|
|
145
|
+
--_leading-icon-color: var(--md-sys-color-primary);
|
|
146
|
+
--_trailing-icon-color: var(--md-sys-on-surface-variant);
|
|
147
|
+
--_outline-color: var(--md-sys-color-outline-variant);
|
|
148
|
+
--_outline-size: 1px;
|
|
149
|
+
--_color: var(--md-sys-color-on-surface-variant);
|
|
139
150
|
}
|
|
140
151
|
|
|
141
|
-
:host([
|
|
142
|
-
|
|
152
|
+
:host([type='filter'][checked]) {
|
|
153
|
+
--_outline-size: 1px;
|
|
143
154
|
}
|
|
144
155
|
|
|
145
|
-
:host([checked])
|
|
146
|
-
|
|
147
|
-
|
|
156
|
+
:host([type='filter'][checked]:not([disabled])) {
|
|
157
|
+
--_leading-icon-color: var(--md-sys-color-on-secondary-container);
|
|
158
|
+
--_trailing-icon-color: var(--md-sys-on-secondary-container);
|
|
159
|
+
--_outline-color: var(--md-sys-color-secondary-container);
|
|
160
|
+
--_color: var(--md-sys-color-on-secondary-container);
|
|
148
161
|
}
|
|
149
162
|
|
|
150
|
-
:host([type='
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
:host([type='input']:not([disabled])) {
|
|
164
|
+
--_outline-color: var(--md-sys-color-outline-variant);
|
|
165
|
+
--_outline-size: 1px;
|
|
166
|
+
--_leading-icon-color: var(--md-sys-color-primary);
|
|
167
|
+
--_trailing-icon-color: var(--md-sys-color-on-surface-variant);
|
|
168
|
+
--_color: var(--md-sys-color-on-surface-variant);
|
|
154
169
|
}
|
|
155
170
|
|
|
156
|
-
:host([type='
|
|
157
|
-
|
|
158
|
-
color: var(--md-sys-color-on-secondary-container);
|
|
171
|
+
:host([type='input'][checked]) {
|
|
172
|
+
--_outline-size: 0px;
|
|
159
173
|
}
|
|
160
174
|
|
|
161
|
-
:host([type='
|
|
162
|
-
|
|
163
|
-
color: var(--md-sys-color-
|
|
175
|
+
:host([type='suggestion']) {
|
|
176
|
+
--_outline-size: 1px;
|
|
177
|
+
--_outline-color: var(--md-sys-color-outline-variant);
|
|
178
|
+
--_color: var(--md-sys-color-on-surface-variant);
|
|
164
179
|
}
|
|
165
180
|
|
|
166
|
-
:host([type='
|
|
167
|
-
|
|
168
|
-
color: var(--md-sys-color-on-surface-variant);
|
|
169
|
-
fill: var(--md-sys-color-on-surface-variant);
|
|
181
|
+
:host([type='suggestion']:not([disabled])) {
|
|
182
|
+
--_leading-icon-color: var(--md-sys-color-primary);
|
|
170
183
|
}
|
|
171
184
|
`
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { cancelEvent } from '@api-client/core/lib/events/Utils.js'
|
|
2
2
|
import { html, nothing, PropertyValues, TemplateResult } from 'lit'
|
|
3
|
-
import { property,
|
|
3
|
+
import { property, query, state } from 'lit/decorators.js'
|
|
4
4
|
import { classMap } from 'lit/directives/class-map.js'
|
|
5
|
-
import { when } from 'lit/directives/when.js'
|
|
6
5
|
import { UiElement } from '../../UiElement.js'
|
|
7
6
|
import UiRipple from '../../ripple/internals/ripple.js'
|
|
8
|
-
import { ripple } from '../../effects/rippleDirective.js'
|
|
9
7
|
import { close, arrowDropDown, check } from '../../icons/Icons.js'
|
|
10
8
|
import { setDisabled } from '../../../lib/disabled.js'
|
|
11
9
|
import { BeginPressConfig, EndPressConfig } from '../../../controllers/ActionController.js'
|
|
@@ -22,9 +20,9 @@ export enum ChipType {
|
|
|
22
20
|
* @slot The content of the chip.
|
|
23
21
|
* @slot icon - The leading icon, sized 18x18 px
|
|
24
22
|
* @slot avatar - The leading image, sized 24x24 px
|
|
25
|
-
* @fires list - When the user requested to activate the list associated with the element.
|
|
26
23
|
* @fires select - When the checked state changed through a user interaction. This only related to
|
|
27
24
|
* `filter` chips. Note, `select` is dispatched just before the `click` event.
|
|
25
|
+
* @fires remove - When the user clicks the "remove" icon on the chip.
|
|
28
26
|
*/
|
|
29
27
|
export default class UiChip extends UiElement {
|
|
30
28
|
/**
|
|
@@ -51,7 +49,7 @@ export default class UiChip extends UiElement {
|
|
|
51
49
|
* Whether the chip renders the "close" icon at the end.
|
|
52
50
|
* @attribute
|
|
53
51
|
*/
|
|
54
|
-
@property({ type: Boolean, reflect: true }) accessor
|
|
52
|
+
@property({ type: Boolean, reflect: true }) accessor removable: boolean | undefined
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
55
|
* Whether the chip is currently checked.
|
|
@@ -61,17 +59,14 @@ export default class UiChip extends UiElement {
|
|
|
61
59
|
@property({ type: Boolean, reflect: true }) accessor checked: boolean | undefined
|
|
62
60
|
|
|
63
61
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* attributes informing the assistive technology that this chip controls a list.
|
|
62
|
+
* When set, the chip will render a trailing icon that indicates that the chip is associated
|
|
63
|
+
* with a list. It does not do anything.
|
|
67
64
|
*
|
|
68
65
|
* @attribute
|
|
69
66
|
*/
|
|
70
|
-
@property({ type:
|
|
67
|
+
@property({ type: Boolean, reflect: true }) accessor list: boolean | undefined
|
|
71
68
|
|
|
72
|
-
@
|
|
73
|
-
|
|
74
|
-
@state() protected accessor showRipple = false
|
|
69
|
+
@query('ui-ripple') protected accessor ripple!: UiRipple | null
|
|
75
70
|
|
|
76
71
|
/**
|
|
77
72
|
* Determines when the element has an icon in the "icon" slot.
|
|
@@ -93,13 +88,14 @@ export default class UiChip extends UiElement {
|
|
|
93
88
|
|
|
94
89
|
this.actionController.cancelKeyboardEvents = true
|
|
95
90
|
|
|
96
|
-
this.addEventListener('click', this.handleClick.bind(this))
|
|
97
91
|
this.addEventListener('keydown', this.handleKeyDown.bind(this))
|
|
98
92
|
this.addEventListener('keyup', this.handleKeyUp.bind(this))
|
|
93
|
+
this.addEventListener('click', this.handleClick.bind(this))
|
|
99
94
|
this.addEventListener('pointerdown', this.handlePointerDown.bind(this))
|
|
100
95
|
this.addEventListener('pointerup', this.handlePointerUp.bind(this))
|
|
101
96
|
this.addEventListener('pointercancel', this.handlePointerCancel.bind(this))
|
|
102
97
|
this.addEventListener('pointerleave', this.handlePointerLeave.bind(this))
|
|
98
|
+
this.addEventListener('pointerenter', this.handlePointerEnter.bind(this))
|
|
103
99
|
this.addEventListener('contextmenu', this.handleContextMenu.bind(this))
|
|
104
100
|
this.addEventListener('focus', this.handleFocus.bind(this))
|
|
105
101
|
this.addEventListener('blur', this.handleBlur.bind(this))
|
|
@@ -121,52 +117,32 @@ export default class UiChip extends UiElement {
|
|
|
121
117
|
}
|
|
122
118
|
}
|
|
123
119
|
|
|
124
|
-
protected async pressRipple(): Promise<void> {
|
|
125
|
-
const element = await this.getRipple()
|
|
126
|
-
if (element && !element.isPressed) {
|
|
127
|
-
element.beginPress()
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
protected async endRipple(): Promise<void> {
|
|
132
|
-
const element = await this.getRipple()
|
|
133
|
-
element?.endPress()
|
|
134
|
-
}
|
|
135
|
-
|
|
136
120
|
override beginPress(options: BeginPressConfig): void {
|
|
137
121
|
super.beginPress(options)
|
|
138
|
-
this.
|
|
122
|
+
this.classList.add('pressed')
|
|
123
|
+
this.ripple?.beginPress(options.positionEvent)
|
|
139
124
|
}
|
|
140
125
|
|
|
141
126
|
override async handleKeyDown(e: KeyboardEvent): Promise<void> {
|
|
142
127
|
super.handleKeyDown(e)
|
|
143
|
-
if (this.
|
|
128
|
+
if (this.removable && e.code === 'Backspace') {
|
|
144
129
|
e.preventDefault()
|
|
145
|
-
this.
|
|
146
|
-
} else if (this.closable && e.code === 'Backspace') {
|
|
147
|
-
e.preventDefault()
|
|
148
|
-
this.closeAction()
|
|
130
|
+
this.removeAction()
|
|
149
131
|
}
|
|
150
132
|
}
|
|
151
133
|
|
|
152
134
|
protected async handleFocus(): Promise<void> {
|
|
153
|
-
|
|
154
|
-
element?.beginFocus()
|
|
135
|
+
this.ripple?.beginFocus()
|
|
155
136
|
}
|
|
156
137
|
|
|
157
138
|
protected async handleBlur(): Promise<void> {
|
|
158
|
-
|
|
159
|
-
element?.endFocus()
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
protected readonly getRipple = (): Promise<UiRipple | null> => {
|
|
163
|
-
this.showRipple = true
|
|
164
|
-
return this.ripple
|
|
139
|
+
this.ripple?.endFocus()
|
|
165
140
|
}
|
|
166
141
|
|
|
167
142
|
override endPress(info: EndPressConfig): void {
|
|
168
143
|
super.endPress(info)
|
|
169
|
-
this.
|
|
144
|
+
this.classList.remove('pressed')
|
|
145
|
+
this.ripple?.endPress()
|
|
170
146
|
const { cancelled, reason } = info
|
|
171
147
|
if (cancelled) {
|
|
172
148
|
return
|
|
@@ -183,6 +159,16 @@ export default class UiChip extends UiElement {
|
|
|
183
159
|
}
|
|
184
160
|
}
|
|
185
161
|
|
|
162
|
+
override handlePointerEnter(e: PointerEvent): void {
|
|
163
|
+
super.handlePointerEnter(e)
|
|
164
|
+
this.ripple?.beginHover(e)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
override handlePointerLeave(e: PointerEvent): void {
|
|
168
|
+
super.handlePointerLeave(e)
|
|
169
|
+
this.ripple?.endHover()
|
|
170
|
+
}
|
|
171
|
+
|
|
186
172
|
/**
|
|
187
173
|
* Toggles the "filter" type of the chip.
|
|
188
174
|
*/
|
|
@@ -207,47 +193,37 @@ export default class UiChip extends UiElement {
|
|
|
207
193
|
this.hasAvatar = !!slot.assignedNodes().length
|
|
208
194
|
}
|
|
209
195
|
|
|
210
|
-
protected handleListClick(e: Event): void {
|
|
211
|
-
e.preventDefault()
|
|
212
|
-
e.stopPropagation()
|
|
213
|
-
this.listAction()
|
|
214
|
-
}
|
|
215
|
-
|
|
216
196
|
protected handleClose(e: Event): void {
|
|
217
197
|
e.preventDefault()
|
|
218
198
|
e.stopPropagation()
|
|
219
|
-
this.
|
|
199
|
+
this.removeAction()
|
|
220
200
|
}
|
|
221
201
|
|
|
222
|
-
protected async
|
|
223
|
-
this.dispatchEvent(new Event('
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
protected async listAction(): Promise<void> {
|
|
227
|
-
this.dispatchEvent(new Event('list'))
|
|
202
|
+
protected async removeAction(): Promise<void> {
|
|
203
|
+
this.dispatchEvent(new Event('remove'))
|
|
228
204
|
}
|
|
229
205
|
|
|
230
206
|
protected override render(): TemplateResult {
|
|
231
|
-
const { pressed = false } = this
|
|
232
207
|
const containerClasses = classMap({
|
|
233
|
-
surface: true,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
208
|
+
'surface': true,
|
|
209
|
+
'has-icon': this.hasIcon,
|
|
210
|
+
'has-avatar': this.hasAvatar,
|
|
211
|
+
'has-trailing-icon': this.hasTrailingIcon,
|
|
237
212
|
})
|
|
238
213
|
return html`
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
${
|
|
242
|
-
<
|
|
243
|
-
|
|
244
|
-
<slot></slot>
|
|
245
|
-
${this.renderTrailingIcon()}
|
|
246
|
-
</div>
|
|
214
|
+
${this.renderRipple()}
|
|
215
|
+
<div class="${containerClasses}">
|
|
216
|
+
${this.renderLeadingIcon()} ${this.renderAvatar()}
|
|
217
|
+
<slot></slot>
|
|
218
|
+
${this.renderTrailingIcon()}
|
|
247
219
|
</div>
|
|
248
220
|
`
|
|
249
221
|
}
|
|
250
222
|
|
|
223
|
+
protected renderRipple(): TemplateResult {
|
|
224
|
+
return html`<ui-ripple class="ripple" ?disabled="${this.disabled}"></ui-ripple>`
|
|
225
|
+
}
|
|
226
|
+
|
|
251
227
|
protected renderLeadingIcon(): TemplateResult | typeof nothing {
|
|
252
228
|
const { type } = this
|
|
253
229
|
if (type === ChipType.suggestion) {
|
|
@@ -261,31 +237,19 @@ export default class UiChip extends UiElement {
|
|
|
261
237
|
})
|
|
262
238
|
return html`<span class="${iconClasses}" role="presentation">${check}</span>`
|
|
263
239
|
}
|
|
264
|
-
return html`<slot name="icon" @slotchange="${this.handleIconSlotChange}"></slot>`
|
|
240
|
+
return html`<slot class="leading-icon" name="icon" @slotchange="${this.handleIconSlotChange}"></slot>`
|
|
265
241
|
}
|
|
266
242
|
|
|
267
243
|
protected renderAvatar(): TemplateResult | typeof nothing {
|
|
268
|
-
|
|
269
|
-
if (type === ChipType.input) {
|
|
270
|
-
return html`<slot name="avatar" @slotchange="${this.handleAvatarSlotChange}"></slot>`
|
|
271
|
-
}
|
|
272
|
-
return nothing
|
|
244
|
+
return html`<slot name="avatar" @slotchange="${this.handleAvatarSlotChange}"></slot>`
|
|
273
245
|
}
|
|
274
246
|
|
|
275
247
|
protected renderTrailingIcon(): TemplateResult | typeof nothing {
|
|
276
|
-
const {
|
|
277
|
-
if (type === ChipType.filter) {
|
|
278
|
-
|
|
279
|
-
return html`<span
|
|
280
|
-
class="trailing-icon"
|
|
281
|
-
role="presentation"
|
|
282
|
-
@click="${this.handleListClick}"
|
|
283
|
-
@keypress="${cancelEvent}"
|
|
284
|
-
>${arrowDropDown}</span
|
|
285
|
-
>`
|
|
286
|
-
}
|
|
248
|
+
const { removable = false, list, type } = this
|
|
249
|
+
if (type === ChipType.filter && list) {
|
|
250
|
+
return html`<span class="trailing-icon" role="presentation">${arrowDropDown}</span>`
|
|
287
251
|
}
|
|
288
|
-
if (type === ChipType.input &&
|
|
252
|
+
if (type === ChipType.input && removable) {
|
|
289
253
|
return html`<span
|
|
290
254
|
class="trailing-icon"
|
|
291
255
|
@click="${this.handleClose}"
|
|
@@ -298,8 +262,14 @@ export default class UiChip extends UiElement {
|
|
|
298
262
|
return nothing
|
|
299
263
|
}
|
|
300
264
|
|
|
301
|
-
|
|
302
|
-
const {
|
|
303
|
-
|
|
265
|
+
get hasTrailingIcon(): boolean {
|
|
266
|
+
const { removable = false, list, type } = this
|
|
267
|
+
if (type === ChipType.filter && list) {
|
|
268
|
+
return true
|
|
269
|
+
}
|
|
270
|
+
if (type === ChipType.input && removable) {
|
|
271
|
+
return true
|
|
272
|
+
}
|
|
273
|
+
return false
|
|
304
274
|
}
|
|
305
275
|
}
|