-
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.
* Remove link button * Fix up test * Fix up tests * Create rich-tools-cry.md
- Loading branch information
Showing
9 changed files
with
67 additions
and
236 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": patch | ||
--- | ||
|
||
Remove link button from the new button |
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 was deleted.
Oops, something went wrong.
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,17 +1,43 @@ | ||
import React, {forwardRef} from 'react' | ||
import {ButtonProps} from './types' | ||
import {ButtonBase} from './ButtonBase' | ||
import React, {ComponentPropsWithRef, forwardRef, ComponentType} from 'react' | ||
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '@radix-ui/react-polymorphic' | ||
import Box from '../Box' | ||
import {merge, SxProp} from '../sx' | ||
import {useTheme} from '../ThemeProvider' | ||
import {ButtonProps as ButtonComponentProps, StyledButton} from './types' | ||
import {getVariantStyles, getSizeStyles, getButtonStyles} from './styles' | ||
|
||
const ButtonComponent = forwardRef<HTMLButtonElement, ButtonProps>( | ||
({children, ...props}, forwardedRef): JSX.Element => { | ||
const Button = forwardRef<HTMLElement, ButtonComponentProps>( | ||
({children, as: Component = 'button', sx: sxProp = {}, ...props}, forwardedRef): JSX.Element => { | ||
const {leadingIcon: LeadingIcon, trailingIcon: TrailingIcon, variant = 'default', size = 'medium'} = props | ||
const {theme} = useTheme() | ||
const iconWrapStyles = { | ||
display: 'inline-block' | ||
} | ||
const sxStyles = merge.all([ | ||
getButtonStyles(theme), | ||
getSizeStyles(size, variant, false), | ||
getVariantStyles(variant, theme), | ||
sxProp as SxProp | ||
]) | ||
return ( | ||
<ButtonBase ref={forwardedRef} {...props} as="button"> | ||
{children} | ||
</ButtonBase> | ||
<StyledButton as={Component} sx={sxStyles} {...props} ref={forwardedRef}> | ||
{LeadingIcon && ( | ||
<Box as="span" data-component="leadingIcon" sx={iconWrapStyles}> | ||
<LeadingIcon /> | ||
</Box> | ||
)} | ||
{children && <span data-component="text">{children}</span>} | ||
{TrailingIcon && ( | ||
<Box as="span" data-component="trailingIcon" sx={{...iconWrapStyles, ml: 2}}> | ||
<TrailingIcon /> | ||
</Box> | ||
)} | ||
</StyledButton> | ||
) | ||
} | ||
) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
) as PolymorphicForwardRefComponent<string | ComponentType<any> | undefined, ButtonComponentProps> | ||
|
||
ButtonComponent.displayName = 'Button' | ||
export type ButtonProps = ComponentPropsWithRef<typeof Button> | ||
|
||
export {ButtonComponent} | ||
export {Button} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,10 +1,11 @@ | ||
import {ButtonComponent} from './Button' | ||
import {Button as ButtonComponent} from './Button' | ||
import {Counter} from './ButtonCounter' | ||
import {IconButton} from './IconButton' | ||
import {LinkButton} from './LinkButton' | ||
export type {ButtonProps, IconButtonProps} from './types' | ||
export {IconButton, LinkButton} | ||
export {IconButton} | ||
|
||
export const Button = Object.assign(ButtonComponent, { | ||
Counter | ||
}) | ||
|
||
Button.displayName = 'Button' |
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