Skip to content

Commit

Permalink
fix(Banner): rewrite PrimaryAction & SecondaryAction types (#5055)
Browse files Browse the repository at this point in the history
* fix(Banner): rewrite PrimaryAction & SecondaryAction types

* Create modern-cooks-invite.md
  • Loading branch information
francinelucca authored Oct 8, 2024
1 parent ba3a84a commit 73135c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
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>

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}

0 comments on commit 73135c1

Please sign in to comment.