style: 格式化 packages/@ant/ 下所有文件以通过 biome ci

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-05-01 21:55:51 +08:00
parent c32f26cf21
commit 9ea9859dce
92 changed files with 5903 additions and 5188 deletions

View File

@@ -1,39 +1,33 @@
import React, {
type Ref,
useCallback,
useEffect,
useRef,
useState,
} from 'react'
import type { Except } from 'type-fest'
import type { DOMElement } from '../core/dom.js'
import type { ClickEvent } from '../core/events/click-event.js'
import type { FocusEvent } from '../core/events/focus-event.js'
import type { KeyboardEvent } from '../core/events/keyboard-event.js'
import type { Styles } from '../core/styles.js'
import Box from './Box.js'
import React, { type Ref, useCallback, useEffect, useRef, useState } from 'react';
import type { Except } from 'type-fest';
import type { DOMElement } from '../core/dom.js';
import type { ClickEvent } from '../core/events/click-event.js';
import type { FocusEvent } from '../core/events/focus-event.js';
import type { KeyboardEvent } from '../core/events/keyboard-event.js';
import type { Styles } from '../core/styles.js';
import Box from './Box.js';
type ButtonState = {
focused: boolean
hovered: boolean
active: boolean
}
focused: boolean;
hovered: boolean;
active: boolean;
};
export type Props = Except<Styles, 'textWrap'> & {
ref?: Ref<DOMElement>
ref?: Ref<DOMElement>;
/**
* Called when the button is activated via Enter, Space, or click.
*/
onAction: () => void
onAction: () => void;
/**
* Tab order index. Defaults to 0 (in tab order).
* Set to -1 for programmatically focusable only.
*/
tabIndex?: number
tabIndex?: number;
/**
* Focus this button when it mounts.
*/
autoFocus?: boolean
autoFocus?: boolean;
/**
* Render prop receiving the interactive state. Use this to
* style children based on focus/hover/active — Button itself
@@ -41,64 +35,53 @@ export type Props = Except<Styles, 'textWrap'> & {
*
* If not provided, children render as-is (no state-dependent styling).
*/
children: ((state: ButtonState) => React.ReactNode) | React.ReactNode
}
children: ((state: ButtonState) => React.ReactNode) | React.ReactNode;
};
function Button({
onAction,
tabIndex = 0,
autoFocus,
children,
ref,
...style
}: Props): React.ReactNode {
const [isFocused, setIsFocused] = useState(false)
const [isHovered, setIsHovered] = useState(false)
const [isActive, setIsActive] = useState(false)
function Button({ onAction, tabIndex = 0, autoFocus, children, ref, ...style }: Props): React.ReactNode {
const [isFocused, setIsFocused] = useState(false);
const [isHovered, setIsHovered] = useState(false);
const [isActive, setIsActive] = useState(false);
const activeTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
const activeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => {
return () => {
if (activeTimer.current) clearTimeout(activeTimer.current)
}
}, [])
if (activeTimer.current) clearTimeout(activeTimer.current);
};
}, []);
const handleKeyDown = useCallback(
(e: KeyboardEvent) => {
if (e.key === 'return' || e.key === ' ') {
e.preventDefault()
setIsActive(true)
onAction()
if (activeTimer.current) clearTimeout(activeTimer.current)
activeTimer.current = setTimeout(
setter => setter(false),
100,
setIsActive,
)
e.preventDefault();
setIsActive(true);
onAction();
if (activeTimer.current) clearTimeout(activeTimer.current);
activeTimer.current = setTimeout(setter => setter(false), 100, setIsActive);
}
},
[onAction],
)
);
const handleClick = useCallback(
(_e: ClickEvent) => {
onAction()
onAction();
},
[onAction],
)
);
const handleFocus = useCallback((_e: FocusEvent) => setIsFocused(true), [])
const handleBlur = useCallback((_e: FocusEvent) => setIsFocused(false), [])
const handleMouseEnter = useCallback(() => setIsHovered(true), [])
const handleMouseLeave = useCallback(() => setIsHovered(false), [])
const handleFocus = useCallback((_e: FocusEvent) => setIsFocused(true), []);
const handleBlur = useCallback((_e: FocusEvent) => setIsFocused(false), []);
const handleMouseEnter = useCallback(() => setIsHovered(true), []);
const handleMouseLeave = useCallback(() => setIsHovered(false), []);
const state: ButtonState = {
focused: isFocused,
hovered: isHovered,
active: isActive,
}
const content = typeof children === 'function' ? children(state) : children
};
const content = typeof children === 'function' ? children(state) : children;
return (
<Box
@@ -115,8 +98,8 @@ function Button({
>
{content}
</Box>
)
);
}
export default Button
export type { ButtonState }
export default Button;
export type { ButtonState };