@indos/bibliotheque 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ui/panneau.js CHANGED
@@ -3,15 +3,16 @@ import { useRef } from 'react';
3
3
  import { Dialog } from 'radix-ui';
4
4
  import { Bouton } from './bouton.js';
5
5
  import { cn } from './classes.js';
6
- export function Panneau({ titre, surtitre, etiquette, declencheur, ouvert, onOuvertChange, className, children }) {
6
+ export function Panneau({ titre, surtitre, etiquette, declencheur, ouvert, onOuvertChange, retour, className, children }) {
7
7
  // Ce qui avait le focus à l'ouverture, où il revient à la fermeture, même sans déclencheur.
8
8
  const avant = useRef(null);
9
9
  return (_jsxs(Dialog.Root, { open: ouvert, onOpenChange: onOuvertChange, children: [declencheur && _jsx(Dialog.Trigger, { asChild: true, children: declencheur }), _jsxs(Dialog.Portal, { children: [_jsx(Dialog.Overlay, { className: "fixed inset-0 z-50 bg-papier/60" }), _jsxs(Dialog.Content, { "aria-describedby": undefined, onOpenAutoFocus: () => {
10
10
  avant.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
11
11
  }, onCloseAutoFocus: (evenement) => {
12
- if (avant.current?.isConnected) {
12
+ const cible = retour?.current?.isConnected ? retour.current : avant.current;
13
+ if (cible?.isConnected) {
13
14
  evenement.preventDefault();
14
- avant.current.focus();
15
+ cible.focus();
15
16
  }
16
17
  }, className: cn('fixed inset-y-0 right-0 z-50 flex w-[min(560px,100%)] flex-col border-l border-trait bg-papier text-encre', 'max-[760px]:w-full max-[760px]:border-l-0', className), children: [_jsxs("div", { className: "flex items-start justify-between gap-4 border-b border-trait px-[22px] py-4", children: [_jsxs("div", { className: "min-w-0", children: [surtitre && _jsx("p", { className: "m-0 mb-1 text-[11px] tracking-[.07em] text-gris uppercase", children: surtitre }), _jsx(Dialog.Title, { className: "m-0 font-titre text-[26px] leading-[1.1] font-normal [overflow-wrap:anywhere]", children: titre }), etiquette && _jsx("div", { className: "mt-2", children: etiquette })] }), _jsx(Dialog.Close, { asChild: true, children: _jsx(Bouton, { type: "button", sorte: "discret", children: "Fermer" }) })] }), _jsx("div", { className: "min-h-0 flex-1 overflow-y-auto px-[22px] py-5", children: children })] })] })] }));
17
18
  }
@@ -13,6 +13,7 @@ export type ProprietesDUnTableau = {
13
13
  lignes: ReactNode[][];
14
14
  vide?: string;
15
15
  pagination?: Pagination;
16
+ onOuvrirLigne?: (rang: number) => void;
16
17
  className?: string;
17
18
  };
18
- export declare function Tableau({ colonnes, lignes, vide, pagination, className }: ProprietesDUnTableau): import("react").JSX.Element;
19
+ export declare function Tableau({ colonnes, lignes, vide, pagination, onOuvrirLigne, className }: ProprietesDUnTableau): import("react").JSX.Element;
package/src/ui/tableau.js CHANGED
@@ -11,12 +11,33 @@ function etendue(page, total, lignes) {
11
11
  const debut = (page - 1) * lignesParPage + 1;
12
12
  return `${nombre.format(debut)}–${nombre.format(debut + lignes - 1)} sur ${nombre.format(total)}`;
13
13
  }
14
+ // Ce qu'un clic dans une ligne laisse à son élément : un lien, un bouton, une saisie, une entrée de
15
+ // menu.
16
+ const elementsDUneLigne = 'a, button, input, select, textarea, label, [role=menuitem], [role=menu], [role=dialog], [role=alertdialog]';
17
+ // Un clic qui ouvre la ligne : un clic simple, fait dans la ligne elle-même. Un clic venu d'un
18
+ // portail (un menu, une fenêtre), que React fait remonter par la ligne sans qu'il soit dedans, ne
19
+ // l'ouvre pas, ni un clic dans un élément qui a son propre geste.
20
+ function ouvreLaLigne(evenement) {
21
+ const cible = evenement.target;
22
+ if (evenement.defaultPrevented || evenement.button !== 0 || evenement.metaKey || evenement.ctrlKey || evenement.shiftKey || evenement.altKey) {
23
+ return false;
24
+ }
25
+ if (!(cible instanceof Element) || !evenement.currentTarget.contains(cible)) {
26
+ return false;
27
+ }
28
+ return !cible.closest(elementsDUneLigne);
29
+ }
14
30
  // Un tableau : ses colonnes, ses lignes, chaque cellule un contenu, et `vide`, dit sans ligne. Avec
15
- // `pagination`, et plus d'une page, il a sous lui « Précédent », « Suivant » et l'étendue. Sur un
16
- // téléphone, chaque ligne s'empile (la feuille, `.tableau`).
17
- export function Tableau({ colonnes, lignes, vide, pagination, className }) {
31
+ // `pagination`, et plus d'une page, il a sous lui « Précédent », « Suivant » et l'étendue. Avec
32
+ // `onOuvrirLigne`, un clic dans une ligne l'ouvre (`ouvreLaLigne`) ; au clavier, la ligne s'ouvre
33
+ // par le lien qu'elle porte. Sur un téléphone, chaque ligne s'empile (la feuille, `.tableau`).
34
+ export function Tableau({ colonnes, lignes, vide, pagination, onOuvrirLigne, className }) {
18
35
  return (_jsxs("div", { className: className, children: [_jsx("div", { className: "tableau overflow-x-auto rounded-[10px] border border-trait", children: _jsxs("table", { className: "w-full border-collapse text-[13.5px]", children: [_jsx("thead", { children: _jsx("tr", { children: colonnes.map((colonne) => (_jsx("th", { scope: "col", className: "border-b border-trait bg-surface px-3.5 py-2.5 text-left text-[11px] font-medium tracking-[.07em] whitespace-nowrap text-gris uppercase", children: colonne.titre }, colonne.titre))) }) }), _jsx("tbody", { children: lignes.length > 0
19
- ? lignes.map((ligne, rang) => (_jsx("tr", { className: "border-t border-trait first:border-t-0", children: ligne.map((cellule, colonne) => (_jsx("td", { className: cn('px-3.5 py-2.5 align-top', colonnes[colonne]?.fixe && 'font-mono text-[12.5px] whitespace-nowrap tabular-nums'), children: cellule }, colonne))) }, rang)))
36
+ ? lignes.map((ligne, rang) => (_jsx("tr", { onClick: onOuvrirLigne && ((evenement) => {
37
+ if (ouvreLaLigne(evenement)) {
38
+ onOuvrirLigne(rang);
39
+ }
40
+ }), className: cn('border-t border-trait first:border-t-0', onOuvrirLigne && 'cursor-pointer hover:bg-surface'), children: ligne.map((cellule, colonne) => (_jsx("td", { className: cn('px-3.5 py-2.5 align-top', colonnes[colonne]?.fixe && 'font-mono text-[12.5px] whitespace-nowrap tabular-nums'), children: cellule }, colonne))) }, rang)))
20
41
  : (_jsx("tr", { children: _jsx("td", { colSpan: colonnes.length, className: "px-3.5 py-2.5 text-gris", children: vide }) })) })] }) }), pagination && _jsx(Pages, { ...pagination, lignes: lignes.length })] }));
21
42
  }
22
43
  function Pages({ page, total, changerDePage, lignes }) {