"use client"; import { memo } from "react"; import Chip from "../Chip"; import InputLabel from "../../type/InputLabel"; import type { MultiSelectViewProps } from "./MultiSelect.types"; function MultiSelectView({ label, showHelpIcon, size, palette, options, onChipClick, onAddClick, addButton, addButtonText, addButtonAriaLabel, formHeader = true, onCustomChipConfirm, onCustomChipClose, maxSelections, selectionCountText, limitReachedAnnouncement, className, }: MultiSelectViewProps) { const isSmall = size === "s"; const isInverse = palette === "inverse"; // Size-based spacing const gapClass = isSmall ? "gap-[var(--measures-spacing-200,8px)]" : "gap-[var(--measures-spacing-300,12px)]"; const chipSize = size; const selectedCount = options.filter((o) => o.state === "selected").length; const atLimit = maxSelections != null && selectedCount >= maxSelections; const countCaption = selectionCountText?.trim() ?? ""; const helperText = countCaption.length > 0 ? countCaption : false; return (
{/* Label using InputLabel component */} {formHeader && label && ( )} {!formHeader || !label ? ( countCaption.length > 0 ? (

{countCaption}

) : null ) : null} {limitReachedAnnouncement ? (

{atLimit ? limitReachedAnnouncement : ""}

) : null} {/* Chips container */}
{options.map((option) => { const isCustom = option.state === "custom"; const isSelected = option.state === "selected"; const chipDisabled = !isCustom && !isSelected && atLimit; const chipState = chipDisabled ? "disabled" : option.state || "unselected"; return ( { if (!isCustom && !chipDisabled && onChipClick) { onChipClick(option.id); } }} onCheck={(value, e) => { e.stopPropagation(); if (onCustomChipConfirm) { onCustomChipConfirm(option.id, value); } }} onClose={(e) => { e.stopPropagation(); if (onCustomChipClose) { onCustomChipClose(option.id); } }} /> ); })} {/* Add button — icon-only: bordered circle + brand icon (chips stay yellow). With label: Figma 19688:38288 — brand + icon, primary label text, no fill/border. */} {addButton && ( )}
); } MultiSelectView.displayName = "MultiSelectView"; export default memo(MultiSelectView);