@airplane/views
Version:
A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.
56 lines (55 loc) • 2 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { Checkbox as Checkbox$1 } from "@mantine/core";
import { forwardRef, useCallback } from "react";
import { ComponentErrorBoundary } from "../errorBoundary/ComponentErrorBoundary.js";
import { useCheckboxState } from "../../state/components/boolean/useBooleanState.js";
import { useRegisterFormInput } from "../../state/components/form/useRegisterFormInput.js";
import { useInput } from "../../state/components/input/useInput.js";
import { useComponentId } from "../../state/components/useId.js";
const CheckboxComponent = /* @__PURE__ */ forwardRef(({
width,
...props
}, ref) => {
const propsOnChange = props.onChange;
const onChange = useCallback((e) => {
propsOnChange == null ? void 0 : propsOnChange(e.currentTarget.checked);
}, [propsOnChange]);
return /* @__PURE__ */ jsx(Checkbox$1, { ...props, ref, onChange });
});
CheckboxComponent.displayName = "CheckboxComponent";
const Checkbox = /* @__PURE__ */ forwardRef((props, ref) => /* @__PURE__ */ jsx(ComponentErrorBoundary, { componentName: DISPLAY_NAME, children: /* @__PURE__ */ jsx(CheckboxWithoutRef, { ...props, innerRef: ref }) }));
const DISPLAY_NAME = "Checkbox";
Checkbox.displayName = DISPLAY_NAME;
const CheckboxWithoutRef = (props) => {
const id = useComponentId(props.id);
const {
state,
dispatch
} = useCheckboxState(id, {
initialState: {
value: props.checked ?? props.defaultChecked,
disabled: props.disabled ?? props.defaultDisabled
}
});
const {
inputProps
} = useInput(props, state, dispatch, (v) => v);
useRegisterFormInput(id, "checkbox");
const {
value: checked,
...restInputProps
} = inputProps;
const {
innerRef,
validate: _,
onChange: __,
...restProps
} = props;
return /* @__PURE__ */ jsx(CheckboxComponent, { checked, ref: innerRef, ...restInputProps, ...restProps });
};
export {
Checkbox,
CheckboxComponent,
CheckboxWithoutRef
};
//# sourceMappingURL=Checkbox.js.map