feat: support new feature in button component

This commit is contained in:
QiShaoXuan 2023-01-30 18:29:00 +08:00
parent bf6545af7a
commit 0636622158
3 changed files with 19 additions and 7 deletions

View File

@ -15,16 +15,26 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
hoverStyle,
shape = 'default',
icon,
iconPosition = 'start',
type = 'default',
children,
bold = false,
loading = false,
noBorder = false,
...props
},
ref
) => {
const { iconSize } = getSize(size);
const iconElement =
icon &&
cloneElement(Children.only(icon), {
width: iconSize,
height: iconSize,
className: `affine-button-icon ${icon.props.className ?? ''}`,
});
return (
<StyledButton
ref={ref}
@ -38,19 +48,16 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
// @ts-ignore
type={type}
bold={bold}
noBorder={noBorder}
{...props}
>
{loading ? (
<Loading type={type}></Loading>
) : (
<>
{icon &&
cloneElement(Children.only(icon), {
width: iconSize,
height: iconSize,
className: `affine-button-icon ${icon.props.className ?? ''}`,
})}
{iconPosition === 'start' && iconElement}
{children && <span>{children}</span>}
{iconPosition === 'end' && iconElement}
</>
)}
</StyledButton>

View File

@ -17,8 +17,10 @@ export type ButtonProps = PropsWithChildren &
hoverColor?: CSSProperties['color'];
hoverStyle?: CSSProperties;
icon?: ReactElement;
iconPosition?: 'start' | 'end';
shape?: 'default' | 'round' | 'circle';
type?: 'primary' | 'warning' | 'danger' | 'default';
bold?: boolean;
loading?: boolean;
noBorder?: boolean;
};

View File

@ -149,6 +149,7 @@ export const StyledButton = styled('button', {
'hoverStyle',
'type',
'bold',
'noBorder',
].includes(prop);
},
})<
@ -162,6 +163,7 @@ export const StyledButton = styled('button', {
| 'shape'
| 'type'
| 'bold'
| 'noBorder'
>
>(
({
@ -174,6 +176,7 @@ export const StyledButton = styled('button', {
bold = false,
shape = 'default',
type = 'default',
noBorder = false,
}) => {
const { fontSize, borderRadius, padding, height } = getSize(size);
@ -181,7 +184,7 @@ export const StyledButton = styled('button', {
height,
paddingLeft: padding,
paddingRight: padding,
border: '1px solid',
border: noBorder ? 'none' : '1px solid',
...displayInlineFlex('center', 'center'),
position: 'relative',
// TODO: disabled color is not decided