Files
resharespace-static/_includes/calendar_input.liquid
T

134 lines
6.9 KiB
Plaintext

{% comment %}
Pure CSS Scrolling Date Picker Visual Mock-up
Usage:
{% include calendar_input.liquid
id="unique_calendar_id" (required for multiple instances)
label="Select Date" (optional, defaults to "Select Date")
placeholder="YYYY-MM-DD" (optional, defaults to "YYYY-MM-DD")
%}
This component is a visual mock-up and does not provide actual date selection functionality.
The input field will not be updated by this picker.
{% endcomment %}
{% assign current_year = "now" | date: "%Y" | plus: 0 %}
{% assign future_year_limit = current_year | plus: 10 %}
{% assign years = "" %}
{% for i in (current_year..future_year_limit) %}
{% assign years = years | append: i | append: "," %}
{% endfor %}
{% assign years_array = years | split: "," %}
{% assign months_array = "January,February,March,April,May,June,July,August,September,October,November,December" | split: "," %}
{% assign days_array = "" %}
{% for i in (1..31) %}
{% assign days_array = days_array | append: i | append: "," %}
{% endfor %}
{% assign days_array = days_array | split: "," %}
<div class="relative group">
<label for="calendar-input-{{ include.id | default: 'default' }}" class="block text-xs font-medium text-gray-700 mb-1">{{ include.label | default: "Select Date" }}</label>
<div class="relative">
<input
type="text"
id="calendar-input-{{ include.id | default: 'default' }}"
name="{{ include.id | default: 'default' }}_date_display"
readonly
placeholder="{{ include.placeholder | default: 'YYYY-MM-DD' }}"
class="w-full px-3 py-2 pr-10 border border-gray-300 rounded-sm focus:outline-none focus:border-indigo-700 focus:ring-1 focus:ring-indigo-700 text-sm cursor-pointer bg-white peer"
aria-label="{{ include.label | default: 'Select Date' }}"
>
<div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
<svg class="h-5 w-5 text-gray-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd" />
</svg>
</div>
</div>
<!-- CSS-only "Dropdown" - Appears on input focus or hover of the parent div -->
<!-- For a pure CSS dropdown, we often rely on :focus-within or :hover on a parent.
Here, using :focus on the input (peer) to show the picker.
Alternatively, wrap input and picker in a div and use group-hover.
For simplicity, this example shows it on input focus.
-->
<div class="absolute z-20 mt-1 w-full sm:w-80 bg-white shadow-lg rounded-base border border-gray-300 p-3
opacity-0 pointer-events-none peer-focus:opacity-100 peer-focus:pointer-events-auto
group-hover:opacity-100 group-hover:pointer-events-auto
transition-opacity duration-150 ease-in-out">
<div class="flex justify-between items-stretch h-48 relative">
<!-- Selection Indicator Line -->
<div class="absolute top-1/2 left-0 right-0 h-px bg-indigo-300 -translate-y-1/2 z-0"></div>
<div class="absolute top-1/2 left-0 right-0 h-8 bg-indigo-50 -translate-y-1/2 z-0 rounded-sm"></div>
<!-- Year Column -->
<div class="flex-1 overflow-y-scroll scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-gray-100 relative z-10">
<div class="flex flex-col items-center justify-start pt-16 pb-16"> <!-- Padding top/bottom to center items -->
{% for year_val in years_array %}
{% if year_val != "" %}
<div class="h-8 flex items-center justify-center text-sm text-gray-700 hover:text-indigo-700 w-full cursor-default">{{ year_val }}</div>
{% endif %}
{% endfor %}
</div>
</div>
<!-- Month Column -->
<div class="flex-1 overflow-y-scroll scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-gray-100 relative z-10">
<div class="flex flex-col items-center justify-start pt-16 pb-16">
{% for month_val in months_array %}
{% if month_val != "" %}
<div class="h-8 flex items-center justify-center text-sm text-gray-700 hover:text-indigo-700 w-full cursor-default">{{ month_val }}</div>
{% endif %}
{% endfor %}
</div>
</div>
<!-- Day Column -->
<div class="flex-1 overflow-y-scroll scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-gray-100 relative z-10">
<div class="flex flex-col items-center justify-start pt-16 pb-16">
{% for day_val in days_array %}
{% if day_val != "" %}
<div class="h-8 flex items-center justify-center text-sm text-gray-700 hover:text-indigo-700 w-full cursor-default">{{ day_val }}</div>
{% endif %}
{% endfor %}
</div>
</div>
</div>
<!-- Buttons Below -->
<div class="mt-3 pt-2.5 border-t border-gray-200 flex justify-end items-center space-x-2">
<button type="button" class="text-xs text-gray-600 hover:text-gray-800 font-medium px-3 py-1.5 rounded-sm hover:bg-gray-100 focus:outline-none focus:ring-1 focus:ring-indigo-500">Cancel</button>
<button type="button" class="text-xs text-white bg-indigo-700 hover:bg-indigo-800 font-medium px-3 py-1.5 rounded-sm focus:outline-none focus:ring-1 focus:ring-offset-1 focus:ring-indigo-500">Set Date</button>
</div>
<p class="text-xs text-gray-500 mt-2 text-center">This is a visual mock-up. Date selection is not functional.</p>
</div>
</div>
<style>
/* Minimal scrollbar styling for webkit browsers */
.scrollbar-thin::-webkit-scrollbar {
width: 6px;
height: 6px;
}
.scrollbar-thin::-webkit-scrollbar-track {
background: #f1f1f1; /* gray-100 approx */
border-radius: 10px;
}
.scrollbar-thin::-webkit-scrollbar-thumb {
background: #d1d5db; /* gray-300 approx */
border-radius: 10px;
}
.scrollbar-thin::-webkit-scrollbar-thumb:hover {
background: #9ca3af; /* gray-400 approx */
}
/* For Firefox */
.scrollbar-thin {
scrollbar-width: thin;
scrollbar-color: #d1d5db #f1f1f1;
}
/* Ensure scrolling snaps to items if desired (more complex, browser support varies) */
/* Basic approach: each item has a fixed height, scroll container has a height multiple of item height */
/* The pt-16/pb-16 on the inner divs of scroll columns is a hack to "center" the first/last few items against the selection line */
</style>