Skip to content

Commit 73135c1

Browse files
fix(Banner): rewrite PrimaryAction & SecondaryAction types (#5055)
* fix(Banner): rewrite PrimaryAction & SecondaryAction types * Create modern-cooks-invite.md
1 parent ba3a84a commit 73135c1

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

.changeset/modern-cooks-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
fix(Banner): rewrite PrimaryAction & SecondaryAction types

packages/react/src/Banner/Banner.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {clsx} from 'clsx'
2-
import React, {useEffect} from 'react'
2+
import React, {forwardRef, useEffect} from 'react'
33
import styled from 'styled-components'
44
import {AlertIcon, InfoIcon, StopIcon, CheckCircleIcon, XIcon} from '@primer/octicons-react'
5-
import {Button, IconButton} from '../Button'
5+
import {Button, IconButton, type ButtonProps} from '../Button'
66
import {get} from '../constants'
77
import {VisuallyHidden} from '../VisuallyHidden'
88
import {useMergedRefs} from '../internal/hooks/useMergedRefs'
99
import {useFeatureFlag} from '../FeatureFlags'
1010
import classes from './Banner.module.css'
1111
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
12+
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
1213

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

@@ -474,22 +475,28 @@ export function BannerActions({primaryAction, secondaryAction}: BannerActionsPro
474475
)
475476
}
476477

477-
export type BannerPrimaryActionProps = Omit<React.ComponentPropsWithoutRef<typeof Button>, 'variant'>
478+
export type BannerPrimaryActionProps = Omit<ButtonProps, 'variant'>
478479

479-
export function BannerPrimaryAction({children, className, ...rest}: BannerPrimaryActionProps) {
480+
const BannerPrimaryAction = forwardRef(({children, className, ...rest}, forwardedRef) => {
480481
return (
481-
<Button className={clsx('BannerPrimaryAction', className)} variant="default" {...rest}>
482+
<Button ref={forwardedRef} className={clsx('BannerPrimaryAction', className)} variant="default" {...rest}>
482483
{children}
483484
</Button>
484485
)
485-
}
486+
}) as PolymorphicForwardRefComponent<'button', BannerPrimaryActionProps>
487+
488+
BannerPrimaryAction.displayName = 'BannerPrimaryAction'
486489

487-
export type BannerSecondaryActionProps = Omit<React.ComponentPropsWithoutRef<typeof Button>, 'variant'>
490+
export type BannerSecondaryActionProps = Omit<ButtonProps, 'variant'>
488491

489-
export function BannerSecondaryAction({children, className, ...rest}: BannerSecondaryActionProps) {
492+
const BannerSecondaryAction = forwardRef(({children, className, ...rest}, forwardedRef) => {
490493
return (
491-
<Button className={clsx('BannerPrimaryAction', className)} variant="link" {...rest}>
494+
<Button ref={forwardedRef} className={clsx('BannerPrimaryAction', className)} variant="link" {...rest}>
492495
{children}
493496
</Button>
494497
)
495-
}
498+
}) as PolymorphicForwardRefComponent<'button', BannerSecondaryActionProps>
499+
500+
BannerSecondaryAction.displayName = 'BannerSecondaryAction'
501+
502+
export {BannerPrimaryAction, BannerSecondaryAction}

0 commit comments

Comments
 (0)