import { XMarkMini } from "@medusajs/icons" import { Button, clx } from "@medusajs/ui" import { Children, PropsWithChildren, createContext, useContext } from "react" import { useTranslation } from "react-i18next" type ChipGroupVariant = "base" | "component" type ChipGroupProps = PropsWithChildren<{ onClearAll?: () => void onRemove?: (index: number) => void variant?: ChipGroupVariant className?: string }> type GroupContextValue = { onRemove?: (index: number) => void variant: ChipGroupVariant } const GroupContext = createContext(null) const useGroupContext = () => { const context = useContext(GroupContext) if (!context) { throw new Error("useGroupContext must be used within a ChipGroup component") } return context } const Group = ({ onClearAll, onRemove, variant = "component", className, children, }: ChipGroupProps) => { const { t } = useTranslation() const showClearAll = !!onClearAll && Children.count(children) > 0 return ( ) } type ChipProps = PropsWithChildren<{ index: number className?: string }> const Chip = ({ index, className, children }: ChipProps) => { const { onRemove, variant } = useGroupContext() return (
  • {children} {!!onRemove && ( )}
  • ) } export const ChipGroup = Object.assign(Group, { Chip })