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): Add slots for filter actions #7183

Merged
merged 7 commits into from
Jun 28, 2023
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
14 changes: 9 additions & 5 deletions packages/calcite-components/src/components/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
@apply w-full border-collapse;
}

.stack {
--calcite-stack-padding-inline: 0;
--calcite-stack-padding-block: 0;
}

::slotted(calcite-list-item) {
@apply shadow-border-bottom mb-px;
}
Expand All @@ -34,12 +39,11 @@
}

.sticky-pos {
@apply sticky top-0 z-sticky;
@apply sticky
top-0
z-sticky
bg-foreground-1;
& th {
@apply p-0;
}
}

calcite-filter {
@apply mb-px;
}
47 changes: 47 additions & 0 deletions packages/calcite-components/src/components/list/list.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,50 @@ export const filteredChildListItems_TestOnly = (): string => html` <calcite-list
</calcite-list-item>
</calcite-list-item-group>
</calcite-list>`;

export const filterActions_TestOnly = (): string => html`<calcite-list
selection-mode="single"
label="test"
filter-enabled
>
<calcite-action
appearance="transparent"
icon="banana"
text="menu"
label="menu"
slot="filter-actions-start"
></calcite-action>
<calcite-action
appearance="transparent"
icon="ellipsis"
text="menu"
label="menu"
slot="filter-actions-start"
></calcite-action>
<calcite-action
appearance="transparent"
icon="filter"
text="menu"
label="menu"
slot="filter-actions-end"
></calcite-action>
<calcite-action
appearance="transparent"
icon="sort-ascending"
text="menu"
label="menu"
slot="filter-actions-end"
></calcite-action>
<calcite-list-item label="test1" value="test1" description="hello world 1">
<calcite-icon icon="banana" slot="content-start" style="color: var(--calcite-ui-success)"></calcite-icon>
</calcite-list-item>
<calcite-list-item label="test2" value="test2" description="hello world 2">
<calcite-icon icon="compass" slot="content-start" style="color: var(--calcite-ui-success)"></calcite-icon>
</calcite-list-item>
<calcite-list-item label="test3" value="test3" description="hello world 3">
<calcite-icon icon="compass" slot="content-start" style="color: var(--calcite-ui-success)"></calcite-icon>
</calcite-list-item>
<calcite-list-item disabled label="test4" value="test4" description="hello world 4">
<calcite-icon icon="compass" slot="content-start" style="color: var(--calcite-ui-success)"></calcite-icon>
</calcite-list-item>
</calcite-list>`;
57 changes: 43 additions & 14 deletions packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Watch
} from "@stencil/core";
import { debounce } from "lodash-es";
import { toAriaBoolean } from "../../utils/dom";
import { slotChangeHasAssignedElement, toAriaBoolean } from "../../utils/dom";
import {
connectInteractive,
disconnectInteractive,
Expand All @@ -24,7 +24,8 @@ import { SelectionMode } from "../interfaces";
import { ItemData } from "../list-item/interfaces";
import { MAX_COLUMNS } from "../list-item/resources";
import { getListItemChildren, updateListItemChildren } from "../list-item/utils";
import { CSS, debounceTimeout, SelectionAppearance } from "./resources";
import { CSS, debounceTimeout, SelectionAppearance, SLOTS } from "./resources";
import { SLOTS as STACK_SLOTS } from "../stack/resources";

const listItemSelector = "calcite-list-item";
const parentSelector = "calcite-list-item-group, calcite-list-item";
Expand All @@ -40,6 +41,8 @@ import {
* A general purpose list that enables users to construct list items that conform to Calcite styling.
*
* @slot - A slot for adding `calcite-list-item` elements.
* @slot filter-actions-start - A slot for adding actionable `calcite-action` elements before the filter component.
* @slot filter-actions-end - A slot for adding actionable `calcite-action` elements after the filter component.
*/
@Component({
tag: "calcite-list",
Expand Down Expand Up @@ -247,6 +250,10 @@ export class List implements InteractiveComponent, LoadableComponent {

@State() dataForFilter: ItemData = [];

@State() hasFilterActionsStart = false;

@State() hasFilterActionsEnd = false;

filterEl: HTMLCalciteFilterElement;

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -276,7 +283,9 @@ export class List implements InteractiveComponent, LoadableComponent {
dataForFilter,
filterEnabled,
filterPlaceholder,
filterText
filterText,
hasFilterActionsStart,
hasFilterActionsEnd
} = this;
return (
<div class={CSS.container}>
Expand All @@ -288,20 +297,32 @@ export class List implements InteractiveComponent, LoadableComponent {
onKeyDown={this.handleListKeydown}
role="treegrid"
>
{filterEnabled ? (
{filterEnabled || hasFilterActionsStart || hasFilterActionsEnd ? (
<thead>
<tr class={{ [CSS.sticky]: true }}>
<th colSpan={MAX_COLUMNS}>
<calcite-filter
aria-label={filterPlaceholder}
disabled={loading || disabled}
items={dataForFilter}
onCalciteFilterChange={this.handleFilterChange}
placeholder={filterPlaceholder}
value={filterText}
// eslint-disable-next-line react/jsx-sort-props
ref={this.setFilterEl}
/>
<calcite-stack class={CSS.stack}>
Copy link
Member

Choose a reason for hiding this comment

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

Awesome to see stack in action! 🥞

<slot
name={SLOTS.filterActionsStart}
onSlotchange={this.handleFilterActionsStartSlotChange}
slot={STACK_SLOTS.actionsStart}
/>
<calcite-filter
aria-label={filterPlaceholder}
disabled={loading || disabled}
items={dataForFilter}
onCalciteFilterChange={this.handleFilterChange}
placeholder={filterPlaceholder}
value={filterText}
// eslint-disable-next-line react/jsx-sort-props
ref={this.setFilterEl}
/>
<slot
name={SLOTS.filterActionsEnd}
onSlotchange={this.handleFilterActionsEndSlotChange}
slot={STACK_SLOTS.actionsEnd}
/>
</calcite-stack>
</th>
</tr>
</thead>
Expand All @@ -324,6 +345,14 @@ export class List implements InteractiveComponent, LoadableComponent {
updateListItemChildren(getListItemChildren(event));
};

private handleFilterActionsStartSlotChange = (event: Event): void => {
this.hasFilterActionsStart = slotChangeHasAssignedElement(event);
};

private handleFilterActionsEndSlotChange = (event: Event): void => {
this.hasFilterActionsEnd = slotChangeHasAssignedElement(event);
};

private setActiveListItem = (): void => {
const { enabledListItems } = this;

Expand Down
6 changes: 6 additions & 0 deletions packages/calcite-components/src/components/list/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ export const CSS = {
container: "container",
table: "table",
scrim: "scrim",
stack: "stack",
tableContainer: "table-container",
sticky: "sticky-pos"
};

export const debounceTimeout = 0;

export type SelectionAppearance = "border" | "icon";

export const SLOTS = {
filterActionsStart: "filter-actions-start",
filterActionsEnd: "filter-actions-end"
};
28 changes: 28 additions & 0 deletions packages/calcite-components/src/demos/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ <h1 style="margin: 0 auto; text-align: center">List</h1>

<div class="child">
<calcite-list selection-mode="single" label="test" filter-enabled>
<calcite-action
appearance="transparent"
icon="banana"
text="menu"
label="menu"
slot="filter-actions-start"
></calcite-action>
<calcite-action
appearance="transparent"
icon="ellipsis"
text="menu"
label="menu"
slot="filter-actions-start"
></calcite-action>
<calcite-action
appearance="transparent"
icon="filter"
text="menu"
label="menu"
slot="filter-actions-end"
></calcite-action>
<calcite-action
appearance="transparent"
icon="sort-ascending"
text="menu"
label="menu"
slot="filter-actions-end"
></calcite-action>
<calcite-list-item label="test1" value="test1" description="hello world 1">
<calcite-icon icon="banana" slot="content-start" style="color: var(--calcite-ui-success)"></calcite-icon>
</calcite-list-item>
Expand Down