|
1 | 1 | import {clsx} from 'clsx'
|
2 |
| -import React, {useEffect} from 'react' |
| 2 | +import React, {forwardRef, useEffect} from 'react' |
3 | 3 | import styled from 'styled-components'
|
4 | 4 | import {AlertIcon, InfoIcon, StopIcon, CheckCircleIcon, XIcon} from '@primer/octicons-react'
|
5 |
| -import {Button, IconButton} from '../Button' |
| 5 | +import {Button, IconButton, type ButtonProps} from '../Button' |
6 | 6 | import {get} from '../constants'
|
7 | 7 | import {VisuallyHidden} from '../VisuallyHidden'
|
8 | 8 | import {useMergedRefs} from '../internal/hooks/useMergedRefs'
|
9 | 9 | import {useFeatureFlag} from '../FeatureFlags'
|
10 | 10 | import classes from './Banner.module.css'
|
11 | 11 | import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
|
| 12 | +import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic' |
12 | 13 |
|
13 | 14 | type BannerVariant = 'critical' | 'info' | 'success' | 'upsell' | 'warning'
|
14 | 15 |
|
@@ -474,22 +475,28 @@ export function BannerActions({primaryAction, secondaryAction}: BannerActionsPro
|
474 | 475 | )
|
475 | 476 | }
|
476 | 477 |
|
477 |
| -export type BannerPrimaryActionProps = Omit<React.ComponentPropsWithoutRef<typeof Button>, 'variant'> |
| 478 | +export type BannerPrimaryActionProps = Omit<ButtonProps, 'variant'> |
478 | 479 |
|
479 |
| -export function BannerPrimaryAction({children, className, ...rest}: BannerPrimaryActionProps) { |
| 480 | +const BannerPrimaryAction = forwardRef(({children, className, ...rest}, forwardedRef) => { |
480 | 481 | return (
|
481 |
| - <Button className={clsx('BannerPrimaryAction', className)} variant="default" {...rest}> |
| 482 | + <Button ref={forwardedRef} className={clsx('BannerPrimaryAction', className)} variant="default" {...rest}> |
482 | 483 | {children}
|
483 | 484 | </Button>
|
484 | 485 | )
|
485 |
| -} |
| 486 | +}) as PolymorphicForwardRefComponent<'button', BannerPrimaryActionProps> |
| 487 | + |
| 488 | +BannerPrimaryAction.displayName = 'BannerPrimaryAction' |
486 | 489 |
|
487 |
| -export type BannerSecondaryActionProps = Omit<React.ComponentPropsWithoutRef<typeof Button>, 'variant'> |
| 490 | +export type BannerSecondaryActionProps = Omit<ButtonProps, 'variant'> |
488 | 491 |
|
489 |
| -export function BannerSecondaryAction({children, className, ...rest}: BannerSecondaryActionProps) { |
| 492 | +const BannerSecondaryAction = forwardRef(({children, className, ...rest}, forwardedRef) => { |
490 | 493 | return (
|
491 |
| - <Button className={clsx('BannerPrimaryAction', className)} variant="link" {...rest}> |
| 494 | + <Button ref={forwardedRef} className={clsx('BannerPrimaryAction', className)} variant="link" {...rest}> |
492 | 495 | {children}
|
493 | 496 | </Button>
|
494 | 497 | )
|
495 |
| -} |
| 498 | +}) as PolymorphicForwardRefComponent<'button', BannerSecondaryActionProps> |
| 499 | + |
| 500 | +BannerSecondaryAction.displayName = 'BannerSecondaryAction' |
| 501 | + |
| 502 | +export {BannerPrimaryAction, BannerSecondaryAction} |
0 commit comments