EditableMonthYearField
EditableMonthYearField allows users to select a month and year combination. In read mode the current YYYY-MM value is displayed in a disabled input. Clicking the edit icon activates an <input type="month"> picker. Supports optional min/max constraints. On save the YYYY-MM string is persisted via API.
Props
| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| name | string | Yes | — | Field name sent as the key in the update payload. |
| value | string | No | — | Current value in YYYY-MM format. |
| updatePath | string | Yes | — | API endpoint path used to persist the change. |
| label | string | No | — | Label shown above the input. |
| description | string | No | — | Helper text shown below the label. |
| minMonthYear | string | No | — | Minimum selectable month/year in YYYY-MM format. |
| maxMonthYear | string | No | — | Maximum selectable month/year in YYYY-MM format. |
| apiBaseUrl | string | No | — | Base URL prepended to updatePath. |
| useAuthToken | boolean | No | false | When true, the request includes the authorization token. |
| onEditStart | () => void | No | — | Called when edit mode begins. |
| onEditSuccess | (updatedValue: string, newFormData: any) => void | No | — | Called after successful save. |
| onEditError | (error: any) => void | No | — | Called on API error; value is reverted. |
| onEditCancel | () => void | No | — | Called when the user cancels; value is reverted. |
| editIcon | string | No | "pencil" | Icon name for the edit button. |
| saveIcon | string | No | "check" | Icon name for the save button. |
| cancelIcon | string | No | "close" | Icon name for the cancel button. |
| containerStyle | React.CSSProperties | No | — | Style for the outermost wrapper. |
| inputStyle | React.CSSProperties | No | — | Style for the <input> element. |
| labelStyle | React.CSSProperties | No | — | Style for the <label> element. |
| descriptionStyle | React.CSSProperties | No | — | Style for the description <p> element. |
Usage
Basic
import React, { useState } from 'react';
import EditableMonthYearField from '@/components/editable-fields/EditableMonthYearField';
export default function Example() {
const [reportMonth, setReportMonth] = useState('2024-03');
return (
<EditableMonthYearField
label="Report Month"
name="report_month"
value={reportMonth}
updatePath="/v1/reports/12"
apiBaseUrl="https://api.example.com"
useAuthToken
onEditSuccess={(updated) => setReportMonth(updated)}
/>
);
}
With constraints
<EditableMonthYearField
label="Billing Period"
name="billing_period"
value={billingPeriod}
minMonthYear="2023-01"
maxMonthYear="2025-12"
updatePath="/v1/invoices/55"
apiBaseUrl="https://api.example.com"
useAuthToken
onEditSuccess={(updated) => setBillingPeriod(updated)}
/>