@fluid-topics/ftds-chip-group 2.1.0
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/README.md +19 -0
- package/build/FtdsChipGroupMessages.d.ts +8 -0
- package/build/FtdsChipGroupMessages.js +9 -0
- package/build/define.d.ts +1 -0
- package/build/define.js +3 -0
- package/build/definitions.d.ts +5 -0
- package/build/definitions.js +4 -0
- package/build/ftds-chip-group.d.ts +27 -0
- package/build/ftds-chip-group.js +163 -0
- package/build/ftds-chip-group.light.js +2012 -0
- package/build/ftds-chip-group.min.js +2128 -0
- package/build/ftds-chip-group.properties.d.ts +17 -0
- package/build/ftds-chip-group.properties.js +6 -0
- package/build/ftds-chip-group.styles.d.ts +1 -0
- package/build/ftds-chip-group.styles.js +52 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
A chip component.
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-chip-group
|
|
7
|
+
yarn add @fluid-topics/ft-chip-group
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { html } from "lit"
|
|
14
|
+
import "@fluid-topics/ft-chip-group"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html` <ftds-chip-group></ftds-chip-group> `
|
|
18
|
+
}
|
|
19
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
|
|
2
|
+
export interface FtdsChipGroupMessages extends I18nMessages {
|
|
3
|
+
defaultRemoveLabel(): string;
|
|
4
|
+
showMoreChipAriaLabel(count: number): string;
|
|
5
|
+
showMorePopoverTitle(count: number): string;
|
|
6
|
+
}
|
|
7
|
+
export declare const chipGroupContext: I18nMessageContext<FtdsChipGroupMessages>;
|
|
8
|
+
export declare const defaultChipGroupMessages: DefaultI18nMessages<FtdsChipGroupMessages>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { I18nMessageContext, } from "@fluid-topics/ft-i18n";
|
|
2
|
+
export const chipGroupContext = I18nMessageContext.build("ftdsChipGroup");
|
|
3
|
+
export const defaultChipGroupMessages = {
|
|
4
|
+
"defaultRemoveLabel": "Remove",
|
|
5
|
+
"showMoreChipAriaLabel": "{0} more",
|
|
6
|
+
"showMoreChipAriaLabel[\\=1]": "1 more",
|
|
7
|
+
"showMorePopoverTitle[\\=1]": "1 more value",
|
|
8
|
+
"showMorePopoverTitle": "{0} more values",
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/define.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PropertyValues, TemplateResult } from "lit";
|
|
2
|
+
import { ElementDefinitionsMap, FtdsBase } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { ChipElement, FtdsChipGroupProperties } from "./ftds-chip-group.properties";
|
|
4
|
+
import { FtdsChip } from "@fluid-topics/ftds-chip";
|
|
5
|
+
declare const FtdsChipGroup_base: typeof FtdsBase & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
|
|
6
|
+
export declare class FtdsChipGroup extends FtdsChipGroup_base implements FtdsChipGroupProperties {
|
|
7
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
8
|
+
static styles: import("lit").CSSResult[];
|
|
9
|
+
removable: boolean;
|
|
10
|
+
maxNumberOfChips?: number;
|
|
11
|
+
popoverTitle: string;
|
|
12
|
+
chips: ChipElement[];
|
|
13
|
+
isPopoverOpened: boolean;
|
|
14
|
+
allChips?: NodeListOf<FtdsChip>;
|
|
15
|
+
private lastRemovedChipIndex?;
|
|
16
|
+
constructor();
|
|
17
|
+
protected updated(changedProperties: PropertyValues): void;
|
|
18
|
+
protected render(): TemplateResult<1>;
|
|
19
|
+
private renderExtraChipsPopover;
|
|
20
|
+
protected renderChip(chip: ChipElement): TemplateResult;
|
|
21
|
+
private onChipRemoved;
|
|
22
|
+
private handleFocusOnChipDeleted;
|
|
23
|
+
private focusChip;
|
|
24
|
+
private toggleExtraChips;
|
|
25
|
+
private getFamilyIcon;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
import { html, } from "lit";
|
|
8
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
9
|
+
import { property, queryAll, state, } from "lit/decorators.js";
|
|
10
|
+
import { DesignSystemFamily, FtdsBase, jsonProperty, numberProperty, } from "@fluid-topics/ft-wc-utils";
|
|
11
|
+
import { designSystemStyle } from "./ftds-chip-group.styles";
|
|
12
|
+
import { RemoveChipEvent, } from "./ftds-chip-group.properties";
|
|
13
|
+
import { FtdsChip } from "@fluid-topics/ftds-chip";
|
|
14
|
+
import { FtdsPopover } from "@fluid-topics/ftds-popover";
|
|
15
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
16
|
+
import { withI18n } from "@fluid-topics/ft-i18n";
|
|
17
|
+
import { chipGroupContext, defaultChipGroupMessages, } from "./FtdsChipGroupMessages";
|
|
18
|
+
import { FtdsIcons, FtdsIconVariants } from "@fluid-topics/ftds-icon";
|
|
19
|
+
import { FtTooltip } from "@fluid-topics/ft-tooltip";
|
|
20
|
+
import { FtdsTypography, FtdsTypographyVariants, } from "@fluid-topics/ftds-typography";
|
|
21
|
+
export class FtdsChipGroup extends withI18n(FtdsBase) {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.removable = false;
|
|
25
|
+
this.popoverTitle = "";
|
|
26
|
+
this.chips = [];
|
|
27
|
+
this.isPopoverOpened = false;
|
|
28
|
+
this.addI18nContext(chipGroupContext, defaultChipGroupMessages);
|
|
29
|
+
}
|
|
30
|
+
updated(changedProperties) {
|
|
31
|
+
super.updated(changedProperties);
|
|
32
|
+
if (changedProperties.has("chips") && this.lastRemovedChipIndex !== undefined) {
|
|
33
|
+
this.handleFocusOnChipDeleted(this.lastRemovedChipIndex);
|
|
34
|
+
this.lastRemovedChipIndex = undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
render() {
|
|
38
|
+
const visibleChips = this.maxNumberOfChips !== undefined
|
|
39
|
+
? this.chips.slice(0, this.maxNumberOfChips)
|
|
40
|
+
: this.chips;
|
|
41
|
+
const hiddenCount = this.chips.length - visibleChips.length;
|
|
42
|
+
return html `
|
|
43
|
+
<ul>
|
|
44
|
+
${repeat(visibleChips, (chip) => chip.value, (chip) => this.renderChip(chip))}
|
|
45
|
+
${hiddenCount > 0 ? this.renderExtraChipsPopover(hiddenCount) : ""}
|
|
46
|
+
</ul>
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
renderExtraChipsPopover(hiddenCount) {
|
|
50
|
+
const extraChips = this.chips.slice(this.maxNumberOfChips);
|
|
51
|
+
const classes = {
|
|
52
|
+
"show-more-chip": true,
|
|
53
|
+
"show-more-chip--active": this.isPopoverOpened,
|
|
54
|
+
};
|
|
55
|
+
return html `
|
|
56
|
+
<li>
|
|
57
|
+
<ftds-popover margins="dense"
|
|
58
|
+
@opened-changed=${(e) => this.toggleExtraChips(e)}>
|
|
59
|
+
<ftds-chip slot="trigger"
|
|
60
|
+
class="${classMap(classes)}"
|
|
61
|
+
role="button"
|
|
62
|
+
tabindex="0"
|
|
63
|
+
aria-haspopup="true"
|
|
64
|
+
aria-expanded="${this.isPopoverOpened}"
|
|
65
|
+
aria-controls="ftds-popover-wrapper">
|
|
66
|
+
${chipGroupContext.messages.showMoreChipAriaLabel(hiddenCount)}
|
|
67
|
+
</ftds-chip>
|
|
68
|
+
<div>
|
|
69
|
+
<ftds-typography part="label"
|
|
70
|
+
element="span"
|
|
71
|
+
variant="${FtdsTypographyVariants.caption2semibold}">
|
|
72
|
+
${chipGroupContext.messages.showMorePopoverTitle(hiddenCount)}
|
|
73
|
+
</ftds-typography>
|
|
74
|
+
<ul>
|
|
75
|
+
${repeat(extraChips, (chip) => chip.value, (chip) => this.renderChip(chip))}
|
|
76
|
+
</ul>
|
|
77
|
+
</div>
|
|
78
|
+
</ftds-popover>
|
|
79
|
+
</li>
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
renderChip(chip) {
|
|
83
|
+
var _a, _b, _c, _d;
|
|
84
|
+
return html `
|
|
85
|
+
<li>
|
|
86
|
+
<ft-tooltip
|
|
87
|
+
text="${(_a = chip.label) !== null && _a !== void 0 ? _a : chip.value}"
|
|
88
|
+
position="top">
|
|
89
|
+
<ftds-chip class="chip-group-chip"
|
|
90
|
+
exportparts="chip"
|
|
91
|
+
?removable=${this.removable}
|
|
92
|
+
.family=${(_b = chip.family) !== null && _b !== void 0 ? _b : DesignSystemFamily.neutral}
|
|
93
|
+
.icon=${this.getFamilyIcon(chip.family)}
|
|
94
|
+
.iconVariant=${FtdsIconVariants.solid}
|
|
95
|
+
.removeButtonLabel=${(_c = chip.removeLabel) !== null && _c !== void 0 ? _c : chipGroupContext.messages.defaultRemoveLabel()}
|
|
96
|
+
@remove=${() => this.onChipRemoved(chip)}>
|
|
97
|
+
${(_d = chip.label) !== null && _d !== void 0 ? _d : chip.value}
|
|
98
|
+
</ftds-chip>
|
|
99
|
+
</ft-tooltip>
|
|
100
|
+
</li>
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
onChipRemoved(chip) {
|
|
104
|
+
this.lastRemovedChipIndex = this.chips.findIndex((c) => c.value === chip.value);
|
|
105
|
+
this.dispatchEvent(new RemoveChipEvent(chip));
|
|
106
|
+
}
|
|
107
|
+
handleFocusOnChipDeleted(deletedIndex) {
|
|
108
|
+
var _a;
|
|
109
|
+
const chipElements = Array.from((_a = this.allChips) !== null && _a !== void 0 ? _a : []);
|
|
110
|
+
if (chipElements.length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (chipElements[deletedIndex]) {
|
|
114
|
+
void this.focusChip(chipElements[deletedIndex]);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
void this.focusChip(chipElements[deletedIndex - 1]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async focusChip(chip) {
|
|
121
|
+
var _a;
|
|
122
|
+
await chip.updateComplete;
|
|
123
|
+
const deleteButton = (_a = chip.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(".ftds-chip--remove-button");
|
|
124
|
+
await (deleteButton === null || deleteButton === void 0 ? void 0 : deleteButton.updateComplete);
|
|
125
|
+
deleteButton === null || deleteButton === void 0 ? void 0 : deleteButton.focus();
|
|
126
|
+
}
|
|
127
|
+
toggleExtraChips(e) {
|
|
128
|
+
this.isPopoverOpened = e.detail.opened;
|
|
129
|
+
}
|
|
130
|
+
getFamilyIcon(family) {
|
|
131
|
+
switch (family) {
|
|
132
|
+
case DesignSystemFamily.warning:
|
|
133
|
+
return FtdsIcons.TRIANGLE_EXCLAMATION;
|
|
134
|
+
default:
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
FtdsChipGroup.elementDefinitions = {
|
|
140
|
+
"ftds-chip": FtdsChip,
|
|
141
|
+
"ftds-popover": FtdsPopover,
|
|
142
|
+
"ftds-typography": FtdsTypography,
|
|
143
|
+
"ft-tooltip": FtTooltip,
|
|
144
|
+
};
|
|
145
|
+
FtdsChipGroup.styles = designSystemStyle;
|
|
146
|
+
__decorate([
|
|
147
|
+
property({ type: Boolean })
|
|
148
|
+
], FtdsChipGroup.prototype, "removable", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
numberProperty()
|
|
151
|
+
], FtdsChipGroup.prototype, "maxNumberOfChips", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
property()
|
|
154
|
+
], FtdsChipGroup.prototype, "popoverTitle", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
jsonProperty([])
|
|
157
|
+
], FtdsChipGroup.prototype, "chips", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
state()
|
|
160
|
+
], FtdsChipGroup.prototype, "isPopoverOpened", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
queryAll(".chip-group-chip")
|
|
163
|
+
], FtdsChipGroup.prototype, "allChips", void 0);
|