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): Introduce clearer unselected state #8510

Merged
merged 14 commits into from
Jan 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,31 @@
);
}

.container:hover {
.container--hover:hover {
@apply bg-foreground-2 cursor-pointer;
}

.container:active {
@apply bg-foreground-1;
}

.container--border {
border-inline-start-width: theme("borderWidth.4");
border-inline-start-style: solid;
}

.container--border-selected {
border-inline-start: theme("borderWidth.4") solid theme("colors.brand");
border-inline-start-color: theme("colors.brand");
}

.container--border-unselected {
border-inline-start: theme("borderWidth.4") solid transparent;
border-inline-start-color: transparent;
}

.container:hover {
&.container--border-unselected {
@apply border-color-1;
}
}

.nested-container {
Expand Down Expand Up @@ -88,10 +99,18 @@ td:focus {
@apply text-color-1;
}

:host([selected]) .label {
@apply font-medium;
}

.description {
@apply text-color-3 mt-0.5;
}

:host([selected]) .description {
@apply text-color-2;
}

.content-start {
@apply justify-start;
}
Expand Down Expand Up @@ -119,9 +138,31 @@ td:focus {

.selection-container {
@apply flex px-3;
color: theme("borderColor.color.input");
}

.selection-container--single {
color: transparent;
}

:host(:not([disabled]):not([selected])) .container:hover .selection-container--single {
color: theme("borderColor.color.1");
}

:host([selected]:hover) .selection-container,
:host([selected]:hover) .selection-container--single,
:host([selected]) .selection-container {
color: var(--calcite-list-item-icon-color);
}

.open-container {
color: theme("textColor.color.3");
}

:host(:not([disabled])) .container:hover .open-container {
color: theme("textColor.color.1");
}

.actions-start,
.actions-end,
.content-start,
Expand Down
16 changes: 14 additions & 2 deletions packages/calcite-components/src/components/list-item/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,24 @@ export class ListItem
}

return (
<td class={CSS.selectionContainer} key="selection-container" onClick={this.handleItemClick}>
<td
class={{
[CSS.selectionContainer]: true,
[CSS.selectionContainerSingle]:
selectionMode === "single" || selectionMode === "single-persist",
}}
key="selection-container"
onClick={this.handleItemClick}
>
<calcite-icon
icon={
selected
? selectionMode === "multiple"
? ICONS.selectedMultiple
: ICONS.selectedSingle
: ICONS.unselected
: selectionMode === "multiple"
? ICONS.unselectedMultiple
: ICONS.unselectedSingle
}
scale="s"
/>
Expand Down Expand Up @@ -645,6 +655,8 @@ export class ListItem
aria-setsize={setSize}
class={{
[CSS.container]: true,
[CSS.containerHover]: selectionMode !== "none",
[CSS.containerBorder]: showBorder,
[CSS.containerBorderSelected]: borderSelected,
[CSS.containerBorderUnselected]: borderUnselected,
}}
Expand Down
16 changes: 10 additions & 6 deletions packages/calcite-components/src/components/list-item/resources.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const CSS = {
container: "container",
containerHover: "container--hover",
containerBorder: "container--border",
containerBorderSelected: "container--border-selected",
containerBorderUnselected: "container--border-unselected",
contentContainer: "content-container",
Expand All @@ -17,6 +19,7 @@ export const CSS = {
contentBottom: "content-bottom",
actionsEnd: "actions-end",
selectionContainer: "selection-container",
selectionContainerSingle: "selection-container--single",
openContainer: "open-container",
dragContainer: "drag-container",
};
Expand All @@ -34,12 +37,13 @@ export const SLOTS = {
export const MAX_COLUMNS = 0;

export const ICONS = {
selectedMultiple: "check-circle-f",
selectedSingle: "circle-f",
unselected: "blank",
closedLTR: "caret-right",
closedRTL: "caret-left",
open: "caret-down",
selectedMultiple: "check-square-f",
selectedSingle: "bullet-point-large",
unselectedMultiple: "square",
unselectedSingle: "bullet-point-large",
closedLTR: "chevron-right",
closedRTL: "chevron-left",
open: "chevron-down",
blank: "blank",
close: "x",
};
Expand Down
45 changes: 38 additions & 7 deletions packages/calcite-components/src/components/list/list.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ export default {
const thumbnailImage = placeholderImage({ width: 44, height: 44 });

const knobsHTML = (): string =>
html`selection-mode="${select("selection-mode", ["single", "multiple", "none"], "none")}"
html`selection-mode="${select("selection-mode", ["single", "single-persist", "multiple", "none"], "none")}"
selection-appearance="${select("selection-appearance", ["icon", "border"], "icon")}" ${boolean("loading", false)}
${boolean("closable", false)} ${boolean("closed", false)} ${boolean("filter-enabled", false)}
${boolean("drag-enabled", false)} ${boolean("disabled", false)} ${text("label", "My List")}`;

export const simple = (): string => html`
<calcite-list ${knobsHTML()}>
<calcite-list-item
selected
label="Cras iaculis ultricies nulla."
description="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
></calcite-list-item>
Expand Down Expand Up @@ -434,9 +433,41 @@ export const customContent_TestOnly = (): string =>
>
</calcite-list>`;

export const singlePersist_TestOnly = (): string =>
html`<calcite-list selection-mode="single-persist" label="test">
<calcite-list-item selected label="basic" value="basic" description="hello world">
<calcite-icon
icon="banana"
slot="content-start"
style="color: var(--calcite-color-status-success)"
></calcite-icon>
<calcite-action
appearance="transparent"
icon="ellipsis"
text="menu"
label="menu"
slot="actions-end"
></calcite-action>
</calcite-list-item>
<calcite-list-item disabled label="disabled" value="disabled" description="hello world">
<calcite-icon
icon="compass"
slot="content-start"
style="color: var(--calcite-color-status-success)"
></calcite-icon>
</calcite-list-item>
<calcite-list-item label="basic2" value="basic2" description="hello world">
<calcite-icon
icon="compass"
slot="content-start"
style="color: var(--calcite-color-status-success)"
></calcite-icon>
</calcite-list-item>
</calcite-list>`;

export const closableListItems_TestOnly = (): string =>
html`<calcite-list selection-mode="single" label="test" filter-enabled>
<calcite-list-item closable label="basic" value="basic" description="hello world">
<calcite-list-item selected closable label="basic" value="basic" description="hello world">
<calcite-icon
icon="banana"
slot="content-start"
Expand Down Expand Up @@ -475,7 +506,7 @@ export const filteredChildListItems_TestOnly = (): string =>
selection-mode="single"
>
<calcite-list-item-group heading="Layers">
<calcite-list-item label="Hiking trails" value="hiking-trails">
<calcite-list-item selected label="Hiking trails" value="hiking-trails">
<calcite-dropdown slot="actions-end" overlay-positioning="fixed" placement="bottom-end" scale="s">
<calcite-action
slot="trigger"
Expand Down Expand Up @@ -565,7 +596,7 @@ export const filteredChildListItems_TestOnly = (): string =>
selection-mode="single"
>
<calcite-list-item-group heading="Layers">
<calcite-list-item label="Hiking trails" value="hiking-trails">
<calcite-list-item selected label="Hiking trails" value="hiking-trails">
<calcite-dropdown slot="actions-end" overlay-positioning="fixed" placement="bottom-end" scale="s">
<calcite-action
slot="trigger"
Expand Down Expand Up @@ -690,7 +721,7 @@ export const filterActions_TestOnly = (): string =>
style="color: var(--calcite-color-status-success)"
></calcite-icon>
</calcite-list-item>
<calcite-list-item label="test2" value="test2" description="hello world 2">
<calcite-list-item selected label="test2" value="test2" description="hello world 2">
<calcite-icon
icon="compass"
slot="content-start"
Expand Down Expand Up @@ -750,7 +781,7 @@ export const sortableList_TestOnly = (): string =>
style="color: var(--calcite-color-status-success)"
></calcite-icon>
</calcite-list-item>
<calcite-list-item label="test2" value="test2" description="hello world 2">
<calcite-list-item selected label="test2" value="test2" description="hello world 2">
<calcite-icon
icon="compass"
slot="content-start"
Expand Down
Loading