mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-26 11:56:27 -08:00
Slightly improved looks of core components
This commit is contained in:
1 parent
dfd5ceca42
commit
622464f85e
9 files changed
+212
-114
No files matched your search
@@ -96,7 +96,7 @@ export function Button({
|
||||
'focus:ring-4 text-center relative flex items-center justify-center',
|
||||
{
|
||||
'rounded-full p-2 text-center min-h-[35px] min-w-[35px]': rounded,
|
||||
'rounded-md px-5 py-2.5': !rounded,
|
||||
'rounded-md px-5 py-3 min-h-[48px]': !rounded,
|
||||
},
|
||||
props.className
|
||||
);
|
||||
|
||||
@@ -67,7 +67,7 @@ export const CheckboxInternal = forwardRef<
|
||||
>
|
||||
<label
|
||||
className={classNames(
|
||||
'w-full h-[42px] flex gap-2 items-center text-standard-bold',
|
||||
'w-full h-[48px] flex gap-2 items-center text-standard-bold',
|
||||
{
|
||||
'px-3': outlined,
|
||||
'cursor-pointer': !disabled || !loading,
|
||||
|
||||
@@ -23,6 +23,11 @@ import { ProgressBar } from './ProgressBar';
|
||||
import { a11yClick } from '@/utils/a11y';
|
||||
import './Dropdown.scss';
|
||||
import { Typography } from './Typography';
|
||||
import {
|
||||
FLOATING_LABEL_PADDING,
|
||||
FieldCaption,
|
||||
FloatingLabel,
|
||||
} from './FloatingLabel';
|
||||
|
||||
export type DropdownItem = {
|
||||
value: string;
|
||||
@@ -46,6 +51,15 @@ type DropdownProps = {
|
||||
alignment?: 'left' | 'right';
|
||||
display?: 'fit' | 'block';
|
||||
placeholder: ReactNode;
|
||||
// Field label. Rendered as a caption above the box, unless `inside` is 'label'.
|
||||
label?: string;
|
||||
// What fills the box while nothing is selected:
|
||||
// 'placeholder' (default) - the placeholder text (blank if it is empty/null)
|
||||
// 'label' - the label, as a floating label inside the box
|
||||
// 'none' - nothing
|
||||
inside?: 'placeholder' | 'label' | 'none';
|
||||
// Keep the caption once a value is selected (default). Set false to drop it.
|
||||
persistLabel?: boolean;
|
||||
name: string;
|
||||
items: DropdownItem[];
|
||||
maxHeight?: string | number;
|
||||
@@ -87,13 +101,13 @@ function DropdownItem({
|
||||
}) {
|
||||
const variantStyles = {
|
||||
primary:
|
||||
'text-background-20 checked-hover:text-background-10 checked-hover:bg-background-50 focus:text-background-10 focus:bg-background-50',
|
||||
'text-background-10 checked-hover:text-background-10 checked-hover:bg-background-50 focus:text-background-10 focus:bg-background-50',
|
||||
secondary:
|
||||
'text-background-20 checked-hover:text-background-10 checked-hover:bg-background-40 focus:text-background-10 focus:bg-background-40',
|
||||
'text-background-10 checked-hover:text-background-10 checked-hover:bg-background-40 focus:text-background-10 focus:bg-background-40',
|
||||
tertiary:
|
||||
'bg-accent-background-30 checked-hover:bg-accent-background-20 focus:bg-accent-background-20 text-background-10',
|
||||
quaternary:
|
||||
'text-background-20 checked-hover:text-background-10 checked-hover:bg-background-60 focus:text-background-10 focus:bg-background-60',
|
||||
'text-background-10 checked-hover:text-background-10 checked-hover:bg-background-60 focus:text-background-10 focus:bg-background-60',
|
||||
};
|
||||
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
@@ -120,7 +134,7 @@ function DropdownItem({
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'py-2 px-2 min-w-max cursor-pointer text-standard-bold transition-colors select-none',
|
||||
'py-2 px-2 min-w-max cursor-pointer transition-colors select-none',
|
||||
variantStyles[variant],
|
||||
innerFocusValue === item.value && 'ring-inset ring-4'
|
||||
)}
|
||||
@@ -298,6 +312,9 @@ export function DropdownInside(
|
||||
alignment = 'right',
|
||||
display = 'fit',
|
||||
placeholder,
|
||||
label,
|
||||
inside = 'placeholder',
|
||||
persistLabel = true,
|
||||
name,
|
||||
items,
|
||||
maxHeight = '50vh',
|
||||
@@ -320,16 +337,21 @@ export function DropdownInside(
|
||||
block: 'w-full',
|
||||
};
|
||||
|
||||
const hasValue = props.multiple ? props.value.length > 0 : !!props.value;
|
||||
const labelInside = inside === 'label' && !!label;
|
||||
const showCaption = !!label && !labelInside && (persistLabel || !hasValue);
|
||||
const emptyValue = inside === 'placeholder' ? placeholder : '';
|
||||
|
||||
const getShownValue = (): ReactNode => {
|
||||
if (renderValue) return renderValue();
|
||||
if (props.multiple) {
|
||||
return props.value.length > 0
|
||||
? `${props.value.length} selected`
|
||||
: placeholder;
|
||||
: emptyValue;
|
||||
}
|
||||
return props.value
|
||||
? (items.find((item) => item.value === props.value)?.label ?? placeholder)
|
||||
: placeholder;
|
||||
: emptyValue;
|
||||
};
|
||||
|
||||
const selectItem = (item: DropdownItem) => {
|
||||
@@ -393,10 +415,11 @@ export function DropdownInside(
|
||||
}, [isOpen]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={classNames('flex flex-col gap-1', displayStyles[display])}>
|
||||
{showCaption && <FieldCaption>{label}</FieldCaption>}
|
||||
<div
|
||||
className={classNames(
|
||||
'min-h-[42px] min-w-0 text-background-10 text-left dropdown',
|
||||
'min-h-[48px] min-w-0 text-background-10 text-left dropdown',
|
||||
displayStyles[display]
|
||||
)}
|
||||
onKeyDown={(e) => {
|
||||
@@ -470,7 +493,8 @@ export function DropdownInside(
|
||||
if (!loading) setIsOpen((o) => !o);
|
||||
}}
|
||||
className={classNames(
|
||||
'flex flex-row justify-between items-center gap-2 pl-3 pr-5 py-3 rounded-md focus:ring-4 relative min-w-0 overflow-hidden',
|
||||
'flex flex-row items-center gap-2 pl-3 pr-11 rounded-md focus:ring-4 relative min-h-[48px] min-w-0 overflow-hidden',
|
||||
labelInside ? FLOATING_LABEL_PADDING : 'py-3',
|
||||
loading ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',
|
||||
variantStyles[variant]
|
||||
)}
|
||||
@@ -486,8 +510,16 @@ export function DropdownInside(
|
||||
}
|
||||
role="combobox"
|
||||
>
|
||||
<span className="min-w-0 truncate">{getShownValue()}</span>
|
||||
<div className="fill-background-10 shrink-0">
|
||||
{labelInside && <FloatingLabel label={label} floating={hasValue} />}
|
||||
<span
|
||||
className={classNames(
|
||||
'min-w-0 flex-grow truncate',
|
||||
!hasValue && 'text-background-20 italic'
|
||||
)}
|
||||
>
|
||||
{getShownValue()}
|
||||
</span>
|
||||
<div className="fill-background-10 pointer-events-none absolute inset-y-0 right-5 flex items-center">
|
||||
{direction === 'up' ? (
|
||||
<ArrowUpIcon size={16} />
|
||||
) : (
|
||||
@@ -529,7 +561,7 @@ export function DropdownInside(
|
||||
name={name}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import classNames from 'classnames';
|
||||
import { ReactNode } from 'react';
|
||||
import { Typography } from './Typography';
|
||||
|
||||
export function FloatingLabel({
|
||||
label,
|
||||
floating,
|
||||
className,
|
||||
}: {
|
||||
label: ReactNode;
|
||||
floating: boolean;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<Typography
|
||||
variant="standard"
|
||||
bold={floating}
|
||||
italic={!floating}
|
||||
color={classNames(
|
||||
'text-background-10 pointer-events-none absolute left-3 z-20 leading-none transition-all duration-150 ease-out',
|
||||
floating ? `top-[0.5rem] origin-left` : 'top-1/2 -translate-y-1/2',
|
||||
className
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
export function FieldCaption({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<Typography
|
||||
variant="standard"
|
||||
bold
|
||||
color={classNames('text-background-10 leading-none origin-left')}
|
||||
>
|
||||
{children}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
// Vertical padding a control needs so a floating label clears its value.
|
||||
export const FLOATING_LABEL_PADDING = 'pt-[1.15rem] pb-[0.15rem]';
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from 'react-hook-form';
|
||||
import { EyeIcon } from './icon/EyeIcon';
|
||||
import { Typography } from './Typography';
|
||||
import { FLOATING_LABEL_PADDING, FloatingLabel } from './FloatingLabel';
|
||||
|
||||
interface InputProps {
|
||||
variant?: 'primary' | 'secondary' | 'tertiary';
|
||||
@@ -47,6 +48,7 @@ export const InputInside = forwardRef<
|
||||
ref
|
||||
) {
|
||||
const [forceText, setForceText] = useState(false);
|
||||
const [focused, setFocused] = useState(false);
|
||||
|
||||
const togglePassword = (e: MouseEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
@@ -77,7 +79,7 @@ export const InputInside = forwardRef<
|
||||
|
||||
return classNames(
|
||||
variantsMap[variant],
|
||||
'w-full focus:ring-transparent focus:ring-offset-transparent min-h-[42px] z-10',
|
||||
'w-full focus:ring-transparent focus:ring-offset-transparent min-h-[48px] z-10',
|
||||
'focus:outline-transparent rounded-md focus:border-accent-background-40',
|
||||
'text-standard text-background-10 relative transition-colors',
|
||||
error && 'border-status-critical border-1'
|
||||
@@ -90,9 +92,18 @@ export const InputInside = forwardRef<
|
||||
? value
|
||||
: '';
|
||||
|
||||
// The label sits inside the field as a floating label: centered while the
|
||||
// field is empty and unfocused, shrunk to the top-left once focused or filled.
|
||||
// A bare placeholder with no label behaves the same way.
|
||||
const floatingText = label || placeholder;
|
||||
const hasFloatingLabel = !!floatingText && !disabled;
|
||||
const hasValue =
|
||||
value !== undefined && value !== null && String(value).length > 0;
|
||||
const floating = focused || hasValue;
|
||||
|
||||
return (
|
||||
<label className="flex flex-col gap-1">
|
||||
{label && <Typography>{label}</Typography>}
|
||||
{label && !hasFloatingLabel && <Typography>{label}</Typography>}
|
||||
<div className="relative w-full">
|
||||
<input
|
||||
type={forceText ? 'text' : type}
|
||||
@@ -100,18 +111,32 @@ export const InputInside = forwardRef<
|
||||
classes,
|
||||
{
|
||||
'pr-10 sentry-mask': type === 'password',
|
||||
[FLOATING_LABEL_PADDING]: hasFloatingLabel,
|
||||
},
|
||||
className
|
||||
)}
|
||||
placeholder={placeholder || undefined}
|
||||
placeholder={
|
||||
hasFloatingLabel
|
||||
? focused && placeholder && placeholder !== floatingText
|
||||
? placeholder
|
||||
: undefined
|
||||
: placeholder || undefined
|
||||
}
|
||||
autoComplete={autocomplete ? 'off' : 'on'}
|
||||
onChange={onChange}
|
||||
onFocus={() => setFocused(true)}
|
||||
name={name}
|
||||
value={computedValue} // Do we want that behaviour ?
|
||||
disabled={disabled}
|
||||
ref={ref}
|
||||
onBlur={onBlur}
|
||||
onBlur={() => {
|
||||
setFocused(false);
|
||||
onBlur?.();
|
||||
}}
|
||||
/>
|
||||
{hasFloatingLabel && (
|
||||
<FloatingLabel label={floatingText} floating={floating} />
|
||||
)}
|
||||
{type === 'password' && (
|
||||
<div
|
||||
className="fill-background-10 absolute inset-y-0 right-0 pr-6 z-10 my-auto w-[16px] h-[16px] cursor-pointer"
|
||||
@@ -123,7 +148,8 @@ export const InputInside = forwardRef<
|
||||
{error?.message && (
|
||||
<div
|
||||
className={classNames(
|
||||
'absolute top-[38px] z-0 pt-1.5 px-1 w-full rounded-b-md bg-dark-background-600 text-status-critical',
|
||||
'absolute z-0 pt-1.5 px-1 w-full rounded-b-md bg-dark-background-600 text-status-critical',
|
||||
hasFloatingLabel ? 'top-[calc(100%-4px)]' : 'top-[44px]',
|
||||
errorClassName
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Control, Controller, FieldPath, FieldValues } from 'react-hook-form';
|
||||
import { Button } from './Button';
|
||||
import { FieldCaption } from './FloatingLabel';
|
||||
import { Typography } from './Typography';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useLocaleConfig } from '@/i18n/config';
|
||||
@@ -58,57 +58,58 @@ export function NumberSelector<T extends FieldValues = FieldValues>({
|
||||
control={control}
|
||||
name={name}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
const hasLabel = label !== undefined && label.length !== 0;
|
||||
const shown = valueLabelFormat ? valueLabelFormat(value) : value;
|
||||
// Flat full-height stepper segments hugging the box edges.
|
||||
const segment =
|
||||
'flex min-w-[3rem] shrink-0 items-center justify-center px-3 text-lg font-bold leading-none text-background-10 fill-background-10 transition-colors enabled:hover:bg-background-50 disabled:opacity-30';
|
||||
return (
|
||||
<div className="flex flex-col gap-1 w-full">
|
||||
{label?.length != 0 ? <Typography bold>{label}</Typography> : <></>}
|
||||
<div className="flex gap-5 bg-background-60 p-2 rounded-lg">
|
||||
<div className="flex gap-1">
|
||||
{doubleStep !== undefined && (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(doubleStepFn(value, false))}
|
||||
disabled={doubleStepFn(value, false) < min || disabled}
|
||||
>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(-doubleStep)
|
||||
: '--'}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(stepFn(value, false))}
|
||||
disabled={stepFn(value, false) < min || disabled}
|
||||
{hasLabel && <FieldCaption>{label}</FieldCaption>}
|
||||
<div className="relative flex items-stretch min-h-[48px] overflow-hidden rounded-md bg-background-60">
|
||||
{doubleStep !== undefined && (
|
||||
<button
|
||||
type="button"
|
||||
className={segment}
|
||||
onClick={() => onChange(doubleStepFn(value, false))}
|
||||
disabled={doubleStepFn(value, false) < min || disabled}
|
||||
>
|
||||
-
|
||||
</Button>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(-doubleStep)
|
||||
: '−−'}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className={segment}
|
||||
onClick={() => onChange(stepFn(value, false))}
|
||||
disabled={stepFn(value, false) < min || disabled}
|
||||
>
|
||||
−
|
||||
</button>
|
||||
<div className="flex flex-grow items-center justify-center px-2 select-none">
|
||||
<Typography variant="standard">{shown}</Typography>
|
||||
</div>
|
||||
<div className="flex flex-grow justify-center text-center items-center w-10 text-standard">
|
||||
{valueLabelFormat ? valueLabelFormat(value) : value}
|
||||
</div>
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(stepFn(value, true))}
|
||||
disabled={stepFn(value, true) > max || disabled}
|
||||
<button
|
||||
type="button"
|
||||
className={segment}
|
||||
onClick={() => onChange(stepFn(value, true))}
|
||||
disabled={stepFn(value, true) > max || disabled}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
{doubleStep !== undefined && (
|
||||
<button
|
||||
type="button"
|
||||
className={segment}
|
||||
onClick={() => onChange(doubleStepFn(value, true))}
|
||||
disabled={doubleStepFn(value, true) > max || disabled}
|
||||
>
|
||||
+
|
||||
</Button>
|
||||
{doubleStep !== undefined && (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(doubleStepFn(value, true))}
|
||||
disabled={doubleStepFn(value, true) > max || disabled}
|
||||
>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(doubleStep)
|
||||
: '++'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(doubleStep)
|
||||
: '++'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -90,7 +90,6 @@ function BoardDefaultsGraph({ graph }: { graph: ComponentNode[] }) {
|
||||
<InputInside
|
||||
name={c.label}
|
||||
label={c.label}
|
||||
placeholder={c.label}
|
||||
value={c.value}
|
||||
type={c.format === 'number' ? 'number' : 'text'}
|
||||
error={
|
||||
@@ -107,20 +106,18 @@ function BoardDefaultsGraph({ graph }: { graph: ComponentNode[] }) {
|
||||
|
||||
if (c.type === 'dropdown') {
|
||||
return (
|
||||
<div
|
||||
className="flex flex-col pt-2 gap-1 min-w-0"
|
||||
key={c.path.join('/')}
|
||||
>
|
||||
<Typography>{c.label}</Typography>
|
||||
<div className="flex flex-col pt-2 min-w-0" key={c.path.join('/')}>
|
||||
<DropdownInside
|
||||
items={c.items.map((i) => ({ value: i, label: i }))}
|
||||
name={c.label}
|
||||
label={c.label}
|
||||
onChange={c.onMutate}
|
||||
error={
|
||||
c.error
|
||||
? { type: 'validate', message: l10n.getString(c.error) }
|
||||
: undefined
|
||||
}
|
||||
inside="label"
|
||||
placeholder={c.label}
|
||||
display="block"
|
||||
value={c.value}
|
||||
|
||||
@@ -201,48 +201,36 @@ export function TapDetectionSettings() {
|
||||
/>
|
||||
</div>
|
||||
<div className="grid sm:grid-cols-3 gap-5 pb-2">
|
||||
<div>
|
||||
<Typography bold>
|
||||
{l10n.getString(
|
||||
'settings-general-gesture_control-yawResetTracker'
|
||||
)}
|
||||
</Typography>
|
||||
<Dropdown
|
||||
display="block"
|
||||
control={control}
|
||||
placeholder={''}
|
||||
name="yawResetTracker"
|
||||
items={bodyParts}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Typography bold>
|
||||
{l10n.getString(
|
||||
'settings-general-gesture_control-fullResetTracker'
|
||||
)}
|
||||
</Typography>
|
||||
<Dropdown
|
||||
display="block"
|
||||
control={control}
|
||||
placeholder={''}
|
||||
name="fullResetTracker"
|
||||
items={bodyParts}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Typography bold>
|
||||
{l10n.getString(
|
||||
'settings-general-gesture_control-mountingResetTracker'
|
||||
)}
|
||||
</Typography>
|
||||
<Dropdown
|
||||
display="block"
|
||||
control={control}
|
||||
placeholder={''}
|
||||
name="mountingResetTracker"
|
||||
items={bodyParts}
|
||||
/>
|
||||
</div>
|
||||
<Dropdown
|
||||
display="block"
|
||||
control={control}
|
||||
placeholder={''}
|
||||
label={l10n.getString(
|
||||
'settings-general-gesture_control-yawResetTracker'
|
||||
)}
|
||||
name="yawResetTracker"
|
||||
items={bodyParts}
|
||||
/>
|
||||
<Dropdown
|
||||
display="block"
|
||||
control={control}
|
||||
placeholder={''}
|
||||
label={l10n.getString(
|
||||
'settings-general-gesture_control-fullResetTracker'
|
||||
)}
|
||||
name="fullResetTracker"
|
||||
items={bodyParts}
|
||||
/>
|
||||
<Dropdown
|
||||
display="block"
|
||||
control={control}
|
||||
placeholder={''}
|
||||
label={l10n.getString(
|
||||
'settings-general-gesture_control-mountingResetTracker'
|
||||
)}
|
||||
name="mountingResetTracker"
|
||||
items={bodyParts}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid sm:grid-cols-3 gap-5 pb-2">
|
||||
|
||||
@@ -420,6 +420,17 @@ input::-ms-clear {
|
||||
display: none;
|
||||
}
|
||||
|
||||
input[type='number']::-webkit-outer-spin-button,
|
||||
input[type='number']::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
input[type='number'] {
|
||||
-moz-appearance: textfield;
|
||||
appearance: textfield;
|
||||
}
|
||||
|
||||
.crisp-edges {
|
||||
image-rendering: -webkit-optimize-contrast;
|
||||
image-rendering: crisp-edges;
|
||||
|
||||
Reference in new issue
Block a user