UNPKG

@kanaksan/tamil-calendar-widget

Version:

A reusable React widget for displaying Tamil daily calendar sheets

155 lines (119 loc) • 4.68 kB
# Tamil Calendar Widget A beautiful, lightweight React component for displaying Tamil daily calendar sheets as images. ## Features šŸŽÆ **Simple Integration** - Just one prop for API URL and date šŸš€ **Smart Caching** - Automatic image caching to minimize API calls ⚔ **Fast Loading** - Optimized blob URL handling for better performance šŸ›”ļø **Error Handling** - Comprehensive error states with meaningful messages šŸ“± **Responsive** - Works on all screen sizes šŸŽØ **Customizable** - Easy styling with CSS classes and inline styles šŸ“¦ **Lightweight** - Minimal bundle size with zero dependencies šŸ”’ **TypeScript** - Full TypeScript support with detailed type definitions ## Installation ```bash npm install @kanaksan/tamil-calendar-widget ``` ## Quick Start ```jsx import React from 'react'; import { TamilCalendarWidget } from '@kanaksan/tamil-calendar-widget'; function App() { return ( <div> <h1>Tamil Calendar</h1> <TamilCalendarWidget apiUrl="<api-url>" date="2025-02-22" width={400} /> </div> ); } ``` ## Getting API Access To use this widget, you need access to the Tamil Calendar API: šŸ“§ **Contact**: helpdesk@kanaksan.com 🌐 **Website**: https://tamilcalendarwidget.netlify.app/ ### API Access Tiers: - **Free Tier**: 100 requests/day - **Pro Tier**: 1000 requests/day + historical data - **Enterprise**: Unlimited + custom features ## Props | Prop | Type | Required | Default | Description | |------|------|----------|---------|-------------| | `apiUrl` | `string` | āœ… | - | Complete API URL with authentication | | `date` | `string` | āœ… | - | Date in YYYY-MM-DD format | | `width` | `number` | āŒ | `400` | Image width in pixels | | `height` | `number` | āŒ | `auto` | Image height in pixels | | `alt` | `string` | āŒ | `"Tamil Daily Calendar"` | Alt text for accessibility | | `className` | `string` | āŒ | `""` | Additional CSS class | | `style` | `CSSProperties` | āŒ | `{}` | Inline styles for container | | `onLoad` | `function` | āŒ | - | Callback when image loads | | `onError` | `function` | āŒ | - | Callback when error occurs | | `showLoader` | `boolean` | āŒ | `true` | Show loading indicator | | `loaderComponent` | `ReactNode` | āŒ | - | Custom loading component | | `errorComponent` | `ReactNode` | āŒ | - | Custom error component | ## Advanced Usage ### Custom Styling ```jsx <TamilCalendarWidget apiUrl="https://api.example.com/calendar?token=abc123" date="2025-02-22" className="my-calendar" style={{ borderRadius: '12px', boxShadow: '0 4px 12px rgba(0,0,0,0.15)' }} /> ``` ### Error Handling ```jsx <TamilCalendarWidget apiUrl="https://api.example.com/calendar?token=abc123" date="2025-02-22" onLoad={() => console.log('Calendar loaded successfully')} onError={(error) => console.error('Failed to load:', error.message)} /> ``` ### Custom Loading and Error Components ```jsx <TamilCalendarWidget apiUrl="https://api.example.com/calendar?token=abc123" date="2025-02-22" loaderComponent={<div>šŸ”„ Loading your Tamil calendar...</div>} errorComponent={<div>āŒ Calendar unavailable</div>} /> ``` ## Caching The widget automatically caches images for 24 hours to improve performance and reduce API calls. You can access the cache manager: ```jsx import { imageCache } from '@kanaksan/tamil-calendar-widget'; // Clear all cached images imageCache.clearCache(); // Clean up expired entries imageCache.cleanupExpired(); ``` ## Error Messages The component provides user-friendly error messages for common scenarios: - **Network issues**: "Network error: Unable to connect to the calendar service" - **Authentication**: "Authentication failed: Invalid API key or token" - **Not found**: "Calendar not found: No calendar available for the selected date" - **Rate limiting**: "Rate limit exceeded: Too many requests" - **Server errors**: "Server error: The calendar service is temporarily unavailable" ## TypeScript Support Full TypeScript definitions included: ```typescript import { TamilCalendarWidget, TamilCalendarWidgetProps } from '@kanaksan/tamil-calendar-widget'; const props: TamilCalendarWidgetProps = { apiUrl: "https://api.example.com/calendar?token=abc123", date: "2025-02-22", width: 500, onLoad: () => console.log('Loaded!') }; ``` ## Browser Support - Chrome 60+ - Firefox 60+ - Safari 12+ - Edge 79+ ## License MIT Ā© calendar.kanaksan.com --- For API access and support, please contact: helpdesk@kanaksan.com