Files
Netcatty/domain/hostClickBehavior.ts
T
bincxz a80b1bfbaa fix(vault): tighten list padding and use inset ring for focus
Selected list borders were eating into content and looking like extra
left padding. Use inset primary ring (no layout shift) and reduce list
row horizontal padding from px-3 to px-2.
2026-07-14 13:43:16 +08:00

56 lines
1.8 KiB
TypeScript

/**
* Vault host/group click activation.
*
* - `connect` (default): single click immediately connects / opens
* - `select`: first click focuses; click the focused item again to activate
*/
export type HostClickBehavior = 'connect' | 'select';
export const DEFAULT_HOST_CLICK_BEHAVIOR: HostClickBehavior = 'connect';
export function isHostClickBehavior(value: unknown): value is HostClickBehavior {
return value === 'connect' || value === 'select';
}
export function resolveHostActivateAction(input: {
behavior: HostClickBehavior;
isMultiSelectMode: boolean;
focusedHostId: string | null | undefined;
hostId: string;
}): 'connect' | 'select' | 'toggle-multi' {
if (input.isMultiSelectMode) return 'toggle-multi';
if (input.behavior === 'connect') return 'connect';
if (input.focusedHostId === input.hostId) return 'connect';
return 'select';
}
export function resolveGroupActivateAction(input: {
behavior: HostClickBehavior;
focusedGroupPath: string | null | undefined;
groupPath: string;
}): 'open' | 'select' {
if (input.behavior === 'connect') return 'open';
if (input.focusedGroupPath === input.groupPath) return 'open';
return 'select';
}
/**
* Focus styles for vault host/group cards.
* Unfocused: no visible fill. Focused: accent edge only (no bg wash).
*
* List/tree use inset ring so content/padding does not shift when selected
* (adding a real border would push icons inward and look like extra padding).
*/
export function hostCardFocusClassName(
viewMode: 'grid' | 'list' | 'tree',
isFocused: boolean,
): string {
if (!isFocused) return '';
// Grid soft-card already draws a border; force accent color (beat .soft-card).
if (viewMode === 'grid') {
return '!border-primary';
}
// Inset ring draws on top of padding without changing layout.
return 'ring-1 ring-inset ring-primary';
}