mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix(component): loading in button should be white for primary variant (#10073)
close AF-2178
This commit is contained in:
@@ -6,7 +6,7 @@ import type {
|
|||||||
ReactElement,
|
ReactElement,
|
||||||
SVGAttributes,
|
SVGAttributes,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { cloneElement, forwardRef, useCallback } from 'react';
|
import { cloneElement, forwardRef, useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
import { useAutoFocus } from '../../hooks';
|
import { useAutoFocus } from '../../hooks';
|
||||||
import { Loading } from '../loading';
|
import { Loading } from '../loading';
|
||||||
@@ -78,16 +78,28 @@ const IconSlot = ({
|
|||||||
icon,
|
icon,
|
||||||
loading,
|
loading,
|
||||||
className,
|
className,
|
||||||
|
variant,
|
||||||
...attrs
|
...attrs
|
||||||
}: {
|
}: {
|
||||||
icon?: ReactElement<SVGAttributes<SVGElement>>;
|
icon?: ReactElement<SVGAttributes<SVGElement>>;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
|
variant?: ButtonType;
|
||||||
} & HTMLAttributes<HTMLElement>) => {
|
} & HTMLAttributes<HTMLElement>) => {
|
||||||
const showLoadingHere = loading !== undefined;
|
const showLoadingHere = loading !== undefined;
|
||||||
const visible = icon || loading;
|
const visible = icon || loading;
|
||||||
|
|
||||||
|
const loadingStrokeColor = useMemo(() => {
|
||||||
|
const usePureWhite =
|
||||||
|
variant &&
|
||||||
|
(['primary', 'error', 'success'] as ButtonType[]).includes(variant);
|
||||||
|
return usePureWhite ? '#fff' : undefined;
|
||||||
|
}, [variant]);
|
||||||
|
|
||||||
return visible ? (
|
return visible ? (
|
||||||
<div className={clsx(styles.icon, className)} {...attrs}>
|
<div className={clsx(styles.icon, className)} {...attrs}>
|
||||||
{showLoadingHere && loading ? <Loading size="100%" /> : null}
|
{showLoadingHere && loading ? (
|
||||||
|
<Loading size="100%" strokeColor={loadingStrokeColor} />
|
||||||
|
) : null}
|
||||||
{icon && !loading
|
{icon && !loading
|
||||||
? cloneElement(icon, {
|
? cloneElement(icon, {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@@ -174,6 +186,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
className={prefixClassName}
|
className={prefixClassName}
|
||||||
style={prefixStyle}
|
style={prefixStyle}
|
||||||
|
variant={variant}
|
||||||
/>
|
/>
|
||||||
{children ? (
|
{children ? (
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ export interface LoadingProps {
|
|||||||
size?: number | string;
|
size?: number | string;
|
||||||
speed?: number;
|
speed?: number;
|
||||||
progress?: number;
|
progress?: number;
|
||||||
|
strokeColor?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Loading = ({
|
export const Loading = ({
|
||||||
size,
|
size,
|
||||||
speed = 1.2,
|
speed = 1.2,
|
||||||
progress = 0.2,
|
progress = 0.2,
|
||||||
|
strokeColor,
|
||||||
}: LoadingProps) => {
|
}: LoadingProps) => {
|
||||||
// allow `string` such as `16px` | `100%` | `1em`
|
// allow `string` such as `16px` | `100%` | `1em`
|
||||||
const sizeWithUnit = size ? withUnit(size, 'px') : '16px';
|
const sizeWithUnit = size ? withUnit(size, 'px') : '16px';
|
||||||
@@ -43,10 +45,11 @@ export const Loading = ({
|
|||||||
cy={12}
|
cy={12}
|
||||||
r={8}
|
r={8}
|
||||||
strokeWidth={4}
|
strokeWidth={4}
|
||||||
stroke="var(--affine-primary-color)"
|
stroke={strokeColor || 'var(--affine-primary-color)'}
|
||||||
strokeDasharray={`${2 * Math.PI * 8 * progress} ${
|
strokeDasharray={`${2 * Math.PI * 8 * progress} ${
|
||||||
2 * Math.PI * 8 * (1 - progress)
|
2 * Math.PI * 8 * (1 - progress)
|
||||||
}`}
|
}`}
|
||||||
|
strokeLinecap="round"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user