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
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
104 lines
3.3 KiB
TypeScript
104 lines
3.3 KiB
TypeScript
'use client';
|
|
|
|
import React, { InputHTMLAttributes, useEffect, useRef } from 'react';
|
|
import { useRegisterUIComponent } from '../ui-reflection/useRegisterUIComponent';
|
|
import { FormFieldComponent, AutomationProps } from '../ui-reflection/types';
|
|
import { withDataAutomationId } from '../ui-reflection/withDataAutomationId';
|
|
import { cn } from '../lib/utils';
|
|
|
|
interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'id' | 'size'> {
|
|
label?: string | React.ReactNode;
|
|
/** Unique identifier for UI reflection system */
|
|
id?: string;
|
|
/** Whether the checkbox is required */
|
|
required?: boolean;
|
|
/** Skip UI reflection registration (useful when parent component handles registration) */
|
|
skipRegistration?: boolean;
|
|
/** Optional wrapper class overrides */
|
|
containerClassName?: string;
|
|
/** Display indeterminate state */
|
|
indeterminate?: boolean;
|
|
/** Size variant */
|
|
size?: 'sm' | 'md' | 'lg';
|
|
}
|
|
|
|
const checkboxSizeClasses: Record<'sm' | 'md' | 'lg', string> = {
|
|
sm: 'h-3.5 w-3.5',
|
|
md: 'h-4 w-4',
|
|
lg: 'h-5 w-5',
|
|
};
|
|
|
|
export function Checkbox({
|
|
label,
|
|
className,
|
|
id,
|
|
checked,
|
|
disabled,
|
|
required,
|
|
skipRegistration = false,
|
|
containerClassName,
|
|
indeterminate,
|
|
size = 'md',
|
|
...props
|
|
}: CheckboxProps & AutomationProps): React.ReactElement {
|
|
const checkboxRef = useRef<HTMLInputElement | null>(null);
|
|
|
|
// Register with UI reflection system if id is provided and not skipped
|
|
const updateMetadata = useRegisterUIComponent<FormFieldComponent>({
|
|
type: 'formField',
|
|
fieldType: 'checkbox',
|
|
id: skipRegistration ? '__skip_registration_checkbox' : (id || '__skip_registration_checkbox'),
|
|
label: typeof label === 'string' ? label : undefined,
|
|
value: typeof checked === 'boolean' ? checked : undefined,
|
|
disabled,
|
|
required
|
|
});
|
|
|
|
// Update metadata when field props change
|
|
useEffect(() => {
|
|
if (updateMetadata) {
|
|
updateMetadata({
|
|
value: typeof checked === 'boolean' ? checked : undefined,
|
|
label: typeof label === 'string' ? label : undefined,
|
|
disabled,
|
|
required
|
|
});
|
|
}
|
|
}, [checked, updateMetadata, label, disabled, required]);
|
|
|
|
useEffect(() => {
|
|
if (checkboxRef.current) {
|
|
checkboxRef.current.indeterminate = !!indeterminate && !checked;
|
|
}
|
|
}, [indeterminate, checked]);
|
|
|
|
const wrapperClasses = cn('flex items-center gap-2', containerClassName ?? 'mb-4');
|
|
|
|
return (
|
|
<div className={wrapperClasses}>
|
|
<input
|
|
type="checkbox"
|
|
className={`alga-checkbox ${checkboxSizeClasses[size]} rounded-md border-[rgb(var(--color-border-300))] text-primary-500 focus-visible:outline-none focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-0 focus:border-primary-500 ${className || ''}`}
|
|
style={{
|
|
accentColor: 'rgb(var(--color-primary-500))',
|
|
borderRadius: '0.375rem'
|
|
}}
|
|
checked={checked}
|
|
disabled={disabled}
|
|
required={required}
|
|
ref={checkboxRef}
|
|
onChange={(event) => {
|
|
props.onChange?.(event);
|
|
}}
|
|
{...props}
|
|
{...withDataAutomationId({ id })}
|
|
/>
|
|
{label && (
|
|
<label htmlFor={id} className="ml-2 block text-sm text-[rgb(var(--color-text-900))]">
|
|
{label}
|
|
</label>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|