Repository Public
1// SP Mail Next — libellés d'une conversation ouverte, sous l'objet : pastilles cliquables (recherche `label:`) et retirables.2import { t } from "../../i18n"3import { labelColor, labelsCollection, labelsOfKeywords } from "../../next/labels"4import { applyLabel, labelHref } from "../../next/labelsUi"5import { rowTargets } from "../../next/rowmenu"6import { S } from "../../state/app"7import type { ReaderPanelProps } from "../../state/registry"8import { linkProps } from "../../state/session"9import { useStore } from "../../state/store"10import { Icon } from "../kit"11import "./labels.css"1213export default function LabelChips({ mailboxId, emailIds }: ReaderPanelProps) {14 const labels = labelsCollection.use()15 // signature des mots-clés `lbl_` du fil : le panneau ne se redessine que si un libellé change16 const sig = useStore(S, (s) => emailIds.map((id) => Object.keys(s.open?.emails[id]?.keywords ?? {}).filter((k) => k.startsWith("lbl_")).sort().join(",")).join("|"))17 const perEmail = sig.split("|").map((x) => (x ? x.split(",") : []))18 const worn = labelsOfKeywords([...new Set(perEmail.flat())], labels)19 if (!worn.length) return null20 return (21 <ul className="nx-label-chips" aria-label={t("nx.labels.chips")}>22 {worn.map((l) => (23 <li key={l.id} className="nx-label-chip" style={{ "--lc": labelColor(l.color) } as React.CSSProperties} data-label={l.name}>24 <a {...linkProps(labelHref(l))} title={t("nx.labels.open", { name: l.name })}>25 <span className="label-dot" style={{ background: "var(--lc)" }} aria-hidden="true" />26 <span className="truncate">{l.name}</span>27 </a>28 <button29 type="button"30 aria-label={t("nx.labels.remove", { name: l.name })}31 title={t("nx.labels.remove", { name: l.name })}32 onClick={() => void applyLabel(l, false, rowTargets(mailboxId, emailIds.filter((_, i) => perEmail[i]?.includes(l.keyword)), true))}33 >34 <Icon name="close" small />35 </button>36 </li>37 ))}38 </ul>39 )40}41