forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelect.js
More file actions
41 lines (39 loc) · 1.04 KB
/
Copy pathSelect.js
File metadata and controls
41 lines (39 loc) · 1.04 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
'use client';
import React from 'react';
/**
* Select component — supports label, error state, helper text.
* Closes #610
*/
export default function Select({
id,
label,
options = [],
error,
helperText,
className = '',
...props
}) {
const selectId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
const hasError = Boolean(error);
return (
<div className={`ui-select-wrapper ${className}`}>
{label && (
<label className="ui-input__label" htmlFor={selectId}>
{label}
</label>
)}
<select
id={selectId}
className={`ui-select ${hasError ? 'ui-input--error' : ''}`}
aria-invalid={hasError}
{...props}
>
{options.map(({ value, label: optLabel }) => (
<option key={value} value={value}>{optLabel}</option>
))}
</select>
{error && <span className="ui-input__error" role="alert">{error}</span>}
{helperText && !error && <span className="ui-input__helper">{helperText}</span>}
</div>
);
}