EditableYearField
EditableYearField provides an inline-editable year picker. In read mode the current year is displayed in a disabled number input. Clicking the edit icon enables the field, allowing the user to type or spin to a new year. Supports min/max year bounds and a configurable step. On save the numeric year is persisted via API.
Props
| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| name | string | Yes | — | Field name sent as the key in the update payload. |
| value | number | No | — | Currently selected year (e.g. 2024). |
| 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. |
| minYear | number | No | — | Minimum selectable year. |
| maxYear | number | No | — | Maximum selectable year. |
| step | number | No | 1 | Increment/decrement step when using the spinner. |
| 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: number, 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 EditableYearField from '@/components/editable-fields/EditableYearField';
export default function Example() {
const [foundedYear, setFoundedYear] = useState(2010);
return (
<EditableYearField
label="Founded Year"
name="founded_year"
value={foundedYear}
updatePath="/v1/organizations/3"
apiBaseUrl="https://api.example.com"
useAuthToken
onEditSuccess={(updated) => setFoundedYear(updated)}
/>
);
}
With year bounds
<EditableYearField
label="Model Year"
name="model_year"
value={modelYear}
minYear={1990}
maxYear={2030}
updatePath="/v1/vehicles/7"
apiBaseUrl="https://api.example.com"
useAuthToken
onEditSuccess={(updated) => setModelYear(updated)}
/>