Skip to content

Commit

Permalink
feat(list-item): add unavailable property (#10377)
Browse files Browse the repository at this point in the history
**Related Issue:** #5664

## Summary

- add `unavailable` property to `list-item`.
- add e2e test
- add entry in story
- update demo
  • Loading branch information
driskull authored Sep 25, 2024
1 parent 98177f0 commit 9332733
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,10 @@ export namespace Components {
* Used to specify the aria-setsize attribute to define the number of items in the current set of list for accessibility.
*/
"setSize": number;
/**
* When `true`, the component's content appears inactive.
*/
"unavailable": boolean;
/**
* The component's value.
*/
Expand Down Expand Up @@ -11440,6 +11444,10 @@ declare namespace LocalJSX {
* Used to specify the aria-setsize attribute to define the number of items in the current set of list for accessibility.
*/
"setSize"?: number;
/**
* When `true`, the component's content appears inactive.
*/
"unavailable"?: boolean;
/**
* The component's value.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newE2EPage } from "@stencil/core/testing";
import { defaults, disabled, focusable, hidden, renders, slots } from "../../tests/commonTests";
import { defaults, disabled, focusable, hidden, reflects, renders, slots } from "../../tests/commonTests";
import { html } from "../../../support/formatting";
import { CSS, SLOTS } from "./resources";

Expand Down Expand Up @@ -56,6 +56,19 @@ describe("calcite-list-item", () => {
propertyName: "filterHidden",
defaultValue: false,
},
{
propertyName: "unavailable",
defaultValue: false,
},
]);
});

describe("reflects", () => {
reflects("calcite-list-item", [
{
propertyName: "unavailable",
value: true,
},
]);
});

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

it("adds unavailable class", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-list-item></calcite-list-item>`);
await page.waitForChanges();

expect(await page.find(`calcite-list-item >>> .${CSS.contentContainerUnavailable}`)).toBeNull();

const item = await page.find("calcite-list-item");
item.setProperty("unavailable", true);
await page.waitForChanges();

expect(await page.find(`calcite-list-item >>> .${CSS.contentContainerUnavailable}`)).not.toBeNull();
});

it("renders dragHandle when property is true", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-list-item></calcite-list-item>`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
p-0;
}

.content-container--unavailable {
@apply opacity-disabled;
}

tr,
td {
@apply focus-base;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ export class ListItem
this.calciteInternalListItemSelect.emit();
}

/**
* When `true`, the component's content appears inactive.
*/
@Prop({ reflect: true }) unavailable = false;

/**
* The component's value.
*/
Expand Down Expand Up @@ -613,7 +618,7 @@ export class ListItem
}

renderContentContainer(): VNode {
const { description, label, selectionMode, hasCustomContent } = this;
const { description, label, selectionMode, hasCustomContent, unavailable } = this;
const hasCenterContent = hasCustomContent || !!label || !!description;
const content = [
this.renderContentStart(),
Expand All @@ -627,6 +632,7 @@ export class ListItem
aria-label={label}
class={{
[CSS.contentContainer]: true,
[CSS.contentContainerUnavailable]: unavailable,
[CSS.contentContainerSelectable]: selectionMode !== "none",
[CSS.contentContainerHasCenterContent]: hasCenterContent,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CSS = {
containerBorderSelected: "container--border-selected",
containerBorderUnselected: "container--border-unselected",
contentContainer: "content-container",
contentContainerUnavailable: "content-container--unavailable",
contentContainerSelectable: "content-container--selectable",
contentContainerHasCenterContent: "content-container--has-center-content",
nestedContainer: "nested-container",
Expand Down
16 changes: 16 additions & 0 deletions packages/calcite-components/src/components/list/list.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export const simple = (args: ListStoryArgs): string => html`
description="Vestibulum auctor dapibus neque.
"
></calcite-list-item>
<calcite-list-item
unavailable
label="Vestibulum commodo felis quis tortor."
description="Vestibulum auctor dapibus neque."
></calcite-list-item>
</calcite-list>
`;

Expand Down Expand Up @@ -286,6 +291,14 @@ export const startAndEndContentSlots = (): string =>
<calcite-chip class="list-chip" icon="bell" scale="s">Halp!</calcite-chip>
</div>
</calcite-list-item>
<calcite-list-item unavailable>
<calcite-action slot="actions-end" icon="ellipsis"> </calcite-action>
<calcite-icon icon="user" scale="m" slot="content-start"></calcite-icon>
<span slot="content-start">Some value or something and a <b>thing</b>.</span>
<div slot="content-end" style="display: flex; justify-content: flex-end">
<calcite-chip class="list-chip" icon="bell" scale="s">Halp!</calcite-chip>
</div>
</calcite-list-item>
</calcite-list> `;

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

export const contentBottomSlotsNested = (): string =>
Expand Down
9 changes: 8 additions & 1 deletion packages/calcite-components/src/demos/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ <h1 style="margin: 0 auto; text-align: center">List</h1>
--calcite-color-status-success
></calcite-icon>
</calcite-list-item>
<calcite-list-item disabled label="test4" value="test4" description="hello world 4">
<calcite-list-item disabled label="test4" value="test4" description="hello world 4: disabled">
<calcite-icon
icon="compass"
slot="content-start"
style="color: var(--calcite-color-status-success)"
></calcite-icon>
</calcite-list-item>
<calcite-list-item unavailable label="test4" value="test5" description="hello world 5: unavailable">
<calcite-icon
icon="compass"
slot="content-start"
Expand Down

0 comments on commit 9332733

Please sign in to comment.