diff --git a/components/dashboard/package.json b/components/dashboard/package.json index 5749dccb6118a0..0e722aeb564da8 100644 --- a/components/dashboard/package.json +++ b/components/dashboard/package.json @@ -10,6 +10,7 @@ "@gitpod/gitpod-protocol": "0.1.5", "@gitpod/public-api": "0.1.5", "@radix-ui/react-dropdown-menu": "^2.0.6", + "@radix-ui/react-label": "^2.0.2", "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-tooltip": "^1.0.7", diff --git a/components/dashboard/src/components/podkit/forms/Label.tsx b/components/dashboard/src/components/podkit/forms/Label.tsx new file mode 100644 index 00000000000000..eea1307559205c --- /dev/null +++ b/components/dashboard/src/components/podkit/forms/Label.tsx @@ -0,0 +1,20 @@ +/** + * 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 * as React from "react"; +import * as LabelPrimitive from "@radix-ui/react-label"; +import { cva, VariantProps } from "class-variance-authority"; +import { cn } from "@podkit/lib/cn"; + +const labelVariants = cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"); + +export const Label = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & VariantProps +>(({ className, ...props }, ref) => ( + +)); +Label.displayName = LabelPrimitive.Root.displayName; diff --git a/components/dashboard/src/components/podkit/forms/RadioListField.tsx b/components/dashboard/src/components/podkit/forms/RadioListField.tsx index fbbc69eb590b64..4eef5cba8cd673 100644 --- a/components/dashboard/src/components/podkit/forms/RadioListField.tsx +++ b/components/dashboard/src/components/podkit/forms/RadioListField.tsx @@ -5,45 +5,31 @@ */ import { cn } from "@podkit/lib/cn"; -import * as RadioGroup from "@radix-ui/react-radio-group"; +import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"; import { Circle } from "lucide-react"; -import React, { useCallback } from "react"; -import { useId } from "../../../hooks/useId"; -import { InputField } from "../../forms/InputField"; -import { InputFieldHint } from "../../forms/InputFieldHint"; - -type RadioListFieldProps = { - id?: string; - selectedValue: string; - hint?: React.ReactNode; - error?: React.ReactNode; - topMargin?: boolean; - onChange: (value: string) => void; - children: RadioListItem[]; - className?: string; -}; +import React from "react"; export const RadioGroupItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef + React.ElementRef, + React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => { return ( - - - - - + + + + ); }); -RadioGroupItem.displayName = RadioGroup.Item.displayName; +RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName; export type RadioListItem = { radio: React.ReactElement; @@ -51,45 +37,10 @@ export type RadioListItem = { hint?: React.ReactNode; }; -export const RadioListField: React.FC = ({ - id, - selectedValue, - error, - topMargin = true, - onChange, - children, - className, -}) => { - const maybeId = useId(); - const elementId = id || maybeId; - - const handleChange = useCallback( - (value) => { - onChange(value); - }, - [onChange], - ); - - return ( - - - {children.map((child, index) => ( -
- {React.cloneElement(child.radio, { - id: `${elementId}-${index}`, - })} - - {child.hint && {child.hint}} -
- ))} -
-
- ); -}; +export const RadioGroup = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + return ; +}); +RadioGroup.displayName = RadioGroupPrimitive.Root.displayName; diff --git a/components/dashboard/src/repositories/detail/workspaces/WorkpaceSizeOptions.tsx b/components/dashboard/src/repositories/detail/workspaces/WorkpaceSizeOptions.tsx index fbae3801ccee08..639516a322337a 100644 --- a/components/dashboard/src/repositories/detail/workspaces/WorkpaceSizeOptions.tsx +++ b/components/dashboard/src/repositories/detail/workspaces/WorkpaceSizeOptions.tsx @@ -5,9 +5,10 @@ */ import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb"; -import { RadioGroupItem, RadioListField } from "../../../components/podkit/forms/RadioListField"; import { useState } from "react"; import { useWorkspaceClasses } from "../../../data/workspaces/workspace-classes-query"; +import { Label } from "@podkit/forms/Label"; +import { RadioGroup, RadioGroupItem } from "@podkit/forms/RadioListField"; interface Props { configuration: Configuration; @@ -28,14 +29,13 @@ export const ConfigurationWorkspaceSizeOptions = ({ configuration }: Props) => { } return ( - ({ - radio: , - label: c.displayName, - hint: c.description, - }))} - /> + + {classes.map((wsClass) => ( +
+ + +
+ ))} +
); }; diff --git a/yarn.lock b/yarn.lock index 5c86a65f864295..00f040be3d8f56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2580,6 +2580,14 @@ "@babel/runtime" "^7.13.10" "@radix-ui/react-use-layout-effect" "1.0.1" +"@radix-ui/react-label@^2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@radix-ui/react-label/-/react-label-2.0.2.tgz#9c72f1d334aac996fdc27b48a8bdddd82108fb6d" + integrity sha512-N5ehvlM7qoTLx7nWPodsPYPgMzA5WM8zZChQg8nyFJKnDO5WHdba1vv5/H6IO5LtJMfD2Q3wh1qHFGNtK0w3bQ== + dependencies: + "@babel/runtime" "^7.13.10" + "@radix-ui/react-primitive" "1.0.3" + "@radix-ui/react-menu@2.0.6": version "2.0.6" resolved "https://registry.yarnpkg.com/@radix-ui/react-menu/-/react-menu-2.0.6.tgz#2c9e093c1a5d5daa87304b2a2f884e32288ae79e"