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

ActionList/ActionMenu API: Add trailingVisual alias #1521

Merged
merged 6 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 14 additions & 1 deletion src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,22 @@ export interface ItemProps extends SxProp {
leadingVisual?: React.FunctionComponent<IconProps>

/**
* @deprecated Use `trailingVisual` instead
* Icon (or similar) positioned after `Item` text.
*/
trailingIcon?: React.FunctionComponent<IconProps>

/**
* @deprecated Use `trailingVisual` instead
* Text positioned after `Item` text and optional trailing icon.
*/
trailingText?: string

/**
* Icon or text positioned after `Item` text.
*/
trailingVisual?: React.FunctionComponent<IconProps> | string

/**
* Style variations associated with various `Item` types.
*
Expand Down Expand Up @@ -343,6 +350,7 @@ export const Item = React.forwardRef((itemProps, ref) => {
selectionVariant,
leadingVisual: LeadingVisual,
trailingIcon: TrailingIcon,
trailingVisual: TrailingVisual,
trailingText,
variant = 'default',
showDivider,
Expand Down Expand Up @@ -469,7 +477,12 @@ export const Item = React.forwardRef((itemProps, ref) => {
</DescriptionContainer>
) : null}
</MainContent>
{TrailingIcon || trailingText ? (
{/* backward compatibility: prefer TrailingVisual but fallback to TrailingIcon */}
{TrailingVisual ? (
<TrailingContent variant={variant} disabled={disabled}>
{typeof TrailingVisual === 'function' ? <TrailingVisual /> : TrailingVisual}
</TrailingContent>
) : TrailingIcon || trailingText ? (
<TrailingContent variant={variant} disabled={disabled}>
{trailingText}
{TrailingIcon && <TrailingIcon />}
Expand Down
7 changes: 3 additions & 4 deletions src/stories/ActionList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,20 @@ export function SizeStressTestingStory(): JSX.Element {
text: 'Block Description. Long text should wrap',
description: 'This description is long, but it is block so it wraps',
descriptionVariant: 'block',
trailingIcon: ArrowLeftIcon,

trailingVisual: ArrowLeftIcon,
showDivider: true
},
{
leadingVisual: ArrowRightIcon,
text: 'Inline Description',
description: 'This description gets truncated because it is inline',
trailingIcon: ArrowLeftIcon,
trailingVisual: ArrowLeftIcon,
showDivider: true
},
{
leadingVisual: ArrowRightIcon,
text: 'Really long text without a description should wrap',
trailingIcon: ArrowLeftIcon,
trailingIcon: ArrowLeftIcon, // backward compatible
showDivider: true
}
]}
Expand Down
16 changes: 14 additions & 2 deletions src/stories/ActionMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,20 @@ export function ComplexListStory(): JSX.Element {
text: 'repo:github/github',
groupId: '1',
renderItem: props => <ActionList.Item style={{color: 'rebeccapurple'}} {...props} />,
trailingText: '⌘S',
trailingIcon: ArrowRightIcon
trailingVisual: () => (
<>
⌘S
<ArrowRightIcon />
</>
)
},
{
leadingVisual: SearchIcon,
text: 'repo:github/github',
groupId: '1',
renderItem: props => <ActionList.Item style={{color: 'rebeccapurple'}} {...props} />,
trailingText: '⌘S', // backward compatible
trailingIcon: ArrowRightIcon // backward compatible
},
{
leadingVisual: NoteIcon,
Expand Down