Skip to content

Commit

Permalink
feat(tile): add content-top and content-bottom slots, deprecate conte…
Browse files Browse the repository at this point in the history
…nt-start and content-end slots (#8984)

**Related Issue:** #3462 

## Summary

This PR adds 2 new slots `content-top` and `content-bottom` to replace
the now deprecated `content-start` and `content-end` slots.

---------

Co-authored-by: Erik Harper <eriklharper@pm.me>
  • Loading branch information
eriklharper and Erik Harper committed Mar 26, 2024
1 parent ee72777 commit eb000d8
Show file tree
Hide file tree
Showing 6 changed files with 789 additions and 115 deletions.
16 changes: 16 additions & 0 deletions packages/calcite-components/src/components.d.ts
Expand Up @@ -5007,6 +5007,10 @@ export namespace Components {
*/
"wrap": "soft" | "hard";
}
/**
* @deprecated use `content-top` slot instead
* @deprecated use `content-bottom` slot instead
*/
interface CalciteTile {
/**
* When `true`, the component is active.
Expand Down Expand Up @@ -7239,6 +7243,10 @@ declare global {
prototype: HTMLCalciteTextAreaElement;
new (): HTMLCalciteTextAreaElement;
};
/**
* @deprecated use `content-top` slot instead
* @deprecated use `content-bottom` slot instead
*/
interface HTMLCalciteTileElement extends Components.CalciteTile, HTMLStencilElement {
}
var HTMLCalciteTileElement: {
Expand Down Expand Up @@ -12620,6 +12628,10 @@ declare namespace LocalJSX {
*/
"wrap"?: "soft" | "hard";
}
/**
* @deprecated use `content-top` slot instead
* @deprecated use `content-bottom` slot instead
*/
interface CalciteTile {
/**
* When `true`, the component is active.
Expand Down Expand Up @@ -13309,6 +13321,10 @@ declare module "@stencil/core" {
"calcite-table-row": LocalJSX.CalciteTableRow & JSXBase.HTMLAttributes<HTMLCalciteTableRowElement>;
"calcite-tabs": LocalJSX.CalciteTabs & JSXBase.HTMLAttributes<HTMLCalciteTabsElement>;
"calcite-text-area": LocalJSX.CalciteTextArea & JSXBase.HTMLAttributes<HTMLCalciteTextAreaElement>;
/**
* @deprecated use `content-top` slot instead
* @deprecated use `content-bottom` slot instead
*/
"calcite-tile": LocalJSX.CalciteTile & JSXBase.HTMLAttributes<HTMLCalciteTileElement>;
"calcite-tile-group": LocalJSX.CalciteTileGroup & JSXBase.HTMLAttributes<HTMLCalciteTileGroupElement>;
"calcite-tile-select": LocalJSX.CalciteTileSelect & JSXBase.HTMLAttributes<HTMLCalciteTileSelectElement>;
Expand Down
5 changes: 3 additions & 2 deletions packages/calcite-components/src/components/tile/resources.ts
Expand Up @@ -2,13 +2,14 @@ export const CSS = {
container: "container",
content: "content",
contentContainer: "content-container",
contentSlotContainer: "content-slot-container",
description: "description",
heading: "heading",
largeVisual: "large-visual",
};

export const SLOTS = {
contentStart: "content-start",
contentBottom: "content-bottom",
contentEnd: "content-end",
contentStart: "content-start",
contentTop: "content-top",
};
26 changes: 13 additions & 13 deletions packages/calcite-components/src/components/tile/tile.scss
Expand Up @@ -21,6 +21,7 @@
min-inline-size: 140px;

.container {
align-items: flex-start;
background-color: var(--calcite-tile-background-color);
block-size: var(--calcite-container-size-content-fluid);
box-sizing: border-box;
Expand All @@ -36,22 +37,15 @@

.content-container {
display: flex;
gap: var(--calcite-spacing-md);
inline-size: 100%;
outline-color: transparent;
padding: 0;
inline-size: 100%;
}

.content-slot-container {
align-items: center;
.content {
display: flex;

&:first-child {
padding-inline: 0 0.75rem;
}

&:last-child {
padding-inline: 0.75rem 0;
}
flex-direction: column;
}

.heading {
Expand Down Expand Up @@ -89,12 +83,17 @@
align-items: center;
text-align: center;
}
slot[name="content-start"]::slotted(*),
slot[name="content-end"]::slotted(*) {
align-self: center;
}
}

:host([scale="s"]) {
max-inline-size: 400px;
min-inline-size: 100px;
.container {
.container,
.content-container {
gap: var(--calcite-spacing-sm);
}
.heading {
Expand All @@ -110,7 +109,8 @@
:host([scale="l"]) {
max-inline-size: 520px;
min-inline-size: 160px;
.container {
.container,
.content-container {
gap: var(--calcite-spacing-xl);
}
.heading {
Expand Down
414 changes: 379 additions & 35 deletions packages/calcite-components/src/components/tile/tile.stories.ts

Large diffs are not rendered by default.

39 changes: 10 additions & 29 deletions packages/calcite-components/src/components/tile/tile.tsx
@@ -1,4 +1,4 @@
import { Component, Element, h, Prop, State, VNode } from "@stencil/core";
import { Component, Element, h, Prop, VNode } from "@stencil/core";
import {
connectInteractive,
disconnectInteractive,
Expand All @@ -8,11 +8,12 @@ import {
} from "../../utils/interactive";
import { CSS, SLOTS } from "./resources";
import { Alignment, Scale } from "../interfaces";
import { slotChangeHasAssignedElement } from "../../utils/dom";

/**
* @slot content-start - A slot for adding non-actionable elements before the component's content.
* @slot content-end - A slot for adding non-actionable elements after the component's content.
* @slot content-top - A slot for adding non-actionable elements above the component's content. Content slotted here will render in place of the `icon` property.
* @slot content-bottom - A slot for adding non-actionable elements below the component's content.
* @slot content-start - [Deprecated] use `content-top` slot instead. A slot for adding non-actionable elements before the component's content.
* @slot content-end - [Deprecated] use `content-bottom` slot instead. A slot for adding non-actionable elements after the component's content.
*/
@Component({
tag: "calcite-tile",
Expand Down Expand Up @@ -88,24 +89,6 @@ export class Tile implements InteractiveComponent {

@Element() el: HTMLCalciteTileElement;

@State() hasContentStart = false;

@State() hasContentEnd = false;

// --------------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------------

private handleContentStartSlotChange = (event: Event): void => {
this.hasContentStart = slotChangeHasAssignedElement(event);
};

private handleContentEndSlotChange = (event: Event): void => {
this.hasContentEnd = slotChangeHasAssignedElement(event);
};

// --------------------------------------------------------------------------
//
// Lifecycle
Expand All @@ -131,24 +114,22 @@ export class Tile implements InteractiveComponent {
// --------------------------------------------------------------------------

renderTile(): VNode {
const { icon, hasContentStart, hasContentEnd, heading, description, iconFlipRtl } = this;
const { icon, heading, description, iconFlipRtl } = this;
const isLargeVisual = heading && icon && !description;

return (
<div class={{ [CSS.container]: true, [CSS.largeVisual]: isLargeVisual }}>
<slot name={SLOTS.contentTop} />
{icon && <calcite-icon flipRtl={iconFlipRtl} icon={icon} scale="l" />}
<div class={CSS.contentContainer}>
<div class={{ [CSS.contentSlotContainer]: hasContentStart }}>
<slot name={SLOTS.contentStart} onSlotchange={this.handleContentStartSlotChange} />
</div>
<slot name={SLOTS.contentStart} />
<div class={CSS.content}>
{heading && <div class={CSS.heading}>{heading}</div>}
{description && <div class={CSS.description}>{description}</div>}
</div>
<div class={{ [CSS.contentSlotContainer]: hasContentEnd }}>
<slot name={SLOTS.contentEnd} onSlotchange={this.handleContentEndSlotChange} />
</div>
<slot name={SLOTS.contentEnd} />
</div>
<slot name={SLOTS.contentBottom} />
</div>
);
}
Expand Down

0 comments on commit eb000d8

Please sign in to comment.