|
|
@ -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,9 +112,11 @@ 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)}>
|
|
|
|
|
|
|
|
<div className="grow">
|
|
|
|
<Select
|
|
|
|
<Select
|
|
|
|
key={`month:${monthCounter}`}
|
|
|
|
key={`month:${monthCounter}`}
|
|
|
|
|
|
|
|
display="block"
|
|
|
|
label={monthLabel}
|
|
|
|
label={monthLabel}
|
|
|
|
options={MONTH_OPTIONS}
|
|
|
|
options={MONTH_OPTIONS}
|
|
|
|
placeholder="Select month"
|
|
|
|
placeholder="Select month"
|
|
|
@ -121,8 +126,11 @@ export default function MonthYearPicker({
|
|
|
|
onChange({ month: Number(newMonth) as Month, year: value.year })
|
|
|
|
onChange({ month: Number(newMonth) as Month, year: value.year })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="grow">
|
|
|
|
<Select
|
|
|
|
<Select
|
|
|
|
key={`year:${yearCounter}`}
|
|
|
|
key={`year:${yearCounter}`}
|
|
|
|
|
|
|
|
display="block"
|
|
|
|
label={yearLabel}
|
|
|
|
label={yearLabel}
|
|
|
|
options={YEAR_OPTIONS}
|
|
|
|
options={YEAR_OPTIONS}
|
|
|
|
placeholder="Select year"
|
|
|
|
placeholder="Select year"
|
|
|
@ -133,6 +141,7 @@ export default function MonthYearPicker({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</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}>
|
|
|
|
{errorMessage}
|
|
|
|
{errorMessage}
|
|
|
|