Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

107 lines
2.9 KiB
TypeScript

'use client';
import * as React from 'react';
import * as SwitchPrimitives from '@radix-ui/react-switch';
import { useRegisterUIComponent } from '../ui-reflection/useRegisterUIComponent';
import { FormFieldComponent, AutomationProps } from '../ui-reflection/types';
import { withDataAutomationId } from '../ui-reflection/withDataAutomationId';
interface SwitchProps extends Omit<React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>, 'id'> {
/** Label text */
label?: string;
/** Unique identifier for UI reflection system */
id?: string;
/** Whether the switch is required */
required?: boolean;
/** Size variant */
size?: 'sm' | 'md' | 'lg';
/** Ref for the switch element */
ref?: React.Ref<React.ElementRef<typeof SwitchPrimitives.Root>>;
}
const switchSizeStyles: Record<'sm' | 'md' | 'lg', { root: React.CSSProperties; thumb: React.CSSProperties }> = {
sm: {
root: { width: '34px', height: '20px' },
thumb: { width: '16px', height: '16px', transform: 'translateX(2px)' },
},
md: {
root: {},
thumb: {},
},
lg: {
root: { width: '50px', height: '30px' },
thumb: { width: '26px', height: '26px', transform: 'translateX(2px)' },
},
};
const switchThumbCheckedTranslate: Record<'sm' | 'md' | 'lg', string> = {
sm: 'translateX(14px)',
md: '',
lg: 'translateX(20px)',
};
function Switch({
className,
label,
id,
required,
checked,
disabled,
size = 'md',
ref,
...props
}: SwitchProps & AutomationProps) {
// Register with UI reflection system
const updateMetadata = useRegisterUIComponent<FormFieldComponent>({
type: 'formField',
fieldType: 'checkbox',
id: id || '__skip_registration_switch',
label,
value: checked,
disabled,
required
});
// Update metadata when field props change
React.useEffect(() => {
if (updateMetadata) {
updateMetadata({
value: checked,
label,
disabled,
required
});
}
}, [checked, updateMetadata, label, disabled, required]);
const sizeRoot = switchSizeStyles[size].root;
const sizeThumb = switchSizeStyles[size].thumb;
const thumbStyle: React.CSSProperties = checked && switchThumbCheckedTranslate[size]
? { ...sizeThumb, transform: switchThumbCheckedTranslate[size] }
: { ...sizeThumb };
return (
<div className="flex items-center gap-2">
<SwitchPrimitives.Root
className={`switch-root ${className}`}
style={sizeRoot}
checked={checked}
disabled={disabled}
required={required}
{...withDataAutomationId({ id })}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb className="switch-thumb" style={thumbStyle} />
</SwitchPrimitives.Root>
{label && (
<label className="text-sm font-medium text-[rgb(var(--color-text-700))]">
{label}
</label>
)}
</div>
);
}
export { Switch };