From da07ab1dcd5d0b830c46b00b76c6d5724ff38c60 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Wed, 28 Jun 2023 11:34:48 -0700 Subject: [PATCH] feat(list): Add slots for filter actions (#7183) **Related Issue:** #6600 ## Summary - adds slot `filter-actions-start`. - adds slot `filter-actions-end`. - Uses `calcite-stack` internally for layout. - Adds story - Updates demo file --- .../src/components/list/list.scss | 14 +++-- .../src/components/list/list.stories.ts | 47 +++++++++++++++ .../src/components/list/list.tsx | 57 ++++++++++++++----- .../src/components/list/resources.ts | 6 ++ .../calcite-components/src/demos/list.html | 28 +++++++++ 5 files changed, 133 insertions(+), 19 deletions(-) diff --git a/packages/calcite-components/src/components/list/list.scss b/packages/calcite-components/src/components/list/list.scss index 94826085f27..3fac143679a 100755 --- a/packages/calcite-components/src/components/list/list.scss +++ b/packages/calcite-components/src/components/list/list.scss @@ -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; } @@ -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; -} diff --git a/packages/calcite-components/src/components/list/list.stories.ts b/packages/calcite-components/src/components/list/list.stories.ts index b889a258c2d..e34d6d3993c 100644 --- a/packages/calcite-components/src/components/list/list.stories.ts +++ b/packages/calcite-components/src/components/list/list.stories.ts @@ -543,3 +543,50 @@ export const filteredChildListItems_TestOnly = (): string => html` `; + +export const filterActions_TestOnly = (): string => html` + + + + + + + + + + + + + + + + +`; diff --git a/packages/calcite-components/src/components/list/list.tsx b/packages/calcite-components/src/components/list/list.tsx index c0c7a3432ed..427d41eb922 100755 --- a/packages/calcite-components/src/components/list/list.tsx +++ b/packages/calcite-components/src/components/list/list.tsx @@ -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, @@ -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"; @@ -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", @@ -247,6 +250,10 @@ export class List implements InteractiveComponent, LoadableComponent { @State() dataForFilter: ItemData = []; + @State() hasFilterActionsStart = false; + + @State() hasFilterActionsEnd = false; + filterEl: HTMLCalciteFilterElement; // -------------------------------------------------------------------------- @@ -276,7 +283,9 @@ export class List implements InteractiveComponent, LoadableComponent { dataForFilter, filterEnabled, filterPlaceholder, - filterText + filterText, + hasFilterActionsStart, + hasFilterActionsEnd } = this; return (
@@ -288,20 +297,32 @@ export class List implements InteractiveComponent, LoadableComponent { onKeyDown={this.handleListKeydown} role="treegrid" > - {filterEnabled ? ( + {filterEnabled || hasFilterActionsStart || hasFilterActionsEnd ? ( - + + + + + @@ -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; diff --git a/packages/calcite-components/src/components/list/resources.ts b/packages/calcite-components/src/components/list/resources.ts index 9949b4ae477..72c08c58070 100644 --- a/packages/calcite-components/src/components/list/resources.ts +++ b/packages/calcite-components/src/components/list/resources.ts @@ -2,6 +2,7 @@ export const CSS = { container: "container", table: "table", scrim: "scrim", + stack: "stack", tableContainer: "table-container", sticky: "sticky-pos" }; @@ -9,3 +10,8 @@ export const CSS = { export const debounceTimeout = 0; export type SelectionAppearance = "border" | "icon"; + +export const SLOTS = { + filterActionsStart: "filter-actions-start", + filterActionsEnd: "filter-actions-end" +}; diff --git a/packages/calcite-components/src/demos/list.html b/packages/calcite-components/src/demos/list.html index 25d45b0537e..e440e0bc0fb 100644 --- a/packages/calcite-components/src/demos/list.html +++ b/packages/calcite-components/src/demos/list.html @@ -39,6 +39,34 @@

List

+ + + +