Skip to content

Commit e218a08

Browse files
committed
feat: Add mobileBreakpoint property in config prop, replace @import with @use in scss (resolves #993)
1 parent 06529e6 commit e218a08

18 files changed

+85
-26
lines changed

dev/serve.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</script>
1313

1414
<style lang="scss">
15-
@import 'src/VueDatePicker/style/main';
15+
@use 'src/VueDatePicker/style/main';
1616
.wrapper {
1717
padding: 200px;
1818
}

src/VueDatePicker/VueDatePicker.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div ref="pickerWrapperRef" :class="wrapperClass" data-datepicker-instance>
2+
<div ref="pickerWrapperRef" :class="wrapperClass" data-datepicker-instance :data-dp-mobile="isMobile">
33
<DatepickerInput
44
ref="inputRef"
55
v-model:input-value="inputValue"
@@ -110,6 +110,7 @@
110110
MaybeElementRef,
111111
} from '@/interfaces';
112112
import { useDefaults } from '@/composables/defaults';
113+
import { useResponsive } from '@/composables/responsive';
113114
114115
const emit = defineEmits([
115116
'update:model-value',
@@ -174,6 +175,7 @@
174175
defaultedMultiDates,
175176
} = useDefaults(props);
176177
const { menuTransition, showTransition } = useTransitions(defaultedTransitions);
178+
const { isMobile } = useResponsive(defaultedConfig);
177179
178180
onMounted(() => {
179181
parseExternalModelValue(props.modelValue);

src/VueDatePicker/components/Common/InstanceWrap.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
dp__flex_display: multiCalendars > 0,
77
'dp--flex-display-collapsed': collapse,
88
}"
9+
:data-dp-mobile="isMobile"
910
>
1011
<div v-for="(instance, i) in instances" :key="instance" :class="calendarInstanceClassWrapper">
1112
<slot :instance="instance" :index="i"></slot>
@@ -16,7 +17,7 @@
1617
<script lang="ts" setup>
1718
import { computed } from 'vue';
1819
19-
const props = defineProps<{ multiCalendars: number; stretch?: boolean; collapse?: boolean }>();
20+
const props = defineProps<{ multiCalendars: number; stretch?: boolean; collapse?: boolean; isMobile?: boolean }>();
2021
2122
const instances = computed((): number[] =>
2223
props.multiCalendars > 0 ? [...Array(props.multiCalendars).keys()] : [0],

src/VueDatePicker/components/DatePicker/DatePicker.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<template>
2-
<InstanceWrap v-slot="{ instance, index }" :multi-calendars="defaultedMultiCalendars.count" :collapse="collapse">
2+
<InstanceWrap
3+
v-slot="{ instance, index }"
4+
:multi-calendars="defaultedMultiCalendars.count"
5+
:collapse="collapse"
6+
:is-mobile="isMobile"
7+
>
38
<DpHeader
49
v-if="!disableMonthYearSelect"
510
:ref="

src/VueDatePicker/components/DatepickerMenu.vue

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'dp--menu-content-wrapper-collapsed':
2626
collapse && (presetDates?.length || !!$slots['left-sidebar'] || !!$slots['right-sidebar']),
2727
}"
28+
:data-dp-mobile="isMobile"
2829
:style="{ '--dp-menu-width': `${calendarWidth}px` }"
2930
>
3031
<div v-if="$slots['left-sidebar']" class="dp__sidebar_left">
@@ -33,6 +34,7 @@
3334
<div
3435
v-if="presetDates.length"
3536
:class="{ 'dp--preset-dates-collapsed': collapse, 'dp--preset-dates': true }"
37+
:data-dp-mobile="isMobile"
3638
>
3739
<template v-for="(preset, i) in presetDates" :key="i">
3840
<template v-if="preset.slot">
@@ -50,6 +52,7 @@
5052
class="dp__btn dp--preset-range"
5153
:class="{ 'dp--preset-range-collapsed': collapse }"
5254
:data-test-id="preset.testId ?? undefined"
55+
:data-dp-mobile="isMobile"
5356
@click.prevent="presetDate(preset.value, preset.noTz)"
5457
@keydown="checkKeyDown($event, () => presetDate(preset.value, preset.noTz), true)"
5558
>
@@ -134,6 +137,7 @@
134137
import type { DynamicClass, MenuView, InternalModuleValue, MenuExposedFn, MonthModel } from '@/interfaces';
135138
import type { PropType } from 'vue';
136139
import { ArrowDirection, EventKey } from '@/constants';
140+
import { useResponsive } from '@/composables/responsive';
137141
138142
defineOptions({
139143
compatConfig: {
@@ -182,6 +186,7 @@
182186
const { openOnTop: _, ...initProps } = props;
183187
return {
184188
...initProps,
189+
isMobile: isMobile.value,
185190
flowStep: flowStep.value,
186191
menuWrapRef: dpMenuRef.value,
187192
};
@@ -190,6 +195,7 @@
190195
const { setMenuFocused, setShiftKey, control } = useState();
191196
const slots = useSlots();
192197
const { defaultedTextInput, defaultedInline, defaultedConfig, defaultedUI } = useDefaults(props);
198+
const { isMobile } = useResponsive(defaultedConfig);
193199
194200
const calendarWrapperRef = ref(null);
195201
const calendarWidth = ref(0);

src/VueDatePicker/components/MonthPicker/MonthPicker.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
2-
<InstanceWrap v-slot="{ instance }" :multi-calendars="defaultedMultiCalendars.count" :collapse="collapse" stretch>
2+
<InstanceWrap
3+
v-slot="{ instance }"
4+
:multi-calendars="defaultedMultiCalendars.count"
5+
:collapse="collapse"
6+
stretch
7+
:is-mobile="isMobile"
8+
>
39
<slot v-if="$slots['top-extra']" name="top-extra" :value="internalModelValue" />
410
<template v-if="$slots['month-year']">
511
<slot

src/VueDatePicker/components/QuarterPicker/QuarterPicker.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
2-
<InstanceWrap v-slot="{ instance }" :multi-calendars="defaultedMultiCalendars.count" :collapse="collapse" stretch>
2+
<InstanceWrap
3+
v-slot="{ instance }"
4+
:multi-calendars="defaultedMultiCalendars.count"
5+
:collapse="collapse"
6+
stretch
7+
:is-mobile="isMobile"
8+
>
39
<div class="dp-quarter-picker-wrap" :style="{ minHeight: `${defaultedConfig.modeHeight}px` }">
410
<slot v-if="$slots['top-extra']" name="top-extra" :value="internalModelValue" />
511
<div>

src/VueDatePicker/components/TimePicker/TimePicker.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="dp--tp-wrap">
2+
<div class="dp--tp-wrap" :data-dp-mobile="isMobile">
33
<button
44
v-if="!timePicker && !timePickerInline"
55
v-show="!hideNavigationButtons(hideNavigation, 'time')"

src/VueDatePicker/components/TimePicker/TimePickerSolo.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<InstanceWrap :multi-calendars="0" stretch>
2+
<InstanceWrap :multi-calendars="0" stretch :is-mobile="isMobile">
33
<TimePicker
44
ref="tpRef"
55
v-bind="$props"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { computed, type ComputedRef, onMounted, onUnmounted, ref } from 'vue';
2+
import type { Config } from '@/interfaces';
3+
4+
export const useResponsive = (config: ComputedRef<Config>) => {
5+
const windowWidth = ref(0);
6+
7+
onMounted(() => {
8+
updateWindowWidth();
9+
window.addEventListener('resize', updateWindowWidth, { passive: true });
10+
});
11+
12+
onUnmounted(() => {
13+
window.removeEventListener('resize', updateWindowWidth);
14+
});
15+
16+
const updateWindowWidth = () => {
17+
windowWidth.value = window.document.documentElement.clientWidth;
18+
};
19+
20+
const isMobile = computed(() => (windowWidth.value <= config.value.mobileBreakpoint ? true : undefined));
21+
22+
return {
23+
isMobile,
24+
};
25+
};

src/VueDatePicker/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export interface IDefaultSelect<T = number> {
1111
className?: DynamicClass;
1212
}
1313

14-
1514
export type VueEmit = (event: any, ...args: any[]) => void;
1615

1716
export enum OpenPosition {
@@ -294,6 +293,7 @@ export interface Config {
294293
keepViewOnOffsetClick?: boolean;
295294
timeArrowHoldThreshold: number;
296295
shadowDom?: boolean;
296+
mobileBreakpoint: number;
297297
}
298298

299299
export interface Highlight {

src/VueDatePicker/props.ts

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export const PickerBaseProps = {
167167
menuWrapRef: { type: Object as PropType<HTMLElement | null>, default: null },
168168
getInputRect: { type: Function as PropType<() => DOMRect>, default: () => ({}) },
169169
isTextInputDate: { type: Boolean as PropType<boolean>, default: false },
170+
isMobile: { type: Boolean as PropType<boolean>, default: false },
170171
};
171172

172173
export type AllPropsType = ExtractPropTypes<typeof AllProps>;

src/VueDatePicker/style/components/_Calendar.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@
256256
width: 100%;
257257
}
258258

259-
@media only screen and (width <= 600px) {
260-
.dp__flex_display {
261-
flex-direction: column;
262-
}
259+
.dp__flex_display {
260+
&[data-dp-mobile] {
261+
flex-direction: column;
262+
}
263263
}
264264

265265
.dp--flex-display-collapsed {

src/VueDatePicker/style/components/_DatepickerMenu.scss

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
padding: 5px;
131131
border-inline-end: 1px solid var(--dp-border-color);
132132

133-
@media only screen and (width <= 600px) {
133+
&[data-dp-mobile] {
134134
display: flex;
135135
align-self: center;
136136
border: none;
@@ -173,7 +173,7 @@
173173
cursor: pointer;
174174
}
175175

176-
@media only screen and (width <= 600px) {
176+
&[data-dp-mobile] {
177177
border: 1px solid var(--dp-border-color);
178178
margin: 0 3px;
179179

@@ -203,7 +203,7 @@
203203
.dp__menu_content_wrapper {
204204
display: flex;
205205

206-
@media only screen and (width <= 600px) {
206+
&[data-dp-mobile] {
207207
flex-direction: column-reverse;
208208
}
209209
}

src/VueDatePicker/style/components/_QuarterPicker.scss

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "shared";
2+
13
.dp-quarter-picker-wrap {
24
display: flex;
35
flex-direction: column;

src/VueDatePicker/style/components/_TimeInput.scss

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
@import "shared";
1+
@use "shared";
22

33
.dp--tp-wrap {
44
max-width: var(--dp-menu-min-width);
5+
6+
&[data-dp-mobile] {
7+
max-width: 100%;
8+
}
59
}
610

711
.dp__time_input {

src/VueDatePicker/style/main.scss

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
@import "components/DatepickerInput";
2-
@import "components/DatepickerMenu";
3-
@import "components/Calendar";
4-
@import "components/MonthYearInput";
5-
@import "components/SelectionOverlay";
6-
@import "components/TimeInput";
7-
@import "components/ActionRow";
8-
@import "components/QuarterPicker";
9-
@import "components/shared";
1+
@use "components/DatepickerInput";
2+
@use "components/DatepickerMenu";
3+
@use "components/Calendar";
4+
@use "components/MonthYearInput";
5+
@use "components/SelectionOverlay";
6+
@use "components/TimeInput";
7+
@use "components/ActionRow";
8+
@use "components/QuarterPicker";
9+
@use "components/shared";
1010

1111
:root {
1212
--dp-common-transition: all 0.1s ease-in;

src/VueDatePicker/utils/defaults.ts

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export const getDefaultConfig = (config?: Partial<Config>): Config => {
175175
keepViewOnOffsetClick: false,
176176
timeArrowHoldThreshold: 0,
177177
shadowDom: false,
178+
mobileBreakpoint: 600,
178179
};
179180
return { ...defaultConfig, ...(config ?? {}) };
180181
};

0 commit comments

Comments
 (0)