-
Notifications
You must be signed in to change notification settings - Fork 642
Update types for IconButton, ActionMenu.Button, TabNav.Link and internal consumers #2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f8396de
update types for many buttony things
mattcosta7 22d54d0
update anchor type
mattcosta7 ff81b15
changeset
mattcosta7 821d888
avoid a type assignment for button component
mattcosta7 4acd672
use default sx propr broader
mattcosta7 e731b2b
slight type tweak
mattcosta7 73b7829
fixup invalid types
mattcosta7 4c5f3ee
scope readonly to dev
mattcosta7 e9d50df
Merge branch 'main' into fix-up-types-for-buttony-things
mattcosta7 ae1b022
Merge remote-tracking branch 'origin/main' into fix-up-types-for-butt…
mattcosta7 96a6224
update tabnavlink to work with button props
mattcosta7 bf1f55e
explitly allow href, even if as doesnt support it
mattcosta7 b8fc520
Merge branch 'main' into fix-up-types-for-buttony-things
mattcosta7 a2a252e
merge main
mattcosta7 a324bea
lint
mattcosta7 98f7989
fix unused
mattcosta7 6db1ab6
fix types
mattcosta7 4761a20
remove a prop re-added in a merge
mattcosta7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 +1,5 @@ | ||
| import React, {ComponentPropsWithRef} from 'react' | ||
| import React from 'react' | ||
| import styled from 'styled-components' | ||
| import {IconProps} from '@primer/octicons-react' | ||
| import sx, {SxProp} from '../sx' | ||
| import getGlobalFocusStyles from '../_getGlobalFocusStyles' | ||
|
|
||
|
|
@@ -15,14 +14,9 @@ export type Size = 'small' | 'medium' | 'large' | |
|
|
||
| export type AlignContent = 'start' | 'center' | ||
|
|
||
| /** | ||
| * Remove styled-components polymorphic as prop, which conflicts with radix's | ||
| */ | ||
| type StyledButtonProps = Omit<ComponentPropsWithRef<typeof StyledButton>, 'as'> | ||
|
|
||
| type ButtonA11yProps = | ||
| | {'aria-label': string; 'aria-labelledby'?: never} | ||
| | {'aria-label'?: never; 'aria-labelledby': string} | ||
| | {'aria-label': string; 'aria-labelledby'?: undefined} | ||
| | {'aria-label'?: undefined; 'aria-labelledby': string} | ||
mattcosta7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export type ButtonBaseProps = { | ||
| /** | ||
|
|
@@ -42,22 +36,21 @@ export type ButtonBaseProps = { | |
| */ | ||
| block?: boolean | ||
| } & SxProp & | ||
| React.ButtonHTMLAttributes<HTMLButtonElement> & | ||
| StyledButtonProps | ||
| React.ButtonHTMLAttributes<HTMLButtonElement> | ||
|
|
||
| export type ButtonProps = { | ||
| /** | ||
| * The leading icon comes before button content | ||
| */ | ||
| leadingIcon?: React.FunctionComponent<React.PropsWithChildren<IconProps>> | ||
| leadingIcon?: React.ComponentType | null | undefined | ||
| /** | ||
| * The trailing icon comes after button content | ||
| */ | ||
| trailingIcon?: React.FunctionComponent<React.PropsWithChildren<IconProps>> | ||
| trailingIcon?: React.ComponentType | null | undefined | ||
| /** | ||
| * Trailing action appears to the right of the trailing visual and is always locked to the end | ||
| */ | ||
| trailingAction?: React.FunctionComponent<React.PropsWithChildren<IconProps>> | ||
| trailingAction?: React.ComponentType | null | undefined | ||
| children: React.ReactNode | ||
| /** | ||
| * Content alignment for when visuals are present | ||
|
|
@@ -66,8 +59,8 @@ export type ButtonProps = { | |
| } & ButtonBaseProps | ||
|
|
||
| export type IconButtonProps = ButtonA11yProps & { | ||
| icon: React.FunctionComponent<React.PropsWithChildren<IconProps>> | ||
| } & ButtonBaseProps | ||
| icon: React.ComponentType | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. broadens these to they work with arbitrary components, and not only primer octicons |
||
| } & Omit<ButtonBaseProps, 'aria-label' | 'aria-labelledby'> | ||
mattcosta7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // adopted from React.AnchorHTMLAttributes | ||
| export type LinkButtonProps = { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.