-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update types for IconButton, ActionMenu.Button, TabNav.Link and inter…
…nal consumers (#2677) * update types for many buttony things * update anchor type * changeset * avoid a type assignment for button component * use default sx propr broader * slight type tweak * fixup invalid types * scope readonly to dev * update tabnavlink to work with button props * explitly allow href, even if as doesnt support it * lint * fix unused * fix types * remove a prop re-added in a merge
- Loading branch information
1 parent
386561a
commit d356be8
Showing
34 changed files
with
187 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/react': minor | ||
--- | ||
|
||
update types for button extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import React, {forwardRef} from 'react' | ||
import {merge, SxProp} from '../sx' | ||
import {merge, BetterSystemStyleObject} from '../sx' | ||
import {useTheme} from '../ThemeProvider' | ||
import {IconButtonProps, StyledButton} from './types' | ||
import {getBaseStyles, getVariantStyles} from './styles' | ||
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic' | ||
import {defaultSxProp} from '../utils/defaultSxProp' | ||
|
||
const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>((props, forwardedRef): JSX.Element => { | ||
const {variant = 'default', size = 'medium', sx: sxProp = {}, icon: Icon, ...rest} = props | ||
const IconButton = forwardRef((props, forwardedRef): JSX.Element => { | ||
const {variant = 'default', size = 'medium', sx: sxProp = defaultSxProp, icon: Icon, ...rest} = props | ||
const {theme} = useTheme() | ||
const sxStyles = merge.all([getBaseStyles(theme), getVariantStyles(variant, theme), sxProp as SxProp]) | ||
const sxStyles = merge.all<BetterSystemStyleObject>([getBaseStyles(theme), getVariantStyles(variant, theme), sxProp]) | ||
return ( | ||
<StyledButton data-component="IconButton" data-size={size} sx={sxStyles} {...rest} ref={forwardedRef}> | ||
<StyledButton | ||
data-component="IconButton" | ||
data-size={size} | ||
sx={sxStyles} | ||
{...rest} | ||
// @ts-expect-error StyledButton wants both Anchor and Button refs | ||
ref={forwardedRef} | ||
> | ||
<Icon /> | ||
</StyledButton> | ||
) | ||
}) | ||
}) as PolymorphicForwardRefComponent<'button' | 'a', IconButtonProps> | ||
|
||
export {IconButton} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import React, {forwardRef} from 'react' | ||
import {merge, SxProp} from '../sx' | ||
import {BetterSystemStyleObject, merge} from '../sx' | ||
import {LinkButtonProps} from './types' | ||
import {ButtonBase, ButtonBaseProps} from './ButtonBase' | ||
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic' | ||
import {defaultSxProp} from '../utils/defaultSxProp' | ||
|
||
type MyProps = LinkButtonProps & ButtonBaseProps | ||
|
||
const LinkButton = forwardRef<HTMLElement, MyProps>( | ||
({children, as: Component = 'a', sx = {}, ...props}, forwardedRef): JSX.Element => { | ||
const sxStyle = merge.all([sx as SxProp]) | ||
const LinkButton = forwardRef( | ||
({children, as: Component = 'a', sx = defaultSxProp, ...props}, forwardedRef): JSX.Element => { | ||
const sxStyle = merge.all<BetterSystemStyleObject>([sx]) | ||
return ( | ||
<ButtonBase as={Component} ref={forwardedRef} sx={sxStyle} {...props}> | ||
<ButtonBase | ||
as={Component} | ||
// @ts-expect-error ButtonBase wants both Anchor and Button refs | ||
ref={forwardedRef} | ||
sx={sxStyle} | ||
{...props} | ||
> | ||
{children} | ||
</ButtonBase> | ||
) | ||
}, | ||
) as PolymorphicForwardRefComponent<'a', ButtonBaseProps> | ||
) as PolymorphicForwardRefComponent<'a', MyProps> | ||
|
||
export {LinkButton} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.