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

Fix: Date Select Sizing #1267

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 11 additions & 13 deletions demo/sections/components/DateRangeSelect.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<ComponentPage title="Date Range Select" :demos="[{ title: 'Date Range Select' }]">
<ComponentPage title="Date Range Select" :demos="[{ title: 'Date Range Select' }, { title: 'Date Range Selesct' }]">
<template #description>
<DemoState v-model:state="exampleState" v-model:disabled="disabled" />
<p-checkbox v-model="clearable" :disabled="disabled" label="Clearable" />
</template>

<template #date-range-select>
Expand All @@ -10,18 +11,15 @@
<p-code inline>
value: {{ JSON.stringify(value) }}
</p-code>
<div class="flex justify-start gap-4">
<p-checkbox v-model="clearable" :disabled="disabled" label="Clearable" />
</div>
<div class="flex gap-4 w-1/2">
<p-label label="Min Value" :message="min ? format(min, 'MMM do, yyyy h:mm a') : ''">
<p-native-date-input v-model="min" :disabled="disabled" :state="exampleState" />
</p-label>

<p-label label="Max Value" :message="max ? format(max, 'MMM do, yyyy h:mm a') : ''">
<p-native-date-input v-model="max" :disabled="disabled" :state="exampleState" />
</p-label>
</div>
</p-content>
</template>
<template #date-range-selesct>
<p-content>
<p-date-range-select v-model="value" v-bind="{ min, max, clearable, disabled }" size="sm">
<p-code inline>
value: {{ JSON.stringify(value) }}
</p-code>
</p-date-range-select>
</p-content>
</template>
</ComponentPage>
Expand Down
58 changes: 48 additions & 10 deletions src/components/DateRangeSelect/PDateRangeSelect.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<PPopOver ref="popover" class="p-date-range-select" :placement="placement" auto-close>
<template #target="{ open }">
<PButton class="p-date-range-select__button" icon="ArrowSmallLeftIcon" :disabled="previousDisabled" @click="previous" />
<PButton class="p-date-range-select__button p-date-range-select__input" :disabled="disabled" @click="open">
<PButton class="p-date-range-select__button" icon="ArrowSmallLeftIcon" :disabled="previousDisabled" :size="size" @click="previous" />
<PButton class="p-date-range-select__button p-date-range-select__input" :class="button({ size })" :disabled="disabled" :size="size" @click="open">
<div class="p-date-range-select__content">
<PIcon icon="CalendarIcon" class="shrink-0" />
<span class="p-date-range-select__label" :class="classes.label">
Expand All @@ -13,9 +13,9 @@
</PButton>

<template v-if="modelValue && clearable && !disabled">
<PButton class="p-date-range-select__button" icon="XCircleIcon" @click="clear" />
<PButton class="p-date-range-select__button" icon="XCircleIcon" :size="size" @click="clear" />
</template>
<PButton class="p-date-range-select__button" icon="ArrowSmallRightIcon" :disabled="nextDisabled" @click="next" />
<PButton class="p-date-range-select__button" icon="ArrowSmallRightIcon" :disabled="nextDisabled" :size="size" @click="next" />
</template>

<template #default>
Expand All @@ -42,6 +42,7 @@

<script lang="ts" setup>
import { useElementRect, useKeyDown } from '@prefecthq/vue-compositions'
import { cva, type VariantProps } from 'class-variance-authority'
import { addDays, addSeconds, isAfter, isBefore } from 'date-fns'
import { secondsInDay } from 'date-fns/constants'
import { computed, ref, watch } from 'vue'
Expand All @@ -58,19 +59,39 @@
import { mapDateRangeSelectValueToDateRange } from '@/utilities/dateRangeSelect'
import { bottomRight, topRight, bottomLeft, topLeft, rightInside, leftInside } from '@/utilities/position'

const button = cva(
'',
{
variants: {
size: {
default: 'h-10',
sm: 'h-7',
},
},
})

type ButtonProps = VariantProps<typeof button>

type DateRange = { startDate: Date, endDate: Date }

export type DateRangeSelectMode = 'span' | 'range' | 'around' | null

const props = defineProps<{
const props = withDefaults(defineProps<{
modelValue: DateRangeSelectValue,
placeholder?: string,
maxSpanInSeconds?: number,
clearable?: boolean,
disabled?: boolean,
min?: Date,
max?: Date,
}>()
size?: ButtonProps['size'],
}>(), {
min: undefined,
max: undefined,
placeholder: undefined,
maxSpanInSeconds: undefined,
size: 'default',
})

const emit = defineEmits<{
'update:modelValue': [DateRangeSelectValue],
Expand Down Expand Up @@ -219,24 +240,41 @@
flex
flex-nowrap
items-center
rounded-none
}

.p-date-range-select__button { @apply
rounded-none

-ml-[1px]
}

.p-date-range-select__button:hover { @apply
z-10
z-50
}

.p-date-range-select__button:first-child { @apply
ml-0
rounded-l-default
rounded-r-none
}

.p-date-range-select__button:last-child { @apply
rounded-r-default
rounded-l-none
}

.p-date-range-select__input { @apply
overflow-hidden
grow
shrink
min-w-0
rounded-none
}

.p-date-range-select__content { @apply
w-full
flex
items-center
gap-2
min-w-0
}

.p-date-range-select__input { @apply
Expand Down
Loading