Skip to content

Commit 9332733

Browse files
authored
feat(list-item): add unavailable property (#10377)
**Related Issue:** #5664 ## Summary - add `unavailable` property to `list-item`. - add e2e test - add entry in story - update demo
1 parent 98177f0 commit 9332733

File tree

7 files changed

+72
-3
lines changed

7 files changed

+72
-3
lines changed

packages/calcite-components/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,10 @@ export namespace Components {
33123312
* Used to specify the aria-setsize attribute to define the number of items in the current set of list for accessibility.
33133313
*/
33143314
"setSize": number;
3315+
/**
3316+
* When `true`, the component's content appears inactive.
3317+
*/
3318+
"unavailable": boolean;
33153319
/**
33163320
* The component's value.
33173321
*/
@@ -11440,6 +11444,10 @@ declare namespace LocalJSX {
1144011444
* Used to specify the aria-setsize attribute to define the number of items in the current set of list for accessibility.
1144111445
*/
1144211446
"setSize"?: number;
11447+
/**
11448+
* When `true`, the component's content appears inactive.
11449+
*/
11450+
"unavailable"?: boolean;
1144311451
/**
1144411452
* The component's value.
1144511453
*/

packages/calcite-components/src/components/list-item/list-item.e2e.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { newE2EPage } from "@stencil/core/testing";
2-
import { defaults, disabled, focusable, hidden, renders, slots } from "../../tests/commonTests";
2+
import { defaults, disabled, focusable, hidden, reflects, renders, slots } from "../../tests/commonTests";
33
import { html } from "../../../support/formatting";
44
import { CSS, SLOTS } from "./resources";
55

@@ -56,6 +56,19 @@ describe("calcite-list-item", () => {
5656
propertyName: "filterHidden",
5757
defaultValue: false,
5858
},
59+
{
60+
propertyName: "unavailable",
61+
defaultValue: false,
62+
},
63+
]);
64+
});
65+
66+
describe("reflects", () => {
67+
reflects("calcite-list-item", [
68+
{
69+
propertyName: "unavailable",
70+
value: true,
71+
},
5972
]);
6073
});
6174

@@ -75,6 +88,20 @@ describe("calcite-list-item", () => {
7588
expect(await page.find(`calcite-list-item >>> .${CSS.containerHover}`)).not.toBeNull();
7689
});
7790

91+
it("adds unavailable class", async () => {
92+
const page = await newE2EPage();
93+
await page.setContent(`<calcite-list-item></calcite-list-item>`);
94+
await page.waitForChanges();
95+
96+
expect(await page.find(`calcite-list-item >>> .${CSS.contentContainerUnavailable}`)).toBeNull();
97+
98+
const item = await page.find("calcite-list-item");
99+
item.setProperty("unavailable", true);
100+
await page.waitForChanges();
101+
102+
expect(await page.find(`calcite-list-item >>> .${CSS.contentContainerUnavailable}`)).not.toBeNull();
103+
});
104+
78105
it("renders dragHandle when property is true", async () => {
79106
const page = await newE2EPage();
80107
await page.setContent(`<calcite-list-item></calcite-list-item>`);

packages/calcite-components/src/components/list-item/list-item.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
p-0;
7676
}
7777

78+
.content-container--unavailable {
79+
@apply opacity-disabled;
80+
}
81+
7882
tr,
7983
td {
8084
@apply focus-base;

packages/calcite-components/src/components/list-item/list-item.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ export class ListItem
196196
this.calciteInternalListItemSelect.emit();
197197
}
198198

199+
/**
200+
* When `true`, the component's content appears inactive.
201+
*/
202+
@Prop({ reflect: true }) unavailable = false;
203+
199204
/**
200205
* The component's value.
201206
*/
@@ -613,7 +618,7 @@ export class ListItem
613618
}
614619

615620
renderContentContainer(): VNode {
616-
const { description, label, selectionMode, hasCustomContent } = this;
621+
const { description, label, selectionMode, hasCustomContent, unavailable } = this;
617622
const hasCenterContent = hasCustomContent || !!label || !!description;
618623
const content = [
619624
this.renderContentStart(),
@@ -627,6 +632,7 @@ export class ListItem
627632
aria-label={label}
628633
class={{
629634
[CSS.contentContainer]: true,
635+
[CSS.contentContainerUnavailable]: unavailable,
630636
[CSS.contentContainerSelectable]: selectionMode !== "none",
631637
[CSS.contentContainerHasCenterContent]: hasCenterContent,
632638
}}

packages/calcite-components/src/components/list-item/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const CSS = {
77
containerBorderSelected: "container--border-selected",
88
containerBorderUnselected: "container--border-unselected",
99
contentContainer: "content-container",
10+
contentContainerUnavailable: "content-container--unavailable",
1011
contentContainerSelectable: "content-container--selectable",
1112
contentContainerHasCenterContent: "content-container--has-center-content",
1213
nestedContainer: "nested-container",

packages/calcite-components/src/components/list/list.stories.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export const simple = (args: ListStoryArgs): string => html`
9090
description="Vestibulum auctor dapibus neque.
9191
"
9292
></calcite-list-item>
93+
<calcite-list-item
94+
unavailable
95+
label="Vestibulum commodo felis quis tortor."
96+
description="Vestibulum auctor dapibus neque."
97+
></calcite-list-item>
9398
</calcite-list>
9499
`;
95100

@@ -286,6 +291,14 @@ export const startAndEndContentSlots = (): string =>
286291
<calcite-chip class="list-chip" icon="bell" scale="s">Halp!</calcite-chip>
287292
</div>
288293
</calcite-list-item>
294+
<calcite-list-item unavailable>
295+
<calcite-action slot="actions-end" icon="ellipsis"> </calcite-action>
296+
<calcite-icon icon="user" scale="m" slot="content-start"></calcite-icon>
297+
<span slot="content-start">Some value or something and a <b>thing</b>.</span>
298+
<div slot="content-end" style="display: flex; justify-content: flex-end">
299+
<calcite-chip class="list-chip" icon="bell" scale="s">Halp!</calcite-chip>
300+
</div>
301+
</calcite-list-item>
289302
</calcite-list> `;
290303

291304
export const contentBottomSlots = (): string =>
@@ -299,6 +312,9 @@ export const contentBottomSlots = (): string =>
299312
<calcite-list-item label="Princess Bubblegum" description="Ruler of The Candy Kingdom">
300313
<span slot="content-bottom">Some value or something and a <b>thing</b>.</span>
301314
</calcite-list-item>
315+
<calcite-list-item unavailable label="Princess Bubblegum" description="Ruler of The Candy Kingdom">
316+
<span slot="content-bottom">Some value or something and a <b>thing</b>.</span>
317+
</calcite-list-item>
302318
</calcite-list> `;
303319

304320
export const contentBottomSlotsNested = (): string =>

packages/calcite-components/src/demos/list.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ <h1 style="margin: 0 auto; text-align: center">List</h1>
9090
--calcite-color-status-success
9191
></calcite-icon>
9292
</calcite-list-item>
93-
<calcite-list-item disabled label="test4" value="test4" description="hello world 4">
93+
<calcite-list-item disabled label="test4" value="test4" description="hello world 4: disabled">
94+
<calcite-icon
95+
icon="compass"
96+
slot="content-start"
97+
style="color: var(--calcite-color-status-success)"
98+
></calcite-icon>
99+
</calcite-list-item>
100+
<calcite-list-item unavailable label="test4" value="test5" description="hello world 5: unavailable">
94101
<calcite-icon
95102
icon="compass"
96103
slot="content-start"

0 commit comments

Comments
 (0)