Skip to content

Commit 9e19aa7

Browse files
author
iliran11
committed
added RTL support for hebrew and arabic
1 parent 0f3141f commit 9e19aa7

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

src/Demo.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@
8585
<datepicker :inline="true"></datepicker>
8686
</code>
8787
</div>
88+
<div class="example">
89+
<h3>RTL datepicker</h3>
90+
<datepicker :inline="true" language="he"></datepicker>
91+
<code>
92+
&lt;datepicker :inline="true"&gt;&lt;/datepicker&gt;
93+
</code>
94+
</div>
95+
96+
<div class="example">
97+
<h3>Day view only RTL</h3>
98+
<datepicker :day-view-only="true" language="he"></datepicker>
99+
<code>
100+
&lt;datepicker :day-view-only="true"&gt;&lt;/datepicker&gt;
101+
</code>
102+
</div>
88103

89104
<div class="example">
90105
<h3>Day view only</h3>

src/components/Datepicker.vue

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="vdp-datepicker" :class="wrapperClass">
2+
<div class="vdp-datepicker" :class="['wrapperClass',isRtl ? 'rtl' : '']">
33
<div :class="{'input-group' : bootstrapStyling}">
44
<span class="vdp-datepicker__calendar-button" :class="{'input-group-addon' : bootstrapStyling}" v-if="calendarButton" @click="showCalendar"><i :class="calendarButtonIcon"><span v-if="calendarButtonIcon.length === 0">&hellip;</span></i></span>
55
<input
@@ -21,23 +21,25 @@
2121
<div :class="[calendarClass, 'vdp-datepicker__calendar']" v-show="showDayView" v-bind:style="calendarStyle">
2222
<header>
2323
<span
24-
@click="previousMonth"
24+
@click="isRtl ? nextMonth() : previousMonth()"
2525
class="prev"
26-
v-bind:class="{ 'disabled' : previousMonthDisabled(pageDate) }">&lt;</span>
26+
v-bind:class="{ 'disabled' : isRtl ? nextMonthDisabled(pageDate) : previousMonthDisabled(pageDate) }">&lt;</span>
2727
<span @click="showMonthCalendar" :class="!dayViewOnly ? 'up' : ''">{{ currMonthName }} {{ currYear }}
2828
</span>
2929
<span
30-
@click="nextMonth"
30+
@click="isRtl ? previousMonth() : nextMonth()"
3131
class="next"
32-
v-bind:class="{ 'disabled' : nextMonthDisabled(pageDate) }">&gt;</span>
32+
v-bind:class="{ 'disabled' : isRtl ? previousMonthDisabled(pageDate) : nextMonthDisabled(pageDate) }">&gt;</span>
3333
</header>
34-
<span class="cell day-header" v-for="d in daysOfWeek">{{ d }}</span>
35-
<span class="cell day blank" v-for="d in blankDays"></span><!--
36-
--><span class="cell day"
37-
v-for="day in days"
38-
track-by="timestamp"
39-
v-bind:class="dayClasses(day)"
40-
@click="selectDate(day)">{{ day.date }}</span>
34+
<div :class="isRtl ? 'flex-rtl' : ''">
35+
<span class="cell day-header" v-for="d in daysOfWeek">{{ d }}</span>
36+
<span class="cell day blank" v-for="d in blankDays"></span><!--
37+
--><span class="cell day"
38+
v-for="day in days"
39+
track-by="timestamp"
40+
v-bind:class="dayClasses(day)"
41+
@click="selectDate(day)">{{ day.date }}</span>
42+
</div>
4143
</div>
4244

4345
<!-- Month View -->
@@ -300,6 +302,10 @@ export default {
300302
},
301303
isInline () {
302304
return typeof this.inline !== 'undefined' && this.inline
305+
},
306+
isRtl () {
307+
if (this.translation.rtl === true) return true
308+
return false
303309
}
304310
},
305311
methods: {
@@ -835,6 +841,8 @@ export default {
835841
836842
$width = 300px
837843
844+
.rtl
845+
direction:rtl
838846
.vdp-datepicker
839847
position relative
840848
text-align left
@@ -893,6 +901,10 @@ $width = 300px
893901
.disabled
894902
color #ddd
895903
cursor default
904+
.flex-rtl
905+
display flex
906+
width inherit
907+
flex-wrap wrap
896908
897909
.cell
898910
display inline-block

src/utils/DateLanguages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default {
22
translations: {
33
'ar': {
44
'language': 'Arabic',
5+
'rtl': true,
56
'months': {
67
'original': ['يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوڤمبر', 'ديسمبر'],
78
'abbr': ['يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوڤمبر', 'ديسمبر']
@@ -106,6 +107,7 @@ export default {
106107
},
107108
'he': {
108109
'language': 'Hebrew',
110+
'rtl': true,
109111
'months': {
110112
'original': ['ינואר', 'פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר', 'דצמבר'],
111113
'abbr': ['ינו', 'פבר', 'מרץ', 'אפר', 'מאי', 'יונ', 'יול', 'אוג', 'ספט', 'אוק', 'נוב', 'דצמ']

0 commit comments

Comments
 (0)