"use client" /** * Highlight colour for one conditional formatting rule. * * Three sources, because "green" and "the colour Overdue already is" are * different intents: `Palette` for a neutral tint, `Status` to borrow the status * badge fill so a highlighted row and its chip read as one colour, `Custom` for * a colour the workspace brings with it. Custom is stored as a tint at the * palette's strength (`customRuleBackground`), which is what keeps cell text * above the contrast floor in light, dark, and high-contrast modes. */ import * as React from "react" import { cn } from "../../lib/utils" import { Button } from "../ui/button" import { ButtonSegmentedControl } from "../ui/button-segmented-control" import { Tip } from "../ui/tip" import { CONDITIONAL_RULE_COLOR_SOURCES, STATUS_RULE_COLORS, customRuleBackground, resolveRuleColorSource, ruleColorSourcePatch, ruleCustomColor, } from "../../lib/conditional-rule-colors" import { RULE_COLORS, type ConditionalRule, type ConditionalRuleColorSource, } from "../../lib/table-properties-types" import { PROPERTIES_SHEET_TOOLTIP_Z, PROPERTIES_SHEET_TOOLTIP_Z_INDEX, } from "./sheet-portal-z" export function ConditionalRuleColorPicker({ rule, onUpdate, }: { rule: ConditionalRule onUpdate: (id: string, patch: Partial) => void }) { const source = resolveRuleColorSource(rule) const customColor = ruleCustomColor(rule) const customInputId = React.useId() const swatches = source === "status" ? STATUS_RULE_COLORS : RULE_COLORS return (

Highlight color

aria-label="Highlight color source" value={source} onValueChange={next => onUpdate(rule.id, ruleColorSourcePatch(rule, next))} options={CONDITIONAL_RULE_COLOR_SOURCES} /> {source === "custom" ? (
{ const next = e.target.value onUpdate(rule.id, { colorSource: "custom", customColor: next, bgColor: customRuleBackground(next), }) }} className={cn( "size-6 shrink-0 cursor-pointer rounded-md border border-input bg-background p-0.5", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1", )} /> {customColor.toUpperCase()}
) : (
{swatches.map(c => { const selected = rule.bgColor === c.bg return (
)} {source === "custom" ? (

Applied as a tint of this color so cell text stays readable in every theme.

) : null}
) }