Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2824 date input #2864

Merged
merged 36 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5f76b11
updating date input
kwongz Nov 28, 2024
e31bbd4
removed dateInput dropdown
kwongz Nov 28, 2024
46dd252
removed docwrapper
kwongz Nov 28, 2024
959a449
fixed preset select
kwongz Nov 28, 2024
a9edd33
chore: ling + changeset
kwongz Nov 28, 2024
9da5eb0
added redirect
kwongz Nov 29, 2024
49c1bac
added package manager, linted
kwongz Nov 29, 2024
923a5f2
Merge branch 'next' into feature/2824-date-input
kwongz Nov 29, 2024
af36798
updated docs changes, added default title
kwongz Nov 29, 2024
4be852e
removed y2 from barcharts
kwongz Nov 29, 2024
0527feb
updated date input ui
kwongz Nov 29, 2024
95667bf
added margin, lighten color calendar icon
kwongz Nov 29, 2024
41d31ca
matched ranged and non-ranged border styling
kwongz Dec 2, 2024
f728875
lighten border divider
kwongz Dec 2, 2024
389ef3d
matched date input with dropdown seperator styling
kwongz Dec 2, 2024
ef35f7b
updated icon
kwongz Dec 2, 2024
175be7f
stroke-1 text-black
kwongz Dec 2, 2024
3150c62
changed calendar icon
kwongz Dec 4, 2024
9505d54
linted
kwongz Dec 4, 2024
d3c9818
add icon to smaller screen width version
kwongz Dec 5, 2024
a51230d
added toBoolean check for range prop, removed commented out code
kwongz Dec 5, 2024
849bef5
refactored reused functions into helper.js - DateInput & DateRange
kwongz Dec 5, 2024
9a54784
fixed code from comments
kwongz Dec 13, 2024
8beb4b3
Merge branch 'next' into feature/2824-date-input
kwongz Dec 13, 2024
b928a5d
fixed dark mode docs tabs
kwongz Dec 13, 2024
d721651
Merge branch 'next' into feature/2824-date-input
kwongz Dec 17, 2024
39e967b
updated dateInput themes styling
kwongz Dec 17, 2024
9396059
updated _DateInput + calendar with new themes styles
kwongz Dec 17, 2024
5a151a1
removed logs, shorthand boolean dateRange
kwongz Dec 18, 2024
c85d90b
swapped query.create for buildReactiveInputQuery
kwongz Dec 18, 2024
3db1c6a
evidence reset
kwongz Dec 18, 2024
87bb43a
pnpm i
kwongz Dec 18, 2024
42e305e
Merge branch 'next' into feature/2824-date-input
kwongz Dec 18, 2024
d1fcb9d
pnpm i
kwongz Dec 18, 2024
44f356f
switched buildreactiveinputquery for buildquery
kwongz Dec 18, 2024
4ac903d
linted
kwongz Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-trains-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/core-components': patch
---

Feature: DateInput - supports single and ranged calendar date inputs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@
}
},
"packageManager": "[email protected]+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script context="module">
/** @type {import("@storybook/svelte").Meta}*/
export const meta = {
title: 'Atoms/inputs/DateInput',
argTypes: {},
args: {
title: 'Date Input',
name: 'DateInput',
omitGroup: []
}
};
</script>

<script>
import { Template, Story } from '@storybook/addon-svelte-csf';
import DateInput from './DateInput.svelte';
import { getInputContext } from '@evidence-dev/sdk/utils/svelte';
const inputStore = getInputContext();

// Mock "today"
import MockDate from 'mockdate';
MockDate.set('2024-12-30');
kwongz marked this conversation as resolved.
Show resolved Hide resolved
</script>

<Template let:args>
<DateInput {...args} />
</Template>

<Story name="Basic Usage" let:args>
<h1>
Input Store:
<h2>value: {$inputStore.dateInput.value}</h2>
<h2>start: {$inputStore.dateInput.start}</h2>
<h2>end: {$inputStore.dateInput.end}</h2>
</h1>
<DateInput {...args} name="dateInput" />
</Story>
<Story name="dateInput_range" let:args>
<h1>
Input Store:
<h2>value: {$inputStore.dateInput_range.value}</h2>
<h2>start: {$inputStore.dateInput_range.start}</h2>
<h2>end: {$inputStore.dateInput_range.end}</h2>
</h1>
<DateInput {...args} name="dateInput_range" range />
</Story>
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<script context="module">
export const evidenceInclude = true;
</script>

<script>
import DateInput from './_DateInput.svelte';
import { Query } from '@evidence-dev/sdk/usql';
import { getQueryFunction } from '@evidence-dev/component-utilities/buildQuery';
import { getLocalTimeZone } from '@internationalized/date';
import HiddenInPrint from '../shared/HiddenInPrint.svelte';
import { page } from '$app/stores';
import QueryLoad from '$lib/atoms/query-load/QueryLoad.svelte';
import { Skeleton } from '$lib/atoms/skeletons/index.js';
import { getInputContext } from '@evidence-dev/sdk/utils/svelte';

function dateToYYYYMMDD(date) {
return date.toISOString().split('T')[0];
}

const inputs = getInputContext();

/** @type {string} */
export let name;
/** @type {string | undefined} */
export let title;
kwongz marked this conversation as resolved.
Show resolved Hide resolved
/** @type {boolean} */
export let hideDuringPrint = true;

/** @type {string | Date | undefined} */
export let start;
/** @type {string | Date | undefined} */
export let end;

/** @type {Query | string | undefined} */
export let data;
/** @type {string | undefined} */
export let dates;
/** @type {[]string | undefined} */
kwongz marked this conversation as resolved.
Show resolved Hide resolved
export let presetRanges;
/** @type {string | undefined} */
export let defaultValue;
/** @type {boolean} */
export let range = false;
kwongz marked this conversation as resolved.
Show resolved Hide resolved

const exec = getQueryFunction();
kwongz marked this conversation as resolved.
Show resolved Hide resolved
let query;
$: if (data && dates) {
const source = typeof data === 'string' ? data : `(${data.text})`;
query = Query.create(
`SELECT min(${dates}) as start, max(${dates}) as end FROM ${source}`,
exec,
{
initialData: $page?.data?.data[`DateInput-${name}_data`],
knownColumns: $page?.data?.data[`DateInput-${name}_columns`],
disableCache: true,
noResolve: false,
id: `DateInput-${name}`
}
);
query.fetch();
}
const YYYYMMDD = /^\d{4}-\d{2}-\d{2}$/;
$: startString =
typeof start === 'string' && YYYYMMDD.test(start)
? start
: start instanceof Date
? dateToYYYYMMDD(start)
: $query?.[0].start instanceof Date
? dateToYYYYMMDD($query?.[0].start)
: dateToYYYYMMDD(new Date(0));
$: endString =
typeof end === 'string' && YYYYMMDD.test(end)
? end
: end instanceof Date
? dateToYYYYMMDD(end)
: $query?.[0].end instanceof Date
? dateToYYYYMMDD($query?.[0].end)
: dateToYYYYMMDD(new Date());

$: if ((query && $query.dataLoaded) || !query) {
if (range) {
$inputs[name] = { value: undefined, start: startString, end: endString };
} else {
$inputs[name] = { value: startString, start: startString, end: undefined };
kwongz marked this conversation as resolved.
Show resolved Hide resolved
}
}

let currentDate = dateToYYYYMMDD(new Date(Date.now()));
kwongz marked this conversation as resolved.
Show resolved Hide resolved

let selectedDateInput;
$: if (selectedDateInput && (selectedDateInput.start || selectedDateInput.end) && range) {
$inputs[name] = {
value: undefined,
start: dateToYYYYMMDD(selectedDateInput.start?.toDate(getLocalTimeZone()) ?? new Date(0)),
end: dateToYYYYMMDD(selectedDateInput.end?.toDate(getLocalTimeZone()) ?? new Date())
};
} else if (selectedDateInput && selectedDateInput && !range) {
$inputs[name] = {
value: dateToYYYYMMDD(selectedDateInput.toDate(getLocalTimeZone()) ?? new Date(0)),
start: dateToYYYYMMDD(selectedDateInput.toDate(getLocalTimeZone()) ?? new Date(0)),
end: undefined
};
kwongz marked this conversation as resolved.
Show resolved Hide resolved
}
</script>

<HiddenInPrint enabled={hideDuringPrint}>
<div class="mt-2 mb-4 ml-0 mr-2 inline-block">
{#if title && range}
<span class="text-sm text-gray-500 block mb-1">{title}</span>
{/if}

{#if $query?.error}
<span
class="group inline-flex items-center relative cursor-help cursor-helpfont-sans px-1 border border-red-200 py-[1px] bg-red-50 rounded"
>
<span class="inline font-sans font-medium text-xs text-red-600">error</span>
<span
class="hidden text-white font-sans group-hover:inline absolute -top-1 left-[105%] text-sm z-10 px-2 py-1 bg-gray-800/80 leading-relaxed min-w-[150px] w-max max-w-[400px] rounded-md"
>
{$query.error}
</span>
</span>
{:else}
<QueryLoad data={query} let:loaded>
<svelte:fragment slot="skeleton">
<Skeleton class="h-8 w-72" />
</svelte:fragment>
<DateInput
bind:selectedDateInput
start={startString}
end={endString}
loaded={loaded?.ready ?? true}
{presetRanges}
{defaultValue}
{range}
{currentDate}
{title}
/>
</QueryLoad>
{/if}
</div>
</HiddenInPrint>
Loading
Loading