Skip to content

Commit 407edd8

Browse files
authored
feat: improve "required field" design (#576)
fixes #509
1 parent 30d2654 commit 407edd8

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

renderer/src/common/components/ui/form.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313

1414
import { cn } from '@/common/lib/utils'
1515
import { Label } from '@/common/components/ui/label'
16+
import { TooltipValueRequired } from './tooltip-value-required'
1617

1718
const Form = FormProvider
1819

@@ -88,9 +89,13 @@ function FormItem({ className, ...props }: React.ComponentProps<'div'>) {
8889
function FormLabel({
8990
className,
9091
readOnly,
92+
required,
9193
children,
9294
...props
93-
}: React.ComponentProps<typeof LabelPrimitive.Root> & { readOnly?: boolean }) {
95+
}: React.ComponentProps<typeof LabelPrimitive.Root> & {
96+
readOnly?: boolean
97+
required?: boolean
98+
}) {
9499
const { error, formItemId } = useFormField()
95100

96101
return (
@@ -102,6 +107,7 @@ function FormLabel({
102107
{...props}
103108
>
104109
{children}
110+
{required && <TooltipValueRequired />}
105111
{readOnly && (
106112
<span className="text-muted-foreground text-xs">(read-only)</span>
107113
)}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Tooltip, TooltipTrigger, TooltipContent } from './tooltip'
2+
3+
export function TooltipValueRequired() {
4+
return (
5+
<Tooltip>
6+
<TooltipTrigger asChild autoFocus={false}>
7+
<span
8+
aria-label="required"
9+
className="text-destructive ml-0.5 cursor-help align-super font-sans text-sm"
10+
>
11+
*
12+
</span>
13+
</TooltipTrigger>
14+
<TooltipContent>Required</TooltipContent>
15+
</Tooltip>
16+
)
17+
}

renderer/src/features/registry-servers/components/form-run-from-registry/configuration-tab-content.tsx

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ import { AlertErrorFormSubmission } from '../alert-error-form-submission'
1212
import type { UseFormReturn } from 'react-hook-form'
1313
import type { FormSchemaRunFromRegistry } from '../../lib/get-form-schema-run-from-registry'
1414
import type { GroupedEnvVars } from '../../lib/group-env-vars'
15-
import {
16-
Tooltip,
17-
TooltipContent,
18-
TooltipTrigger,
19-
} from '@/common/components/ui/tooltip'
2015
import type { RegistryEnvVar } from '@/common/api/generated/types.gen'
2116
import { cn } from '@/common/lib/utils'
22-
import { AsteriskIcon } from 'lucide-react'
2317
import { FormComboboxSecretStore } from '@/common/components/secrets/form-combobox-secrets-store'
2418

2519
interface ConfigurationTabContentProps {
@@ -30,21 +24,6 @@ interface ConfigurationTabContentProps {
3024
groupedEnvVars: GroupedEnvVars
3125
}
3226

33-
/**
34-
* Renders an asterisk icon & tooltip for required fields.
35-
* NOTE: uses absolute positioning & assumes that it is being rendered inside a container with `position: relative`.
36-
*/
37-
function TooltipValueRequired() {
38-
return (
39-
<Tooltip>
40-
<TooltipTrigger asChild autoFocus={false}>
41-
<AsteriskIcon className="text-muted-foreground size-4" />
42-
</TooltipTrigger>
43-
<TooltipContent>Required</TooltipContent>
44-
</Tooltip>
45-
)
46-
}
47-
4827
function SecretRow({
4928
secret,
5029
form,
@@ -63,16 +42,15 @@ function SecretRow({
6342
<FormItem>
6443
<div className="relative">
6544
<FormControl>
66-
<Label
45+
<FormLabel
46+
required={secret.required}
6747
htmlFor={`secrets.${index}.value`}
6848
className={cn(
69-
'text-muted-foreground !border-input h-full items-center font-mono !ring-0',
70-
secret.required ? 'pr-8' : ''
49+
'text-muted-foreground !border-input h-full items-center font-mono !ring-0'
7150
)}
7251
>
73-
<span>{secret.name}</span>
74-
{secret.required && <TooltipValueRequired />}
75-
</Label>
52+
{secret.name}
53+
</FormLabel>
7654
</FormControl>
7755
</div>
7856
<FormMessage />
@@ -142,16 +120,16 @@ function EnvVarRow({
142120
<FormItem>
143121
<div className="relative">
144122
<FormControl>
145-
<Label
123+
<FormLabel
124+
required={envVar.required}
146125
htmlFor={`envVar.${index}.value`}
147126
className={cn(
148127
`text-muted-foreground !border-input flex h-full items-center gap-1 font-mono
149128
!ring-0`
150129
)}
151130
>
152-
<span>{envVar.name}</span>
153-
{envVar.required && <TooltipValueRequired />}
154-
</Label>
131+
{envVar.name}
132+
</FormLabel>
155133
</FormControl>
156134
</div>
157135
<FormMessage />

0 commit comments

Comments
 (0)