-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDominantField.tsx
More file actions
73 lines (71 loc) · 1.81 KB
/
DominantField.tsx
File metadata and controls
73 lines (71 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import type { JSX, Ref } from 'preact';
interface DominantFieldProps {
className?: string;
id: string;
label: string;
value: string;
placeholder?: string;
type?: string;
readOnly?: boolean;
autoFocus?: boolean;
disabled?: boolean;
actionLabel: string;
actionText: string;
actionVariant?: 'default' | 'soft';
onAction?: () => void;
onInput?: JSX.GenericEventHandler<HTMLInputElement>;
inputRef?: Ref<HTMLInputElement>;
error?: string;
}
export function DominantField({
className,
id,
label,
value,
placeholder,
type = 'text',
readOnly = false,
autoFocus = false,
disabled = false,
actionLabel,
actionText,
actionVariant = 'default',
onAction,
onInput,
inputRef,
error,
}: DominantFieldProps) {
return (
<div class={className ? `dominant-field ${className}` : 'dominant-field'}>
<label class="field-block field-block--centered" htmlFor={id}>
<span class="field-label field-label--ghost">{label}</span>
<input
id={id}
name={id}
type={type}
class="input input--mono input--lg"
placeholder={placeholder}
autocomplete={type === 'url' ? 'url' : 'off'}
autoFocus={autoFocus}
ref={inputRef}
value={value}
readOnly={readOnly}
disabled={disabled}
onInput={onInput}
/>
<span class="field-error">{error ?? ''}</span>
</label>
<button
type={onAction ? 'button' : 'submit'}
class={`dominant-field__action${actionText.length > 1 ? ' dominant-field__action--text' : ''}${
actionVariant === 'soft' ? ' dominant-field__action--soft' : ''
}`}
disabled={disabled}
aria-label={actionLabel}
onClick={onAction}
>
{actionText}
</button>
</div>
);
}