The DateField
component is a customizable Date field component.
To use the DateField
component in your project, you can install it via npm (or include it as part of your component library):
npm install custom-headless-date-field"
Here’s a simple example of how to use the DateField
component in your application:
import React, { useState } from "react";
import { DateField } from "rcustom-headless-date-field";
const App = () => {
const [dob, setDOB] = useState("");
return (
<div>
<DateField
label={"Date of Birth"}
selectedDate={dod} // Ensure this matches the prop name
handleDateChange={(e) => setDOB(e.target.value)} // Function to handle date changes
className={
"hover:ring-2 ring-olive-green focus:ring-2 focus:ring-inset focus:ring-olive-green"
}
/>
</div>
);
};
export default App;
Prop | Type | Description |
---|---|---|
label |
React.ReactNode |
Label to assign to the field. |
selectedDate |
string |
Variable that holds the date selected |
handleDateChange |
function |
A callback function that is called to save the DateField value |
className |
string |
Variable that holds the custom class for the date field (optional) |
The DateField
component is styled using Tailwind CSS classes. Make sure to include Tailwind CSS in your project to apply the styles correctly.
If you haven’t set up Tailwind CSS yet, here’s a basic example of how to do it:
- Install Tailwind CSS:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
- Configure your tailwind.config.js file:
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"],
theme: {
extend: {},
},
plugins: [],
};
- Include Tailwind in your CSS file: Add the following lines to your main CSS file to include Tailwind’s base, components, and utilities:
@tailwind base;
@tailwind components;
@tailwind utilities;
Feel free to customize the Tailwind classes used in the DateField
component as needed to fit the design of your application.