Skip to content

Commit

Permalink
Merge pull request #219 from os2ulf/feature/OS2UOL-1000
Browse files Browse the repository at this point in the history
Feature/os2 uol 1000
  • Loading branch information
tutaru99 authored Dec 6, 2024
2 parents 5d6349d + 79d26fd commit 3793899
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
4 changes: 4 additions & 0 deletions assets/css/_datepicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
padding-right: 0 @(--sm) 32px;
}

.dp__instance_calendar:last-child {
padding-right: 0 !important;
}

.dp__month_year_wrap {
font-size: 16px;
font-weight: 700;
Expand Down
63 changes: 57 additions & 6 deletions components/base/BaseDatePicker.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
// @ts-nocheck
import { v4 as uuidv4 } from 'uuid';
import { createPopper } from '@popperjs/core';
const id = `datepicker-${uuidv4()}`;
Expand All @@ -17,19 +18,69 @@ const props = defineProps({
const datepicker = ref();
const date = ref();
let popperInstance = null;
const emit = defineEmits(['datepickerValue']);
const handleDateChange = (newDate: object) => {
emit('datepickerValue', newDate);
setTimeout(() => {
showDatepicker.value = false;
destroyPopper();
}, 200);
};
const showDatepicker = ref(false);
const toggleDatepicker = () => {
showDatepicker.value = !showDatepicker.value;
if (showDatepicker.value) {
nextTick(() => {
initPopper();
});
} else {
destroyPopper();
}
};
const initPopper = () => {
const triggerEl = document.getElementById(id);
const datePickerEl = datepicker.value?.$el;
if (triggerEl && datePickerEl) {
popperInstance = createPopper(triggerEl, datePickerEl, {
placement: 'bottom',
modifiers: [
{
name: 'offset',
options: {
offset: [0, 8],
},
},
{
name: 'preventOverflow',
options: {
boundary: 'viewport',
},
},
{
name: 'flip',
options: {
fallbackPlacements: ['bottom-start'],
},
},
],
});
} else {
console.warn('Popper.js: Unable to initialize due to missing elements');
}
};
const destroyPopper = () => {
if (popperInstance) {
popperInstance.destroy();
popperInstance = null;
}
};
const setDate = (dates: object) => {
Expand All @@ -53,6 +104,7 @@ const convertToISO = (dateString) => {
const handleClickOutside = (e) => {
if (!e.target.closest('.datepicker')) {
showDatepicker.value = false;
destroyPopper();
}
};
Expand All @@ -69,6 +121,7 @@ onMounted(() => {
onUnmounted(() => {
document.removeEventListener('click', handleClickOutside);
destroyPopper();
});
</script>

Expand Down Expand Up @@ -111,9 +164,8 @@ onUnmounted(() => {

<style lang="postcss" scoped>
.datepicker {
position: relative;
width: inherit;
min-width: 300px;
min-width: 313px;
&__icon {
margin-right: 8px;
Expand All @@ -135,13 +187,13 @@ onUnmounted(() => {
align-items: center;
text-align: left;
width: 100%;
min-width: 300px;
min-width: 313px;
height: 55px;
border: 1px solid #707070;
border-radius: 32px;
background: none;
line-height: 18px;
height: inherit;
color: var(--color-gray-62);
font-weight: 400;
font-size: var(--font-size-paragraph-sm);
Expand All @@ -162,9 +214,8 @@ onUnmounted(() => {
}
&__component {
padding-top: 3px;
width: 100%;
z-index: 8;
width: auto;
}
}
</style>
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"dependencies": {
"@pinia/nuxt": "^0.5.1",
"@popperjs/core": "^2.11.8",
"@vee-validate/i18n": "^4.7.3",
"@vee-validate/rules": "^4.7.3",
"@vuepic/vue-datepicker": "^9.0.2",
Expand Down

0 comments on commit 3793899

Please sign in to comment.