Refine toolbox navigation and local data controls
All checks were successful
Deploy Sokko G / deploy (push) Successful in 20s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 20s
This commit is contained in:
parent
954240adf9
commit
2f2e79d200
27 changed files with 614 additions and 302 deletions
|
|
@ -1,12 +1,25 @@
|
|||
// Rôle : encapsule l'input fichier JSON derrière un bouton d'import réutilisable.
|
||||
import { useRef } from "react";
|
||||
import { Icon } from "./Icon.jsx";
|
||||
import { Tooltip } from "./Tooltip.jsx";
|
||||
|
||||
export function ImportButton({ className, label, title, ariaLabel, icon, onFile, tooltip = "", tooltipPosition = "top", ...props }) {
|
||||
export function ImportButton({ className, label, title, ariaLabel, icon, onFile, onKeyDown, tabIndex = 0, tooltip = "", tooltipPosition = "top", ...props }) {
|
||||
const inputRef = useRef(null);
|
||||
const buttonProps = {
|
||||
...props,
|
||||
role: "button",
|
||||
tabIndex,
|
||||
onKeyDown: (event) => {
|
||||
onKeyDown?.(event);
|
||||
if (event.defaultPrevented || (event.key !== "Enter" && event.key !== " ")) return;
|
||||
event.preventDefault();
|
||||
inputRef.current?.click();
|
||||
}
|
||||
};
|
||||
const children = <>
|
||||
{icon && <Icon name={icon} />}
|
||||
{label}
|
||||
<input type="file" accept="application/json" hidden onChange={async (event) => {
|
||||
<input ref={inputRef} type="file" accept="application/json" hidden onChange={async (event) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (file) await onFile(file);
|
||||
event.target.value = "";
|
||||
|
|
@ -14,7 +27,7 @@ export function ImportButton({ className, label, title, ariaLabel, icon, onFile,
|
|||
</>;
|
||||
|
||||
if (tooltip) {
|
||||
return <Tooltip as="label" className={className} content={tooltip} position={tooltipPosition} aria-label={ariaLabel} {...props}>{children}</Tooltip>;
|
||||
return <Tooltip as="label" className={className} content={tooltip} position={tooltipPosition} aria-label={ariaLabel} {...buttonProps}>{children}</Tooltip>;
|
||||
}
|
||||
return <label className={className} aria-label={ariaLabel} title={title} {...props}>{children}</label>;
|
||||
return <label className={className} aria-label={ariaLabel} title={title} {...buttonProps}>{children}</label>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue