Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Use Text component for texts, place hint above the action field

Blue Mouse7369e0e380d3
diff --git a/web/app/ui/Checkbox.tsx b/web/app/ui/Checkbox.tsx
index e44f3e3d1..9458e95e9 100644
--- a/web/app/ui/Checkbox.tsx
+++ b/web/app/ui/Checkbox.tsx
@@ -5,8 +5,9 @@ import {
Label,
} from '@headlessui/react'
import { CheckIcon, MinusIcon } from '@phosphor-icons/react'
-import cx from 'clsx'
import React, { memo } from 'react'
+import { Text } from './Text'
+import { cn } from '~/utils/generic'
interface CheckboxProps {
label: React.ReactNode
@@ -33,13 +34,13 @@ const Checkbox = ({
classes,
}: CheckboxProps) => (
<Field disabled={disabled}>
- <div className={cx('group flex items-center gap-x-2', classes?.label)}>
+ <div className={cn('group flex items-center gap-x-2', classes?.label)}>
<HeadlessCheckbox
name={name}
checked={checked}
indeterminate={indeterminate}
onChange={onChange}
- className={cx(
+ className={cn(
'group/checkbox relative size-4 shrink-0 cursor-pointer rounded-[5px] bg-white ring-1 ring-gray-300 transition-[background-color,box-shadow] duration-150 ease-out ring-inset',
'group-hover:ring-gray-400 dark:bg-slate-950 dark:ring-slate-700/80 dark:group-hover:ring-slate-600',
'data-checked:bg-slate-900 data-checked:ring-slate-900 dark:data-checked:bg-slate-100 dark:data-checked:ring-slate-100',
@@ -65,13 +66,15 @@ const Checkbox = ({
</Label>
</div>
{hint ? (
- <Description
- className={cx(
- 'mt-1 text-sm text-gray-500 dark:text-gray-400',
- classes?.hint,
- )}
- >
- {hint}
+ <Description>
+ <Text
+ as='span'
+ className={cn('mt-1 block leading-tight', classes?.hint)}
+ colour='secondary'
+ size='sm'
+ >
+ {hint}
+ </Text>
</Description>
) : null}
</Field>
diff --git a/web/app/ui/FileUpload.tsx b/web/app/ui/FileUpload.tsx
index 80a4e54a6..890f3e445 100644
--- a/web/app/ui/FileUpload.tsx
+++ b/web/app/ui/FileUpload.tsx
@@ -29,6 +29,8 @@ export default function FileUpload({
const [dragOver, setDragOver] = useState(false)
const isDisabled = disabled || loading
+ const hintId = `${inputId}-hint`
+ const showHint = Boolean(hint && !loading)
const handleFile = useCallback(
(file: File | undefined) => {
@@ -73,76 +75,85 @@ export default function FileUpload({
)
return (
- <label
- htmlFor={inputId}
- className={cn(
- 'group relative flex cursor-pointer flex-col items-center justify-center rounded-xl border-2 border-dashed p-6 text-center transition-[background-color,border-color,box-shadow] duration-200 ease-out',
- 'focus-within:ring-2 focus-within:ring-slate-900 focus-within:ring-offset-2 dark:focus-within:ring-slate-300 dark:focus-within:ring-offset-slate-950',
- isDisabled
- ? 'cursor-not-allowed border-gray-200 bg-gray-50/50 dark:border-slate-800 dark:bg-slate-900/40'
- : dragOver
- ? 'border-slate-900 bg-slate-50 dark:border-slate-300 dark:bg-slate-800/40'
- : 'border-gray-300 hover:border-gray-400 hover:bg-gray-50/60 dark:border-slate-700 dark:hover:border-slate-600 dark:hover:bg-slate-900/40',
- className,
- )}
- aria-disabled={isDisabled || undefined}
- onDragOver={handleDragOver}
- onDragLeave={handleDragLeave}
- onDrop={handleDrop}
- >
- <input
- ref={inputRef}
- id={inputId}
- type='file'
- className='sr-only'
- accept={accept}
- disabled={isDisabled}
- onChange={handleChange}
- />
+ <div className='flex flex-col gap-1'>
+ {showHint ? (
+ <Text
+ as='span'
+ id={hintId}
+ className='block leading-tight whitespace-pre-line'
+ size='sm'
+ colour='secondary'
+ >
+ {hint}
+ </Text>
+ ) : null}
+ <label
+ htmlFor={inputId}
+ className={cn(
+ 'group relative flex cursor-pointer flex-col items-center justify-center rounded-xl border-2 border-dashed p-6 text-center transition-[background-color,border-color,box-shadow] duration-200 ease-out',
+ 'focus-within:ring-2 focus-within:ring-slate-900 focus-within:ring-offset-2 dark:focus-within:ring-slate-300 dark:focus-within:ring-offset-slate-950',
+ isDisabled
+ ? 'cursor-not-allowed border-gray-200 bg-gray-50/50 dark:border-slate-800 dark:bg-slate-900/40'
+ : dragOver
+ ? 'border-slate-900 bg-slate-50 dark:border-slate-300 dark:bg-slate-800/40'
+ : 'border-gray-300 hover:border-gray-400 hover:bg-gray-50/60 dark:border-slate-700 dark:hover:border-slate-600 dark:hover:bg-slate-900/40',
+ className,
+ )}
+ aria-disabled={isDisabled || undefined}
+ onDragOver={handleDragOver}
+ onDragLeave={handleDragLeave}
+ onDrop={handleDrop}
+ >
+ <input
+ ref={inputRef}
+ id={inputId}
+ type='file'
+ className='sr-only'
+ accept={accept}
+ disabled={isDisabled}
+ aria-describedby={showHint ? hintId : undefined}
+ onChange={handleChange}
+ />
- {loading ? (
- <div className='space-y-2'>
- <SpinnerIcon className='mx-auto size-8 animate-spin text-gray-400 dark:text-gray-500' />
- {label && (
- <Text
- as='p'
- size='sm'
- colour='inherit'
- className='text-gray-500 dark:text-gray-400'
+ {loading ? (
+ <div className='space-y-2'>
+ <SpinnerIcon className='mx-auto size-8 animate-spin text-gray-400 dark:text-gray-500' />
+ {label && (
+ <Text
+ as='p'
+ size='sm'
+ colour='inherit'
+ className='text-gray-500 dark:text-gray-400'
+ >
+ {label}
+ </Text>
+ )}
+ </div>
+ ) : (
+ <div className='space-y-2'>
+ <div
+ className={cn(
+ 'mx-auto flex size-10 items-center justify-center rounded-lg bg-gray-100 text-gray-500 transition-colors duration-200 ease-out dark:bg-slate-800/80 dark:text-gray-400',
+ !isDisabled &&
+ 'group-hover:bg-gray-200 group-hover:text-gray-700 dark:group-hover:bg-slate-800 dark:group-hover:text-gray-200',
+ dragOver &&
+ 'bg-slate-200 text-slate-900 dark:bg-slate-700 dark:text-white',
+ )}
>
- {label}
- </Text>
- )}
- </div>
- ) : (
- <div className='space-y-2'>
- <div
- className={cn(
- 'mx-auto flex size-10 items-center justify-center rounded-lg bg-gray-100 text-gray-500 transition-colors duration-200 ease-out dark:bg-slate-800/80 dark:text-gray-400',
- !isDisabled &&
- 'group-hover:bg-gray-200 group-hover:text-gray-700 dark:group-hover:bg-slate-800 dark:group-hover:text-gray-200',
- dragOver &&
- 'bg-slate-200 text-slate-900 dark:bg-slate-700 dark:text-white',
+ <UploadIcon
+ className='size-5'
+ weight='duotone'
+ aria-hidden='true'
+ />
+ </div>
+ {label && (
+ <Text as='p' size='sm' weight='medium' colour='primary'>
+ {label}
+ </Text>
)}
- >
- <UploadIcon
- className='size-5'
- weight='duotone'
- aria-hidden='true'
- />
</div>
- {label && (
- <Text as='p' size='sm' weight='medium' colour='primary'>
- {label}
- </Text>
- )}
- {hint && (
- <Text as='p' size='xs' colour='muted'>
- {hint}
- </Text>
- )}
- </div>
- )}
- </label>
+ )}
+ </label>
+ </div>
)
}
diff --git a/web/app/ui/MultiSelect.tsx b/web/app/ui/MultiSelect.tsx
index 4822d554e..0a3d74e82 100644
--- a/web/app/ui/MultiSelect.tsx
+++ b/web/app/ui/MultiSelect.tsx
@@ -4,20 +4,28 @@ import cx from 'clsx'
import _includes from 'lodash/includes'
import _isEmpty from 'lodash/isEmpty'
import _map from 'lodash/map'
-import { useState, useEffect, useRef, useId, useMemo } from 'react'
+import {
+ useState,
+ useEffect,
+ useRef,
+ useId,
+ useMemo,
+ type ReactNode,
+} from 'react'
+import { Text } from './Text'
interface MultiSelectProps {
className?: string
onRemove: (item: any) => void
onSelect: (item: any) => void
items: any[]
- labelExtractor?: (item: any) => string
+ labelExtractor?: (item: any) => ReactNode
keyExtractor?: (item: any) => string
label: any[]
- hint?: string
+ hint?: ReactNode
placeholder?: string
onSearch?: (search: string) => void
- itemExtractor?: (item: any) => string
+ itemExtractor?: (item: any) => ReactNode
}
const MultiSelect = ({
@@ -39,6 +47,7 @@ const MultiSelect = ({
const dropdownRef = useRef<HTMLDivElement>(null)
const inputRef = useRef<HTMLInputElement>(null)
const listboxId = useId()
+ const hintId = useId()
const optionIdPrefix = useId()
useEffect(() => {
@@ -68,7 +77,7 @@ const MultiSelect = ({
const itemKey = useMemo(
() => (item: any) =>
- keyExtractor ? keyExtractor(item) : (itemExtractor?.(item) ?? item),
+ keyExtractor ? keyExtractor(item) : String(itemExtractor?.(item) ?? item),
[keyExtractor, itemExtractor],
)
@@ -146,6 +155,17 @@ const MultiSelect = ({
ref={dropdownRef}
className={cx('relative flex w-full flex-col', className)}
>
+ {hint ? (
+ <Text
+ as='span'
+ id={hintId}
+ className='mb-1 block leading-tight whitespace-pre-line'
+ size='sm'
+ colour='secondary'
+ >
+ {hint}
+ </Text>
+ ) : null}
<div className='relative'>
<input
ref={inputRef}
@@ -155,6 +175,7 @@ const MultiSelect = ({
aria-controls={listboxId}
aria-autocomplete='list'
aria-activedescendant={activeOptionId}
+ aria-describedby={hint ? hintId : undefined}
className='block w-full rounded-md border-0 bg-white py-2 pr-9 pl-3 text-sm font-medium text-gray-900 ring-1 ring-gray-300 transition-[background-color,box-shadow] duration-150 ease-out ring-inset placeholder:text-gray-400 hover:ring-gray-400 focus:ring-2 focus:ring-slate-900 focus:outline-hidden dark:bg-slate-950 dark:text-gray-50 dark:ring-slate-700/80 dark:placeholder:text-gray-500 dark:hover:ring-slate-600 dark:focus:ring-slate-300'
placeholder={placeholder}
value={searchValue}
@@ -182,9 +203,14 @@ const MultiSelect = ({
className='absolute top-full z-30 mt-1.5 max-h-60 w-full overflow-auto rounded-lg bg-white py-1 text-sm shadow-lg ring-1 ring-gray-200/80 focus:outline-hidden dark:bg-slate-950 dark:ring-slate-700/60'
>
{_isEmpty(items) ? (
- <div className='mx-1 px-3 py-2 text-gray-500 dark:text-gray-400'>
+ <Text
+ as='div'
+ size='sm'
+ colour='muted'
+ className='mx-1 px-3 py-2'
+ >
No options available
- </div>
+ </Text>
) : (
_map(items, (item, index) => {
const isSelected = _includes(label, item)
@@ -211,14 +237,16 @@ const MultiSelect = ({
},
)}
>
- <span
- className={cx('block truncate', {
- 'font-semibold': isSelected,
- 'font-normal': !isSelected,
- })}
+ <Text
+ as='span'
+ size='sm'
+ weight={isSelected ? 'semibold' : 'normal'}
+ colour='inherit'
+ truncate
+ className='block'
>
{itemExtractor ? itemExtractor(item) : item}
- </span>
+ </Text>
{isSelected ? (
<span className='absolute inset-y-0 right-2 flex items-center text-slate-900 dark:text-slate-100'>
<CheckIcon
@@ -243,9 +271,15 @@ const MultiSelect = ({
key={itemKey(item)}
className='inline-flex items-center gap-1.5 rounded-md bg-gray-100 py-1 pr-1.5 pl-2.5 text-xs font-medium text-gray-800 ring-1 ring-gray-200/70 ring-inset dark:bg-slate-800/60 dark:text-gray-100 dark:ring-slate-700/60'
>
- <span className='flex items-center gap-1.5'>
+ <Text
+ as='span'
+ size='xs'
+ weight='medium'
+ colour='inherit'
+ className='flex items-center gap-1.5'
+ >
{labelExtractor ? labelExtractor(item) : item}
- </span>
+ </Text>
<button
type='button'
onClick={(e) => {
@@ -253,7 +287,7 @@ const MultiSelect = ({
e.stopPropagation()
onRemove(item)
}}
- aria-label={`Remove ${labelExtractor ? labelExtractor(item) : item}`}
+ aria-label={`Remove ${itemKey(item)}`}
className='inline-flex size-4 shrink-0 items-center justify-center rounded text-gray-500 transition-colors hover:bg-gray-200 hover:text-gray-800 focus-visible:ring-2 focus-visible:ring-slate-900 focus-visible:outline-hidden dark:text-gray-400 dark:hover:bg-slate-700 dark:hover:text-gray-100 dark:focus-visible:ring-slate-300'
>
<XIcon className='size-3' weight='bold' aria-hidden='true' />
@@ -262,12 +296,6 @@ const MultiSelect = ({
))}
</div>
) : null}
-
- {hint ? (
- <p className='mt-1.5 text-sm whitespace-pre-line text-gray-500 dark:text-gray-400'>
- {hint}
- </p>
- ) : null}
</div>
)
}
diff --git a/web/app/ui/RadioCardGroup.tsx b/web/app/ui/RadioCardGroup.tsx
index d6cc31bad..c18676974 100644
--- a/web/app/ui/RadioCardGroup.tsx
+++ b/web/app/ui/RadioCardGroup.tsx
@@ -1,9 +1,11 @@
-import { Field, Label, Radio, RadioGroup } from '@headlessui/react'
+import { Description, Field, Label, Radio, RadioGroup } from '@headlessui/react'
import _map from 'lodash/map'
import { Fragment, type ReactNode } from 'react'
import { cn } from '~/utils/generic'
+import { Text } from './Text'
+
interface RadioCardOption<T extends string> {
value: T
label: ReactNode
@@ -60,12 +62,36 @@ export function RadioCardGroup<T extends string>({
const total = options.length
return (
- <Field as='div' className={className} disabled={disabled}>
+ <Field
+ as='div'
+ className={cn('flex flex-col gap-1', className)}
+ disabled={disabled}
+ >
{label ? (
- <Label className='mb-1 block text-sm font-medium text-gray-900 dark:text-gray-200'>
- {label}
+ <Label>
+ <Text
+ as='span'
+ className='block leading-tight whitespace-pre-line'
+ size='sm'
+ weight='medium'
+ colour='primary'
+ >
+ {label}
+ </Text>
</Label>
) : null}
+ {hint ? (
+ <Description as='div'>
+ <Text
+ as='span'
+ className='block leading-tight whitespace-pre-line'
+ size='sm'
+ colour='secondary'
+ >
+ {hint}
+ </Text>
+ </Description>
+ ) : null}
<RadioGroup
name={name}
value={value ?? undefined}
@@ -105,27 +131,34 @@ export function RadioCardGroup<T extends string>({
<RadioDot checked={checked} />
</span>
<span className='flex min-w-0 flex-col'>
- <span
+ <Text
+ as='span'
+ size='sm'
+ weight='medium'
+ colour='inherit'
className={cn(
- 'block text-sm font-medium',
+ 'block',
checked
? 'text-slate-900 dark:text-white'
: 'text-gray-700 dark:text-gray-200',
)}
>
{option.label}
- </span>
+ </Text>
{option.description ? (
- <span
+ <Text
+ as='span'
+ size='sm'
+ colour='inherit'
className={cn(
- 'mt-0.5 block text-sm',
+ 'mt-0.5 block',
checked
? 'text-slate-700 dark:text-slate-300'
: 'text-gray-500 dark:text-gray-400',
)}
>
{option.description}
- </span>
+ </Text>
) : null}
</span>
</label>
@@ -135,17 +168,9 @@ export function RadioCardGroup<T extends string>({
})}
</RadioGroup>
{isError && typeof error === 'string' ? (
- <p
- className='mt-1.5 text-sm text-red-600 dark:text-red-400'
- role='alert'
- >
+ <Text as='span' className='block' size='sm' colour='error' role='alert'>
{error}
- </p>
- ) : null}
- {hint ? (
- <p className='mt-1.5 text-sm whitespace-pre-line text-gray-500 dark:text-gray-400'>
- {hint}
- </p>
+ </Text>
) : null}
</Field>
)
diff --git a/web/app/ui/Select.tsx b/web/app/ui/Select.tsx
index 8d08c1a13..072870d43 100644
--- a/web/app/ui/Select.tsx
+++ b/web/app/ui/Select.tsx
@@ -10,12 +10,13 @@ import { CheckIcon, CaretUpDownIcon } from '@phosphor-icons/react'
import cx from 'clsx'
import _map from 'lodash/map'
import React, { Fragment, Key, memo } from 'react'
+import { Text } from './Text'
interface SelectProps<T> {
title?: React.ReactNode
description?: React.ReactNode
- label?: string
- hint?: string | React.ReactNode
+ label?: React.ReactNode
+ hint?: React.ReactNode
className?: string
fieldLabelClassName?: string
labelClassName?: string
@@ -30,7 +31,6 @@ interface SelectProps<T> {
descriptionExtractor?: (item: T, index: number) => React.ReactNode | null
onSelect: (item: T) => void
selectedItem?: T
- // Allow the button label to wrap to multiple lines instead of truncating.
wrap?: boolean
}
@@ -66,49 +66,79 @@ function Select<T>({
}
const hasDescriptions = !!descriptionExtractor
+ const generatedHintId = React.useId()
+ const hintId = hint ? `${id || generatedHintId}-hint` : undefined
return (
- <Listbox as='div' id={id || ''} value={selectedItem} onChange={onSelect}>
+ <Listbox
+ as='div'
+ className='flex flex-col gap-1'
+ id={id || ''}
+ value={selectedItem}
+ onChange={onSelect}
+ >
{({ open }) => (
<>
{label ? (
- <Label
+ <Label className={cx('block', fieldLabelClassName)}>
+ <Text
+ as='span'
+ className='flex leading-tight whitespace-pre-line'
+ size='sm'
+ weight='medium'
+ colour='primary'
+ >
+ {label}
+ </Text>
+ </Label>
+ ) : null}
+ {hint ? (
+ <Text
+ as='span'
+ id={hintId}
className={cx(
- 'mb-1 block text-sm font-medium whitespace-pre-line text-gray-900 dark:text-gray-200',
- fieldLabelClassName,
+ 'block leading-tight whitespace-pre-line',
+ hintClassName,
)}
+ size='sm'
+ colour='secondary'
>
- {label}
- </Label>
+ {hint}
+ </Text>
) : null}
<div className={cx('relative', className)}>
<ListboxButton
+ aria-describedby={hintId}
className={cx(
'relative w-full rounded-md border-0 bg-white py-2 pr-9 pl-3 text-left text-sm font-medium text-gray-900 ring-1 ring-gray-300 transition-[background-color,box-shadow] duration-150 ease-out ring-inset hover:ring-gray-400 focus-visible:ring-2 focus-visible:ring-slate-900 focus-visible:outline-hidden dark:bg-slate-950 dark:text-gray-50 dark:ring-slate-700/80 dark:hover:ring-slate-600 dark:focus-visible:ring-slate-300',
buttonClassName,
)}
>
- <span
+ <Text
+ as='span'
+ size='sm'
+ weight='medium'
+ colour='inherit'
+ truncate={!wrap}
className={cx('block', {
- truncate: !wrap,
'wrap-break-word': wrap,
'first-letter:capitalize': capitalise,
})}
>
{title}
- </span>
+ </Text>
{description ? (
- <span
- className={cx(
- 'mt-0.5 block text-xs font-normal text-gray-500 dark:text-gray-400',
- {
- truncate: !wrap,
- 'wrap-break-word': wrap,
- },
- )}
+ <Text
+ as='span'
+ size='xs'
+ colour='secondary'
+ truncate={!wrap}
+ className={cx('mt-0.5 block', {
+ 'wrap-break-word': wrap,
+ })}
>
{description}
- </span>
+ </Text>
) : null}
<span className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2'>
<CaretUpDownIcon
@@ -169,13 +199,15 @@ function Select<T>({
</span>
) : null}
- <span
+ <Text
+ as='span'
+ size='sm'
+ weight={selected ? 'semibold' : 'normal'}
+ colour='inherit'
className={cx(
'block wrap-break-word',
iconExtractor && 'pl-6',
{
- 'font-semibold': selected,
- 'font-normal': !selected,
'first-letter:capitalize': capitalise,
},
labelClassName,
@@ -184,17 +216,20 @@ function Select<T>({
{labelExtractor
? labelExtractor(item, index)
: (item as React.ReactNode)}
- </span>
+ </Text>
{itemDescription ? (
- <span
+ <Text
+ as='span'
+ size='xs'
+ colour='secondary'
className={cx(
- 'mt-0.5 block text-xs leading-snug font-normal wrap-break-word text-gray-500 dark:text-gray-400',
+ 'mt-0.5 block leading-snug wrap-break-word',
iconExtractor && 'pl-6',
)}
>
{itemDescription}
- </span>
+ </Text>
) : null}
{selected ? (
@@ -218,16 +253,6 @@ function Select<T>({
</ListboxOptions>
</Transition>
</div>
- {hint ? (
- <p
- className={cx(
- 'mt-1.5 text-sm whitespace-pre-line text-gray-500 dark:text-gray-400',
- hintClassName,
- )}
- >
- {hint}
- </p>
- ) : null}
</>
)}
</Listbox>
diff --git a/web/app/ui/Textarea.tsx b/web/app/ui/Textarea.tsx
index 3bd59fa11..41f6879a9 100644
--- a/web/app/ui/Textarea.tsx
+++ b/web/app/ui/Textarea.tsx
@@ -9,10 +9,12 @@ import React, { forwardRef, memo } from 'react'
import { cn } from '~/utils/generic'
+import { Text } from './Text'
+
interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
value: string | number
- label?: string
- hint?: string
+ label?: React.ReactNode
+ hint?: React.ReactNode
classes?: {
container?: string
textarea?: string
@@ -42,12 +44,35 @@ const Textarea = memo(
const isError = !_isEmpty(error)
return (
- <Field as='div' className={classes?.container}>
+ <Field
+ as='div'
+ className={cn('flex flex-col gap-1', classes?.container)}
+ >
{label ? (
- <Label className='mb-1 flex text-sm font-medium text-gray-900 dark:text-gray-200'>
- {label}
+ <Label>
+ <Text
+ as='span'
+ className='flex leading-tight whitespace-pre-line'
+ size='sm'
+ weight='medium'
+ colour='primary'
+ >
+ {label}
+ </Text>
</Label>
) : null}
+ {hint ? (
+ <Description as='div'>
+ <Text
+ as='span'
+ className='block leading-tight whitespace-pre-line'
+ size='sm'
+ colour='secondary'
+ >
+ {hint}
+ </Text>
+ </Description>
+ ) : null}
<HeadlessTextarea
ref={ref}
rows={rows}
@@ -76,17 +101,15 @@ const Textarea = memo(
{...rest}
/>
{isError ? (
- <p
- className='mt-1.5 text-sm text-red-600 dark:text-red-400'
+ <Text
+ as='span'
+ className='block'
+ size='sm'
+ colour='error'
role='alert'
>
{error}
- </p>
- ) : null}
- {hint ? (
- <Description className='mt-1.5 text-sm whitespace-pre-line text-gray-500 dark:text-gray-400'>
- {hint}
- </Description>
+ </Text>
) : null}
</Field>
)