Skip to content

Commit 7782b3a

Browse files
committed
feat(@clayui/core): LPD-40160 Add floating menubar action button
1 parent 2bbfd72 commit 7782b3a

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

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

+22-38
Original file line numberDiff line numberDiff line change
@@ -52,44 +52,6 @@ export const Link = React.forwardRef<
5252
},
5353
ref
5454
) => {
55-
if (showIcon) {
56-
return (
57-
<div
58-
{...(otherProps as Omit<
59-
IProps,
60-
keyof React.AnchorHTMLAttributes<HTMLAnchorElement>
61-
> &
62-
React.HTMLAttributes<HTMLDivElement>)}
63-
className={classNames('nav-link', className, {
64-
active,
65-
['collapse-icon']: showIcon,
66-
collapsed,
67-
disabled,
68-
})}
69-
ref={ref as React.Ref<HTMLDivElement>}
70-
>
71-
{children}
72-
<span className="collapse-icon-closed">
73-
<Icon
74-
focusable="false"
75-
role="presentation"
76-
spritemap={spritemap}
77-
symbol="angle-right-small"
78-
/>
79-
</span>
80-
81-
<span className="collapse-icon-open">
82-
<Icon
83-
focusable="false"
84-
role="presentation"
85-
spritemap={spritemap}
86-
symbol="angle-down-small"
87-
/>
88-
</span>
89-
</div>
90-
);
91-
}
92-
9355
return (
9456
<LinkOrButton
9557
{...otherProps}
@@ -104,6 +66,28 @@ export const Link = React.forwardRef<
10466
ref={ref}
10567
>
10668
{children}
69+
70+
{showIcon && (
71+
<>
72+
<span className="collapse-icon-closed">
73+
<Icon
74+
focusable="false"
75+
role="presentation"
76+
spritemap={spritemap}
77+
symbol="angle-right-small"
78+
/>
79+
</span>
80+
81+
<span className="collapse-icon-open">
82+
<Icon
83+
focusable="false"
84+
role="presentation"
85+
spritemap={spritemap}
86+
symbol="angle-down-small"
87+
/>
88+
</span>
89+
</>
90+
)}
10791
</LinkOrButton>
10892
);
10993
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {Keys, setElementFullHeight, useId} from '@clayui/shared';
88
import React, {useContext, useMemo, useRef, useState} from 'react';
99
import {CSSTransition} from 'react-transition-group';
1010

11+
import classNames from 'classnames';
12+
import {ClayButtonWithIcon} from '@clayui/button';
1113
import {Collection} from '../collection';
1214
import {Nav} from '../nav';
1315
import {useVertical} from './context';
@@ -41,6 +43,14 @@ interface IProps<T> extends React.HTMLAttributes<HTMLLIElement> {
4143
*/
4244
keyValue?: React.Key;
4345

46+
/**
47+
* Properties to pass to the menubar action
48+
*/
49+
menubarAction?: {
50+
ariaLabel: string;
51+
title: string;
52+
};
53+
4454
/**
4555
* Internal property.
4656
* @ignore
@@ -89,6 +99,7 @@ export function Item<T extends Record<string, any>>({
8999
initialExpanded,
90100
items,
91101
keyValue,
102+
menubarAction,
92103
onClick,
93104
textValue: _textValue,
94105
...otherProps
@@ -137,6 +148,7 @@ export function Item<T extends Record<string, any>>({
137148
aria-controls={items ? ariaControlsId : undefined}
138149
aria-current={active ? ariaCurrent ?? undefined : undefined}
139150
aria-expanded={items ? isExpanded : undefined}
151+
className={menubarAction ? 'menubar-action-1' : ''}
140152
collapsed={!isExpanded}
141153
href={href}
142154
onClick={(event) => {
@@ -204,6 +216,18 @@ export function Item<T extends Record<string, any>>({
204216
{children}
205217
</Nav.Link>
206218

219+
{menubarAction && (
220+
<ClayButtonWithIcon
221+
aria-label={menubarAction.ariaLabel}
222+
className="menubar-action"
223+
displayType="secondary"
224+
monospaced
225+
size="xs"
226+
symbol="plus"
227+
title={menubarAction.title}
228+
/>
229+
)}
230+
207231
{items && (
208232
<CSSTransition
209233
className={isExpanded ? undefined : 'collapse'}

0 commit comments

Comments
 (0)