diff --git a/components/dashboard/src/components/forms/CheckboxInputField.tsx b/components/dashboard/src/components/forms/CheckboxInputField.tsx new file mode 100644 index 00000000000000..5e42de90fb4240 --- /dev/null +++ b/components/dashboard/src/components/forms/CheckboxInputField.tsx @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2023 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License.AGPL.txt in the project root for license information. + */ + +import classNames from "classnames"; +import { FC, ReactNode, useCallback } from "react"; +import { useId } from "../../hooks/useId"; +import { InputField } from "./InputField"; +import { InputFieldHint } from "./InputFieldHint"; + +type CheckboxInputFieldProps = { + label: string; + error?: ReactNode; + className?: string; +}; +export const CheckboxInputField: FC = ({ label, error, className, children }) => { + return ( + +
{children}
+
+ ); +}; + +type CheckboxInputProps = { + id?: string; + value: string; + checked: boolean; + disabled?: boolean; + label: string; + hint?: string; + onChange: (checked: boolean) => void; +}; +export const CheckboxInput: FC = ({ + id, + value, + label, + hint, + checked, + disabled = false, + onChange, +}) => { + const maybeId = useId(); + const elementId = id || maybeId; + + const handleChange = useCallback( + (e) => { + onChange(e.target.checked); + }, + [onChange], + ); + + return ( + + ); +}; diff --git a/components/dashboard/src/components/forms/InputField.tsx b/components/dashboard/src/components/forms/InputField.tsx index 71948045ab9891..056b771750628a 100644 --- a/components/dashboard/src/components/forms/InputField.tsx +++ b/components/dashboard/src/components/forms/InputField.tsx @@ -6,6 +6,7 @@ import classNames from "classnames"; import { FunctionComponent, memo, ReactNode } from "react"; +import { InputFieldHint } from "./InputFieldHint"; type Props = { label?: ReactNode; @@ -21,7 +22,7 @@ export const InputField: FunctionComponent = memo(({ label, id, hint, err {label && (