Attempt to make month picker better

This commit is contained in:
Lim Chee Aun 2023-10-20 19:24:01 +08:00
parent ab7df0f66c
commit 3721acf3d3
3 changed files with 44 additions and 22 deletions

View file

@ -2134,11 +2134,18 @@ ul.link-list li a .icon {
border-radius: 999px; border-radius: 999px;
color: var(--text-color); color: var(--text-color);
background-color: var(--bg-color); background-color: var(--bg-color);
background-image: none;
border: 2px solid transparent; border: 2px solid transparent;
margin: 0; margin: 0;
appearance: none; /* appearance: none; */
line-height: 1; line-height: 1;
font-size: 90%; font-size: 90%;
display: flex;
gap: 8px;
> .icon {
color: var(--link-color);
}
&:placeholder-shown { &:placeholder-shown {
color: var(--text-insignificant-color); color: var(--text-insignificant-color);
@ -2157,6 +2164,7 @@ ul.link-list li a .icon {
:is(input, select) { :is(input, select) {
background-color: transparent; background-color: transparent;
background-image: none;
border: 0; border: 0;
padding: 0; padding: 0;
margin: 0; margin: 0;
@ -2167,6 +2175,12 @@ ul.link-list li a .icon {
border-radius: 0; border-radius: 0;
box-shadow: none; box-shadow: none;
outline: none; outline: none;
&::-webkit-calendar-picker-indicator {
/* replace icon with triangle */
opacity: 0.5;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none"><path d="M4 6L8 10L12 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>');
}
} }
} }
} }

View file

@ -101,6 +101,7 @@ export const ICONS = {
'account-warning': () => import('@iconify-icons/mingcute/user-warning-line'), 'account-warning': () => import('@iconify-icons/mingcute/user-warning-line'),
keyboard: () => import('@iconify-icons/mingcute/keyboard-line'), keyboard: () => import('@iconify-icons/mingcute/keyboard-line'),
cloud: () => import('@iconify-icons/mingcute/cloud-line'), cloud: () => import('@iconify-icons/mingcute/cloud-line'),
month: () => import('@iconify-icons/mingcute/calendar-month-line'),
}; };
function Icon({ function Icon({

View file

@ -16,6 +16,8 @@ import { saveStatus } from '../utils/states';
import useTitle from '../utils/useTitle'; import useTitle from '../utils/useTitle';
const LIMIT = 20; const LIMIT = 20;
const MIN_YEAR = 1983;
const MIN_YEAR_MONTH = `${MIN_YEAR}-01`; // Birth of the Internet
const supportsInputMonth = (() => { const supportsInputMonth = (() => {
try { try {
@ -67,7 +69,9 @@ function AccountStatuses() {
}, [sameCurrentInstance, account?.acct]); }, [sameCurrentInstance, account?.acct]);
async function fetchAccountStatuses(firstLoad) { async function fetchAccountStatuses(firstLoad) {
if (/^\d{4}-[01]\d$/.test(month)) { const isValidMonth = /^\d{4}-[01]\d$/.test(month);
const isValidYear = month?.split?.('-')?.[0] >= MIN_YEAR;
if (isValidMonth && isValidYear) {
if (!account) { if (!account) {
return { return {
value: [], value: [],
@ -297,31 +301,33 @@ function AccountStatuses() {
))} ))}
{searchEnabled && {searchEnabled &&
(supportsInputMonth ? ( (supportsInputMonth ? (
<input <label class={`filter-field ${month ? 'is-active' : ''}`}>
type="month" <Icon icon="month" size="l" />
class={`filter-field ${month ? 'is-active' : ''}`} <input
disabled={!account?.acct} type="month"
value={month || ''} disabled={!account?.acct}
min="1983-01" // Birth of the Internet value={month || ''}
max={new Date().toISOString().slice(0, 7)} min={MIN_YEAR_MONTH}
onInput={(e) => { max={new Date().toISOString().slice(0, 7)}
const { value } = e.currentTarget; onInput={(e) => {
setSearchParams( const { value } = e.currentTarget;
value setSearchParams(
? { value
month: value, ? {
} month: value,
: {}, }
); : {},
}} );
/> }}
/>
</label>
) : ( ) : (
// Fallback to <select> for month and <input type="number"> for year // Fallback to <select> for month and <input type="number"> for year
<MonthPicker <MonthPicker
class={`filter-field ${month ? 'is-active' : ''}`} class={`filter-field ${month ? 'is-active' : ''}`}
disabled={!account?.acct} disabled={!account?.acct}
value={month || ''} value={month || ''}
min="1983-01" // Birth of the Internet min={MIN_YEAR_MONTH}
max={new Date().toISOString().slice(0, 7)} max={new Date().toISOString().slice(0, 7)}
onInput={(e) => { onInput={(e) => {
const { value } = e; const { value } = e;
@ -465,6 +471,7 @@ function MonthPicker(props) {
return ( return (
<div class={className}> <div class={className}>
<Icon icon="month" size="l" />
<select <select
ref={monthFieldRef} ref={monthFieldRef}
disabled={disabled} disabled={disabled}
@ -497,7 +504,7 @@ function MonthPicker(props) {
type="number" type="number"
disabled={disabled} disabled={disabled}
value={_year || new Date().getFullYear()} value={_year || new Date().getFullYear()}
min={min?.slice(0, 4) || '1983'} min={min?.slice(0, 4) || MIN_YEAR}
max={max?.slice(0, 4) || new Date().getFullYear()} max={max?.slice(0, 4) || new Date().getFullYear()}
onInput={(e) => { onInput={(e) => {
const { value } = e.currentTarget; const { value } = e.currentTarget;