Skip to content

Commit

Permalink
feat: date range picker modal
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikmehinagic committed Nov 22, 2023
1 parent 9a481da commit 860f909
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/Calendar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ defineExpose({
</script>

<template>
<div class="relative flex w-max select-none flex-col sm:flex-row">
<div class="relative flex w-full select-none flex-col sm:flex-row">
<div
v-if="presets.length"
class="relative hidden min-h-0 w-48 border-r border-gray-200 dark:border-gray-700 lg:block"
Expand Down Expand Up @@ -595,7 +595,7 @@ defineExpose({
</button>
</div>

<div class="relative w-max">
<div class="relative w-full">
<div
v-if="showMonthSelectionActive"
class="absolute inset-0 z-10 grid grid-cols-3 gap-4"
Expand Down
3 changes: 3 additions & 0 deletions src/components/DateRangePicker/index.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const Default: Story = {
const activePresetComparison = ref(undefined);
const perspectivePreset = ref(undefined);
const perspectivePresetComparison = ref(undefined);
const showComparison = ref(false);

return {
args,
Expand All @@ -64,6 +65,7 @@ export const Default: Story = {
activePresetComparison,
perspectivePreset,
perspectivePresetComparison,
showComparison,
};
},
template: `
Expand All @@ -77,6 +79,7 @@ export const Default: Story = {
v-model:active-preset-comparison="activePresetComparison"
v-model:perspective-preset="perspectivePreset"
v-model:perspective-preset-comparison="perspectivePresetComparison"
v-model:show-comparison="showComparison"
>
</DaterangePicker>
`,
Expand Down
48 changes: 33 additions & 15 deletions src/components/DateRangePicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RobustCheckbox,
RobustDatePicker,
RobustTabs,
RobustModal,
} from '..';
import { PhCaretDown, PhCalendar } from '@phosphor-icons/vue';
import { computed, PropType, ref, watch } from 'vue';
Expand Down Expand Up @@ -99,6 +100,10 @@ const props = defineProps({
type: String,
default: 'Perspective of',
},
type: {
type: String as PropType<'dropdown' | 'modal'>,
default: 'modal',
},
});
const emit = defineEmits([
Expand Down Expand Up @@ -304,7 +309,7 @@ const displayComparisonPreset = computed(() => {
});
onClickOutside(elementRef, (event) => {
if (!open.value) {
if (!open.value || props.type === 'modal') {
return;
}
Expand All @@ -322,9 +327,26 @@ function closeDropdown() {
}
}
const handleClick = () => {
open.value = !open.value;
};
const wrapperAttrs = computed(() => {
if (props.type === 'modal') {
return {
opened: open.value,
size: 'xl',
center: true,
'onUpdate:opened': (value: boolean) => {
open.value = false;
},
};
}
return {
open: open.value,
class: 'z-[100] origin-top-left',
reference: inputWrapperRef.value?.wrapperRef,
options: {
placement: 'bottom-start',
},
};
});
const saveTime = async () => {
emit('update:dateRange', stagedDateRange.value);
Expand Down Expand Up @@ -439,16 +461,12 @@ const saveTime = async () => {
/>
</div>
</RobustInputWrapper>
<RobustFloating
v-if="inputWrapperRef?.wrapperRef"
<Component
:is="type === 'modal' ? RobustModal : RobustFloating"
v-bind="wrapperAttrs"
ref="elementRef"
v-model:open="open"
class="z-[100] origin-top-left"
:reference="inputWrapperRef?.wrapperRef"
:options="{
placement: 'bottom-start',
}"
>
<template #title> </template>
<div
class="flex items-center justify-between border-gray-200 dark:border-gray-700"
>
Expand Down Expand Up @@ -481,7 +499,7 @@ const saveTime = async () => {
:title="perspectiveTitle"
condensed
resetable
class="mb-4 w-56"
class="mb-4 w-full"
:presets="perspectiveDatePresets"
/>

Expand All @@ -508,7 +526,7 @@ const saveTime = async () => {
:title="perspectiveTitle"
condensed
resetable
class="mb-4 w-56"
class="mb-4 w-full"
:presets="perspectiveDatePresets"
/>
</RobustCalendar>
Expand All @@ -521,5 +539,5 @@ const saveTime = async () => {
>Apply time range</RobustButton
>
</div>
</RobustFloating>
</Component>
</template>

0 comments on commit 860f909

Please sign in to comment.