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
Prop | Type | Default | Description |
---|---|---|---|
date | string | Required | The currently selected date in ISO format (YYYY-MM-DD) |
setDate | function | Required | A function to update the selected date |
label | string | "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
- Date Input: Users can manually enter a date in the text field.
- Date Picker: Clicking on the input field opens a popover with a calendar for date selection.
- Visual Feedback: The component uses the Shopify Polaris CalendarIcon for clear visual indication.
- 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
, andIcon
. - 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
andsetDate
props.
Key Features
- Controlled Input: The date can be controlled externally through the
date
prop. - Popover Calendar: Provides a user-friendly calendar interface for date selection.
- Manual Input: Allows users to type the date directly into the text field.
- 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.