Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
}
}
}
}
}
146 changes: 146 additions & 0 deletions packages/visual-editor/src/components/header/ExpandedHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,152 @@ const tests: ComponentTest[] = [
},
version: 48,
},
{
name: "version 50 props - no logo",
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no version 50?

document: {},
props: {
styles: {
maxWidth: "theme",
headerPosition: "scrollsWithPage",
},
slots: {
PrimaryHeaderSlot: [
{
type: "PrimaryHeaderSlot",
props: {
styles: {
backgroundColor: backgroundColors.background6.value,
},
slots: {
LogoSlot: [],
LinksSlot: [
{
type: "HeaderLinks",
props: {
data: {
links: [
{
linkType: "URL",
label: {
en: "Primary Header Link",
hasLocalizedValue: "true",
},
link: "#",
},
{
linkType: "URL",
label: {
en: "Primary Header Link",
hasLocalizedValue: "true",
},
link: "#",
},
],
},
parentData: {
type: "Primary",
},
},
},
],
PrimaryCTASlot: [
{
type: "CTASlot",
props: {
data: {
show: true,
entityField: {
field: "",
constantValue: {
label: { en: "CTA", hasLocalizedValue: "true" },
link: "#",
linkType: "URL",
},
constantValueEnabled: true,
},
},
styles: {
displayType: "textAndLink",
variant: "primary",
},
},
},
],
SecondaryCTASlot: [
{
type: "CTASlot",
props: {
data: {
show: true,
entityField: {
field: "",
constantValue: {
label: {
en: "Secondary CTA",
hasLocalizedValue: "true",
},
link: "#",
linkType: "URL",
},
constantValueEnabled: true,
},
},
styles: {
displayType: "textAndLink",
variant: "secondary",
},
},
},
],
},
},
},
],
SecondaryHeaderSlot: [
{
type: "SecondaryHeaderSlot",
props: {
data: {
show: true,
showLanguageDropdown: false,
},
styles: {
backgroundColor: backgroundColors.background4.value,
},
slots: {
LinksSlot: [
{
type: "HeaderLinks",
props: {
data: {
links: [
{
linkType: "URL",
label: {
en: "Secondary Header Link",
hasLocalizedValue: "true",
},
link: "#",
},
],
},
parentData: {
type: "Secondary",
},
},
},
],
},
},
},
],
},
analytics: {
scope: "expandedHeader",
},
},
version: 50,
},
];

describe("ExpandedHeader", async () => {
Expand Down
23 changes: 21 additions & 2 deletions packages/visual-editor/src/components/header/PrimaryHeaderSlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface PrimaryHeaderSlotProps {
conditionalRender?: {
navContent: boolean;
CTAs: boolean;
hasLogoImage?: boolean;
};

/** @internal */
Expand Down Expand Up @@ -88,15 +89,23 @@ const PrimaryHeaderSlotWrapper: PuckComponent<PrimaryHeaderSlotProps> = ({
const { t } = useTranslation();

const [isMobileMenuOpen, setMobileMenuOpen] = React.useState<boolean>(false);

const containerRef = React.useRef<HTMLDivElement>(null);
const contentRef = React.useRef<HTMLDivElement>(null);
const showHamburger = useOverflow(containerRef, contentRef);

const hasImage = conditionalRender?.hasLogoImage;

const showCTAs = puck.isEditing || conditionalRender?.CTAs;
const showNavContent = puck.isEditing || conditionalRender?.navContent;

const LogoSlot = <slots.LogoSlot style={{ height: "auto", width: "auto" }} />;
const LogoSlot = (
<div
className="flex-shrink-0"
style={{ minHeight: hasImage ? undefined : "100px" }}
>
<slots.LogoSlot style={{ height: "auto", width: "auto" }} />
</div>
);

const navContent = (
<>
Expand Down Expand Up @@ -323,6 +332,15 @@ export const PrimaryHeaderSlot: ComponentConfig<{
return data;
}

const logoSlotItem = data.props.slots.LogoSlot?.[0];

const hasLogoImage =
logoSlotItem?.type === "ImageSlot" &&
!!(
logoSlotItem?.props?.data?.image?.constantValue ||
logoSlotItem?.props?.data?.image?.field
);

// Check if PrimaryCTA has data to display
const primaryCTA = resolveComponentData(
data.props.slots.PrimaryCTASlot[0]?.props.data
Expand Down Expand Up @@ -366,6 +384,7 @@ export const PrimaryHeaderSlot: ComponentConfig<{
conditionalRender: {
navContent: showNavContent,
CTAs: showPrimaryCTA || showSecondaryCTA,
hasLogoImage,
},
},
};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@
"rollup": "npm:@rollup/wasm-node"
}
}
}
}