@momentum-design/components 0.28.8 → 0.28.10
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/dist/browser/index.js +1032 -926
- package/dist/browser/index.js.map +4 -4
- package/dist/components/checkbox/checkbox.component.js +2 -0
- package/dist/components/input/input.component.d.ts +1 -0
- package/dist/components/input/input.component.js +3 -1
- package/dist/components/list/index.d.ts +8 -0
- package/dist/components/list/index.js +5 -0
- package/dist/components/list/list.component.d.ts +64 -0
- package/dist/components/list/list.component.js +138 -0
- package/dist/components/list/list.constants.d.ts +9 -0
- package/dist/components/list/list.constants.js +10 -0
- package/dist/components/list/list.styles.d.ts +2 -0
- package/dist/components/list/list.styles.js +7 -0
- package/dist/components/listitem/index.d.ts +8 -0
- package/dist/components/listitem/index.js +5 -0
- package/dist/components/listitem/listitem.component.d.ts +90 -0
- package/dist/components/listitem/listitem.component.js +153 -0
- package/dist/components/listitem/listitem.constants.d.ts +10 -0
- package/dist/components/listitem/listitem.constants.js +11 -0
- package/dist/components/listitem/listitem.styles.d.ts +2 -0
- package/dist/components/listitem/listitem.styles.js +70 -0
- package/dist/components/listitem/listitem.types.d.ts +4 -0
- package/dist/components/listitem/listitem.types.js +1 -0
- package/dist/components/radio/radio.component.js +2 -0
- package/dist/components/toggle/toggle.component.js +2 -0
- package/dist/custom-elements.json +700 -166
- package/dist/index.d.ts +19 -17
- package/dist/index.js +18 -16
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +2 -0
- package/dist/react/list/index.d.ts +12 -0
- package/dist/react/list/index.js +21 -0
- package/dist/react/listitem/index.d.ts +34 -0
- package/dist/react/listitem/index.js +43 -0
- package/dist/utils/mixins/FormInternalsMixin.js +0 -2
- package/package.json +1 -1
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
10
10
|
import { html, nothing } from 'lit';
|
11
11
|
import { property } from 'lit/decorators.js';
|
12
12
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
13
|
+
import { v4 as uuidv4 } from 'uuid';
|
13
14
|
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
14
15
|
import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
|
15
16
|
import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
|
@@ -78,6 +79,7 @@ class Checkbox extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
|
|
78
79
|
};
|
79
80
|
// Checkbox does not contain helpTextType property.
|
80
81
|
this.helpTextType = undefined;
|
82
|
+
this.id = `mdc-input-${uuidv4()}`;
|
81
83
|
}
|
82
84
|
/**
|
83
85
|
* Updates the form value to reflect the current state of the checkbox.
|
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
10
10
|
import { html, nothing } from 'lit';
|
11
11
|
import { property } from 'lit/decorators.js';
|
12
12
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
13
|
+
import { v4 as uuidv4 } from 'uuid';
|
13
14
|
import styles from './input.styles';
|
14
15
|
import FormfieldWrapper from '../formfieldwrapper';
|
15
16
|
import { AUTO_CAPITALIZE, DEFAULTS, PREFIX_TEXT_OPTIONS } from './input.constants';
|
@@ -59,7 +60,7 @@ import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
|
|
59
60
|
*/
|
60
61
|
class Input extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
|
61
62
|
constructor() {
|
62
|
-
super(
|
63
|
+
super();
|
63
64
|
/**
|
64
65
|
* The placeholder text that is displayed when the input field is empty.
|
65
66
|
*/
|
@@ -93,6 +94,7 @@ class Input extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
|
|
93
94
|
* @default ''
|
94
95
|
*/
|
95
96
|
this.clearAriaLabel = '';
|
97
|
+
this.id = `mdc-input-${uuidv4()}`;
|
96
98
|
}
|
97
99
|
connectedCallback() {
|
98
100
|
super.connectedCallback();
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import type { CSSResult } from 'lit';
|
2
|
+
import { Component } from '../../models';
|
3
|
+
declare const List_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof Component;
|
4
|
+
/**
|
5
|
+
* mdc-list component is used to display a group of list items. It is used as a container to wrap other list items.
|
6
|
+
*
|
7
|
+
* @tagname mdc-list
|
8
|
+
*
|
9
|
+
* @dependency mdc-text
|
10
|
+
*
|
11
|
+
* @slot default - This is a default/unnamed slot
|
12
|
+
*/
|
13
|
+
declare class List extends List_base {
|
14
|
+
listItems: Array<HTMLElement>;
|
15
|
+
/**
|
16
|
+
* The header text of the list.
|
17
|
+
*/
|
18
|
+
headerText?: string;
|
19
|
+
constructor();
|
20
|
+
/**
|
21
|
+
* Handles the keydown event on the list element.
|
22
|
+
* If the key is 'ArrowUp' or 'ArrowDown', it focuses to the previous or next list item
|
23
|
+
* and sets the active tabindex of the list item.
|
24
|
+
* Prevents the default event behavior.
|
25
|
+
* @param event - The keyboard event.
|
26
|
+
*/
|
27
|
+
private handleKeyDown;
|
28
|
+
/**
|
29
|
+
* Returns the index of the given target in the listItems array.
|
30
|
+
* If the target is not a list item, but a child element of a list item,
|
31
|
+
* it returns the index of the parent list item.
|
32
|
+
* @param target - The target element to find the index of.
|
33
|
+
* @returns The index of the target element in the listItems array.
|
34
|
+
*/
|
35
|
+
private getCurrentIndex;
|
36
|
+
/**
|
37
|
+
* Calculates a new index based on the pressed keyboard key.
|
38
|
+
* Supports navigation keys for moving focus within a list.
|
39
|
+
* @param key - The key that was pressed.
|
40
|
+
* @param currentIndex - The current index of the focused list item.
|
41
|
+
* @param wrappedDivsCount - The total number of list items.
|
42
|
+
* @returns The new index to focus on, or undefined if the key is not supported.
|
43
|
+
*/
|
44
|
+
private getNewIndexBasedOnKey;
|
45
|
+
/**
|
46
|
+
* Handles the mouse click event on the list element.
|
47
|
+
* Finds the index of the target element in the list items array and calls
|
48
|
+
* `resetTabIndexAndSetActiveTabIndex` with that index.
|
49
|
+
* @param event - The mouse event.
|
50
|
+
*/
|
51
|
+
private handleMouseClick;
|
52
|
+
/**
|
53
|
+
* Resets all list items tabindex to -1 and sets the tabindex of the
|
54
|
+
* element at the given index to 0, effectively setting the active
|
55
|
+
* element. This is used when navigating the list via keyboard.
|
56
|
+
*
|
57
|
+
* @param newIndex - The index of the new active element in the list.
|
58
|
+
*/
|
59
|
+
private resetTabIndexAndSetActiveTabIndex;
|
60
|
+
firstUpdated(): void;
|
61
|
+
render(): import("lit-html").TemplateResult<1>;
|
62
|
+
static styles: Array<CSSResult>;
|
63
|
+
}
|
64
|
+
export default List;
|
@@ -0,0 +1,138 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html, nothing } from 'lit';
|
11
|
+
import { property, queryAssignedElements } from 'lit/decorators.js';
|
12
|
+
import { Component } from '../../models';
|
13
|
+
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
14
|
+
import { TAG_NAME as LISTITEM_TAGNAME } from '../listitem/listitem.constants';
|
15
|
+
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
16
|
+
import { HEADER_ID, KEYS } from './list.constants';
|
17
|
+
import styles from './list.styles';
|
18
|
+
/**
|
19
|
+
* mdc-list component is used to display a group of list items. It is used as a container to wrap other list items.
|
20
|
+
*
|
21
|
+
* @tagname mdc-list
|
22
|
+
*
|
23
|
+
* @dependency mdc-text
|
24
|
+
*
|
25
|
+
* @slot default - This is a default/unnamed slot
|
26
|
+
*/
|
27
|
+
class List extends DataAriaLabelMixin(Component) {
|
28
|
+
constructor() {
|
29
|
+
super();
|
30
|
+
this.addEventListener('keydown', this.handleKeyDown);
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Handles the keydown event on the list element.
|
34
|
+
* If the key is 'ArrowUp' or 'ArrowDown', it focuses to the previous or next list item
|
35
|
+
* and sets the active tabindex of the list item.
|
36
|
+
* Prevents the default event behavior.
|
37
|
+
* @param event - The keyboard event.
|
38
|
+
*/
|
39
|
+
handleKeyDown(event) {
|
40
|
+
var _a;
|
41
|
+
const currentIndex = this.getCurrentIndex(event.target);
|
42
|
+
const newIndex = this.getNewIndexBasedOnKey(event.key, currentIndex, this.listItems.length);
|
43
|
+
if (newIndex !== undefined) {
|
44
|
+
(_a = this.listItems[newIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
45
|
+
this.resetTabIndexAndSetActiveTabIndex(newIndex);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Returns the index of the given target in the listItems array.
|
50
|
+
* If the target is not a list item, but a child element of a list item,
|
51
|
+
* it returns the index of the parent list item.
|
52
|
+
* @param target - The target element to find the index of.
|
53
|
+
* @returns The index of the target element in the listItems array.
|
54
|
+
*/
|
55
|
+
getCurrentIndex(target) {
|
56
|
+
return this.listItems.findIndex((node) => node === target || node === target.parentElement);
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* Calculates a new index based on the pressed keyboard key.
|
60
|
+
* Supports navigation keys for moving focus within a list.
|
61
|
+
* @param key - The key that was pressed.
|
62
|
+
* @param currentIndex - The current index of the focused list item.
|
63
|
+
* @param wrappedDivsCount - The total number of list items.
|
64
|
+
* @returns The new index to focus on, or undefined if the key is not supported.
|
65
|
+
*/
|
66
|
+
getNewIndexBasedOnKey(key, currentIndex, wrappedDivsCount) {
|
67
|
+
switch (key) {
|
68
|
+
case KEYS.ARROW_DOWN:
|
69
|
+
return (currentIndex + 1) % wrappedDivsCount;
|
70
|
+
case KEYS.ARROW_UP:
|
71
|
+
return (currentIndex - 1 + wrappedDivsCount) % wrappedDivsCount;
|
72
|
+
case KEYS.HOME:
|
73
|
+
return 0;
|
74
|
+
case KEYS.END:
|
75
|
+
return wrappedDivsCount - 1;
|
76
|
+
default:
|
77
|
+
return undefined;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
/**
|
81
|
+
* Handles the mouse click event on the list element.
|
82
|
+
* Finds the index of the target element in the list items array and calls
|
83
|
+
* `resetTabIndexAndSetActiveTabIndex` with that index.
|
84
|
+
* @param event - The mouse event.
|
85
|
+
*/
|
86
|
+
handleMouseClick(event) {
|
87
|
+
const newIndex = this.getCurrentIndex(event.target);
|
88
|
+
this.resetTabIndexAndSetActiveTabIndex(newIndex);
|
89
|
+
}
|
90
|
+
/**
|
91
|
+
* Resets all list items tabindex to -1 and sets the tabindex of the
|
92
|
+
* element at the given index to 0, effectively setting the active
|
93
|
+
* element. This is used when navigating the list via keyboard.
|
94
|
+
*
|
95
|
+
* @param newIndex - The index of the new active element in the list.
|
96
|
+
*/
|
97
|
+
resetTabIndexAndSetActiveTabIndex(newIndex) {
|
98
|
+
this.listItems.forEach((node, index) => {
|
99
|
+
const newTabindex = newIndex === index ? '0' : '-1';
|
100
|
+
node === null || node === void 0 ? void 0 : node.setAttribute('tabindex', newTabindex);
|
101
|
+
});
|
102
|
+
}
|
103
|
+
firstUpdated() {
|
104
|
+
// For the first, we set the first element only as active.
|
105
|
+
this.resetTabIndexAndSetActiveTabIndex(0);
|
106
|
+
}
|
107
|
+
render() {
|
108
|
+
var _a;
|
109
|
+
const headerText = this.headerText ? html `
|
110
|
+
<mdc-text
|
111
|
+
id="${HEADER_ID}"
|
112
|
+
part="header-text"
|
113
|
+
type="${TYPE.BODY_MIDSIZE_BOLD}"
|
114
|
+
tagname="${VALID_TEXT_TAGS.SPAN}"
|
115
|
+
>${this.headerText}</mdc-text>
|
116
|
+
` : nothing;
|
117
|
+
return html `
|
118
|
+
<div
|
119
|
+
role="list"
|
120
|
+
aria-labelledby="${this.headerText ? HEADER_ID : ''}"
|
121
|
+
aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
|
122
|
+
>
|
123
|
+
${headerText}
|
124
|
+
<slot role="presentation" @click="${this.handleMouseClick}"></slot>
|
125
|
+
</div>
|
126
|
+
`;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
List.styles = [...Component.styles, ...styles];
|
130
|
+
__decorate([
|
131
|
+
queryAssignedElements({ selector: LISTITEM_TAGNAME }),
|
132
|
+
__metadata("design:type", Array)
|
133
|
+
], List.prototype, "listItems", void 0);
|
134
|
+
__decorate([
|
135
|
+
property({ type: String, attribute: 'header-text', reflect: true }),
|
136
|
+
__metadata("design:type", String)
|
137
|
+
], List.prototype, "headerText", void 0);
|
138
|
+
export default List;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import utils from '../../utils/tag-name';
|
2
|
+
const TAG_NAME = utils.constructTagName('list');
|
3
|
+
const KEYS = {
|
4
|
+
ARROW_DOWN: 'ArrowDown',
|
5
|
+
ARROW_UP: 'ArrowUp',
|
6
|
+
HOME: 'Home',
|
7
|
+
END: 'End',
|
8
|
+
};
|
9
|
+
const HEADER_ID = 'header-id';
|
10
|
+
export { TAG_NAME, KEYS, HEADER_ID };
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import type { CSSResult, PropertyValues } from 'lit';
|
2
|
+
import { TemplateResult } from 'lit';
|
3
|
+
import { Component } from '../../models';
|
4
|
+
import type { ListItemVariants } from './listitem.types';
|
5
|
+
declare const ListItem_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DisabledMixin").DisabledMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/TabIndexMixin").TabIndexMixinInterface> & typeof Component;
|
6
|
+
/**
|
7
|
+
* mdc-listitem component is used to display a label with different types of controls.
|
8
|
+
* There can be three types of controls, a radio button, a checkbox on the
|
9
|
+
* leading side and a toggle on the trailing side.
|
10
|
+
* The list item can contain an avatar on the leading side and a badge on the trailing side.
|
11
|
+
* Additionally, the list item can contain a side header and a subline text.
|
12
|
+
*
|
13
|
+
* The leading and trailing slots can be used to display controls and text. <br/>
|
14
|
+
* Based on the leading/trailing slot, the position of the controls and text can be adjusted. <br/>
|
15
|
+
* Please use mdc-list as a parent element even when there is only listitem for a11y purpose.
|
16
|
+
*
|
17
|
+
* @tagname mdc-listitem
|
18
|
+
*
|
19
|
+
* @dependency mdc-text
|
20
|
+
*
|
21
|
+
* @slot leading-controls - slot for list item controls to appear of leading end.
|
22
|
+
* @slot leading-text-primary-label - slot for list item primary label.
|
23
|
+
* @slot leading-text-secondary-label - slot for list item secondary label.
|
24
|
+
* @slot leading-text-tertiary-label - slot for list item tertiary label.
|
25
|
+
* @slot trailing-text-side-header - slot for list item side header text.
|
26
|
+
* @slot trailing-text-subline - slot for list item subline text.
|
27
|
+
* @slot trailing-controls - slot for list item controls to appear of trailing end.
|
28
|
+
*
|
29
|
+
* @cssproperty --mdc-listitem-default-background-color - Allows customization of the default background color.
|
30
|
+
* @cssproperty --mdc-listitem-background-color-hover - Allows customization of the background color on hover.
|
31
|
+
* @cssproperty --mdc-listitem-background-color-active - Allows customization of the background color when pressed.
|
32
|
+
* @cssproperty --mdc-listitem-primary-label-color
|
33
|
+
* - Allows customization of the primary label, side header and subline text slot color.
|
34
|
+
* @cssproperty --mdc-listitem-secondary-label-color
|
35
|
+
* - Allows customization of the secondary and teritary label text slot color.
|
36
|
+
*/
|
37
|
+
declare class ListItem extends ListItem_base {
|
38
|
+
leadingControlsSlot: Array<HTMLElement>;
|
39
|
+
trailingControlsSlot: Array<HTMLElement>;
|
40
|
+
/**
|
41
|
+
* The variant of the list item. It can be a pill, rectangle or a full-width.
|
42
|
+
* @default 'full-width'
|
43
|
+
*/
|
44
|
+
variant: ListItemVariants;
|
45
|
+
/**
|
46
|
+
* The primary label of the list item.
|
47
|
+
* This appears on the leading side of the list item.
|
48
|
+
*/
|
49
|
+
label?: string;
|
50
|
+
/**
|
51
|
+
* The secondary label of the list item.
|
52
|
+
* This appears on the leading side of the list item.
|
53
|
+
*/
|
54
|
+
secondaryLabel?: string;
|
55
|
+
/**
|
56
|
+
* The tertiary label of the list item.
|
57
|
+
* This appears on the leading side of the list item.
|
58
|
+
*/
|
59
|
+
tertiaryLabel?: string;
|
60
|
+
/**
|
61
|
+
* The header text of the list item.
|
62
|
+
* This appears on the trailing side of the list item.
|
63
|
+
*/
|
64
|
+
sideHeaderText?: string;
|
65
|
+
/**
|
66
|
+
* The subline text of the list item.
|
67
|
+
* This appears on the trailing side of the list item.
|
68
|
+
*/
|
69
|
+
sublineText?: string;
|
70
|
+
constructor();
|
71
|
+
/**
|
72
|
+
* Generates a template for a text slot with the specified content.
|
73
|
+
*
|
74
|
+
* @param slotName - The name of the slot to be used.
|
75
|
+
* @param type - The type of the text element.
|
76
|
+
* @param content - The text content to be displayed within the slot.
|
77
|
+
* @returns A TemplateResult containing a slot with an `mdc-text` element of type BODY_SMALL_REGULAR.
|
78
|
+
*/
|
79
|
+
private getText;
|
80
|
+
/**
|
81
|
+
* Disable or enable all slotted elements in the leading and trailing slots.
|
82
|
+
* This is useful when the list item is disabled, to prevent the user from interacting with the controls.
|
83
|
+
* @param disabled - Whether to disable or enable the controls.
|
84
|
+
*/
|
85
|
+
private disableSlottedChildren;
|
86
|
+
update(changedProperties: PropertyValues): void;
|
87
|
+
render(): TemplateResult<1>;
|
88
|
+
static styles: Array<CSSResult>;
|
89
|
+
}
|
90
|
+
export default ListItem;
|
@@ -0,0 +1,153 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html, nothing } from 'lit';
|
11
|
+
import { property, queryAssignedElements } from 'lit/decorators.js';
|
12
|
+
import { Component } from '../../models';
|
13
|
+
import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
|
14
|
+
import { DisabledMixin } from '../../utils/mixins/DisabledMixin';
|
15
|
+
import { TabIndexMixin } from '../../utils/mixins/TabIndexMixin';
|
16
|
+
import { TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
|
17
|
+
import { DEFAULTS } from './listitem.constants';
|
18
|
+
import styles from './listitem.styles';
|
19
|
+
/**
|
20
|
+
* mdc-listitem component is used to display a label with different types of controls.
|
21
|
+
* There can be three types of controls, a radio button, a checkbox on the
|
22
|
+
* leading side and a toggle on the trailing side.
|
23
|
+
* The list item can contain an avatar on the leading side and a badge on the trailing side.
|
24
|
+
* Additionally, the list item can contain a side header and a subline text.
|
25
|
+
*
|
26
|
+
* The leading and trailing slots can be used to display controls and text. <br/>
|
27
|
+
* Based on the leading/trailing slot, the position of the controls and text can be adjusted. <br/>
|
28
|
+
* Please use mdc-list as a parent element even when there is only listitem for a11y purpose.
|
29
|
+
*
|
30
|
+
* @tagname mdc-listitem
|
31
|
+
*
|
32
|
+
* @dependency mdc-text
|
33
|
+
*
|
34
|
+
* @slot leading-controls - slot for list item controls to appear of leading end.
|
35
|
+
* @slot leading-text-primary-label - slot for list item primary label.
|
36
|
+
* @slot leading-text-secondary-label - slot for list item secondary label.
|
37
|
+
* @slot leading-text-tertiary-label - slot for list item tertiary label.
|
38
|
+
* @slot trailing-text-side-header - slot for list item side header text.
|
39
|
+
* @slot trailing-text-subline - slot for list item subline text.
|
40
|
+
* @slot trailing-controls - slot for list item controls to appear of trailing end.
|
41
|
+
*
|
42
|
+
* @cssproperty --mdc-listitem-default-background-color - Allows customization of the default background color.
|
43
|
+
* @cssproperty --mdc-listitem-background-color-hover - Allows customization of the background color on hover.
|
44
|
+
* @cssproperty --mdc-listitem-background-color-active - Allows customization of the background color when pressed.
|
45
|
+
* @cssproperty --mdc-listitem-primary-label-color
|
46
|
+
* - Allows customization of the primary label, side header and subline text slot color.
|
47
|
+
* @cssproperty --mdc-listitem-secondary-label-color
|
48
|
+
* - Allows customization of the secondary and teritary label text slot color.
|
49
|
+
*/
|
50
|
+
class ListItem extends DataAriaLabelMixin(DisabledMixin(TabIndexMixin(Component))) {
|
51
|
+
constructor() {
|
52
|
+
super();
|
53
|
+
/**
|
54
|
+
* The variant of the list item. It can be a pill, rectangle or a full-width.
|
55
|
+
* @default 'full-width'
|
56
|
+
*/
|
57
|
+
this.variant = DEFAULTS.VARIANT;
|
58
|
+
this.role = 'listitem';
|
59
|
+
}
|
60
|
+
/**
|
61
|
+
* Generates a template for a text slot with the specified content.
|
62
|
+
*
|
63
|
+
* @param slotName - The name of the slot to be used.
|
64
|
+
* @param type - The type of the text element.
|
65
|
+
* @param content - The text content to be displayed within the slot.
|
66
|
+
* @returns A TemplateResult containing a slot with an `mdc-text` element of type BODY_SMALL_REGULAR.
|
67
|
+
*/
|
68
|
+
getText(slotName, type, content) {
|
69
|
+
if (!content) {
|
70
|
+
return nothing;
|
71
|
+
}
|
72
|
+
return html `
|
73
|
+
<slot name="${slotName}">
|
74
|
+
<mdc-text part="${slotName}" type="${type}" tagname="${VALID_TEXT_TAGS.SPAN}">${content}</mdc-text>
|
75
|
+
</slot>
|
76
|
+
`;
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* Disable or enable all slotted elements in the leading and trailing slots.
|
80
|
+
* This is useful when the list item is disabled, to prevent the user from interacting with the controls.
|
81
|
+
* @param disabled - Whether to disable or enable the controls.
|
82
|
+
*/
|
83
|
+
disableSlottedChildren(disabled) {
|
84
|
+
[...this.leadingControlsSlot, ...this.trailingControlsSlot].forEach((element) => {
|
85
|
+
if (disabled) {
|
86
|
+
element.setAttribute('disabled', '');
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
element.removeAttribute('disabled');
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
update(changedProperties) {
|
94
|
+
super.update(changedProperties);
|
95
|
+
if (changedProperties.has('disabled')) {
|
96
|
+
this.tabIndex = this.disabled ? -1 : 0;
|
97
|
+
this.disableSlottedChildren(this.disabled);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
render() {
|
101
|
+
return html `
|
102
|
+
<div part="leading">
|
103
|
+
<slot name="leading-controls"></slot>
|
104
|
+
<div part="leading-text">
|
105
|
+
${this.getText('leading-text-primary-label', TYPE.BODY_MIDSIZE_REGULAR, this.label)}
|
106
|
+
${this.getText('leading-text-secondary-label', TYPE.BODY_SMALL_REGULAR, this.secondaryLabel)}
|
107
|
+
${this.getText('leading-text-tertiary-label', TYPE.BODY_SMALL_REGULAR, this.tertiaryLabel)}
|
108
|
+
</div>
|
109
|
+
</div>
|
110
|
+
<div part="trailing">
|
111
|
+
<div part="trailing-text">
|
112
|
+
${this.getText('trailing-text-side-header', TYPE.BODY_MIDSIZE_REGULAR, this.sideHeaderText)}
|
113
|
+
${this.getText('trailing-text-subline', TYPE.BODY_SMALL_REGULAR, this.sublineText)}
|
114
|
+
</div>
|
115
|
+
<slot name="trailing-controls"></slot>
|
116
|
+
</div>
|
117
|
+
`;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
ListItem.styles = [...Component.styles, ...styles];
|
121
|
+
__decorate([
|
122
|
+
queryAssignedElements({ slot: 'leading-controls' }),
|
123
|
+
__metadata("design:type", Array)
|
124
|
+
], ListItem.prototype, "leadingControlsSlot", void 0);
|
125
|
+
__decorate([
|
126
|
+
queryAssignedElements({ slot: 'trailing-controls' }),
|
127
|
+
__metadata("design:type", Array)
|
128
|
+
], ListItem.prototype, "trailingControlsSlot", void 0);
|
129
|
+
__decorate([
|
130
|
+
property({ type: String, reflect: true }),
|
131
|
+
__metadata("design:type", String)
|
132
|
+
], ListItem.prototype, "variant", void 0);
|
133
|
+
__decorate([
|
134
|
+
property({ type: String, reflect: true }),
|
135
|
+
__metadata("design:type", String)
|
136
|
+
], ListItem.prototype, "label", void 0);
|
137
|
+
__decorate([
|
138
|
+
property({ type: String, reflect: true, attribute: 'secondary-label' }),
|
139
|
+
__metadata("design:type", String)
|
140
|
+
], ListItem.prototype, "secondaryLabel", void 0);
|
141
|
+
__decorate([
|
142
|
+
property({ type: String, reflect: true, attribute: 'tertiary-label' }),
|
143
|
+
__metadata("design:type", String)
|
144
|
+
], ListItem.prototype, "tertiaryLabel", void 0);
|
145
|
+
__decorate([
|
146
|
+
property({ type: String, reflect: true, attribute: 'side-header-text' }),
|
147
|
+
__metadata("design:type", String)
|
148
|
+
], ListItem.prototype, "sideHeaderText", void 0);
|
149
|
+
__decorate([
|
150
|
+
property({ type: String, reflect: true, attribute: 'subline-text' }),
|
151
|
+
__metadata("design:type", String)
|
152
|
+
], ListItem.prototype, "sublineText", void 0);
|
153
|
+
export default ListItem;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
declare const TAG_NAME: "mdc-listitem";
|
2
|
+
declare const LISTITEM_VARIANTS: {
|
3
|
+
readonly FULL_WIDTH: "full-width";
|
4
|
+
readonly INSET_PILL: "inset-pill";
|
5
|
+
readonly INSET_RECTANGLE: "inset-rectangle";
|
6
|
+
};
|
7
|
+
declare const DEFAULTS: {
|
8
|
+
readonly VARIANT: "full-width";
|
9
|
+
};
|
10
|
+
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS };
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import utils from '../../utils/tag-name';
|
2
|
+
const TAG_NAME = utils.constructTagName('listitem');
|
3
|
+
const LISTITEM_VARIANTS = {
|
4
|
+
FULL_WIDTH: 'full-width',
|
5
|
+
INSET_PILL: 'inset-pill',
|
6
|
+
INSET_RECTANGLE: 'inset-rectangle',
|
7
|
+
};
|
8
|
+
const DEFAULTS = {
|
9
|
+
VARIANT: LISTITEM_VARIANTS.FULL_WIDTH,
|
10
|
+
};
|
11
|
+
export { DEFAULTS, TAG_NAME, LISTITEM_VARIANTS };
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { css } from 'lit';
|
2
|
+
import { hostFocusRingStyles } from '../../utils/styles';
|
3
|
+
const styles = css `
|
4
|
+
:host {
|
5
|
+
--mdc-listitem-default-background-color: var(--mds-color-theme-background-primary-ghost);
|
6
|
+
--mdc-listitem-background-color-hover: var(--mds-color-theme-background-primary-hover);
|
7
|
+
--mdc-listitem-background-color-active: var(--mds-color-theme-background-primary-active);
|
8
|
+
--mdc-listitem-primary-label-color: var(--mds-color-theme-text-primary-normal);
|
9
|
+
--mdc-listitem-secondary-label-color: var(--mds-color-theme-text-secondary-normal);
|
10
|
+
--mdc-listitem-disabled-color: var(--mds-color-theme-text-primary-disabled);
|
11
|
+
}
|
12
|
+
:host {
|
13
|
+
background-color: var(--mdc-listitem-default-background-color);
|
14
|
+
column-gap: 0.75rem;
|
15
|
+
cursor: pointer;
|
16
|
+
display: flex;
|
17
|
+
flex-direction: row;
|
18
|
+
padding: 0.5rem 0.75rem;
|
19
|
+
width: 100%;
|
20
|
+
}
|
21
|
+
:host([variant="inset-rectangle"]) {
|
22
|
+
border-radius: 0.5rem;
|
23
|
+
}
|
24
|
+
:host([variant="inset-pill"]) {
|
25
|
+
border-radius: 3.125rem;
|
26
|
+
}
|
27
|
+
:host([disabled]),
|
28
|
+
:host([disabled])::part(leading-text-secondary-label),
|
29
|
+
:host([disabled])::part(leading-text-tertiary-label),
|
30
|
+
:host([disabled])::part(leading-text-primary-label),
|
31
|
+
:host([disabled])::part(trailing-text-side-header),
|
32
|
+
:host([disabled])::part(trailing-text-subline) {
|
33
|
+
color: var(--mdc-listitem-disabled-color);
|
34
|
+
cursor: default;
|
35
|
+
}
|
36
|
+
:host(:hover) {
|
37
|
+
background-color: var(--mdc-listitem-background-color-hover);
|
38
|
+
}
|
39
|
+
:host(:active) {
|
40
|
+
background-color: var(--mdc-listitem-background-color-active);
|
41
|
+
}
|
42
|
+
:host::part(trailing) {
|
43
|
+
margin-left: auto;
|
44
|
+
}
|
45
|
+
:host::part(trailing):dir(rtl) {
|
46
|
+
margin-left: unset;
|
47
|
+
margin-right: auto;
|
48
|
+
}
|
49
|
+
:host::part(leading), :host::part(trailing) {
|
50
|
+
align-items: center;
|
51
|
+
column-gap: 0.75rem;
|
52
|
+
display: flex;
|
53
|
+
}
|
54
|
+
:host::part(leading-text-secondary-label), :host::part(leading-text-tertiary-label) {
|
55
|
+
color: var(--mdc-listitem-secondary-label-color);
|
56
|
+
}
|
57
|
+
:host::part(leading-text-primary-label), :host::part(trailing-text-side-header), :host::part(trailing-text-subline) {
|
58
|
+
color: var(--mdc-listitem-primary-label-color);
|
59
|
+
}
|
60
|
+
:host::part(trailing-text) {
|
61
|
+
text-align: right;
|
62
|
+
}
|
63
|
+
::slotted([slot="leading-controls"]), ::slotted([slot="trailing-controls"]) {
|
64
|
+
align-items: center;
|
65
|
+
column-gap: 0.75rem;
|
66
|
+
display: flex;
|
67
|
+
flex-direction: row;
|
68
|
+
}
|
69
|
+
`;
|
70
|
+
export default [styles, ...hostFocusRingStyles()];
|