Skip to content

Commit 98651e9

Browse files
committed
Fix: page sub components condition to fit with Shopify examples
1 parent 795ecf1 commit 98651e9

File tree

8 files changed

+76
-47
lines changed

8 files changed

+76
-47
lines changed

src/components/ActionMenu/ActionMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
div(
3-
v-if="actions && groups && actions.length && groups.length",
3+
v-if="(actions && actions.length) || (groups && groups.length)",
44
:class="actionMenuClassNames",
55
)
66
RollupActions(

src/components/ActionMenu/components/MenuGroup/MenuGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Popover(
88
)
99
template(#activator)
1010
SecondaryAction(
11-
disclosure,
11+
:disclosure="true",
1212
:icon="icon",
1313
:accessibilityLabel="accessibilityLabel",
1414
@click="handleOpen",

src/components/ActionMenu/components/RollupActions/RollupActions.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
Popover(
3-
v-if="items?.length && sections?.length",
3+
v-if="items?.length || sections?.length",
44
:active="rollupOpen",
55
preferredAlignment="right",
66
@close="toggleRollupOpen",

src/components/Page/components/Header/Header.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ HeaderWrapper(v-bind="props")
1111
ActionMenu(v-bind="actionMenuProps")
1212
slot(name="secondaryActions")
1313
PrimaryAction(
14-
v-if="!isNavigationCollapsed && !conditionDesktopCompact",
14+
v-if="(slots.primaryAction || props.primaryAction) && !isNavigationCollapsed && !conditionDesktopCompact",
1515
v-bind="primaryActionProps",
1616
)
1717
slot(name="primaryAction")
1818

1919
template(#slot4, v-if="conditionSlot4")
2020
PrimaryAction(
21-
v-if="isNavigationCollapsed || conditionDesktopCompact",
21+
v-if="(slots.primaryAction || props.primaryAction) && (isNavigationCollapsed || conditionDesktopCompact)",
2222
v-bind="primaryActionProps",
2323
)
24-
slot(name="primaryAction", v-if="slots.primaryAction")
24+
slot(name="primaryAction")
2525
Pagination(
2626
v-if="!isNavigationCollapsed && !conditionDesktopCompact",
2727
:pagination="pagination",
@@ -110,8 +110,8 @@ const additionalMetadataProps = computed(() => {
110110
111111
const conditionMobileCompact = computed(() => {
112112
return isNavigationCollapsed
113-
&& (props.breadcrumbs && props.breadcrumbs.length > 0)
114-
&& props.title != null
113+
&& (!props.breadcrumbs || !props.breadcrumbs.length)
114+
&& props.title
115115
&& props.title.length <= REALLY_SHORT_TITLE
116116
});
117117

src/components/Page/components/Header/HeaderWrapper.vue

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
<template lang="pug">
22
div(:class="headerClassNames")
3-
template(v-if="slots.slot1 || slots.slot2 || slots.slot3 || slots.slot4")
3+
template(v-if="hasSlot1 || hasSlot2 || hasSlot3 || hasSlot4")
44
div(:class="styles.Row")
55
slot(name="slot1")
66
slot(name="slot2")
7-
template(v-if="slots.slot3 || slots.slot4")
7+
template(v-if="hasSlot3 || hasSlot4")
88
div(:class="styles.RightAlign")
9-
div(v-if="slots.slot3", :class="styles.Actions")
9+
div(
10+
v-if="hasSlot3 && hasSlot4",
11+
:class="styles.Actions"
12+
)
1013
slot(name="slot3")
11-
div(v-if="slots.slot4", :class="styles.Actions")
1214
slot(name="slot4")
13-
template(v-if="slots.slot5 || slots.slot6")
15+
template(v-else)
16+
slot(name="slot3")
17+
slot(name="slot4")
18+
template(v-if="hasSlot5 || hasSlot6")
1419
div(:class="styles.Row")
1520
div(:class="styles.LeftAlign")
1621
slot(name="slot5")
17-
template(v-if="slots.slot6")
22+
template(v-if="hasSlot6")
1823
div(:class="styles.RightAlign")
1924
slot(name="slot6")
2025
</template>
@@ -30,6 +35,7 @@ import type { MenuActionDescriptor } from '@/utilities/interface';
3035
import type { MenuGroupDescriptor } from '@/components/ActionMenu/components/MenuGroup/utils';
3136
import { UseMediaQuery } from '@/utilities/media-query';
3237
import type { ActionMenuProps } from '@/components/ActionMenu/utils';
38+
import hasSlot from '@/utilities/has-slot';
3339
3440
const LONG_TITLE = 34;
3541
@@ -101,17 +107,43 @@ const hasActionMenuMarkup = computed(() => {
101107
|| hasGroupsWithActions(props.actionGroups))
102108
});
103109
104-
const headerClassNames = classNames(
105-
styles.Header,
106-
isSingleRow.value && styles.isSingleRow,
107-
props.titleHidden && styles.titleHidden,
108-
hasNavigationMarkup.value && styles.hasNavigation,
109-
hasActionMenuMarkup.value && styles.hasActionMenu,
110-
isNavigationCollapsed && styles.mobileView,
111-
(!props.breadcrumbs || !props.breadcrumbs.length) && styles.noBreadcrumbs,
112-
props.title && props.title.length < LONG_TITLE && styles.mediumTitle,
113-
props.title && props.title.length > LONG_TITLE && styles.longTitle,
114-
);
110+
const headerClassNames = computed(() => {
111+
return classNames(
112+
styles.Header,
113+
isSingleRow.value && styles.isSingleRow,
114+
props.titleHidden && styles.titleHidden,
115+
hasNavigationMarkup.value && styles.hasNavigation,
116+
hasActionMenuMarkup.value && styles.hasActionMenu,
117+
isNavigationCollapsed && styles.mobileView,
118+
(!props.breadcrumbs || !props.breadcrumbs.length) && styles.noBreadcrumbs,
119+
props.title && props.title.length < LONG_TITLE && styles.mediumTitle,
120+
props.title && props.title.length > LONG_TITLE && styles.longTitle,
121+
);
122+
});
123+
124+
const hasSlot1 = computed(() => {
125+
return hasSlot(slots.slot1);
126+
});
127+
128+
const hasSlot2 = computed(() => {
129+
return hasSlot(slots.slot2);
130+
});
131+
132+
const hasSlot3 = computed(() => {
133+
return hasSlot(slots.slot3);
134+
});
135+
136+
const hasSlot4 = computed(() => {
137+
return hasSlot(slots.slot4);
138+
});
139+
140+
const hasSlot5 = computed(() => {
141+
return hasSlot(slots.slot5);
142+
});
143+
144+
const hasSlot6 = computed(() => {
145+
return hasSlot(slots.slot6);
146+
});
115147
116148
function hasGroupsWithActions(groups: ActionMenuProps['groups'] = []) {
117149
return groups.length === 0

src/components/Page/components/Header/children/ActionMenu.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
slot(v-if="hasSlot")
2+
slot(v-if="hasSlot(slots.default)")
33
ActionMenu(
44
v-else-if="(secondaryActions && secondaryActions.length > 0) || hasGroupsWithActions(actionGroups)",
55
:actions="secondaryActions",
@@ -16,6 +16,7 @@ import type { MenuActionDescriptor } from '@/utilities/interface';
1616
import type { ActionMenuProps } from '@/components/ActionMenu/utils';
1717
import type { MenuGroupDescriptor } from '@/components/ActionMenu/components/MenuGroup/utils';
1818
import { UseMediaQuery } from '@/utilities/media-query';
19+
import hasSlot from '@/utilities/has-slot';
1920
2021
const props = defineProps<{
2122
title?: string;
@@ -28,16 +29,6 @@ const slots = useSlots();
2829
const { useMediaQuery } = UseMediaQuery();
2930
const { isNavigationCollapsed } = useMediaQuery();
3031
31-
const hasSlot = computed(() => {
32-
if (slots.default && slots.default()[0].children) {
33-
if (typeof slots.default()[0].children === 'string') {
34-
return slots.default()[0].children !== 'v-if';
35-
}
36-
return Array.isArray(slots.default()[0].children) && (slots.default()[0].children as []).length > 0;
37-
}
38-
return true;
39-
});
40-
4132
function hasGroupsWithActions(groups: ActionMenuProps['groups'] = []) {
4233
return groups.length === 0
4334
? false

src/components/Page/components/Header/children/PrimaryAction.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
div(:class="styles.PrimaryActionWrapper")
3-
slot(v-if="hasSlot")
3+
slot(v-if="hasSlot(slots.default)")
44
ButtonFrom(
55
v-else,
66
:action="iconOnly",
@@ -17,6 +17,7 @@ import { ButtonFrom } from '@/components/Button';
1717
import styles from '@/classes/Page-Header.json';
1818
import { UseMediaQuery } from '@/utilities/media-query';
1919
import type { IconSource } from '@/utilities/type';
20+
import hasSlot from '@/utilities/has-slot';
2021
2122
interface PrimaryActionProps {
2223
id?: string;
@@ -48,16 +49,6 @@ const iconOnly = computed(() => {
4849
return shouldShowIconOnly(isNavigationCollapsed, props);
4950
});
5051
51-
const hasSlot = computed(() => {
52-
if (slots.default && slots.default()[0].children) {
53-
if (typeof slots.default()[0].children === 'string') {
54-
return slots.default()[0].children !== 'v-if';
55-
}
56-
return Array.isArray(slots.default()[0].children) && (slots.default()[0].children as []).length > 0;
57-
}
58-
return true;
59-
});
60-
6152
function shouldShowIconOnly(
6253
isMobile: boolean,
6354
action: PrimaryActionProps,

src/utilities/has-slot.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Slot } from 'vue';
2+
3+
export default function hasSlot(slot?: Slot) {
4+
if (slot && slot()[0].children) {
5+
if (typeof slot()[0].children === 'string') {
6+
return slot()[0].children !== 'v-if';
7+
}
8+
9+
if (Array.isArray(slot()[0].children)) {
10+
return (slot()[0].children as []).length > 0;
11+
}
12+
}
13+
14+
return true;
15+
}

0 commit comments

Comments
 (0)