/v1.0

EditableDateField

EditableDateField displays a date in a read-only input. Clicking the edit icon enables the date picker (<input type="date">), allowing the user to select a new date. Supports optional min/max date constraints. On save the ISO date string (YYYY-MM-DD) 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 date value in YYYY-MM-DD format. | | updatePath | string | Yes | — | API endpoint path used to persist the change. | | label | string | No | — | Label shown above the date input. | | description | string | No | — | Helper text shown below the label. | | placeholder | string | No | — | Placeholder shown inside the input. | | minDate | string | No | — | Minimum selectable date in YYYY-MM-DD format. | | maxDate | string | No | — | Maximum selectable date in YYYY-MM-DD 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 EditableDateField from '@/components/editable-fields/EditableDateField';

export default function Example() {
  const [birthdate, setBirthdate] = useState('1990-06-15');

  return (
    <EditableDateField
      label="Date of Birth"
      name="birthdate"
      value={birthdate}
      updatePath="/v1/users/42"
      apiBaseUrl="https://api.example.com"
      useAuthToken
      onEditSuccess={(updated) => setBirthdate(updated)}
    />
  );
}

With date constraints

<EditableDateField
  label="Expiry Date"
  name="expiry_date"
  value={expiryDate}
  minDate="2024-01-01"
  maxDate="2030-12-31"
  updatePath="/v1/subscriptions/10"
  apiBaseUrl="https://api.example.com"
  useAuthToken
  onEditSuccess={(updated) => setExpiryDate(updated)}
/>