Skip to content

Commit

Permalink
spike on allowing text
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 committed Jun 10, 2024
1 parent 96a9ef3 commit bc1a30a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 31 deletions.
24 changes: 18 additions & 6 deletions packages/react/src/ActionList/ActionList.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -744,23 +744,35 @@ export const WithTrailingAction = () => {
<FileDirectoryIcon />
</ActionList.LeadingVisual>
Item 1 (with default TrailingAction)
<ActionList.TrailingAction aria-label="Expand sidebar" icon={ArrowLeftIcon} />
<ActionList.TrailingAction label="Expand sidebar" icon={ArrowLeftIcon} />
</ActionList.Item>
<ActionList.Item>
Item 2 (with link TrailingAction)
<ActionList.TrailingAction as="a" href="#" aria-label="Some action 1" icon={ArrowRightIcon} />
<ActionList.TrailingAction as="a" href="#" label="Some action 1" icon={ArrowRightIcon} />
</ActionList.Item>
<ActionList.Item>
Item 3<ActionList.Description>This is an inline description.</ActionList.Description>
<ActionList.TrailingAction aria-label="Some action 2" icon={BookIcon} />
<ActionList.TrailingAction label="Some action 2" icon={BookIcon} />
</ActionList.Item>
<ActionList.Item>
Item 4<ActionList.Description variant="block">This is a block description.</ActionList.Description>
<ActionList.TrailingAction aria-label="Some action 2" icon={BookIcon} />
<ActionList.TrailingAction label="Some action 3" icon={BookIcon} />
</ActionList.Item>
<ActionList.Item>
Item 5<ActionList.Description variant="block">This is a block description.</ActionList.Description>
<ActionList.TrailingAction label="Some action 4" />
</ActionList.Item>
<ActionList.Item>
Item 6
<ActionList.TrailingAction href="#" as="a" label="Some action 5" />
</ActionList.Item>
<ActionList.Item>
Item 7
<ActionList.TrailingAction showOnHover href="#" as="a" label="Some action 5" />
</ActionList.Item>
<ActionList.LinkItem href="#">
LinkItem 1<ActionList.Description>with TrailingAction shown on hover</ActionList.Description>
<ActionList.TrailingAction aria-label="Some action 3" icon={BookIcon} showOnHover />
<ActionList.TrailingAction label="Some action 6" icon={BookIcon} showOnHover />
</ActionList.LinkItem>
<ActionList.LinkItem href="#">
LinkItem 2<ActionList.Description>with TrailingVisual</ActionList.Description>
Expand All @@ -770,7 +782,7 @@ export const WithTrailingAction = () => {
</ActionList.LinkItem>
<ActionList.Item inactiveText="Unavailable due to an outage">
Inactive Item<ActionList.Description>With TrailingAction</ActionList.Description>
<ActionList.TrailingAction as="a" href="#" aria-label="Some action 4" icon={ArrowRightIcon} />
<ActionList.TrailingAction as="a" href="#" label="Some action 4" icon={ArrowRightIcon} />
</ActionList.Item>
</ActionList>
</FeatureFlags>
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
'[data-component="IconButton"]': {
display: 'flex',
},
// TODO: How do we target Button?
'[data-component="Button"]': {
display: 'flex',
},
},
},
}
Expand Down
73 changes: 48 additions & 25 deletions packages/react/src/ActionList/TrailingAction.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,64 @@
import React, {forwardRef} from 'react'
import Box from '../Box'
import {IconButton} from '../Button'
import {Button, IconButton} from '../Button'
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'

export type ActionListTrailingActionProps = {
as?: 'button' | 'a'
href?: string
icon: React.ElementType
'aria-label': string
icon?: React.ElementType
label: string
showOnHover?: boolean
}

export const TrailingAction = forwardRef(
({as = 'button', icon, 'aria-label': ariaLabel, showOnHover = false, href = null}, forwardedRef) => {
return (
<Box
as="span"
sx={{
flexShrink: 0,
}}
>
<IconButton
as={as}
aria-label={ariaLabel}
icon={icon}
variant="invisible"
unsafeDisableTooltip={false}
tooltipDirection="w"
({as = 'button', icon, label, showOnHover = false, href = null}, forwardedRef) => {
if (!icon) {
return (
<Box
as="span"
sx={{
display: showOnHover ? 'none' : 'flex',
flexShrink: 0,
}}
href={href}
// @ts-expect-error StyledButton wants both Anchor and Button refs
ref={forwardedRef}
/>
</Box>
)
>
{/* @ts-expect-error TODO: Fix this */}
<Button
variant="invisible"
as={as}
href={href}
sx={{
display: showOnHover ? 'none' : 'flex',
}}
>
{label}
</Button>
</Box>
)
} else {
return (
<Box
as="span"
sx={{
flexShrink: 0,
}}
>
<IconButton
as={as}
aria-label={label}
icon={icon}
variant="invisible"
unsafeDisableTooltip={false}
tooltipDirection="w"
sx={{
display: showOnHover ? 'none' : 'flex',
}}
href={href}
// @ts-expect-error StyledButton wants both Anchor and Button refs
ref={forwardedRef}
/>
</Box>
)
}
},
) as PolymorphicForwardRefComponent<'button' | 'a', ActionListTrailingActionProps>

Expand Down

0 comments on commit bc1a30a

Please sign in to comment.