Skip to content

Commit b138837

Browse files
committed
added i18n, fix issues placement and locale mode changed
1 parent 179fc8b commit b138837

File tree

11 files changed

+375
-193
lines changed

11 files changed

+375
-193
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ All notable changes to this project will be documented in this file.
3838

3939
## [1.0.7]
4040

41-
- Fix some style
41+
- Fix some style.
42+
43+
## [1.0.8]
44+
45+
- Add localization for `shortcuts`, `footer` & `dayjs` locale.
46+
- New props `i18n`, [Example](https://litepie.com/#i18n).
47+
- Change local model `value` to `pickerValue`.
48+
- Fix issues placement arrow, `left` to `right`.
4249

4350
[Released]: https://github.com/kenhyuwa/litepie-datepicker/
4451
[1.0.0]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.0
@@ -49,3 +56,4 @@ All notable changes to this project will be documented in this file.
4956
[1.0.5]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.5
5057
[1.0.6]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.6
5158
[1.0.7]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.7
59+
[1.0.8]: https://github.com/kenhyuwa/litepie-datepicker/releases/tag/v1.0.8

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ export default {
6464
<img src="https://raw.githubusercontent.com/kenhyuwa/litepie-datepicker/main/assets/dark-mode.png" alt="Dark mode" />
6565
</p>
6666

67+
## Road map todo
68+
69+
Add shortcuts and footer localization match with `dayjs` locale.
70+
71+
- [x] English [en]
72+
- [x] Indonesia [id]
73+
- [ ] _other_
74+
6775
## Changelog
6876
All notable changes to this project will be documented in this file, [Read](CHANGELOG.md).
6977

dev/serve.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
>
66
<div class="mt-10 w-full">
77
<div
8-
class="max-w-lg mx-auto px-6 py-5 bg-white dark:bg-gray-800 rounded-lg"
8+
class="max-w-lg mx-autos ml-auto px-6 py-5 bg-white dark:bg-gray-800 rounded-lg"
99
>
1010
<div class="flex flex-col">
1111
<div class="w-full">
1212
<vue3-tailwind-datepicker
1313
ref="s"
14-
overlay
14+
i18n="id"
1515
:use-range="true"
1616
:formatter="formatter"
1717
v-model="dateValue"
@@ -99,10 +99,10 @@ export default defineComponent({
9999
];
100100
};
101101
onMounted(() => {
102-
dateValue.value = {
103-
startDate: '20 Mar 2021',
104-
endDate: '20 Aug 2021'
105-
};
102+
// dateValue.value = {
103+
// startDate: '20 Mar 2021',
104+
// endDate: '20 Aug 2021'
105+
// };
106106
// dateValue.value = [new Date(2019, 9, 8), new Date(2019, 9, 19)];
107107
// dateValue.value = `${new Date(2019, 9, 8).toString()} ~ ${new Date(
108108
// 2019,
@@ -120,8 +120,8 @@ export default defineComponent({
120120
shortcuts,
121121
away,
122122
formatter: ref({
123-
date: 'DD MMM YYYY',
124-
month: 'MMM'
123+
date: 'DD MMMM YYYY',
124+
month: 'MMMM'
125125
})
126126
};
127127
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "litepie-datepicker",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "A date range picker component for Vue.js and Tailwind CSS, dependent to day.js",
55
"main": "dist/litepie-datepicker.ssr.js",
66
"browser": "dist/litepie-datepicker.esm.js",

src/components/Calendar.vue

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,41 @@
88
leave-from-class="opacity-100"
99
leave-to-class="opacity-0"
1010
>
11-
<div v-for="(date, keyDate) in calendar.date()" :key="keyDate">
12-
<div
13-
class="relative"
14-
:class="{ 'litepie-tooltip': asRange && date.duration() }"
15-
:data-tooltip="`${date.duration()}`"
11+
<div
12+
v-for="(date, keyDate) in calendar.date()"
13+
:key="keyDate"
14+
class="relative"
15+
:class="{ 'litepie-tooltip': asRange && date.duration() }"
16+
:data-tooltip="`${date.duration()}`"
17+
>
18+
<transition
19+
enter-from-class="opacity-0"
20+
enter-to-class="opacity-100"
21+
enter-active-class="transition-opacity ease-out duration-200"
22+
leave-active-class="transition-opacity ease-in duration-150"
23+
leave-from-class="opacity-100"
24+
leave-to-class="opacity-0"
1625
>
17-
<transition
18-
enter-from-class="opacity-0"
19-
enter-to-class="opacity-100"
20-
enter-active-class="transition-opacity ease-out duration-200"
21-
leave-active-class="transition-opacity ease-in duration-150"
22-
leave-from-class="opacity-100"
23-
leave-to-class="opacity-0"
24-
>
25-
<span
26-
v-if="isBetweenRange(date) || date.hovered()"
27-
class="absolute bg-litepie-primary-100 dark:bg-litepie-secondary-700 dark:bg-opacity-50"
28-
:class="betweenRangeClasses(date)"
29-
></span>
30-
</transition>
31-
<button
32-
type="button"
33-
class="litepie-datepicker-date relative w-12 h-12 lg:w-10 lg:h-10 flex justify-center items-center text-xs 2xl:text-sm focus:outline-none"
34-
:class="[
35-
datepickerClasses(date),
36-
asRange ? 'transition-all' : 'transition-colors'
37-
]"
38-
:disabled="date.disabled || date.inRange()"
39-
@click="$emit('update:date', date, asPrevOrNext)"
40-
@mouseenter="atMouseOver(date)"
41-
v-text="date.date()"
42-
:data-date="date.toDate()"
43-
></button>
44-
</div>
26+
<span
27+
v-if="isBetweenRange(date) || date.hovered()"
28+
class="absolute bg-litepie-primary-100 dark:bg-litepie-secondary-700 dark:bg-opacity-50"
29+
:class="betweenRangeClasses(date)"
30+
></span>
31+
</transition>
32+
<button
33+
type="button"
34+
class="litepie-datepicker-date relative w-12 h-12 lg:w-10 lg:h-10 flex justify-center items-center text-xs 2xl:text-sm focus:outline-none"
35+
:class="[
36+
datepickerClasses(date),
37+
asRange ? 'transition-all' : 'transition-colors'
38+
]"
39+
:disabled="date.disabled || date.inRange()"
40+
@click="$emit('update:date', date, asPrevOrNext)"
41+
@mouseenter="atMouseOver(date)"
42+
@focusin="atMouseOver(date)"
43+
v-text="date.date()"
44+
:data-date="date.toDate()"
45+
></button>
4546
</div>
4647
</transition-group>
4748
</div>

src/components/Shortcut.vue

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class="block text-sm lg:text-xs px-2 py-2 sm:leading-4 whitespace-nowrap font-medium rounded text-litepie-primary-600 hover:text-litepie-primary-700 transition-colors hover:bg-litepie-secondary-100 focus:bg-litepie-secondary-100 focus:text-litepie-primary-600 dark:hover:bg-litepie-secondary-700 dark:hover:text-litepie-primary-300 dark:text-litepie-primary-400 dark:focus:bg-litepie-secondary-700 dark:focus:text-litepie-primary-300"
2828
@click.prevent="setToToday"
2929
>
30-
Today
30+
{{ jsonLocale && jsonLocale.today }}
3131
</a>
3232
</li>
3333
<li>
@@ -36,7 +36,7 @@
3636
class="block text-sm lg:text-xs px-2 py-2 sm:leading-4 whitespace-nowrap font-medium rounded text-litepie-primary-600 hover:text-litepie-primary-700 transition-colors hover:bg-litepie-secondary-100 focus:bg-litepie-secondary-100 focus:text-litepie-primary-600 dark:hover:bg-litepie-secondary-700 dark:hover:text-litepie-primary-300 dark:text-litepie-primary-400 dark:focus:bg-litepie-secondary-700 dark:focus:text-litepie-primary-300"
3737
@click.prevent="setToYesterday"
3838
>
39-
Yesterday
39+
{{ jsonLocale && jsonLocale.yesterday }}
4040
</a>
4141
</li>
4242
<li>
@@ -45,7 +45,7 @@
4545
class="block text-sm lg:text-xs px-2 py-2 sm:leading-4 whitespace-nowrap font-medium rounded text-litepie-primary-600 hover:text-litepie-primary-700 transition-colors hover:bg-litepie-secondary-100 focus:bg-litepie-secondary-100 focus:text-litepie-primary-600 dark:hover:bg-litepie-secondary-700 dark:hover:text-litepie-primary-300 dark:text-litepie-primary-400 dark:focus:bg-litepie-secondary-700 dark:focus:text-litepie-primary-300"
4646
@click.prevent="setToLastDay(7)"
4747
>
48-
Last 7 Days
48+
{{ jsonLocale && jsonLocale.past(7) }}
4949
</a>
5050
</li>
5151
<li>
@@ -54,7 +54,7 @@
5454
class="block text-sm lg:text-xs px-2 py-2 sm:leading-4 whitespace-nowrap font-medium rounded text-litepie-primary-600 hover:text-litepie-primary-700 transition-colors hover:bg-litepie-secondary-100 focus:bg-litepie-secondary-100 focus:text-litepie-primary-600 dark:hover:bg-litepie-secondary-700 dark:hover:text-litepie-primary-300 dark:text-litepie-primary-400 dark:focus:bg-litepie-secondary-700 dark:focus:text-litepie-primary-300"
5555
@click.prevent="setToLastDay(30)"
5656
>
57-
Last 30 Days
57+
{{ jsonLocale && jsonLocale.past(30) }}
5858
</a>
5959
</li>
6060
<li>
@@ -63,7 +63,7 @@
6363
class="block text-sm lg:text-xs px-2 py-2 sm:leading-4 whitespace-nowrap font-medium rounded text-litepie-primary-600 hover:text-litepie-primary-700 transition-colors hover:bg-litepie-secondary-100 focus:bg-litepie-secondary-100 focus:text-litepie-primary-600 dark:hover:bg-litepie-secondary-700 dark:hover:text-litepie-primary-300 dark:text-litepie-primary-400 dark:focus:bg-litepie-secondary-700 dark:focus:text-litepie-primary-300"
6464
@click.prevent="setToThisMonth"
6565
>
66-
This Month
66+
{{ jsonLocale && jsonLocale.currentMonth }}
6767
</a>
6868
</li>
6969
<li>
@@ -72,25 +72,27 @@
7272
class="block text-sm lg:text-xs px-2 py-2 sm:leading-4 whitespace-nowrap font-medium rounded text-litepie-primary-600 hover:text-litepie-primary-700 transition-colors hover:bg-litepie-secondary-100 focus:bg-litepie-secondary-100 focus:text-litepie-primary-600 dark:hover:bg-litepie-secondary-700 dark:hover:text-litepie-primary-300 dark:text-litepie-primary-400 dark:focus:bg-litepie-secondary-700 dark:focus:text-litepie-primary-300"
7373
@click.prevent="setToLastMonth"
7474
>
75-
Last Month
75+
{{ jsonLocale && jsonLocale.pastMonth }}
7676
</a>
7777
</li>
7878
</ol>
7979
</div>
8080
</template>
8181

8282
<script>
83-
import { inject } from 'vue';
83+
import { ref, inject, watchEffect } from 'vue';
8484
8585
export default {
8686
name: 'LitepieShortcut',
8787
props: {
8888
shortcuts: [Boolean, Function],
8989
asRange: Boolean,
90-
asSingle: Boolean
90+
asSingle: Boolean,
91+
i18n: String
9192
},
9293
inheritAttrs: false,
9394
setup(props) {
95+
const jsonLocale = ref(null);
9496
const setToToday = inject('setToToday');
9597
const setToYesterday = inject('setToYesterday');
9698
const setToLastDay = inject('setToLastDay');
@@ -104,8 +106,26 @@ export default {
104106
return false;
105107
}
106108
};
109+
const locale = () => {
110+
return import(`./../locale/${props.i18n}`)
111+
.then(async module => {
112+
return await module.default;
113+
})
114+
.catch(() => {
115+
return import(`./../locale/en`).then(async module => {
116+
return await module.default;
117+
});
118+
});
119+
};
120+
121+
watchEffect(() => {
122+
locale().then(v => {
123+
jsonLocale.value = v;
124+
});
125+
});
107126
108127
return {
128+
jsonLocale,
109129
setToToday,
110130
setToYesterday,
111131
setToLastDay,

src/lib/fn.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,10 @@ export const useDirective = binding => {
9797
}
9898
});
9999
};
100+
101+
export const useVisibleViewport = el => {
102+
const { right } = el.getBoundingClientRect();
103+
const vWidth = window.innerWidth || document.documentElement.clientWidth;
104+
105+
return right < vWidth;
106+
};

0 commit comments

Comments
 (0)