|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
import { useEffect, useId, useState } from 'react';
|
|
|
|
import { useEffect, useId, useState } from 'react';
|
|
|
|
import { Select } from '@tih/ui';
|
|
|
|
import { Select } from '@tih/ui';
|
|
|
|
|
|
|
|
|
|
|
@ -14,6 +15,7 @@ export type MonthYearOptional = Readonly<{
|
|
|
|
}>;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
|
|
|
|
type Props = Readonly<{
|
|
|
|
type Props = Readonly<{
|
|
|
|
|
|
|
|
className?: string;
|
|
|
|
errorMessage?: string;
|
|
|
|
errorMessage?: string;
|
|
|
|
monthLabel?: string;
|
|
|
|
monthLabel?: string;
|
|
|
|
monthRequired?: boolean;
|
|
|
|
monthRequired?: boolean;
|
|
|
@ -84,6 +86,7 @@ const YEAR_OPTIONS = Array.from({ length: NUM_YEARS }, (_, i) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
export default function MonthYearPicker({
|
|
|
|
export default function MonthYearPicker({
|
|
|
|
|
|
|
|
className,
|
|
|
|
errorMessage,
|
|
|
|
errorMessage,
|
|
|
|
monthLabel = 'Month',
|
|
|
|
monthLabel = 'Month',
|
|
|
|
value,
|
|
|
|
value,
|
|
|
@ -109,29 +112,35 @@ export default function MonthYearPicker({
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div aria-describedby={hasError ? errorId : undefined}>
|
|
|
|
<div aria-describedby={hasError ? errorId : undefined}>
|
|
|
|
<div className="flex items-end space-x-2">
|
|
|
|
<div className={clsx('flex items-end', className)}>
|
|
|
|
<Select
|
|
|
|
<div className="grow">
|
|
|
|
key={`month:${monthCounter}`}
|
|
|
|
<Select
|
|
|
|
label={monthLabel}
|
|
|
|
key={`month:${monthCounter}`}
|
|
|
|
options={MONTH_OPTIONS}
|
|
|
|
display="block"
|
|
|
|
placeholder="Select month"
|
|
|
|
label={monthLabel}
|
|
|
|
required={monthRequired}
|
|
|
|
options={MONTH_OPTIONS}
|
|
|
|
value={value.month}
|
|
|
|
placeholder="Select month"
|
|
|
|
onChange={(newMonth) =>
|
|
|
|
required={monthRequired}
|
|
|
|
onChange({ month: Number(newMonth) as Month, year: value.year })
|
|
|
|
value={value.month}
|
|
|
|
}
|
|
|
|
onChange={(newMonth) =>
|
|
|
|
/>
|
|
|
|
onChange({ month: Number(newMonth) as Month, year: value.year })
|
|
|
|
<Select
|
|
|
|
}
|
|
|
|
key={`year:${yearCounter}`}
|
|
|
|
/>
|
|
|
|
label={yearLabel}
|
|
|
|
</div>
|
|
|
|
options={YEAR_OPTIONS}
|
|
|
|
<div className="grow">
|
|
|
|
placeholder="Select year"
|
|
|
|
<Select
|
|
|
|
required={yearRequired}
|
|
|
|
key={`year:${yearCounter}`}
|
|
|
|
value={value.year}
|
|
|
|
display="block"
|
|
|
|
onChange={(newYear) =>
|
|
|
|
label={yearLabel}
|
|
|
|
onChange({ month: value.month, year: Number(newYear) })
|
|
|
|
options={YEAR_OPTIONS}
|
|
|
|
}
|
|
|
|
placeholder="Select year"
|
|
|
|
/>
|
|
|
|
required={yearRequired}
|
|
|
|
|
|
|
|
value={value.year}
|
|
|
|
|
|
|
|
onChange={(newYear) =>
|
|
|
|
|
|
|
|
onChange({ month: value.month, year: Number(newYear) })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{errorMessage && (
|
|
|
|
{errorMessage && (
|
|
|
|
<p className="text-danger-600 mt-2 text-sm" id={errorId}>
|
|
|
|
<p className="text-danger-600 mt-2 text-sm" id={errorId}>
|
|
|
|