@ohos-ports/flowbite-datepicker 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +73 -0
  3. package/.stylelintrc +12 -0
  4. package/CHANGELOG.md +72 -0
  5. package/LICENSE +21 -0
  6. package/README.md +71 -0
  7. package/demo/index.html +582 -0
  8. package/demo/live-demo.js +471 -0
  9. package/dist/DateRangePicker.cjs.js +2996 -0
  10. package/dist/DateRangePicker.esm.js +2994 -0
  11. package/dist/DateRangePicker.umd.js +3002 -0
  12. package/dist/Datepicker.cjs.js +2778 -0
  13. package/dist/Datepicker.esm.js +2776 -0
  14. package/dist/Datepicker.umd.js +2784 -0
  15. package/dist/css/datepicker-bs4.css +276 -0
  16. package/dist/css/datepicker-bs4.min.css +1 -0
  17. package/dist/css/datepicker-bs5.css +276 -0
  18. package/dist/css/datepicker-bs5.min.css +1 -0
  19. package/dist/css/datepicker-bulma.css +258 -0
  20. package/dist/css/datepicker-bulma.min.css +1 -0
  21. package/dist/css/datepicker-foundation.css +262 -0
  22. package/dist/css/datepicker-foundation.min.css +1 -0
  23. package/dist/css/datepicker.css +306 -0
  24. package/dist/css/datepicker.min.css +1403 -0
  25. package/dist/js/datepicker-full.js +2777 -0
  26. package/dist/js/datepicker-full.min.js +1 -0
  27. package/dist/js/datepicker.js +2569 -0
  28. package/dist/js/datepicker.min.js +1 -0
  29. package/dist/js/locales/ar-tn.js +15 -0
  30. package/dist/js/locales/ar.js +15 -0
  31. package/dist/js/locales/az.js +14 -0
  32. package/dist/js/locales/bg.js +14 -0
  33. package/dist/js/locales/bm.js +18 -0
  34. package/dist/js/locales/bn.js +19 -0
  35. package/dist/js/locales/br.js +18 -0
  36. package/dist/js/locales/bs.js +15 -0
  37. package/dist/js/locales/ca.js +18 -0
  38. package/dist/js/locales/cs.js +19 -0
  39. package/dist/js/locales/cy.js +14 -0
  40. package/dist/js/locales/da.js +19 -0
  41. package/dist/js/locales/de.js +18 -0
  42. package/dist/js/locales/el.js +16 -0
  43. package/dist/js/locales/en-AU.js +18 -0
  44. package/dist/js/locales/en-CA.js +18 -0
  45. package/dist/js/locales/en-GB.js +18 -0
  46. package/dist/js/locales/en-IE.js +17 -0
  47. package/dist/js/locales/en-NZ.js +17 -0
  48. package/dist/js/locales/en-ZA.js +17 -0
  49. package/dist/js/locales/eo.js +17 -0
  50. package/dist/js/locales/es.js +18 -0
  51. package/dist/js/locales/et.js +18 -0
  52. package/dist/js/locales/eu.js +18 -0
  53. package/dist/js/locales/fa.js +17 -0
  54. package/dist/js/locales/fi.js +17 -0
  55. package/dist/js/locales/fo.js +15 -0
  56. package/dist/js/locales/fr-CH.js +21 -0
  57. package/dist/js/locales/fr.js +18 -0
  58. package/dist/js/locales/gl.js +16 -0
  59. package/dist/js/locales/he.js +15 -0
  60. package/dist/js/locales/hi.js +18 -0
  61. package/dist/js/locales/hr.js +13 -0
  62. package/dist/js/locales/hu.js +18 -0
  63. package/dist/js/locales/hy.js +18 -0
  64. package/dist/js/locales/id.js +15 -0
  65. package/dist/js/locales/is.js +14 -0
  66. package/dist/js/locales/it-CH.js +20 -0
  67. package/dist/js/locales/it.js +18 -0
  68. package/dist/js/locales/ja.js +17 -0
  69. package/dist/js/locales/ka.js +17 -0
  70. package/dist/js/locales/kk.js +15 -0
  71. package/dist/js/locales/km.js +15 -0
  72. package/dist/js/locales/ko.js +18 -0
  73. package/dist/js/locales/lt.js +19 -0
  74. package/dist/js/locales/lv.js +18 -0
  75. package/dist/js/locales/me.js +17 -0
  76. package/dist/js/locales/mk.js +15 -0
  77. package/dist/js/locales/mn.js +17 -0
  78. package/dist/js/locales/mr.js +18 -0
  79. package/dist/js/locales/ms.js +15 -0
  80. package/dist/js/locales/nl-BE.js +18 -0
  81. package/dist/js/locales/nl.js +18 -0
  82. package/dist/js/locales/no.js +18 -0
  83. package/dist/js/locales/oc.js +17 -0
  84. package/dist/js/locales/pl.js +17 -0
  85. package/dist/js/locales/pt-BR.js +17 -0
  86. package/dist/js/locales/pt.js +18 -0
  87. package/dist/js/locales/ro.js +17 -0
  88. package/dist/js/locales/ru.js +18 -0
  89. package/dist/js/locales/si.js +18 -0
  90. package/dist/js/locales/sk.js +18 -0
  91. package/dist/js/locales/sl.js +15 -0
  92. package/dist/js/locales/sq.js +18 -0
  93. package/dist/js/locales/sr-latn.js +16 -0
  94. package/dist/js/locales/sr.js +16 -0
  95. package/dist/js/locales/sv.js +17 -0
  96. package/dist/js/locales/sw.js +15 -0
  97. package/dist/js/locales/ta.js +18 -0
  98. package/dist/js/locales/tg.js +19 -0
  99. package/dist/js/locales/th.js +14 -0
  100. package/dist/js/locales/tk.js +18 -0
  101. package/dist/js/locales/tr.js +17 -0
  102. package/dist/js/locales/uk.js +17 -0
  103. package/dist/js/locales/uz-cyrl.js +18 -0
  104. package/dist/js/locales/uz-latn.js +18 -0
  105. package/dist/js/locales/vi.js +16 -0
  106. package/dist/js/locales/zh-CN.js +19 -0
  107. package/dist/js/locales/zh-TW.js +18 -0
  108. package/dist/locales/index.cjs.js +1028 -0
  109. package/dist/locales/index.esm.js +1028 -0
  110. package/dist/main.cjs.js +2999 -0
  111. package/dist/main.esm.js +2994 -0
  112. package/dist/main.umd.js +3005 -0
  113. package/docs/.nojekyll +0 -0
  114. package/docs/README.md +266 -0
  115. package/docs/_sidebar.md +6 -0
  116. package/docs/api.md +284 -0
  117. package/docs/date-string+format.md +90 -0
  118. package/docs/i18n.md +99 -0
  119. package/docs/images/datepicker-inline.jpg +0 -0
  120. package/docs/images/datepicker.jpg +0 -0
  121. package/docs/images/multidate.jpg +0 -0
  122. package/docs/images/picker-structure.jpg +0 -0
  123. package/docs/images/rangepicker.jpg +0 -0
  124. package/docs/images/view-days.jpg +0 -0
  125. package/docs/images/view-decades.jpg +0 -0
  126. package/docs/images/view-months.jpg +0 -0
  127. package/docs/images/view-years.jpg +0 -0
  128. package/docs/index.html +26 -0
  129. package/docs/options.md +354 -0
  130. package/docs/overview.md +174 -0
  131. package/extras/twoDigitToFullYear/test/twoDigitToFullYear.js +58 -0
  132. package/extras/twoDigitToFullYear/twoDigitToFullYear.js +26 -0
  133. package/js/DateRangePicker.js +210 -0
  134. package/js/Datepicker.js +487 -0
  135. package/js/datepicker-full.js +5 -0
  136. package/js/events/functions.js +48 -0
  137. package/js/events/inputFieldListeners.js +206 -0
  138. package/js/events/otherListeners.js +15 -0
  139. package/js/events/pickerListeners.js +70 -0
  140. package/js/i18n/base-locales.js +13 -0
  141. package/js/i18n/locales/ar-tn.js +15 -0
  142. package/js/i18n/locales/ar.js +15 -0
  143. package/js/i18n/locales/az.js +14 -0
  144. package/js/i18n/locales/bg.js +14 -0
  145. package/js/i18n/locales/bm.js +18 -0
  146. package/js/i18n/locales/bn.js +19 -0
  147. package/js/i18n/locales/br.js +18 -0
  148. package/js/i18n/locales/bs.js +15 -0
  149. package/js/i18n/locales/ca.js +18 -0
  150. package/js/i18n/locales/cs.js +19 -0
  151. package/js/i18n/locales/cy.js +14 -0
  152. package/js/i18n/locales/da.js +19 -0
  153. package/js/i18n/locales/de.js +18 -0
  154. package/js/i18n/locales/el.js +16 -0
  155. package/js/i18n/locales/en-AU.js +18 -0
  156. package/js/i18n/locales/en-CA.js +18 -0
  157. package/js/i18n/locales/en-GB.js +18 -0
  158. package/js/i18n/locales/en-IE.js +17 -0
  159. package/js/i18n/locales/en-NZ.js +17 -0
  160. package/js/i18n/locales/en-ZA.js +17 -0
  161. package/js/i18n/locales/eo.js +17 -0
  162. package/js/i18n/locales/es.js +18 -0
  163. package/js/i18n/locales/et.js +18 -0
  164. package/js/i18n/locales/eu.js +18 -0
  165. package/js/i18n/locales/fa.js +17 -0
  166. package/js/i18n/locales/fi.js +17 -0
  167. package/js/i18n/locales/fo.js +15 -0
  168. package/js/i18n/locales/fr-CH.js +21 -0
  169. package/js/i18n/locales/fr.js +18 -0
  170. package/js/i18n/locales/gl.js +16 -0
  171. package/js/i18n/locales/he.js +15 -0
  172. package/js/i18n/locales/hi.js +18 -0
  173. package/js/i18n/locales/hr.js +13 -0
  174. package/js/i18n/locales/hu.js +18 -0
  175. package/js/i18n/locales/hy.js +18 -0
  176. package/js/i18n/locales/id.js +15 -0
  177. package/js/i18n/locales/is.js +14 -0
  178. package/js/i18n/locales/it-CH.js +20 -0
  179. package/js/i18n/locales/it.js +18 -0
  180. package/js/i18n/locales/ja.js +17 -0
  181. package/js/i18n/locales/ka.js +17 -0
  182. package/js/i18n/locales/kk.js +15 -0
  183. package/js/i18n/locales/km.js +15 -0
  184. package/js/i18n/locales/ko.js +18 -0
  185. package/js/i18n/locales/lt.js +19 -0
  186. package/js/i18n/locales/lv.js +18 -0
  187. package/js/i18n/locales/me.js +17 -0
  188. package/js/i18n/locales/mk.js +15 -0
  189. package/js/i18n/locales/mn.js +17 -0
  190. package/js/i18n/locales/mr.js +18 -0
  191. package/js/i18n/locales/ms.js +15 -0
  192. package/js/i18n/locales/nl-BE.js +18 -0
  193. package/js/i18n/locales/nl.js +18 -0
  194. package/js/i18n/locales/no.js +18 -0
  195. package/js/i18n/locales/oc.js +17 -0
  196. package/js/i18n/locales/pl.js +17 -0
  197. package/js/i18n/locales/pt-BR.js +17 -0
  198. package/js/i18n/locales/pt.js +18 -0
  199. package/js/i18n/locales/ro.js +17 -0
  200. package/js/i18n/locales/ru.js +18 -0
  201. package/js/i18n/locales/si.js +18 -0
  202. package/js/i18n/locales/sk.js +18 -0
  203. package/js/i18n/locales/sl.js +15 -0
  204. package/js/i18n/locales/sq.js +18 -0
  205. package/js/i18n/locales/sr-latn.js +16 -0
  206. package/js/i18n/locales/sr.js +16 -0
  207. package/js/i18n/locales/sv.js +17 -0
  208. package/js/i18n/locales/sw.js +15 -0
  209. package/js/i18n/locales/ta.js +18 -0
  210. package/js/i18n/locales/tg.js +19 -0
  211. package/js/i18n/locales/th.js +14 -0
  212. package/js/i18n/locales/tk.js +18 -0
  213. package/js/i18n/locales/tr.js +17 -0
  214. package/js/i18n/locales/uk.js +17 -0
  215. package/js/i18n/locales/uz-cyrl.js +18 -0
  216. package/js/i18n/locales/uz-latn.js +18 -0
  217. package/js/i18n/locales/vi.js +16 -0
  218. package/js/i18n/locales/zh-CN.js +19 -0
  219. package/js/i18n/locales/zh-TW.js +18 -0
  220. package/js/lib/date-format.js +185 -0
  221. package/js/lib/date.js +82 -0
  222. package/js/lib/dom.js +55 -0
  223. package/js/lib/event.js +68 -0
  224. package/js/lib/utils.js +61 -0
  225. package/js/main.js +4 -0
  226. package/js/options/defaultOptions.js +38 -0
  227. package/js/options/processOptions.js +263 -0
  228. package/js/picker/Picker.js +334 -0
  229. package/js/picker/templates/calendarWeeksTemplate.js +8 -0
  230. package/js/picker/templates/daysTemplate.js +8 -0
  231. package/js/picker/templates/pickerTemplate.js +23 -0
  232. package/js/picker/views/DaysView.js +250 -0
  233. package/js/picker/views/MonthsView.js +198 -0
  234. package/js/picker/views/View.js +55 -0
  235. package/js/picker/views/YearsView.js +170 -0
  236. package/package.json +81 -0
  237. package/postcss.config.js +5 -0
  238. package/rollup.config.js +75 -0
  239. package/sass/_mixins.scss +12 -0
  240. package/sass/datepicker-bs4.scss +91 -0
  241. package/sass/datepicker-bs5.scss +91 -0
  242. package/sass/datepicker-bulma.scss +69 -0
  243. package/sass/datepicker-foundation.scss +66 -0
  244. package/sass/datepicker.scss +436 -0
  245. package/sass/index-bs4.scss +5 -0
  246. package/sass/index-bs5.scss +5 -0
  247. package/sass/index-bulma.scss +6 -0
  248. package/sass/index-foundation.scss +3 -0
  249. package/scripts/build-css.js +39 -0
  250. package/scripts/build-locales.js +57 -0
  251. package/scripts/convert-bsdp-locales.js +65 -0
  252. package/scripts/minify-css.js +31 -0
  253. package/scripts/minify-js.js +17 -0
  254. package/style.css +10 -0
  255. package/tailwind.config.js +16 -0
  256. package/tailwind.css +1389 -0
  257. package/test/DateRangePicker/DateRangePicker.js +547 -0
  258. package/test/DateRangePicker/api-methods.js +415 -0
  259. package/test/DateRangePicker/date-selection.js +472 -0
  260. package/test/DateRangePicker/options.js +308 -0
  261. package/test/Datepicker/Datepicker-object.js +236 -0
  262. package/test/Datepicker/api-methods.js +328 -0
  263. package/test/_utils/date.js +102 -0
  264. package/test/_utils/dom.js +70 -0
  265. package/test/events.js +785 -0
  266. package/test/inline-mode.js +45 -0
  267. package/test/keyboard-operation/arrow-down.js +293 -0
  268. package/test/keyboard-operation/arrow-left.js +255 -0
  269. package/test/keyboard-operation/arrow-right.js +215 -0
  270. package/test/keyboard-operation/arrow-up.js +461 -0
  271. package/test/keyboard-operation/edit-mode.js +458 -0
  272. package/test/keyboard-operation/keyboard-operation.js +146 -0
  273. package/test/mouse-operation.js +580 -0
  274. package/test/options/before-show.js +635 -0
  275. package/test/options/bulma-datepicker.sublime-workspace +1280 -0
  276. package/test/options/buttons.js +383 -0
  277. package/test/options/date-restrictions.js +802 -0
  278. package/test/options/format.js +281 -0
  279. package/test/options/multidate.js +380 -0
  280. package/test/options/options.js +727 -0
  281. package/test/options/orientation.js +410 -0
  282. package/test/options/pick-levle+view.js +357 -0
  283. package/test/test.html +94 -0
  284. package/test/unit/DateRangePicker.js +192 -0
  285. package/test/unit/Datepicker.js +307 -0
  286. package/test/unit/_setup.js +28 -0
  287. package/test/unit/lib/date-format.js +310 -0
  288. package/test/unit/lib/date.js +211 -0
  289. package/test/unit/lib/dom.js +142 -0
  290. package/test/unit/lib/event.js +207 -0
  291. package/test/unit/lib/utils.js +135 -0
@@ -0,0 +1,281 @@
1
+ describe('options - format & language', function () {
2
+ let clock;
3
+ let input;
4
+
5
+ beforeEach(function () {
6
+ clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
7
+ input = document.createElement('input');
8
+ testContainer.appendChild(input);
9
+ });
10
+
11
+ afterEach(function () {
12
+ testContainer.removeChild(input);
13
+ clock.restore();
14
+ });
15
+
16
+ describe('format', function () {
17
+ it('specifies the date format used to parse/format the date string in input', function () {
18
+ const dp = new Datepicker(input, {format: 'yyyy-mm-dd'});
19
+
20
+ dp.setDate(new Date(2020, 1, 14));
21
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
22
+ expect(input.value, 'to be', '2020-02-14');
23
+
24
+ input.value = '2020/4/22';
25
+ dp.update();
26
+ expect(dp.dates, 'to equal', [dateValue(2020, 3, 22)]);
27
+ expect(input.value, 'to be', '2020-04-22');
28
+
29
+ // when a date in a wrong format is given...
30
+ dp.setDate('2/14/2020');
31
+ expect(dp.dates, 'to equal', [dateValue(2, 13, 2020)]);
32
+ expect(input.value, 'to be', '0008-08-12');
33
+
34
+ input.value = '22/4/2020';
35
+ dp.update();
36
+ expect(dp.dates, 'to equal', [dateValue(22, 3, 2020)]);
37
+ expect(input.value, 'to be', '0027-10-11');
38
+
39
+ dp.destroy();
40
+ input.value = '';
41
+ });
42
+
43
+ it('custom parser/fomatter can be used by providing them as toValue/toDisplay of an object', function () {
44
+ const dp = new Datepicker(input, {
45
+ format: {
46
+ toDisplay(date) {
47
+ return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString()
48
+ .slice(0, 10)
49
+ .replace(/-/g, '');
50
+ },
51
+ toValue(date) {
52
+ const parts = [
53
+ parseInt(date.slice(0, 4), 10),
54
+ parseInt(date.slice(4, 6), 10) - 1,
55
+ parseInt(date.slice(6, 8), 10),
56
+ ];
57
+ return dateValue(...parts);
58
+ },
59
+ },
60
+ });
61
+
62
+ dp.setDate(new Date(2020, 1, 14));
63
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
64
+ expect(input.value, 'to be', '20200214');
65
+
66
+ input.value = '20200422';
67
+ dp.update();
68
+ expect(dp.dates, 'to equal', [dateValue(2020, 3, 22)]);
69
+ expect(input.value, 'to be', '20200422');
70
+
71
+ dp.destroy();
72
+ input.value = '';
73
+ });
74
+
75
+ it('can be updated with setOptions()', function () {
76
+ const dp = new Datepicker(input);
77
+ dp.setOptions({format: 'd M, \'yy'});
78
+
79
+ dp.setDate('14/2/2020');
80
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
81
+ expect(input.value, 'to be', '14 Feb, \'20');
82
+
83
+ dp.setOptions({format: 'mm/dd/yyyy'});
84
+ expect(input.value, 'to be', '02/14/2020');
85
+ input.value = '4/22/2020';
86
+ dp.update();
87
+ expect(dp.dates, 'to equal', [dateValue(2020, 3, 22)]);
88
+ expect(input.value, 'to be', '04/22/2020');
89
+
90
+ dp.destroy();
91
+ input.value = '';
92
+ });
93
+ });
94
+
95
+ describe('language', function () {
96
+ const getDayNames = picker => Array.from(picker.querySelectorAll('.dow')).map(el => el.textContent);
97
+
98
+ it('specifies the language used for the month/day names, today/clear buttons and the default format/weekStart', function () {
99
+ const locale = Datepicker.locales['zh-CN'];
100
+ const {dp, picker} = createDP(input, {language: 'zh-CN', todayBtn: true, clearBtn: true});
101
+ const viewSwitch = getViewSwitch(picker);
102
+ dp.setDate(new Date(2020, 1, 14));
103
+ dp.show();
104
+
105
+ expect(viewSwitch.textContent, 'to be', '2020年02月');
106
+ expect(input.value, 'to be', '2020-02-14');
107
+ expect(picker.querySelector('.today-btn').textContent, 'to be', locale.today);
108
+ expect(picker.querySelector('.clear-btn').textContent, 'to be', locale.clear);
109
+
110
+ const dayNames = locale.daysMin.slice(1);
111
+ dayNames.push(locale.daysMin[0]);
112
+ expect(getDayNames(picker), 'to equal', dayNames);
113
+
114
+ let cells = getCells(picker);
115
+ expect(cells[0].textContent, 'to be', '27');
116
+ expect(cells[5].textContent, 'to be', '1');
117
+ expect(cells[33].textContent, 'to be', '29');
118
+ expect(cells[41].textContent, 'to be', '8');
119
+
120
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[18]]);
121
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[18]]);
122
+ expect(cells[18].textContent, 'to be', '14');
123
+
124
+ viewSwitch.click();
125
+ expect(viewSwitch.textContent, 'to be', '2020');
126
+
127
+ cells = getCells(picker);
128
+ expect(Array.from(cells).map(el => el.textContent), 'to equal', locale.monthsShort);
129
+ cells[1].click();
130
+
131
+ input.value = '2020-4-22';
132
+ dp.update();
133
+ expect(viewSwitch.textContent, 'to be', '2020年04月');
134
+ expect(input.value, 'to be', '2020-04-22');
135
+
136
+ cells = getCells(picker);
137
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[23]]);
138
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[23]]);
139
+ expect(cells[23].textContent, 'to be', '22');
140
+
141
+ dp.destroy();
142
+ input.value = '';
143
+ });
144
+
145
+ it('default format/weekStart in the locale are overriden by user-specified ones', function () {
146
+ const locale = Datepicker.locales['zh-CN'];
147
+ const {dp, picker} = createDP(input, {language: 'zh-CN', format: 'yyyy年mm月dd日', weekStart: 0});
148
+ const viewSwitch = getViewSwitch(picker);
149
+ dp.setDate(new Date(2020, 1, 14));
150
+ dp.show();
151
+
152
+ expect(viewSwitch.textContent, 'to be', '2020年02月');
153
+ expect(input.value, 'to be', '2020年02月14日');
154
+ expect(getDayNames(picker), 'to equal', locale.daysMin);
155
+
156
+ let cells = getCells(picker);
157
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
158
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
159
+ expect(cells[19].textContent, 'to be', '14');
160
+
161
+ dp.destroy();
162
+ input.value = '';
163
+ });
164
+
165
+ it('language code + tag not installed falls back to the language code without tag', function () {
166
+ const locale = Datepicker.locales.fr;
167
+ const {dp, picker} = createDP(input, {language: 'fr-CA', todayBtn: true, clearBtn: true});
168
+ const viewSwitch = getViewSwitch(picker);
169
+ dp.setDate(new Date(2020, 1, 14));
170
+ dp.show();
171
+
172
+ expect(viewSwitch.textContent, 'to be', 'février 2020');
173
+ expect(input.value, 'to be', '14/02/2020');
174
+ expect(picker.querySelector('.today-btn').textContent, 'to be', locale.today);
175
+ expect(picker.querySelector('.clear-btn').textContent, 'to be', locale.clear);
176
+
177
+ const dayNames = locale.daysMin.slice(1);
178
+ dayNames.push(locale.daysMin[0]);
179
+ expect(getDayNames(picker), 'to equal', dayNames);
180
+
181
+ dp.destroy();
182
+ input.value = '';
183
+ });
184
+
185
+ it('language code not installed falls back to "en"', function () {
186
+ const locale = Datepicker.locales.en;
187
+ const {dp, picker} = createDP(input, {language: 'it', todayBtn: true, clearBtn: true});
188
+ const viewSwitch = getViewSwitch(picker);
189
+ dp.setDate(new Date(2020, 1, 14));
190
+ dp.show();
191
+
192
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
193
+ expect(input.value, 'to be', '02/14/2020');
194
+ expect(picker.querySelector('.today-btn').textContent, 'to be', locale.today);
195
+ expect(picker.querySelector('.clear-btn').textContent, 'to be', locale.clear);
196
+
197
+ expect(getDayNames(picker), 'to equal', locale.daysMin);
198
+
199
+ dp.destroy();
200
+ input.value = '';
201
+ });
202
+
203
+ it('can be updated with setOptions()', function () {
204
+ const {dp, picker} = createDP(input, {todayBtn: true, clearBtn: true});
205
+ const viewSwitch = getViewSwitch(picker);
206
+ let locale = Datepicker.locales['zh-CN'];
207
+ dp.setDate(new Date(2020, 1, 14));
208
+ dp.setOptions({language: 'zh-CN'});
209
+ dp.show();
210
+
211
+ expect(viewSwitch.textContent, 'to be', '2020年02月');
212
+ expect(input.value, 'to be', '2020-02-14');
213
+ expect(picker.querySelector('.today-btn').textContent, 'to be', locale.today);
214
+ expect(picker.querySelector('.clear-btn').textContent, 'to be', locale.clear);
215
+
216
+ let dayNames = locale.daysMin.slice(1);
217
+ dayNames.push(locale.daysMin[0]);
218
+ expect(getDayNames(picker), 'to equal', dayNames);
219
+
220
+ let cells = getCells(picker);
221
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[18]]);
222
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[18]]);
223
+ expect(cells[18].textContent, 'to be', '14');
224
+
225
+ locale = Datepicker.locales.fr;
226
+ dp.setOptions({language: 'fr'});
227
+
228
+ expect(viewSwitch.textContent, 'to be', 'février 2020');
229
+ expect(input.value, 'to be', '14/02/2020');
230
+ expect(picker.querySelector('.today-btn').textContent, 'to be', locale.today);
231
+ expect(picker.querySelector('.clear-btn').textContent, 'to be', locale.clear);
232
+
233
+ dayNames = locale.daysMin.slice(1);
234
+ dayNames.push(locale.daysMin[0]);
235
+ expect(getDayNames(picker), 'to equal', dayNames);
236
+
237
+ cells = getCells(picker);
238
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[18]]);
239
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[18]]);
240
+ expect(cells[18].textContent, 'to be', '14');
241
+
242
+ locale = Datepicker.locales.en;
243
+ dp.setOptions({language: 'en'});
244
+
245
+ expect(viewSwitch.textContent, 'to be', 'February 2020');
246
+ expect(input.value, 'to be', '02/14/2020');
247
+ expect(picker.querySelector('.today-btn').textContent, 'to be', locale.today);
248
+ expect(picker.querySelector('.clear-btn').textContent, 'to be', locale.clear);
249
+
250
+ expect(getDayNames(picker), 'to equal', locale.daysMin);
251
+
252
+ cells = getCells(picker);
253
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
254
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
255
+ expect(cells[19].textContent, 'to be', '14');
256
+
257
+ dp.destroy();
258
+ input.value = '';
259
+ });
260
+
261
+ it('user-specified format/weekStart other than old language\'s default are kept on being updated dynamically', function () {
262
+ const {dp, picker} = createDP(input, {language: 'zh-CN', format: 'yyyy/mm/dd', weekStart: 0});
263
+ dp.setDate(new Date(2020, 1, 14));
264
+ dp.show();
265
+
266
+ let locale = Datepicker.locales.fr;
267
+ dp.setOptions({language: 'fr'});
268
+
269
+ expect(input.value, 'to be', '2020/02/14');
270
+ expect(getDayNames(picker), 'to equal', locale.daysMin);
271
+
272
+ let cells = getCells(picker);
273
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
274
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
275
+ expect(cells[19].textContent, 'to be', '14');
276
+
277
+ dp.destroy();
278
+ input.value = '';
279
+ });
280
+ });
281
+ });
@@ -0,0 +1,380 @@
1
+ describe('options - multi date', function () {
2
+ let clock;
3
+ let input;
4
+
5
+ beforeEach(function () {
6
+ clock = sinon.useFakeTimers({now: new Date(2020, 1, 14)});
7
+ input = document.createElement('input');
8
+ testContainer.appendChild(input);
9
+ });
10
+
11
+ afterEach(function () {
12
+ testContainer.removeChild(input);
13
+ clock.restore();
14
+ });
15
+
16
+ describe('maxNumberOfDates', function () {
17
+ it('specifies the muximum number of dates the datepicker accepts for the selection', function () {
18
+ let {dp, picker} = createDP(input, {maxNumberOfDates: 2});
19
+
20
+ dp.setDate('2/14/2020', '4/22/2020');
21
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14), dateValue(2020, 3, 22)]);
22
+ expect(input.value, 'to be', '02/14/2020,04/22/2020');
23
+
24
+ // the dates come later win
25
+ dp.setDate('1/4/2020', '2/22/2020', '3/21/2020');
26
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 22), dateValue(2020, 2, 21)]);
27
+ expect(input.value, 'to be', '02/22/2020,03/21/2020');
28
+
29
+ // repeated dates are eliminated
30
+ dp.setDate('4/22/2020', '7/14/2020', '5/5/2020', '7/14/2020');
31
+ expect(dp.dates, 'to equal', [dateValue(2020, 6, 14), dateValue(2020, 4, 5)]);
32
+ expect(input.value, 'to be', '07/14/2020,05/05/2020');
33
+
34
+ dp.destroy();
35
+ input.value = '';
36
+ ({dp, picker} = createDP(input, {maxNumberOfDates: 3}));
37
+ dp.show();
38
+
39
+ let cells = getCells(picker);
40
+ cells[19].click();
41
+ cells[9].click();
42
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14), dateValue(2020, 1, 4)]);
43
+ expect(input.value, 'to be', '02/14/2020,02/04/2020');
44
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[19], cells[9]]);
45
+ // view date is changed co the last selected item
46
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[9]]);
47
+
48
+ input.value = '2/3/2020,2/22/2020';
49
+ dp.update();
50
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 3), dateValue(2020, 1, 22)]);
51
+ expect(input.value, 'to be', '02/03/2020,02/22/2020');
52
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[8], cells[27]]);
53
+ // view date is changed co the last item of the selection
54
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[27]]);
55
+
56
+ dp.destroy();
57
+ input.value = '';
58
+ ({dp, picker} = createDP(input, {maxNumberOfDates: 3}));
59
+
60
+ dp.setDate('2/14/2020', '4/22/2020', '3/21/2020');
61
+ expect(dp.dates, 'to equal', [
62
+ dateValue(2020, 1, 14),
63
+ dateValue(2020, 3, 22),
64
+ dateValue(2020, 2, 21),
65
+ ]);
66
+ expect(input.value, 'to be', '02/14/2020,04/22/2020,03/21/2020');
67
+
68
+ dp.destroy();
69
+ input.value = '';
70
+ ({dp, picker} = createDP(input, {maxNumberOfDates: 3}));
71
+ dp.show();
72
+
73
+ getCells(picker)[1].click();
74
+ getCells(picker)[40].click();
75
+ cells = getCells(picker);
76
+ cells[19].click();
77
+ expect(dp.dates, 'to equal', [
78
+ dateValue(2020, 0, 27),
79
+ dateValue(2020, 1, 7),
80
+ dateValue(2020, 1, 14),
81
+ ]);
82
+ expect(input.value, 'to be', '01/27/2020,02/07/2020,02/14/2020');
83
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[1], cells[12], cells[19]]);
84
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
85
+
86
+ input.value = '2/3/2020,2/22/2020';
87
+ dp.update();
88
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 3), dateValue(2020, 1, 22)]);
89
+ expect(input.value, 'to be', '02/03/2020,02/22/2020');
90
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[8], cells[27]]);
91
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[27]]);
92
+
93
+ // setting initial dates does not cuase error
94
+ // (issue #51)
95
+ dp.destroy();
96
+ input.value = '02/14/2020,04/22/2020,03/21/2020';
97
+ ({dp, picker} = createDP(input, {maxNumberOfDates: 2}));
98
+
99
+ expect(dp.dates, 'to equal', [
100
+ dateValue(2020, 3, 22),
101
+ dateValue(2020, 2, 21),
102
+ ]);
103
+ expect(input.value, 'to be', '04/22/2020,03/21/2020');
104
+
105
+ dp.destroy();
106
+ input.value = '';
107
+ });
108
+
109
+ it('makes the picker deselect the date when a selected date is clicked if value != 1', function () {
110
+ const {dp, picker} = createDP(input, {maxNumberOfDates: 3});
111
+ dp.show();
112
+
113
+ let cells = getCells(picker);
114
+ cells[19].click();
115
+ cells[12].click();
116
+
117
+ cells[19].click();
118
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 7)]);
119
+ expect(input.value, 'to be', '02/07/2020');
120
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[12]]);
121
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[12]]);
122
+
123
+ cells[12].click();
124
+ expect(dp.dates, 'to equal', []);
125
+ expect(input.value, 'to be', '');
126
+ expect(filterCells(cells, '.selected'), 'to equal', []);
127
+ // view date is changed to the default view date
128
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
129
+
130
+ dp.destroy();
131
+ input.value = '';
132
+ });
133
+
134
+ it('makes the picker deselect the date when a selected date is clicked if value != 1', function () {
135
+ const {dp, picker} = createDP(input, {maxNumberOfDates: 3});
136
+ const cells = getCells(picker);
137
+ dp.setDate('2/14/2020', '2/7/2020');
138
+ dp.show();
139
+
140
+ dp.setDate('2/14/2020');
141
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 7)]);
142
+ expect(input.value, 'to be', '02/07/2020');
143
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[12]]);
144
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[12]]);
145
+
146
+ dp.setDate('2/11/2020', '2/7/2020', '2/14/2020');
147
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 11), dateValue(2020, 1, 14)]);
148
+ expect(input.value, 'to be', '02/11/2020,02/14/2020');
149
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[16], cells[19]]);
150
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
151
+
152
+ dp.destroy();
153
+ input.value = '';
154
+ });
155
+
156
+ it('setDate() replaces the selection instead of deselect/merg-ing if clear: true option is passed', function () {
157
+ const {dp, picker} = createDP(input, {maxNumberOfDates: 3});
158
+ const cells = getCells(picker);
159
+ dp.setDate('2/14/2020', '2/7/2020');
160
+ dp.show();
161
+
162
+ dp.setDate('2/14/2020', {clear: true});
163
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
164
+ expect(input.value, 'to be', '02/14/2020');
165
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
166
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
167
+
168
+ dp.setDate('2/11/2020', '2/7/2020', '2/14/2020', {clear: true});
169
+ expect(dp.dates, 'to equal', [
170
+ dateValue(2020, 1, 11),
171
+ dateValue(2020, 1, 7),
172
+ dateValue(2020, 1, 14),
173
+ ]);
174
+ expect(input.value, 'to be', '02/11/2020,02/07/2020,02/14/2020');
175
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[16], cells[12], cells[19]]);
176
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
177
+
178
+ dp.destroy();
179
+ input.value = '';
180
+ });
181
+
182
+ it('setDate() does nothing if no dates or all-invalid dates are passed', function () {
183
+ const dp = new Datepicker(input, {maxNumberOfDates: 3});
184
+ dp.setDate('2/14/2020', '2/7/2020');
185
+ dp.show();
186
+
187
+ const origDates = [...dp.dates];
188
+ dp.setDate([]);
189
+ expect(dp.dates, 'to equal', origDates);
190
+ expect(input.value, 'to be', '02/14/2020,02/07/2020');
191
+
192
+ dp.setDate();
193
+ expect(dp.dates, 'to equal', origDates);
194
+ expect(input.value, 'to be', '02/14/2020,02/07/2020');
195
+
196
+ dp.setDate([false, NaN], {clear: true});
197
+ expect(dp.dates, 'to equal', origDates);
198
+ expect(input.value, 'to be', '02/14/2020,02/07/2020');
199
+
200
+ dp.setDate('', null);
201
+ expect(dp.dates, 'to equal', origDates);
202
+ expect(input.value, 'to be', '02/14/2020,02/07/2020');
203
+
204
+ dp.destroy();
205
+ });
206
+
207
+ it('setDate() clears all selected dates if no dates + clear: true option are passed', function () {
208
+ const dp = new Datepicker(input, {maxNumberOfDates: 3});
209
+ dp.setDate('2/14/2020', '2/7/2020');
210
+ dp.show();
211
+
212
+ dp.setDate([], {clear: true});
213
+ expect(dp.dates, 'to equal', []);
214
+ expect(input.value, 'to be', '');
215
+
216
+ dp.setDate('2/14/2020', '2/7/2020');
217
+
218
+ dp.setDate({clear: true});
219
+ expect(dp.dates, 'to equal', []);
220
+ expect(input.value, 'to be', '');
221
+
222
+ dp.destroy();
223
+ });
224
+
225
+ it('setDate() does nothing if all-invalid dates + clear: true option are passed', function () {
226
+ const dp = new Datepicker(input, {maxNumberOfDates: 3});
227
+ dp.setDate('2/14/2020', '2/7/2020');
228
+ dp.show();
229
+
230
+ const origDates = [...dp.dates];
231
+ dp.setDate([false, NaN], {clear: true});
232
+ expect(dp.dates, 'to equal', origDates);
233
+ expect(input.value, 'to be', '02/14/2020,02/07/2020');
234
+
235
+ dp.setDate('', null, {clear: true});
236
+ expect(dp.dates, 'to equal', origDates);
237
+ expect(input.value, 'to be', '02/14/2020,02/07/2020');
238
+
239
+ dp.destroy();
240
+ });
241
+
242
+ it('does not apply deselecting behavior to update()', function () {
243
+ const {dp, picker} = createDP(input, {maxNumberOfDates: 3});
244
+ const cells = getCells(picker);
245
+ dp.setDate('2/14/2020', '2/7/2020');
246
+ dp.show();
247
+
248
+ input.value = '2/14/2020';
249
+ dp.update();
250
+ expect(dp.dates, 'to equal', [dateValue(2020, 1, 14)]);
251
+ expect(input.value, 'to be', '02/14/2020');
252
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[19]]);
253
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
254
+
255
+ input.value = '2/11/2020,2/7/2020,2/14/2020';
256
+ dp.update();
257
+ expect(dp.dates, 'to equal', [
258
+ dateValue(2020, 1, 11),
259
+ dateValue(2020, 1, 7),
260
+ dateValue(2020, 1, 14),
261
+ ]);
262
+ expect(input.value, 'to be', '02/11/2020,02/07/2020,02/14/2020');
263
+ expect(filterCells(cells, '.selected'), 'to equal', [cells[16], cells[12], cells[19]]);
264
+ expect(filterCells(cells, '.focused'), 'to equal', [cells[19]]);
265
+
266
+ dp.destroy();
267
+ input.value = '';
268
+ });
269
+
270
+ it('makes getDate() return array of dates if value != 1', function () {
271
+ const dp = new Datepicker(input, {maxNumberOfDates: 3});
272
+
273
+ expect(dp.getDate(), 'to equal', []);
274
+ expect(dp.getDate('yyyy-mm-dd'), 'to equal', []);
275
+
276
+ dp.setDate('2/11/2020', '2/7/2020', '2/14/2020');
277
+ expect(dp.getDate(), 'to equal', [new Date(2020, 1, 11), new Date(2020, 1, 7), new Date(2020, 1, 14)]);
278
+ expect(dp.getDate('yyyy-mm-dd'), 'to equal', ['2020-02-11', '2020-02-07', '2020-02-14']);
279
+
280
+ dp.setDate('2/7/2020', {clear: true});
281
+ expect(dp.getDate(), 'to equal', [new Date(2020, 1, 7)]);
282
+ expect(dp.getDate('d M, yyyy'), 'to equal', ['7 Feb, 2020']);
283
+
284
+ const changeDateListener = (e) => {
285
+ evt = e;
286
+ };
287
+ let evt;
288
+ input.addEventListener('changeDate', changeDateListener);
289
+
290
+ dp.setDate('7/4/2020', '7/14/2020');
291
+ expect(evt.detail.date, 'to equal', dp.getDate());
292
+
293
+ input.removeEventListener('changeDate', changeDateListener);
294
+ dp.destroy();
295
+ input.value = '';
296
+ });
297
+
298
+ it('value 0 is considered unlimited', function () {
299
+ if (window.navigator.userAgent.indexOf('Edge') > -1) {
300
+ this.timeout(5000);
301
+ }
302
+
303
+ const max = new Date(2100, 0, 1).getTime();
304
+ const generateDates = (dates, length, index = 0) => {
305
+ const date = dateUtils.stripTime(Math.floor(Math.random() * max));
306
+ if (dates.includes(date)) {
307
+ return generateDates(dates, length, index);
308
+ } else {
309
+ dates.push(date);
310
+ return index <= length
311
+ ? generateDates(dates, length, index + 1)
312
+ : dates;
313
+ }
314
+ };
315
+ const dates = generateDates([], 3000);
316
+
317
+ const dp = new Datepicker(input, {maxNumberOfDates: 0});
318
+ dp.setDate(dates);
319
+ expect(dp.dates, 'to equal', dates);
320
+
321
+ dp.destroy();
322
+ input.value = '';
323
+ });
324
+
325
+ it('can be updated with setOptions()', function () {
326
+ const dp = new Datepicker(input);
327
+ dp.setOptions({maxNumberOfDates: 3});
328
+
329
+ dp.setDate('2/11/2020', '2/7/2020', '2/14/2020');
330
+ expect(dp.dates, 'to equal', [
331
+ dateValue(2020, 1, 11),
332
+ dateValue(2020, 1, 7),
333
+ dateValue(2020, 1, 14),
334
+ ]);
335
+
336
+ dp.setOptions({maxNumberOfDates: 1});
337
+ dp.setDate('7/4/2020', '4/22/2020');
338
+ expect(dp.dates, 'to equal', [dateValue(2020, 3, 22)]);
339
+ expect(dp.getDate(), 'to be a date');
340
+
341
+ dp.destroy();
342
+ input.value = '';
343
+ });
344
+ });
345
+
346
+ describe('dateDelimiter', function () {
347
+ it('specifies the date delemiter for the input string', function () {
348
+ const dp = new Datepicker(input, {maxNumberOfDates: 3, dateDelimiter: '|'});
349
+
350
+ dp.setDate('2/14/2020', '4/22/2020');
351
+ expect(input.value, 'to be', '02/14/2020|04/22/2020');
352
+
353
+ input.value = '2/11/2020|2/7/2020|2/14/2020';
354
+ dp.update();
355
+ expect(dp.dates, 'to equal', [
356
+ dateValue(2020, 1, 11),
357
+ dateValue(2020, 1, 7),
358
+ dateValue(2020, 1, 14),
359
+ ]);
360
+
361
+ dp.destroy();
362
+ input.value = '';
363
+ });
364
+
365
+ it('can be updated with setOptions()', function () {
366
+ const dp = new Datepicker(input, {maxNumberOfDates: 3});
367
+ dp.setOptions({dateDelimiter: '_'});
368
+ dp.setDate('2/11/2020', '2/7/2020', '2/14/2020');
369
+
370
+ dp.setOptions({dateDelimiter: ' - '});
371
+ expect(input.value, 'to be', '02/11/2020 - 02/07/2020 - 02/14/2020');
372
+
373
+ dp.setOptions({dateDelimiter: ','});
374
+ expect(input.value, 'to be', '02/11/2020,02/07/2020,02/14/2020');
375
+
376
+ dp.destroy();
377
+ input.value = '';
378
+ });
379
+ });
380
+ });