From 563f913d2787a219ddfda2cf9c049b27d9ca1b75 Mon Sep 17 00:00:00 2001 From: Brad Harris Date: Fri, 24 Feb 2023 00:37:54 +0000 Subject: [PATCH 1/6] add CheckboxInput component --- .../src/components/forms/CheckboxInput.tsx | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 components/dashboard/src/components/forms/CheckboxInput.tsx diff --git a/components/dashboard/src/components/forms/CheckboxInput.tsx b/components/dashboard/src/components/forms/CheckboxInput.tsx new file mode 100644 index 00000000000000..d4f2bc25f15e5c --- /dev/null +++ b/components/dashboard/src/components/forms/CheckboxInput.tsx @@ -0,0 +1,41 @@ +/** + * 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 { FC, useCallback } from "react"; +import { useId } from "../../hooks/useId"; + +type Props = { + id?: string; + value: string; + checked: boolean; + label: string; + onChange: (checked: boolean) => void; +}; +export const CheckboxInput: FC = ({ id, value, label, checked, onChange }) => { + const maybeId = useId(); + const elementId = id || maybeId; + + const handleChange = useCallback( + (e) => { + onChange(e.target.checked); + }, + [onChange], + ); + + return ( + + ); +}; From 10fb450c80c8e7350de6b41c1948e57274424fb0 Mon Sep 17 00:00:00 2001 From: Brad Harris Date: Fri, 24 Feb 2023 00:38:08 +0000 Subject: [PATCH 2/6] use CheckboxInput component --- .../dashboard/src/onboarding/StepOrgInfo.tsx | 65 ++++++++----------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/components/dashboard/src/onboarding/StepOrgInfo.tsx b/components/dashboard/src/onboarding/StepOrgInfo.tsx index fb6118ad35180f..b9d515a8631b34 100644 --- a/components/dashboard/src/onboarding/StepOrgInfo.tsx +++ b/components/dashboard/src/onboarding/StepOrgInfo.tsx @@ -6,6 +6,7 @@ import { User } from "@gitpod/gitpod-protocol"; import { FC, useCallback, useMemo, useState } from "react"; +import { CheckboxInput } from "../components/forms/CheckboxInput"; import { InputField } from "../components/forms/InputField"; import { SelectInputField } from "../components/forms/SelectInputField"; import { TextInputField } from "../components/forms/TextInputField"; @@ -190,50 +191,38 @@ export const StepOrgInfo: FC = ({ user, onComplete }) => {
{explorationReasonsOptions.map((o) => ( -
- { - if (e.target.checked) { - addExplorationReason(o.value); - } else { - removeExplorationReason(o.value); - } - }} - /> - -
+ { + if (checked) { + addExplorationReason(o.value); + } else { + removeExplorationReason(o.value); + } + }} + /> ))}
{signupGoalsOptions.map((o) => ( -
- { - if (e.target.checked) { - addSignupGoal(o.value); - } else { - removeSignupGoal(o.value); - } - }} - /> - -
+ { + if (checked) { + addSignupGoal(o.value); + } else { + removeSignupGoal(o.value); + } + }} + /> ))}
From 61790c2e486111d8cfa11ff06b174dec502c73af Mon Sep 17 00:00:00 2001 From: Brad Harris Date: Fri, 24 Feb 2023 01:20:31 +0000 Subject: [PATCH 3/6] wip --- .../src/components/forms/CheckboxInput.tsx | 29 ++++++++++++++++--- .../src/components/forms/InputField.tsx | 3 +- .../src/components/forms/InputFieldHint.tsx | 11 +++++++ .../dashboard/src/onboarding/StepOrgInfo.tsx | 2 ++ 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 components/dashboard/src/components/forms/InputFieldHint.tsx diff --git a/components/dashboard/src/components/forms/CheckboxInput.tsx b/components/dashboard/src/components/forms/CheckboxInput.tsx index d4f2bc25f15e5c..afea4fdcbc4968 100644 --- a/components/dashboard/src/components/forms/CheckboxInput.tsx +++ b/components/dashboard/src/components/forms/CheckboxInput.tsx @@ -4,17 +4,21 @@ * See License.AGPL.txt in the project root for license information. */ +import classNames from "classnames"; import { FC, useCallback } from "react"; import { useId } from "../../hooks/useId"; +import { InputFieldHint } from "./InputFieldHint"; type Props = { id?: string; value: string; checked: boolean; + disabled?: boolean; label: string; + hint?: string; onChange: (checked: boolean) => void; }; -export const CheckboxInput: FC = ({ id, value, label, checked, onChange }) => { +export const CheckboxInput: FC = ({ id, value, label, hint, checked, disabled = false, onChange }) => { const maybeId = useId(); const elementId = id || maybeId; @@ -26,16 +30,33 @@ export const CheckboxInput: FC = ({ id, value, label, checked, onChange } ); return ( -