Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

1.3 KB
Raw Blame
import { type ReactNode } from 'react';
import { useTranslations } from 'next-intl';
import { usePriorityLabel } from '@/hooks/usePriorityLabel';
import { Pill } from './Pill';
import { PRIORITY_FIELDS } from './priorityFields';
import PopoverPick from './PopoverPick';

// Value is the priority string, '' for none (matches PRIORITY_FIELDS[0]).
export default function PrioritySelect({
  value,
  onChange,
  readOnly,
  trigger,
}: {
  value: string;
  onChange: (v: string) => void;
  readOnly?: boolean;
  // Replaces the pill where a caller needs its own (a Timeline cell).
  trigger?: ReactNode;
}) {
  const t = useTranslations('common.priority');
  const priorityLabel = usePriorityLabel();
  const prio = PRIORITY_FIELDS.find((p) => p.value === value) ?? PRIORITY_FIELDS[0];
  return (
    <PopoverPick
      readOnly={readOnly}
      trigger={
        trigger ?? (
          <Pill active={!!value}>
            {prio.icon}
            <span className="truncate">{value ? priorityLabel(value) : t('label')}</span>
          </Pill>
        )
      }
      inputPlaceholder={t('setTo')}
      items={PRIORITY_FIELDS.map((p) => ({
        key: p.value || 'none',
        search: priorityLabel(p.value),
        icon: p.icon,
        label: priorityLabel(p.value),
        selected: p.value === value,
        onSelect: () => onChange(p.value),
      }))}
    />
  );
}