Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/modern-cooks-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

fix(Banner): rewrite PrimaryAction & SecondaryAction types
27 changes: 17 additions & 10 deletions packages/react/src/Banner/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {clsx} from 'clsx'
import React, {useEffect} from 'react'
import React, {forwardRef, useEffect} from 'react'
import styled from 'styled-components'
import {AlertIcon, InfoIcon, StopIcon, CheckCircleIcon, XIcon} from '@primer/octicons-react'
import {Button, IconButton} from '../Button'
import {Button, IconButton, type ButtonProps} from '../Button'
import {get} from '../constants'
import {VisuallyHidden} from '../VisuallyHidden'
import {useMergedRefs} from '../internal/hooks/useMergedRefs'
import {useFeatureFlag} from '../FeatureFlags'
import classes from './Banner.module.css'
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'

type BannerVariant = 'critical' | 'info' | 'success' | 'upsell' | 'warning'

Expand Down Expand Up @@ -474,22 +475,28 @@ export function BannerActions({primaryAction, secondaryAction}: BannerActionsPro
)
}

export type BannerPrimaryActionProps = Omit<React.ComponentPropsWithoutRef<typeof Button>, 'variant'>
export type BannerPrimaryActionProps = Omit<ButtonProps, 'variant'>

export function BannerPrimaryAction({children, className, ...rest}: BannerPrimaryActionProps) {
const BannerPrimaryAction = forwardRef(({children, className, ...rest}, forwardedRef) => {
return (
<Button className={clsx('BannerPrimaryAction', className)} variant="default" {...rest}>
<Button ref={forwardedRef} className={clsx('BannerPrimaryAction', className)} variant="default" {...rest}>
{children}
</Button>
)
}
}) as PolymorphicForwardRefComponent<'button', BannerPrimaryActionProps>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we necessarily care about forwarding a ref here but it's the only way I found to get the type-checking to pass (mimicked Button). Open to suggestions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me, I'd do the same but yeah open to be convinced otherwise 😅


BannerPrimaryAction.displayName = 'BannerPrimaryAction'

export type BannerSecondaryActionProps = Omit<React.ComponentPropsWithoutRef<typeof Button>, 'variant'>
export type BannerSecondaryActionProps = Omit<ButtonProps, 'variant'>

export function BannerSecondaryAction({children, className, ...rest}: BannerSecondaryActionProps) {
const BannerSecondaryAction = forwardRef(({children, className, ...rest}, forwardedRef) => {
return (
<Button className={clsx('BannerPrimaryAction', className)} variant="link" {...rest}>
<Button ref={forwardedRef} className={clsx('BannerPrimaryAction', className)} variant="link" {...rest}>
{children}
</Button>
)
}
}) as PolymorphicForwardRefComponent<'button', BannerSecondaryActionProps>

BannerSecondaryAction.displayName = 'BannerSecondaryAction'

export {BannerPrimaryAction, BannerSecondaryAction}