Skip to content

Commit 8cbefc8

Browse files
committed
feat(@clayui/core): LPD-40160 Add displayType primary for VerticalNav for CMS Product Menu variant
1 parent 5144840 commit 8cbefc8

File tree

2 files changed

+101
-65
lines changed

2 files changed

+101
-65
lines changed

packages/clay-core/src/nav/Link.tsx

+34-22
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,40 @@ export const Link = React.forwardRef<
5252
},
5353
ref
5454
) => {
55+
if (showIcon) {
56+
return (
57+
<div
58+
{...otherProps}
59+
className={classNames('nav-link', className, {
60+
active,
61+
['collapse-icon']: showIcon,
62+
collapsed,
63+
disabled,
64+
})}
65+
ref={ref}
66+
>
67+
{children}
68+
<span className="collapse-icon-closed">
69+
<Icon
70+
focusable="false"
71+
role="presentation"
72+
spritemap={spritemap}
73+
symbol="angle-right-small"
74+
/>
75+
</span>
76+
77+
<span className="collapse-icon-open">
78+
<Icon
79+
focusable="false"
80+
role="presentation"
81+
spritemap={spritemap}
82+
symbol="angle-down-small"
83+
/>
84+
</span>
85+
</div>
86+
);
87+
}
88+
5589
return (
5690
<LinkOrButton
5791
{...otherProps}
@@ -66,28 +100,6 @@ export const Link = React.forwardRef<
66100
ref={ref}
67101
>
68102
{children}
69-
70-
{showIcon && (
71-
<>
72-
<span className="collapse-icon-closed">
73-
<Icon
74-
focusable="false"
75-
role="presentation"
76-
spritemap={spritemap}
77-
symbol="caret-right"
78-
/>
79-
</span>
80-
81-
<span className="collapse-icon-open">
82-
<Icon
83-
focusable="false"
84-
role="presentation"
85-
spritemap={spritemap}
86-
symbol="caret-bottom"
87-
/>
88-
</span>
89-
</>
90-
)}
91103
</LinkOrButton>
92104
);
93105
}

packages/clay-core/src/vertical-nav/VerticalNav.tsx

+67-43
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ const Trigger = ({
3434
</Button>
3535
);
3636

37+
const Menubar = ({collection, value}) => {
38+
return (
39+
<Nav aria-orientation="vertical" nested role="menubar">
40+
<VerticalNavContext.Provider value={value}>
41+
<Collection collection={collection} />
42+
</VerticalNavContext.Provider>
43+
</Nav>
44+
);
45+
};
46+
3747
type Props<T extends Record<string, any> | string> = {
3848
/**
3949
* Flag to define which item has the active state/current page.
@@ -54,6 +64,11 @@ type Props<T extends Record<string, any> | string> = {
5464
*/
5565
children?: React.ReactNode | ChildrenFunction<T, null>;
5666

67+
/**
68+
* Determines the Vertical Nav variant to use.
69+
*/
70+
displayType?: null | 'primary';
71+
5772
/**
5873
* Flag to activate the Decorator variation.
5974
*/
@@ -137,6 +152,7 @@ function VerticalNav<T extends Record<string, any> | string>({
137152
activation = 'manual',
138153
children,
139154
decorated,
155+
displayType,
140156
defaultExpandedKeys = new Set(),
141157
expandedKeys: externalExpandedKeys,
142158
itemAriaCurrent: ariaCurrent = true,
@@ -238,57 +254,65 @@ function VerticalNav<T extends Record<string, any> | string>({
238254
return depthActive(items as Array<Record<string, any>>);
239255
}, [active, items]);
240256

257+
const menubarValue = {
258+
activeKey:
259+
active && collection.hasItem(active)
260+
? active
261+
: hasDepthActive
262+
? null
263+
: undefined,
264+
ariaCurrent: ariaCurrent ? 'page' : null,
265+
childrenRoot: childrenRootRef,
266+
close,
267+
expandedKeys,
268+
firstKey: collection.getFirstItem().key,
269+
open,
270+
spritemap,
271+
toggle,
272+
};
273+
241274
return (
242275
<nav
243276
className={classNames('menubar menubar-transparent', {
244277
['menubar-decorated']: decorated,
278+
['menubar-primary']: displayType === 'primary',
245279
['menubar-vertical-expand-lg']: large,
246-
['menubar-vertical-expand-md']: !large,
280+
['menubar-vertical-expand-md']:
281+
!large && displayType !== 'primary',
247282
})}
248283
>
249-
<CustomTrigger onClick={() => setIsOpen(!isOpen)}>
250-
<span className="inline-item inline-item-before">
251-
{triggerLabel}
252-
</span>
253-
254-
<Icon
255-
focusable="false"
256-
role="presentation"
257-
spritemap={spritemap}
258-
symbol="caret-bottom"
259-
/>
260-
</CustomTrigger>
261-
262-
<div
263-
{...navigationProps}
264-
className={classNames('collapse menubar-collapse', {
265-
show: isOpen,
266-
})}
267-
ref={containerRef}
268-
>
269-
<Nav aria-orientation="vertical" nested role="menubar">
270-
<VerticalNavContext.Provider
271-
value={{
272-
activeKey:
273-
active && collection.hasItem(active)
274-
? active
275-
: hasDepthActive
276-
? null
277-
: undefined,
278-
ariaCurrent: ariaCurrent ? 'page' : null,
279-
childrenRoot: childrenRootRef,
280-
close,
281-
expandedKeys,
282-
firstKey: collection.getFirstItem().key,
283-
open,
284-
spritemap,
285-
toggle,
286-
}}
284+
{displayType !== 'primary' && (
285+
<>
286+
<CustomTrigger onClick={() => setIsOpen(!isOpen)}>
287+
<span className="inline-item inline-item-before">
288+
{triggerLabel}
289+
</span>
290+
291+
<Icon
292+
focusable="false"
293+
role="presentation"
294+
spritemap={spritemap}
295+
symbol="caret-bottom"
296+
/>
297+
</CustomTrigger>
298+
299+
<div
300+
{...navigationProps}
301+
className={classNames('collapse menubar-collapse', {
302+
show: isOpen,
303+
})}
304+
ref={containerRef}
287305
>
288-
<Collection<T> collection={collection} />
289-
</VerticalNavContext.Provider>
290-
</Nav>
291-
</div>
306+
<Menubar collection={collection} value={menubarValue} />
307+
</div>
308+
</>
309+
)}
310+
311+
{displayType === 'primary' && (
312+
<>
313+
<Menubar collection={collection} value={menubarValue} />
314+
</>
315+
)}
292316
</nav>
293317
);
294318
}

0 commit comments

Comments
 (0)