Components
ReadyDatePicker

ReadyDatePicker

The ReadyDatePicker is a customizable React component that provides a user-friendly date selection interface for your Shopify app. It combines Shopify Polaris components to create a popover date picker with a text input field.

Import

import { ReadyDatePicker } from 'path/to/ReadyDatePicker';

Props

PropTypeDefaultDescription
datestringRequiredThe currently selected date in ISO format (YYYY-MM-DD)
setDatefunctionRequiredA function to update the selected date
labelstring"Select date"The label for the date input field

Usage

import { useState } from 'react';
import { ReadyDatePicker } from './ReadyDatePicker';
 
function DateSelectionPage() {
  const [selectedDate, setSelectedDate] = useState('2024-08-16');
 
  return (
    <ReadyDatePicker
      date={selectedDate}
      setDate={setSelectedDate}
      label="Event Date"
    />
  );
}

Functionality

  1. Date Input: Users can manually enter a date in the text field.
  2. Date Picker: Clicking on the input field opens a popover with a calendar for date selection.
  3. Visual Feedback: The component uses the Shopify Polaris CalendarIcon for clear visual indication.
  4. Automatic Formatting: Selected dates are automatically formatted to ISO date strings (YYYY-MM-DD).

Component Structure

  • The component uses Shopify Polaris components: Popover, TextField, Card, DatePicker, and Icon.
  • It manages its own state for the popover visibility and display date.
  • The component syncs the internal selected date with the parent component through the date and setDate props.

Key Features

  1. Controlled Input: The date can be controlled externally through the date prop.
  2. Popover Calendar: Provides a user-friendly calendar interface for date selection.
  3. Manual Input: Allows users to type the date directly into the text field.
  4. Month Navigation: Users can navigate through months and years in the calendar view.

Customization

The ReadyDatePicker can be customized by adjusting the props or modifying the component's internal structure. Consider the following customization options:

  • Change the date format displayed in the input field.
  • Modify the popover position or alignment.
  • Add additional validation or date range restrictions.

Notes

  • The component uses the ISO date format (YYYY-MM-DD) for consistency and easy parsing.
  • It handles date parsing and formatting internally, providing a clean interface to the parent component.
  • The popover closes automatically when a date is selected or when the user clicks outside the popover.

Dependencies

This component relies on the following Shopify Polaris components and icons:

  • Popover
  • TextField
  • Card
  • DatePicker
  • Icon
  • CalendarIcon

Ensure these are correctly imported in your project.