mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
refactor(app): move react components to react codebase [EE-3179] (#6971)
This commit is contained in:
parent
212400c283
commit
18252ab854
346 changed files with 642 additions and 644 deletions
57
app/react/components/form-components/Checkbox.tsx
Normal file
57
app/react/components/form-components/Checkbox.tsx
Normal file
|
@ -0,0 +1,57 @@
|
|||
import {
|
||||
forwardRef,
|
||||
useRef,
|
||||
useEffect,
|
||||
MutableRefObject,
|
||||
ChangeEventHandler,
|
||||
HTMLProps,
|
||||
} from 'react';
|
||||
|
||||
interface Props extends HTMLProps<HTMLInputElement> {
|
||||
checked?: boolean;
|
||||
indeterminate?: boolean;
|
||||
title?: string;
|
||||
label?: string;
|
||||
id: string;
|
||||
className?: string;
|
||||
role?: string;
|
||||
onChange?: ChangeEventHandler<HTMLInputElement>;
|
||||
}
|
||||
|
||||
export const Checkbox = forwardRef<HTMLInputElement, Props>(
|
||||
(
|
||||
{ indeterminate, title, label, id, checked, onChange, ...props }: Props,
|
||||
ref
|
||||
) => {
|
||||
const defaultRef = useRef<HTMLInputElement>(null);
|
||||
let resolvedRef = ref as MutableRefObject<HTMLInputElement | null>;
|
||||
if (!ref) {
|
||||
resolvedRef = defaultRef;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (resolvedRef === null || resolvedRef.current === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof indeterminate !== 'undefined') {
|
||||
resolvedRef.current.indeterminate = indeterminate;
|
||||
}
|
||||
}, [resolvedRef, indeterminate]);
|
||||
|
||||
return (
|
||||
<div className="md-checkbox" title={title || label}>
|
||||
<input
|
||||
id={id}
|
||||
type="checkbox"
|
||||
ref={resolvedRef}
|
||||
onChange={onChange}
|
||||
checked={checked}
|
||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||
{...props}
|
||||
/>
|
||||
<label htmlFor={id}>{label}</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue