/* * This file belongs to Hoist, an application development toolkit * developed by Extremely Heavy Industries (www.xh.io | info@xh.io) * * Copyright © 2026 Extremely Heavy Industries Inc. */ import {HoistInputProps, HoistInputModel, useHoistInputModel} from '@xh/hoist/cmp/input'; import {hoistCmp, HoistProps, StyleProps} from '@xh/hoist/core'; import {switchControl} from '@xh/hoist/kit/onsen'; import '@xh/hoist/mobile/register'; import {TEST_ID} from '@xh/hoist/utils/js'; import './SwitchInput.scss'; export interface SwitchInputProps extends HoistProps, HoistInputProps, StyleProps { value?: boolean; /** Onsen modifier string */ modifier?: string; } /** * Switch (toggle) control for non-nullable boolean values. */ export const [SwitchInput, switchInput] = hoistCmp.withFactory({ displayName: 'SwitchInput', className: 'xh-switch-input', render(props, ref) { return useHoistInputModel(cmp, props, ref, SwitchInputModel); } }); class SwitchInputModel extends HoistInputModel { override xhImpl = true; } //----------------------- // Implementation //----------------------- const cmp = hoistCmp.factory(({model, className, ...props}, ref) => { return switchControl({ checked: !!model.renderValue, disabled: props.disabled, modifier: props.modifier, tabIndex: props.tabIndex, className, style: props.style, [TEST_ID]: props.testId, onBlur: model.onBlur, onFocus: model.onFocus, onChange: e => model.noteValueChange(e.target.checked), ref }); });