Files
pn-new-crm/src/components/ui/select.tsx

166 lines
6.1 KiB
TypeScript
Raw Normal View History

'use client';
import * as React from 'react';
import * as SelectPrimitive from '@radix-ui/react-select';
import { Check, ChevronDown, ChevronUp } from 'lucide-react';
import { cn } from '@/lib/utils';
const Select = SelectPrimitive.Root;
const SelectGroup = SelectPrimitive.Group;
const SelectValue = SelectPrimitive.Value;
feat(uat-batch): Group Q — platform refactors Q58, Q59, Q61 from the 2026-05-21 plan. Q57 + Q60 (sweep-scope) parked. Shipped: Q58 SelectTrigger size variant. <SelectTrigger> now accepts `size?: 'default' | 'sm'`. Default = `h-11` so the trigger matches <Input>'s h-11 default and the 8px height mismatch called out in the UAT vanishes platform-wide. Existing call sites that need the legacy compact look (FilterBar, dense table headers) opt back in via `size="sm"`. Nothing breaks — the default render flips height without touching any other styling. Q59 Table density min-widths + nowrap. DataTable cells now default to `whitespace-nowrap` so long values (URLs, names, addresses) don't wrap into 4-5 lines and inflate row height. Columns that need wrapping override via the column def's `meta.wrap = true`. Min-width comes from `column.getSize?.()` when set so a column doesn't shrink- wrap below readability — opt-in per column rather than a sweeping width change. Q61 Error message audit foundation — Documenso 401/403 path enriched. <PortDocumensoConfig> gains `apiKeySource` + `apiUrlSource` ('port' | 'global' | 'env' | 'default' | 'none'). `getPortDocumensoConfig` populates them based on which layer of the resolver chain produced the value. documenso-client's <ResolvedCreds> exposes the source flags; the 401/403 branch surfaces them in the `DOCUMENSO_AUTH_FAILURE` internalMessage so operators see "api key source: env, port: <id>" instead of the prior generic `path → 401` body. Solves the Documenso diagnosis loop that prompted the platform-wide error audit. Same pattern can extend to other integration error paths in follow-ups (S3, Redis, IMAP) — the resolver-source helper lives on PortConfig now. Q60 Tooltip audit primitive already shipped — <FieldLabel> in `ui/field-label.tsx` is the canonical surface with an Info icon + Tooltip slot. One adopter live (custom-field-form); remaining admin-form sweep is the lift that's parked. Deferred: Q57 recharts → ECharts migration (6-10h). Pure visual port of 8 chart components; safer as a focused session with per-chart visual review. Pre-reqs (ECharts deps + the transpilePackages config + the d3-geo install) are in place so the migration can be picked up cleanly. Verified: tsc clean, vitest 1454/1454. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 23:49:22 +02:00
/**
* Size variant mirroring Button's idiom. Default `h-11` (44px) pairs
* with `<Input>`'s default fixes the 8px height mismatch that
* triggered the platform-wide UAT finding. Compact contexts (FilterBar,
* dense table headers) pass `size="sm"` to retain the legacy 36px /
* h-9 footprint. Old call sites that haven't been audited yet still
* render correctly via the default; nothing breaks.
*/
type SelectTriggerSize = 'default' | 'sm';
const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
feat(uat-batch): Group Q — platform refactors Q58, Q59, Q61 from the 2026-05-21 plan. Q57 + Q60 (sweep-scope) parked. Shipped: Q58 SelectTrigger size variant. <SelectTrigger> now accepts `size?: 'default' | 'sm'`. Default = `h-11` so the trigger matches <Input>'s h-11 default and the 8px height mismatch called out in the UAT vanishes platform-wide. Existing call sites that need the legacy compact look (FilterBar, dense table headers) opt back in via `size="sm"`. Nothing breaks — the default render flips height without touching any other styling. Q59 Table density min-widths + nowrap. DataTable cells now default to `whitespace-nowrap` so long values (URLs, names, addresses) don't wrap into 4-5 lines and inflate row height. Columns that need wrapping override via the column def's `meta.wrap = true`. Min-width comes from `column.getSize?.()` when set so a column doesn't shrink- wrap below readability — opt-in per column rather than a sweeping width change. Q61 Error message audit foundation — Documenso 401/403 path enriched. <PortDocumensoConfig> gains `apiKeySource` + `apiUrlSource` ('port' | 'global' | 'env' | 'default' | 'none'). `getPortDocumensoConfig` populates them based on which layer of the resolver chain produced the value. documenso-client's <ResolvedCreds> exposes the source flags; the 401/403 branch surfaces them in the `DOCUMENSO_AUTH_FAILURE` internalMessage so operators see "api key source: env, port: <id>" instead of the prior generic `path → 401` body. Solves the Documenso diagnosis loop that prompted the platform-wide error audit. Same pattern can extend to other integration error paths in follow-ups (S3, Redis, IMAP) — the resolver-source helper lives on PortConfig now. Q60 Tooltip audit primitive already shipped — <FieldLabel> in `ui/field-label.tsx` is the canonical surface with an Info icon + Tooltip slot. One adopter live (custom-field-form); remaining admin-form sweep is the lift that's parked. Deferred: Q57 recharts → ECharts migration (6-10h). Pure visual port of 8 chart components; safer as a focused session with per-chart visual review. Pre-reqs (ECharts deps + the transpilePackages config + the d3-geo install) are in place so the migration can be picked up cleanly. Verified: tsc clean, vitest 1454/1454. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 23:49:22 +02:00
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & {
size?: SelectTriggerSize;
}
>(({ className, children, size = 'default', ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
feat(uat-batch): Group Q — platform refactors Q58, Q59, Q61 from the 2026-05-21 plan. Q57 + Q60 (sweep-scope) parked. Shipped: Q58 SelectTrigger size variant. <SelectTrigger> now accepts `size?: 'default' | 'sm'`. Default = `h-11` so the trigger matches <Input>'s h-11 default and the 8px height mismatch called out in the UAT vanishes platform-wide. Existing call sites that need the legacy compact look (FilterBar, dense table headers) opt back in via `size="sm"`. Nothing breaks — the default render flips height without touching any other styling. Q59 Table density min-widths + nowrap. DataTable cells now default to `whitespace-nowrap` so long values (URLs, names, addresses) don't wrap into 4-5 lines and inflate row height. Columns that need wrapping override via the column def's `meta.wrap = true`. Min-width comes from `column.getSize?.()` when set so a column doesn't shrink- wrap below readability — opt-in per column rather than a sweeping width change. Q61 Error message audit foundation — Documenso 401/403 path enriched. <PortDocumensoConfig> gains `apiKeySource` + `apiUrlSource` ('port' | 'global' | 'env' | 'default' | 'none'). `getPortDocumensoConfig` populates them based on which layer of the resolver chain produced the value. documenso-client's <ResolvedCreds> exposes the source flags; the 401/403 branch surfaces them in the `DOCUMENSO_AUTH_FAILURE` internalMessage so operators see "api key source: env, port: <id>" instead of the prior generic `path → 401` body. Solves the Documenso diagnosis loop that prompted the platform-wide error audit. Same pattern can extend to other integration error paths in follow-ups (S3, Redis, IMAP) — the resolver-source helper lives on PortConfig now. Q60 Tooltip audit primitive already shipped — <FieldLabel> in `ui/field-label.tsx` is the canonical surface with an Info icon + Tooltip slot. One adopter live (custom-field-form); remaining admin-form sweep is the lift that's parked. Deferred: Q57 recharts → ECharts migration (6-10h). Pure visual port of 8 chart components; safer as a focused session with per-chart visual review. Pre-reqs (ECharts deps + the transpilePackages config + the d3-geo install) are in place so the migration can be picked up cleanly. Verified: tsc clean, vitest 1454/1454. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 23:49:22 +02:00
'flex w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background data-placeholder:text-muted-foreground focus:outline-hidden focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1',
size === 'sm' ? 'h-9' : 'h-11',
className,
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDown className="h-4 w-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
const SelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollUpButton
ref={ref}
className={cn('flex cursor-default items-center justify-center py-1', className)}
{...props}
>
<ChevronUp className="h-4 w-4" />
</SelectPrimitive.ScrollUpButton>
));
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
const SelectScrollDownButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollDownButton
ref={ref}
className={cn('flex cursor-default items-center justify-center py-1', className)}
{...props}
>
<ChevronDown className="h-4 w-4" />
</SelectPrimitive.ScrollDownButton>
));
SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
>(({ className, children, position = 'popper', ...props }, ref) => (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
ref={ref}
className={cn(
'relative z-50 max-h-(--radix-select-content-available-height) min-w-32 overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-select-content-transform-origin)',
position === 'popper' &&
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
className,
)}
position={position}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
'p-1',
position === 'popper' &&
'h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width)',
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
));
SelectContent.displayName = SelectPrimitive.Content.displayName;
const SelectLabel = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Label
ref={ref}
className={cn('px-2 py-1.5 text-sm font-semibold', className)}
{...props}
/>
));
SelectLabel.displayName = SelectPrimitive.Label.displayName;
const SelectItem = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Item
ref={ref}
className={cn(
'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-hidden focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50',
className,
)}
{...props}
>
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
));
SelectItem.displayName = SelectPrimitive.Item.displayName;
const SelectSeparator = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Separator
ref={ref}
className={cn('-mx-1 my-1 h-px bg-muted', className)}
{...props}
/>
));
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
export {
Select,
SelectGroup,
SelectValue,
SelectTrigger,
SelectContent,
SelectLabel,
SelectItem,
SelectSeparator,
SelectScrollUpButton,
SelectScrollDownButton,
};