mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
refactor: remove defaultProps
(#9035)
This commit is contained in:
parent
91ebf8b0ea
commit
fa05ae1230
1 changed files with 135 additions and 129 deletions
|
@ -55,11 +55,20 @@ type ToolButtonProps =
|
||||||
onPointerDown?(data: { pointerType: PointerType }): void;
|
onPointerDown?(data: { pointerType: PointerType }): void;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => {
|
export const ToolButton = React.forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
size = "medium",
|
||||||
|
visible = true,
|
||||||
|
className = "",
|
||||||
|
...props
|
||||||
|
}: ToolButtonProps,
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
const { id: excalId } = useExcalidrawContainer();
|
const { id: excalId } = useExcalidrawContainer();
|
||||||
const innerRef = React.useRef(null);
|
const innerRef = React.useRef(null);
|
||||||
React.useImperativeHandle(ref, () => innerRef.current);
|
React.useImperativeHandle(ref, () => innerRef.current);
|
||||||
const sizeCn = `ToolIcon_size_${props.size}`;
|
const sizeCn = `ToolIcon_size_${size}`;
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
@ -108,8 +117,8 @@ export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => {
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"ToolIcon_type_button",
|
"ToolIcon_type_button",
|
||||||
sizeCn,
|
sizeCn,
|
||||||
props.className,
|
className,
|
||||||
props.visible && !props.hidden
|
visible && !props.hidden
|
||||||
? "ToolIcon_type_button--show"
|
? "ToolIcon_type_button--show"
|
||||||
: "ToolIcon_type_button--hide",
|
: "ToolIcon_type_button--hide",
|
||||||
{
|
{
|
||||||
|
@ -155,7 +164,7 @@ export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label
|
<label
|
||||||
className={clsx("ToolIcon", props.className)}
|
className={clsx("ToolIcon", className)}
|
||||||
title={props.title}
|
title={props.title}
|
||||||
onPointerDown={(event) => {
|
onPointerDown={(event) => {
|
||||||
lastPointerTypeRef.current = event.pointerType || null;
|
lastPointerTypeRef.current = event.pointerType || null;
|
||||||
|
@ -184,17 +193,14 @@ export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => {
|
||||||
<div className="ToolIcon__icon">
|
<div className="ToolIcon__icon">
|
||||||
{props.icon}
|
{props.icon}
|
||||||
{props.keyBindingLabel && (
|
{props.keyBindingLabel && (
|
||||||
<span className="ToolIcon__keybinding">{props.keyBindingLabel}</span>
|
<span className="ToolIcon__keybinding">
|
||||||
|
{props.keyBindingLabel}
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
ToolButton.defaultProps = {
|
|
||||||
visible: true,
|
|
||||||
className: "",
|
|
||||||
size: "medium",
|
|
||||||
};
|
|
||||||
|
|
||||||
ToolButton.displayName = "ToolButton";
|
ToolButton.displayName = "ToolButton";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue