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 1 commit
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
33 changes: 16 additions & 17 deletions packages/calcite-components/src/components/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../../utils/openCloseComponent";
import { OverlayPositioning } from "../../utils/floating-ui";
import { FlipContext } from "../interfaces";
import { CSS, ICONS, IDS, SLOTS } from "./resources";
import { CSS, ICONS, IDS, SLOTS, Position } from "./resources";
import { BlockMessages } from "./assets/block/t9n";

/**
Expand Down Expand Up @@ -325,7 +325,7 @@ export class Block
return [loading ? <calcite-scrim loading={loading} /> : null, defaultSlot];
}

renderLoaderStatusIcon(): VNode[] {
private renderLoaderStatusIcon(): VNode[] {
const { loading, messages, status } = this;

const hasSlottedIcon = !!getSlotted(this.el, SLOTS.icon);
Expand Down Expand Up @@ -361,7 +361,7 @@ export class Block
);
}

renderContentStart(): VNode {
private renderContentStart(): VNode {
const { hasContentStart } = this;
return (
<div class={CSS.contentStart} hidden={!hasContentStart}>
Expand All @@ -382,27 +382,28 @@ export class Block
) : null;
}

renderIcon(iconPosition: string): VNode {
private renderIcon(position: Position): VNode {
const { iconFlipRtl } = this;

if (iconPosition === undefined) {
return null;
}

const flipRtl =
iconFlipRtl === "both" || iconPosition === "iconStart"
iconFlipRtl === "both" || position === "start"
? iconFlipRtl === "start"
: iconFlipRtl === "end";

const iconValue = iconPosition === "iconStart" ? this.iconStart : this.iconEnd;
const iconValue = position === "start" ? this.iconStart : this.iconEnd;
const iconClass = position === "start" ? CSS.iconStart : CSS.iconEnd;

if (!iconValue) {
return undefined;
}

/** Icon scale is not variable as the component does not have a scale property */
return (
<calcite-icon
class={CSS[iconPosition]}
class={iconClass}
flipRtl={flipRtl}
icon={iconValue}
key={CSS[iconPosition]}
key={iconClass}
scale="s"
/>
);
Expand All @@ -415,7 +416,7 @@ export class Block

const headerContent = (
<header class={CSS.header} id={IDS.header}>
{this.renderIcon(this.iconStart ? "iconStart" : undefined)}
{this.renderIcon("start")}
{this.renderContentStart()}
{this.renderLoaderStatusIcon()}
{this.renderTitle()}
Expand All @@ -441,16 +442,14 @@ export class Block
>
{headerContent}
<div class={CSS.iconEndContainer}>
{this.renderIcon(this.iconEnd ? "iconEnd" : undefined)}
{this.renderIcon("end")}
<calcite-icon class={CSS.toggleIcon} icon={collapseIcon} scale="s" />
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
</div>
</button>
) : this.iconEnd ? (
<div>
{headerContent}
<div class={CSS.iconEndContainer}>
{this.renderIcon(this.iconEnd ? "iconEnd" : undefined)}
</div>
<div class={CSS.iconEndContainer}>{this.renderIcon("end")}</div>
</div>
) : (
headerContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ export const ICONS = {
valid: "check-circle",
invalid: "exclamation-mark-triangle",
};

export type Position = "start" | "end";
Elijbet marked this conversation as resolved.
Show resolved Hide resolved
Loading