Files
resharespace-static/_includes/calendar_input.liquid
T

131 lines
6.7 KiB
Plaintext

<!-- Scrolling Date Picker Template with Snapping and Infinite Scroll -->
{% 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>
<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">
<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 relative z-10 snap-container" data-scroll-snap>
<div class="flex flex-col items-center justify-start pt-48 pb-48 scroll-list">
{% for repeat in (1..3) %}
{% 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 snap-item">{{ year_val }}</div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
</div>
<!-- Month Column -->
<div class="flex-1 overflow-y-scroll relative z-10 snap-container" data-scroll-snap>
<div class="flex flex-col items-center justify-start pt-48 pb-48 scroll-list">
{% for repeat in (1..3) %}
{% 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 snap-item">{{ month_val }}</div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
</div>
<!-- Day Column -->
<div class="flex-1 overflow-y-scroll relative z-10 snap-container" data-scroll-snap>
<div class="flex flex-col items-center justify-start pt-48 pb-48 scroll-list">
{% for repeat in (1..3) %}
{% 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 snap-item">{{ day_val }}</div>
{% endif %}
{% endfor %}
{% endfor %}
</div>
</div>
</div>
<div class="mt-3 pt-2.5 border-t border-gray-200 flex items-center space-x-2">
<button type="button" class="bg-gray-100 text-gray-700 text-sm font-semibold py-2 px-4 rounded-lg flex-1 flex items-center justify-center border-2 border-transparent hover:bg-gray-200 hover:border-gray-400 focus:outline-none focus:ring-1 focus:ring-indigo-500">Cancel</button>
<button type="button" class="bg-indigo-900 text-sm text-gray-100 font-semibold py-2 px-4 rounded-lg flex-1 flex items-center justify-center border-2 border-transparent hover:border-indigo-700 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>
.snap-container {
scroll-snap-type: y mandatory;
}
.snap-item {
scroll-snap-align: center;
}
</style>
<script>
document.querySelectorAll('[data-scroll-snap]').forEach(container => {
const list = container.querySelector('.scroll-list');
const items = list.children;
const itemHeight = 32;
const totalItems = items.length;
const third = totalItems / 3;
container.scrollTop = third * itemHeight;
let scrollTimeout;
container.addEventListener('scroll', () => {
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(() => {
const scrollPos = container.scrollTop;
const snappedIndex = Math.round(scrollPos / itemHeight);
container.scrollTo({
top: snappedIndex * itemHeight,
behavior: 'smooth'
});
if (snappedIndex < third || snappedIndex >= 2 * third) {
const centerOffset = (snappedIndex % third) + third;
container.scrollTop = centerOffset * itemHeight;
}
}, 100);
});
});
</script>