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

fix(tip): fix rendering tied to named-slot content #10470

Merged
merged 3 commits into from
Oct 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const CSS = {
imageFrame: "image-frame",
content: "content",
info: "info",
infoNoThumbnail: "info--no-thumbnail",
};

export const ICONS = {
Expand Down
7 changes: 4 additions & 3 deletions packages/calcite-components/src/components/tip/tip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
.info {
@apply py-0 px-4;
inline-size: 70%;
&:only-child {
@apply w-full px-0;
}
}

.info--no-thumbnail {
@apply w-full px-0;
}

::slotted(p) {
Expand Down
29 changes: 13 additions & 16 deletions packages/calcite-components/src/components/tip/tip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import {
VNode,
Watch,
} from "@stencil/core";
import {
ConditionalSlotComponent,
connectConditionalSlotComponent,
disconnectConditionalSlotComponent,
} from "../../utils/conditionalSlot";
import { getSlotted } from "../../utils/dom";
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import {
connectMessages,
Expand All @@ -26,6 +20,7 @@ import {
} from "../../utils/t9n";
import { constrainHeadingLevel, Heading, HeadingLevel } from "../functional/Heading";
import { logger } from "../../utils/logger";
import { slotChangeHasAssignedElement } from "../../utils/dom";
import { TipMessages } from "./assets/tip/t9n";
import { CSS, ICONS, SLOTS } from "./resources";

Expand All @@ -46,7 +41,7 @@ logger.deprecated("component", {
shadow: true,
assetsDirs: ["assets"],
})
export class Tip implements ConditionalSlotComponent, LocalizedComponent, T9nComponent {
export class Tip implements LocalizedComponent, T9nComponent {
// --------------------------------------------------------------------------
//
// Properties
Expand Down Expand Up @@ -108,6 +103,8 @@ export class Tip implements ConditionalSlotComponent, LocalizedComponent, T9nCom

@State() defaultMessages: TipMessages;

@State() hasThumbnail = false;

@State() effectiveLocale = "";

@Watch("effectiveLocale")
Expand All @@ -122,7 +119,6 @@ export class Tip implements ConditionalSlotComponent, LocalizedComponent, T9nCom
// --------------------------------------------------------------------------

connectedCallback(): void {
connectConditionalSlotComponent(this);
connectLocalized(this);
connectMessages(this);
}
Expand All @@ -132,7 +128,6 @@ export class Tip implements ConditionalSlotComponent, LocalizedComponent, T9nCom
}

disconnectedCallback(): void {
disconnectConditionalSlotComponent(this);
disconnectLocalized(this);
disconnectMessages(this);
}
Expand Down Expand Up @@ -160,6 +155,10 @@ export class Tip implements ConditionalSlotComponent, LocalizedComponent, T9nCom
this.calciteTipDismiss.emit();
};

private handleThumbnailSlotChange = (event: Event): void => {
this.hasThumbnail = slotChangeHasAssignedElement(event);
};

// --------------------------------------------------------------------------
//
// Render Methods
Expand Down Expand Up @@ -195,18 +194,16 @@ export class Tip implements ConditionalSlotComponent, LocalizedComponent, T9nCom
}

renderImageFrame(): VNode {
const { el } = this;

return getSlotted(el, SLOTS.thumbnail) ? (
<div class={CSS.imageFrame} key="thumbnail">
<slot name={SLOTS.thumbnail} />
return (
<div class={CSS.imageFrame} hidden={!this.hasThumbnail} key="thumbnail">
<slot name={SLOTS.thumbnail} onSlotchange={this.handleThumbnailSlotChange} />
</div>
) : null;
);
}

renderInfoNode(): VNode {
return (
<div class={CSS.info}>
<div class={{ [CSS.info]: true, [CSS.infoNoThumbnail]: !this.hasThumbnail }}>
<slot />
</div>
);
Expand Down
10 changes: 5 additions & 5 deletions packages/calcite-components/src/demos/tip-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<img
slot="thumbnail"
width="1000"
height="600"
height="200"
src="./_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
Expand Down Expand Up @@ -89,7 +89,7 @@
<img
slot="thumbnail"
width="1000"
height="600"
height="200"
Copy link
Member

Choose a reason for hiding this comment

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

Are these tweaks cosmetic? It's fine if they are, just for my understanding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah just cosmetic. they looked rather tall. 😝

src="./_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
Expand Down Expand Up @@ -125,7 +125,7 @@
<img
slot="thumbnail"
width="1000"
height="600"
height="200"
src="./_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
Expand All @@ -145,7 +145,7 @@
<img
slot="thumbnail"
width="1000"
height="600"
height="200"
src="./_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
Expand All @@ -160,7 +160,7 @@
<img
slot="thumbnail"
width="1000"
height="600"
height="200"
src="./_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
Expand Down
28 changes: 14 additions & 14 deletions packages/calcite-components/src/demos/tip/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ <h2>With thumbnail</h2>
<img
slot="thumbnail"
width="1000"
height="600"
src="./_assets/images/placeholder.svg"
height="200"
src="../_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
<p>
Expand Down Expand Up @@ -51,8 +51,8 @@ <h2>Without heading</h2>
<img
slot="thumbnail"
width="1000"
height="600"
src="./_assets/images/placeholder.svg"
height="200"
src="../_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
<p>This tip is how a tip should appear without a dismissible button as well as without a heading.</p>
Expand All @@ -67,8 +67,8 @@ <h2>Without heading, close-disabled</h2>
<img
slot="thumbnail"
width="1000"
height="600"
src="./_assets/images/placeholder.svg"
height="200"
src="../_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
<p>This tip is how a tip should appear without a dismissible button as well as without a heading.</p>
Expand Down Expand Up @@ -103,8 +103,8 @@ <h2>Tip Group with thumbnails</h2>
<img
slot="thumbnail"
width="1000"
height="600"
src="./_assets/images/placeholder.svg"
height="200"
src="../_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
<p>
Expand All @@ -118,8 +118,8 @@ <h2>Tip Group with thumbnails</h2>
<img
slot="thumbnail"
width="1000"
height="600"
src="./_assets/images/placeholder.svg"
height="200"
src="../_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
<p>
Expand All @@ -137,8 +137,8 @@ <h2>Tip Group with thumbnails, close-disabled</h2>
<img
slot="thumbnail"
width="1000"
height="600"
src="./_assets/images/placeholder.svg"
height="200"
src="../_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
<p>
Expand All @@ -152,8 +152,8 @@ <h2>Tip Group with thumbnails, close-disabled</h2>
<img
slot="thumbnail"
width="1000"
height="600"
src="./_assets/images/placeholder.svg"
height="200"
src="../_assets/images/placeholder.svg"
alt="This is an image of nature."
/>
<p>
Expand Down
Loading