UNPKG

react-d-calendar

Version:

A fully customizable, accessible, and responsive React calendar component

754 lines (648 loc) 13.3 kB
.calendar { max-width: 100%; margin: 8px; padding: 0; font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f7fafc; border-radius: 10px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } /* Focus state */ .calendar:focus { box-shadow: 0 0 0 4px rgba(75, 108, 183, 0.3); outline: none; } .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; } /* ========== Header ========== */ .header { display: flex; justify-content: space-between; align-items: center; padding: 1.5rem 2rem; background: #f7fafc; border-bottom: 1px solid #edf2f7; flex-wrap: wrap; gap: 1.5rem; } .header-month-section { display: flex; align-items: center; gap: 1.5rem; } .header-month-nav { display: flex; align-items: center; gap: 1rem; } .header-month-label { font-size: 1.5rem; font-weight: 600; color: #2d3748; text-transform: capitalize; letter-spacing: 0.05rem; } .nav-button { width: 2.75rem; height: 2.75rem; border: none; background: #edf2f7; color: #2d3748; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s ease-in-out; } .nav-button:hover { background: #4b6cb7; color: #ffffff; transform: scale(1.1); } .nav-button:disabled { background: #e6edf2; color: #a0aec0; opacity: 0.6; cursor: not-allowed; transform: none; } /* ========== Year Dropdown ========== */ .header-year-section { position: relative; display: flex; align-items: center; } .year-select-wrapper { padding: 0.75rem 2.5rem 0.75rem 1.25rem; font-size: 1.1rem; border: 1px solid #edf2f7; border-radius: 10px; background: #f7fafc; color: #2d3748; cursor: pointer; display: flex; align-items: center; position: relative; transition: all 0.3s ease-in-out; } .year-select-wrapper:hover, .year-select-wrapper:focus, .year-select-wrapper[aria-expanded='true'] { border-color: #48bb78; box-shadow: 0 0 0 3px rgba(75, 108, 183, 0.2); } .year-select-display { font-weight: 500; } .chevron-down { position: absolute; right: 1rem; font-size: 1.2rem; color: #2d3748; pointer-events: none; transition: transform 0.3s ease-in-out; } .year-select-wrapper[aria-expanded='true'] .chevron-down { transform: rotate(180deg); } .year-dropdown { position: absolute; top: calc(100% + 0.75rem); right: 0; width: 250px; max-height: 320px; background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); z-index: 1000; animation: slideIn 0.3s ease-in-out; overflow: hidden; } @keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } .year-search { width: 100%; padding: 0.75rem 1rem; border: none; border-bottom: 2px solid #edf2f7; font-size: 1rem; color: #2d3748; background: transparent; outline: none; transition: all 0.3s ease-in-out; } .year-search:focus { border-bottom-color: #48bb78; } .year-list { max-height: 150px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #4b6cb7 #edf2f7; padding: 0.5rem 0; } .year-list::-webkit-scrollbar { width: 8px; } .year-list::-webkit-scrollbar-track { background: #edf2f7; border-radius: 4px; } .year-list::-webkit-scrollbar-thumb { background: #4b6cb7; border-radius: 4px; } .year-option { display: block; width: 100%; padding: 0.75rem 1.25rem; border: none; background: transparent; font-size: 1rem; color: #2d3748; text-align: left; cursor: pointer; transition: all 0.3s ease-in-out; } .year-option:hover, .year-option.focused { background: #edf2f7; color: #2d3748; transform: translateX(8px); border-radius: 6px; } .year-option.current-year { background: #024575; color: #ffffff; font-weight: 600; border-radius: 6px; } .year-option:focus { outline: none; box-shadow: 0 0 0 2px rgba(2, 69, 117, 0.2); } .year-option:disabled { color: #ccc; cursor: not-allowed; background-color: #f9f9f9; opacity: 0.6; } .year-option:disabled:hover, .year-option:disabled.focused { background: #ffffff; color: #6b6868; transform: none; } /* ========== Weekday Row ========== */ .calendar-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); background: #f7fafc; padding: 0.75rem 0; border-bottom: 2px solid #edf2f7; } .weekday { text-align: center; font-weight: 600; color: #a0aec0; padding: 0.5rem; font-size: 0.9rem; text-transform: uppercase; transition: all 0.3s ease-in-out; } .weekday.saturday, .weekday.sunday { color: #e53e3e; } .weekday:hover { color: #2d3748; background: #edf2f7; border-radius: 6px; } /* ========== Calendar Grid ========== */ .calendar-days { display: grid; grid-template-columns: repeat(7, 1fr); background: #f7fafc; padding: 0.75rem; gap: 0.25rem; } /* ========== Base Day Style ========== */ .calendar-day { width: 40px; height: 40px; margin: 0; padding: 8px; border: none; background: #f7fafc; cursor: pointer; text-align: center; font-size: 0.95rem; font-weight: 500; color: #2d3748; transition: all 0.3s ease-in-out; min-height: 3.5rem; border-radius: 8px; display: flex; align-items: center; justify-content: center; position: relative; } .calendar-day:hover { background: #e6edf2; color: #024575; transform: scale(1.05); } /* ========== Today Highlight ========== */ .calendar-day.today { background: #1662d4; color: #ffffff; font-weight: 700; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); } .calendar-day.today::after { content: ""; position: absolute; bottom: 6px; left: 30%; width: 40%; height: 1px; background-color: #024575; border-radius: 2px; } .calendar-day.today:hover { background: #2085ad; transform: scale(1.1); } .calendar-day.saturday, .calendar-day.sunday { color: #e53e3e; } .calendar-day.saturday:hover, .calendar-day.sunday:hover { background: #fef2f2; } /* ========== Start/End Dates ========== */ .calendar-day.selected, .calendar-day.selected-start, .calendar-day.selected-end { background: #024575; color: #ffffff; font-weight: 700; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); border: 1px solid #4b6cb7; z-index: 2; } .calendar-day.selected-start:hover, .calendar-day.selected-end:hover { background: #01324f; transform: scale(1.1); } .calendar-day.selected-end.in-range, .calendar-day.selected-start.in-range { background: #024575; border-radius: 8px; z-index: 3; } /* ========== Start/End Circle Marker ========== */ .calendar-day.selected-start::after, .calendar-day.selected-end::after { content: ''; position: absolute; width: 10px; height: 10px; background: #ffffff; border-radius: 50%; border: 2px solid #2a4365; top: 50%; transform: translateY(-50%); } .calendar-day.selected-start::after { left: 4px; } .calendar-day.selected-end::after { right: 4px; } .calendar-day.in-range { background: rgba(2, 69, 117, 0.2); color: #2b2a2a; border-radius: 0; transition: all 0.3s ease-in-out; border-left: 1px solid #e2e8f0; border-right: 1px solid #e2e8f0; position: relative; z-index: 1; } .calendar-day.in-range + .calendar-day.in-range { border-left: none; } .calendar-day.in-range:first-child { border-left: 1px solid #e2e8f0; } .calendar-day.in-range:last-child { border-right: 1px solid #e2e8f0; } .calendar-day.in-range:hover { background: rgba(2, 69, 117, 0.3); } /* ========== Hovered Future Range Preview ========== */ .calendar-day.range-preview { background: rgba(2, 69, 117, 0.3); color: #2b2a2a; border-radius: 0; z-index: 1; transition: all 0.3s ease-in-out; } .calendar-day.range-preview:hover { background: rgba(2, 69, 117, 0.4); } /* ========== Hover Range End ========== */ .calendar-day.hover-range-end { background: rgba(2, 69, 117, 0.6); color: #ffffff; border-radius: 8px; z-index: 2; transform: scale(1.05); } /* ========== Hover Range General ========== */ .calendar-day.hover-range { background: rgba(2, 69, 117, 0.4); color: #ffffff; border-radius: 8px; z-index: 2; transform: scale(1.05); } /* ========== Disabled Dates ========== */ .calendar-day:disabled { background: #ffffff; color: #6b6868; cursor: not-allowed; opacity: 0.6 !important; } .calendar-day:disabled.today, .calendar-day:disabled.selected-start, .calendar-day:disabled.selected-end { opacity: 0.6 !important; } .calendar-day:disabled:hover { background: #ffffff; color: #6b6868; transform: none; } /* ========== Animation ========== */ .calendar-container { display: flex; gap: 12px; padding: 0; margin: 4px; justify-content: space-between; animation: fadeIn 0.4s ease-in-out; background: none; } @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } /* ========== Adjacent Month Dates ========== */ .calendar-day.adjacent-month { color: #6b6868; font-weight: 300; } .calendar-day.adjacent-month:hover { color: #2b2a2a; } /* Event Indicators */ .calendar-day.has-event::before { content: ''; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: #48bb78; bottom: 6px; right: 6px; } .event-indicator { font-size: 0.8rem; font-weight: 500; color: #2d3748; } /* Day View */ .day-view { padding: 1.5rem; background: #f7fafc; border-radius: 0 0 10px 10px; } .day-detail { width: 100%; padding: 1rem; border: none; background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 10px; text-align: center; font-size: 1.1rem; font-weight: 600; color: #2d3748; transition: all 0.3s ease-in-out; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); } .day-detail.today { background: #1662d4; color: #ffffff; border: none; } .day-detail:hover { background: #edf2f7; transform: scale(1.02); } .day-detail.today:hover { background: #2085ad; } .day-detail:disabled { background: #edf2f7; color: #a0aec0; cursor: not-allowed; } .day-detail-content { display: flex; flex-direction: column; gap: 0.5rem; } .day-detail-date { font-size: 1.25rem; font-weight: 700; } .day-detail-events { font-size: 0.9rem; color: #a0aec0; } /* Year View */ .year-view { padding: 1.5rem; background: #f7fafc; } .year-view-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 0.5rem; } .year-month { padding: 0.75rem; border: none; background: #edf2f7; border-radius: 10px; text-align: center; font-size: 1rem; font-weight: 600; color: #2d3748; cursor: pointer; transition: all 0.3s ease-in-out; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); } .year-month:hover { background: #4b6cb7; color: #ffffff; transform: translateY(-3px); } .year-month.selected { background: #4b6cb7; color: #ffffff; font-weight: 700; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); } .year-month.adjacent-year { opacity: 0.7; } .year-month:disabled { background: #a0aec0; color: #ffffff; cursor: not-allowed; opacity: 0.6; } .month-content { display: inline-block; transition: transform 0.2s ease; } .year-month:hover .month-content { transform: scale(1.1); } /* Holiday Styling */ .calendar-day.holiday { background: #f59e0b; color: #ffffff; font-weight: 700; border-radius: 8px; } /* Custom Event Types */ .calendar-day.event-meeting::before { background: #22c55e; } .calendar-day.event-holiday::before { background: #f43f5e; } /* Back Button */ .back-button { background: #4b6cb7; color: #ffffff; border: none; padding: 0.75rem 1.5rem; border-radius: 10px; cursor: pointer; margin: 1rem; transition: all 0.3s ease-in-out; } .back-button:hover { background: #2a4365; transform: translateY(-2px); } /* Double View */ .double-view .calendar-instance { width: 48%; flex: 1; } .calendar.double-view { max-width: 1400px; padding: 0 1.5rem; } /* Responsive Design */ @media (max-width: 900px) { .double-view .calendar-instance { width: 100%; max-width: 500px; } .calendar-container { flex-direction: column; align-items: center; gap: 1.5rem; } .calendar { max-width: 100%; margin: 8px; } .header { padding: 8px 12px; flex-wrap: wrap; } .calendar-day { width: 36px; height: 36px; font-size: 12px; } .year-view-list { grid-template-columns: repeat(2, 1fr); } .year-dropdown { width: 180px; } .year-select-wrapper { min-width: 80px; } } @media (max-width: 600px) { .year-view-list { grid-template-columns: repeat(2, 1fr); } .header-month-label { font-size: 1rem; } .year-select-wrapper { font-size: 0.9rem; padding: 0.5rem 1.5rem 0.5rem 1rem; } .year-dropdown { width: 180px; } .calendar-day { font-size: 0.85rem; min-height: 3rem; } }