f8a41cee16
* Add keybindings for shapes I'm not 100% sure about this one. I feel like it's going to help people be a lot more productive to display the key bindings at all time. But it also clutters the UI... * increase font-size * fix shape keybindings for non-qwerty keyboards * tweak position and color Co-authored-by: David Luzar <luzar.david@gmail.com>
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import "./ToolIcon.scss";
|
|
|
|
import React from "react";
|
|
|
|
type ToolIconSize = "s" | "m";
|
|
|
|
type ToolButtonBaseProps = {
|
|
icon?: React.ReactNode;
|
|
"aria-label": string;
|
|
"aria-keyshortcuts"?: string;
|
|
label?: string;
|
|
title?: string;
|
|
name?: string;
|
|
id?: string;
|
|
size?: ToolIconSize;
|
|
keyBindingLabel?: string;
|
|
};
|
|
|
|
type ToolButtonProps =
|
|
| (ToolButtonBaseProps & { type: "button"; onClick?(): void })
|
|
| (ToolButtonBaseProps & {
|
|
type: "radio";
|
|
|
|
checked: boolean;
|
|
onChange?(): void;
|
|
});
|
|
|
|
const DEFAULT_SIZE: ToolIconSize = "m";
|
|
|
|
export const ToolButton = React.forwardRef(function(
|
|
props: ToolButtonProps,
|
|
ref,
|
|
) {
|
|
const innerRef = React.useRef(null);
|
|
React.useImperativeHandle(ref, () => innerRef.current);
|
|
const sizeCn = `ToolIcon_size_${props.size || DEFAULT_SIZE}`;
|
|
|
|
if (props.type === "button")
|
|
return (
|
|
<button
|
|
className={`ToolIcon_type_button ToolIcon ${sizeCn}`}
|
|
title={props.title}
|
|
aria-label={props["aria-label"]}
|
|
type="button"
|
|
onClick={props.onClick}
|
|
ref={innerRef}
|
|
>
|
|
<div className="ToolIcon__icon" aria-hidden="true">
|
|
{props.icon || props.label}
|
|
</div>
|
|
</button>
|
|
);
|
|
|
|
return (
|
|
<label className="ToolIcon" title={props.title}>
|
|
<input
|
|
className={`ToolIcon_type_radio ${sizeCn}`}
|
|
type="radio"
|
|
name={props.name}
|
|
aria-label={props["aria-label"]}
|
|
aria-keyshortcuts={props["aria-keyshortcuts"]}
|
|
id={props.id}
|
|
onChange={props.onChange}
|
|
checked={props.checked}
|
|
ref={innerRef}
|
|
/>
|
|
<div className="ToolIcon__icon">
|
|
{props.icon}
|
|
{props.keyBindingLabel && (
|
|
<span className="ToolIcon__keybinding">{props.keyBindingLabel}</span>
|
|
)}
|
|
</div>
|
|
</label>
|
|
);
|
|
});
|