Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(list-item): add unavailable property #10377

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+@geospatialem @DitwanP for doc review

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geospatialem @DitwanP i'll merge now. We can update the doc post install if we need to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc LGTM! We can add a new sample to showcase the behavior for folks once 2.13.0 is live for additional context as well. ⚡

*/
@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
Loading