UNPKG

nepali-date-selector

Version:
256 lines (179 loc) โ€ข 6.74 kB
# ๐Ÿš€ Nepali Date Selector (Bikram Sambat) - React.js Component > Modern, customizable Nepali Date Selector (Bikram Sambat) for ReactJS. > > [![NPM](https://img.shields.io/npm/v/nepali-date-selector.svg)](https://www.npmjs.com/package/nepali-date-selector) > [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) > > [๐ŸŒ Live Demo](https://nepalidateselector.durlavparajuli.com.np/) > > ![NepaliDateSelector Demo](example.png) --- ## โœจ Features - Bikram Sambat (BS) Nepali calendar support - Fully localizable (Nepali/English) - Keyboard and mouse navigation - Customizable year and month range - Typeable and searchable year input - Adjustable input width, height, and style - Accessible and responsive design - Zero dependencies except React and Nepali date libraries --- ## ๐Ÿ“ฆ Installation ```bash npm install --save nepali-date-selector # or yarn add nepali-date-selector ``` --- ## ๐Ÿ Quick Start Usage ### Basic Usage Example ```tsx import { useState } from "react" import { NepaliDateSelector } from "nepali-date-selector" const App = () => { const [date, setDate] = useState("") return ( <form> <label htmlFor='date'>Date (BS)</label> <NepaliDateSelector value={date} onChange={setDate} options={{ calenderLocale: "ne", valueLocale: "en" }} inputStyle={{ width: 220, height: 48, fontSize: 18, textAlign: "center", }} /> <div style={{ marginTop: 16 }}> <div> Selected Date (BS): <b>{date}</b> </div> </div> </form> ) } ``` --- ## ๐Ÿ›  **Development Commands** | Command | Description | | --------------------- | ----------------------------------------------------------------- | | `npm run dev` | ๐Ÿš€ **Main development command** - starts example with live reload | | `npm run build` | ๐Ÿ“ฆ Build the library for production | | `npm run dev:package` | ๐Ÿ“ฆ Build library in watch mode (if needed) | | `npm run test` | โœ… Run tests | | `npm run lint` | ๐Ÿ” Check code quality | | `npm run format` | โœจ Format code | --- ## ๐ŸŽฏ **Development Workflow** 1. **Start Development:** ```bash npm run dev ``` 2. **Edit Your Code:** - Edit files in `src/` - See changes instantly in the browser at `http://localhost:5173` 3. **Test Your Changes:** - The example app shows your component in action - All features are testable immediately 4. **Build When Ready:** ```bash npm run build ``` --- ## ๐ŸŽจ **What You Can Do** - โœ… Edit component logic in `src/NepaliDateSelector/` - โœ… Modify styles in `src/NepaliDateSelector.scss` - โœ… Update utilities in `src/NepaliDateSelector/Utils/` - โœ… Test date conversions and calendar behavior - โœ… See results instantly without any build step! --- ## ๐Ÿ“š Date Conversion APIs (Secondary Feature) You can convert dates between English (AD) and Nepali (BS) using these utility functions: ### Convert AD to BS ```typescript import { convertADToBS } from "nepali-date-selector" const bsDate = convertADToBS("2025-07-16") // "2082-04-01" const bsDate2 = convertADToBS(new Date("2025-07-16")) // "2082-04-01" ``` ### Convert BS to AD ```typescript import { convertBSToAD } from "nepali-date-selector" const adDate = convertBSToAD("2082-04-01") // "2025-07-16" ``` - Both functions handle timezone issues and ensure accurate conversion. - Use these APIs anywhere in your app for reliable date conversion. --- ## ๐Ÿ“ **Publishing Workflow** When you're ready to publish: ```bash # 1. Test everything works npm run dev # 2. Build the package npm run build # 3. Test the built package npm run example:build # 4. Publish npm publish ``` --- ## ๐Ÿ”ง **Project Structure** ``` nepali-date-selector/ โ”œโ”€โ”€ src/ # ๐Ÿ‘ˆ Your source code (edit here!) โ”‚ โ”œโ”€โ”€ NepaliDateSelector/ # Main component โ”‚ โ””โ”€โ”€ NepaliDateSelector.scss # Styles โ”œโ”€โ”€ example/ # Test app (auto-imports src/) โ”‚ โ”œโ”€โ”€ src/App.tsx # Example usage โ”‚ โ””โ”€โ”€ vite.config.ts # Configured to use ../src/ โ”œโ”€โ”€ dist/ # Built package (npm run build) โ””โ”€โ”€ dev.sh # Development helper script ``` --- ## ๐Ÿš€ **Benefits of This Setup** - **โšก Lightning Fast**: No build step during development - **๐Ÿ”„ Live Reload**: Instant feedback on changes - **๐ŸŽฏ Real Testing**: Test your component in a real app environment - **๐Ÿ“ฆ Easy Publishing**: `npm run build` when ready to publish - **๐Ÿ›  TypeScript**: Full type checking and IntelliSense --- ## ๐Ÿงฉ Customization & Styling - Uses SCSS for styling - Override styles by importing your own CSS after the default one - Main class: `.nepali-date-selector` - Calendar popup: `.calender` - Controller: `.calendar-controller` - Year/month controls: `.control.year`, `.control.month` - Input: `.nepali-date-input` --- ## ๐ŸŒ Localization - Supports Nepali and English out of the box - Use the `options.calenderLocale` and `options.valueLocale` props to control language --- ## ๐Ÿ“… Year/Month Range - Use `minYear` and `maxYear` props to restrict selectable years - Year selector supports both dropdown and manual typing --- ## โ™ฟ Accessibility - Keyboard navigation for input and dropdowns - All interactive elements are accessible via tab and arrow keys --- ## ๐Ÿงช Testing & Quality - Run tests: `npm run test` - Lint code: `npm run lint` - Format code: `npm run format` --- ## ๐Ÿค Contributing 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/my-feature`) 3. Commit your changes (`git commit -am 'Add new feature'`) 4. Push to the branch (`git push origin feature/my-feature`) 5. Create a new Pull Request ### Code Style - Follows [StandardJS](https://standardjs.com/) and Prettier - Lint and format before submitting PRs --- ## ๐Ÿ“„ License MIT ยฉ [https://github.com/iamdurlove](https://github.com/iamdurlove/nepali-date-selector) --- **For more details, see the [demo](https://nepalidateselector.durlavparajuli.com.np/) or the [source code](https://github.com/iamdurlove/nepali-date-selector)**