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(block): add icon start/end properties (deprecate icon slot and status), add actions-end slot (deprecate control), add content-start #9535

Merged
merged 23 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
26 changes: 26 additions & 0 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,18 @@ export namespace Components {
* Specifies the heading level of the component's `heading` for proper document structure, without affecting visual styling.
*/
"headingLevel": HeadingLevel;
/**
* Specifies an icon to display at the end of the component.
*/
"iconEnd": string;
/**
* Displays the `iconStart` and/or `iconEnd` as flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl": FlipContext;
/**
* Specifies an icon to display at the start of the component.
*/
"iconStart": string;
/**
* When `true`, a busy indicator is displayed.
*/
Expand All @@ -636,6 +648,7 @@ export namespace Components {
"setFocus": () => Promise<void>;
/**
* Displays a status-related indicator icon.
* @deprecated Use `icon-start` instead.
*/
"status": Status;
}
Expand Down Expand Up @@ -8324,6 +8337,18 @@ declare namespace LocalJSX {
* Specifies the heading level of the component's `heading` for proper document structure, without affecting visual styling.
*/
"headingLevel"?: HeadingLevel;
/**
* Specifies an icon to display at the end of the component.
*/
"iconEnd"?: string;
/**
* Displays the `iconStart` and/or `iconEnd` as flipped when the element direction is right-to-left (`"rtl"`).
*/
"iconFlipRtl"?: FlipContext;
/**
* Specifies an icon to display at the start of the component.
*/
"iconStart"?: string;
/**
* When `true`, a busy indicator is displayed.
*/
Expand Down Expand Up @@ -8367,6 +8392,7 @@ declare namespace LocalJSX {
"overlayPositioning"?: OverlayPositioning;
/**
* Displays a status-related indicator icon.
* @deprecated Use `icon-start` instead.
*/
"status"?: Status;
}
Expand Down
40 changes: 31 additions & 9 deletions packages/calcite-components/src/components/block/block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
@import "../../assets/styles/header";

.header {
@apply justify-start p-0;
@apply justify-start;
padding: var(--calcite-spacing-md);
}

.header,
Expand All @@ -35,6 +36,9 @@
grid-column: header-start / menu-end;
grid-row: 1 / 2;
}
.header ::slotted(calcite-icon) {
margin-inline-end: var(--calcite-spacing-md);
}

.toggle {
@apply font-sans
Expand All @@ -47,9 +51,10 @@
justify-between
border-none
p-0;
text-align: initial;

text-align: initial;
background-color: transparent;

&:hover {
@apply bg-foreground-2;
}
Expand All @@ -69,7 +74,6 @@ calcite-handle {

.title {
@apply m-0;
padding: theme("spacing.3");
}

.header .title .heading {
Expand All @@ -93,9 +97,18 @@ calcite-handle {
}

.icon {
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
margin-inline-start: theme("spacing.3");
margin-inline-end: 0px;
@apply flex;
}

.icon--start,
.icon--end {
@apply text-color-3;

margin-inline-end: var(--calcite-spacing-md);
}

.status-icon {
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
margin-inline-end: var(--calcite-spacing-md);
}

.status-icon.valid {
Expand All @@ -118,16 +131,21 @@ calcite-handle {
}
}

.icon-end-container {
@apply flex items-center;

margin-inline-start: auto;
}

.toggle-icon {
@apply text-color-3
transition-color
my-3
self-center
justify-self-end
duration-150
ease-in-out;
margin-inline-end: theme("spacing.3");
margin-inline-start: auto;

margin-inline: var(--calcite-spacing-md);
}

.toggle:hover .toggle-icon {
Expand All @@ -144,6 +162,10 @@ calcite-handle {
padding-inline: var(--calcite-block-padding, var(--calcite-spacing-md));
}

.content-start {
@apply text-color-3;
}

.control-container {
@apply m-0 flex;
grid-area: control;
Expand Down
33 changes: 33 additions & 0 deletions packages/calcite-components/src/components/block/block.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,36 @@ export const icons_TestOnly = (): string => html`
</calcite-block-section>
</calcite-block>
`;

export const actionsEndLoadingIconStartEnd = (): string => html`
<calcite-block
heading="Valid status"
description="summary"
collapsible
icon-start="pen"
icon-end="pen"
style="width: 500px"
>
<calcite-icon
icon="compass"
slot="content-start"
style="color: var(--calcite-color-status-success)"
scale="s"
></calcite-icon>
<calcite-action appearance="transparent" icon="ellipsis" text="menu" label="menu" slot="actions-end" />
</calcite-block>
`;

export const actionsEndContentStartIconStartEnd = (): string => html`
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
<calcite-block
heading="Valid status"
collapsible
status="valid"
icon-start="pen"
icon-end="pen"
loading
style="width: 500px"
>
<calcite-action appearance="transparent" icon="ellipsis" text="menu" label="menu" slot="actions-end" />
</calcite-block>
`;
100 changes: 93 additions & 7 deletions packages/calcite-components/src/components/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {
connectConditionalSlotComponent,
disconnectConditionalSlotComponent,
} from "../../utils/conditionalSlot";
import { focusFirstTabbable, getSlotted, toAriaBoolean } from "../../utils/dom";
import {
focusFirstTabbable,
getSlotted,
toAriaBoolean,
slotChangeHasAssignedElement,
} from "../../utils/dom";
import {
connectInteractive,
disconnectInteractive,
Expand All @@ -42,13 +47,16 @@ import {
} from "../../utils/loadable";
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../../utils/openCloseComponent";
import { OverlayPositioning } from "../../utils/floating-ui";
import { FlipContext } from "../interfaces";
import { CSS, ICONS, IDS, SLOTS } from "./resources";
import { BlockMessages } from "./assets/block/t9n";

/**
* @slot - A slot for adding custom content.
* @slot icon - A slot for adding a leading header icon with `calcite-icon`.
* @slot control - A slot for adding a single HTML input element in a header.
* @slot actions-end - A slot for adding actionable `calcite-action` elements after the content of the component. It is recommended to use two or fewer actions.
* @slot icon - [Deprecated] A slot for adding a leading header icon with `calcite-icon`. Use `icon-start` instead.
Copy link
Member

Choose a reason for hiding this comment

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

✨🏆✨

* @slot content-start - A slot for adding non-actionable elements before content of the component.
* @slot control - [Deprecated] A slot for adding a single HTML input element in a header. Use `actions-end` instead.
* @slot header-menu-actions - A slot for adding an overflow menu with `calcite-action`s inside a dropdown menu.
*/
@Component({
Expand Down Expand Up @@ -97,6 +105,15 @@ export class Block
*/
@Prop({ reflect: true }) headingLevel: HeadingLevel;

/** Specifies an icon to display at the end of the component. */
@Prop({ reflect: true }) iconEnd: string;

/** Displays the `iconStart` and/or `iconEnd` as flipped when the element direction is right-to-left (`"rtl"`). */
@Prop({ reflect: true }) iconFlipRtl: FlipContext;

/** Specifies an icon to display at the start of the component. */
@Prop({ reflect: true }) iconStart: string;

/**
* When `true`, a busy indicator is displayed.
*/
Expand All @@ -114,6 +131,8 @@ export class Block

/**
* Displays a status-related indicator icon.
*
* @deprecated Use `icon-start` instead.
*/
@Prop({ reflect: true }) status: Status;

Expand Down Expand Up @@ -191,14 +210,18 @@ export class Block

@Element() el: HTMLCalciteBlockElement;

@State() defaultMessages: BlockMessages;

@State() hasContentStart = false;
Elijbet marked this conversation as resolved.
Show resolved Hide resolved

@State() effectiveLocale: string;

@Watch("effectiveLocale")
effectiveLocaleChange(): void {
updateMessages(this, this.effectiveLocale);
}

@State() defaultMessages: BlockMessages;
@State() hasEndActions = false;

openTransitionProp = "opacity";

Expand Down Expand Up @@ -281,6 +304,14 @@ export class Block
this.transitionEl = el;
};

private actionsEndSlotChangeHandler = (event: Event): void => {
this.hasEndActions = slotChangeHasAssignedElement(event);
};

handleContentStartSlotChange = (event: Event): void => {
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
this.hasContentStart = slotChangeHasAssignedElement(event);
};

// --------------------------------------------------------------------------
//
// Render Methods
Expand All @@ -294,7 +325,7 @@ export class Block
return [loading ? <calcite-scrim loading={loading} /> : null, defaultSlot];
}

renderIcon(): VNode[] {
renderLoaderStatusIcon(): VNode[] {
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
const { loading, messages, status } = this;

const hasSlottedIcon = !!getSlotted(this.el, SLOTS.icon);
Expand Down Expand Up @@ -322,6 +353,23 @@ export class Block
) : null;
}

private renderActionsEnd(): VNode {
return (
<div class={CSS.actionsEnd}>
<slot name={SLOTS.actionsEnd} onSlotchange={this.actionsEndSlotChangeHandler} />
</div>
);
}

renderContentStart(): VNode {
const { hasContentStart } = this;
return (
<div class={CSS.contentStart} hidden={!hasContentStart}>
<slot name={SLOTS.contentStart} onSlotchange={this.handleContentStartSlotChange} />
</div>
);
}

renderTitle(): VNode {
const { heading, headingLevel, description } = this;
return heading || description ? (
Expand All @@ -338,10 +386,33 @@ export class Block
const { collapsible, el, loading, open, heading, messages } = this;

const toggleLabel = open ? messages.collapse : messages.expand;
const { iconFlipRtl } = this;

/** Icon scale is not variable as the component does not have a scale property */
const iconStartEl = this.iconStart ? (
<calcite-icon
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
class={CSS.iconStart}
flipRtl={iconFlipRtl === "both" || iconFlipRtl === "start"}
icon={this.iconStart}
key="icon-start"
scale="s"
/>
) : null;
const iconEndEl = this.iconEnd ? (
<calcite-icon
class={CSS.iconEnd}
flipRtl={iconFlipRtl === "both" || iconFlipRtl === "end"}
icon={this.iconEnd}
key="icon-end"
scale="s"
/>
) : null;

const headerContent = (
<header class={CSS.header} id={IDS.header}>
{this.renderIcon()}
{iconStartEl}
{this.renderContentStart()}
{this.renderLoaderStatusIcon()}
{this.renderTitle()}
</header>
);
Expand All @@ -364,8 +435,23 @@ export class Block
title={toggleLabel}
>
{headerContent}
<calcite-icon aria-hidden="true" class={CSS.toggleIcon} icon={collapseIcon} scale="s" />
<div class={CSS.iconEndContainer}>
{iconEndEl}
{this.renderActionsEnd()}
<calcite-icon
aria-hidden="true"
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
class={CSS.toggleIcon}
icon={collapseIcon}
scale="s"
/>
</div>
</button>
) : iconEndEl ? (
<div>
{headerContent}
{this.renderActionsEnd()}
<div class={CSS.iconEndContainer}>{iconEndEl}</div>
</div>
) : (
headerContent
)}
Expand Down
Loading
Loading