1 | <div align="center" style="text-align: center;">
|
2 | <h1 style="border-bottom: none;">app-datepicker</h1>
|
3 |
|
4 | <p>Datepicker element built with lit-element and Material Design 2</p>
|
5 | </div>
|
6 |
|
7 | <hr />
|
8 |
|
9 | <a href="https://www.buymeacoffee.com/RLmMhgXFb" target="_blank" rel="noopener noreferrer"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 20px !important;width: auto !important;" ></a>
|
10 | [![tippin.me][tippin-me-badge]][tippin-me-url]
|
11 | [![Follow me][follow-me-badge]][follow-me-url]
|
12 |
|
13 | [![Version][version-badge]][version-url]
|
14 | [![lit-element][lit-element-version-badge]][lit-element-url]
|
15 | [![Node version][node-version-badge]][node-version-url]
|
16 | [![MIT License][mit-license-badge]][mit-license-url]
|
17 |
|
18 | [![Downloads][downloads-badge]][downloads-url]
|
19 | [![Total downloads][total-downloads-badge]][downloads-url]
|
20 | [![Packagephobia][packagephobia-badge]][packagephobia-url]
|
21 | [![Bundlephobia][bundlephobia-badge]][bundlephobia-url]
|
22 |
|
23 | [![ci][ga-ci-badge]][ga-ci-url]
|
24 | [![Sauce Labs][ga-sl-badge]][ga-sl-url]
|
25 | [![Dependency Status][daviddm-badge]][daviddm-url]
|
26 |
|
27 | [![codebeat badge][codebeat-badge]][codebeat-url]
|
28 | [![Language grade: JavaScript][lgtm-badge]][lgtm-url]
|
29 | [![Code of Conduct][coc-badge]][coc-url]
|
30 |
|
31 | > A different way of `datepicker`-ing on the web.
|
32 | >
|
33 | > 💯 Also, featured in [awesome-lit-html].
|
34 |
|
35 | This marks another completion of an important milestone of `app-datepicker` with all the love from the [Web Components community][web-components-community-url] in making this element great and wonderful. As Web Components getting more and more traction and better at providing a web standard way of creating shareable components, it plays an important role in the JavaScript community as many developers depend on a plethora of development tools written in JavaScript for the web to create a better developer experience when developing a library, a component, or even a large scalable application.
|
36 |
|
37 | ![app-datepicker](https://user-images.githubusercontent.com/10607759/67633824-ce170c80-f8ef-11e9-8d20-856eb0e62409.jpg)
|
38 |
|
39 | Today, `app-datepicker` has been completely rewritten to adapt to the best of both worlds by leveraging the modern technologies the community most familiar with since year 2018.
|
40 |
|
41 | The following are the list of tools used that makes it shine:
|
42 |
|
43 | 1. [TypeScript]
|
44 | 2. [lit-element][lit-element-url]
|
45 |
|
46 | ## Table of contents <!-- omit in toc -->
|
47 |
|
48 | - [Pre-requisite](#pre-requisite)
|
49 | - [Installation](#installation)
|
50 | - [How to use](#how-to-use)
|
51 | - [Browser compatibility](#browser-compatibility)
|
52 | - [Q&A](#qa)
|
53 | - [API references](#api-references)
|
54 | - [Demo](#demo)
|
55 | - [Older versions](#older-versions)
|
56 | - [License](#license)
|
57 |
|
58 | ## Pre-requisite
|
59 |
|
60 | - [ES2019] _(The element is compiled with features targeting ES2019, so it might not work properly without transpilation on older browsers.)_
|
61 | - [lit-element][lit-element-url] >= 2.2.1
|
62 | - [OPTIONAL] [TypeScript] >= 3.8.3 _(TypeScript users only)_
|
63 |
|
64 | ## Installation
|
65 |
|
66 | - NPM
|
67 |
|
68 | ```sh
|
69 | $ npm i app-datepicker
|
70 | ```
|
71 |
|
72 | - Alternatively, it can be downloaded from any of the following awesome CDNs:
|
73 |
|
74 | 1. [jsdelivr (ESM)][jsdelivr-url]
|
75 | 2. [unpkg (ESM)][unpkg-url]
|
76 |
|
77 | ## How to use
|
78 |
|
79 | **Polyfills**
|
80 |
|
81 | Please make sure you have all these features available on the browsers you are supporting. If no, please consider polyfill-ing in order to run the datepicker element.
|
82 |
|
83 | * [Array.prototype.find]
|
84 | * [Intl.DateTimeFormat]
|
85 |
|
86 | The following snippet shows a simple script used in the demo to load polyfills via feature detection on different browsers:
|
87 |
|
88 | ```html
|
89 | <script>
|
90 | if (null == Array.prototype.find) {
|
91 | Object.defineProperty(Array.prototype, 'find', {
|
92 | value: function arrayFind(cb) {
|
93 | var filtered = this.filter(cb);
|
94 | return !filtered.length ? void 0 : filtered[0];
|
95 | },
|
96 | });
|
97 | }
|
98 |
|
99 | if (!window.Intl) {
|
100 | var wa = document.createElement('script');
|
101 | /** FIXME: Pin package version due to https://github.com/andyearnshaw/Intl.js/issues/256 */
|
102 | wa.src = 'https://unpkg.com/intl@1.2.4/dist/Intl.complete.js';
|
103 | wa.onload = function onLoad() { console.info('🌐 Intl polyfill loaded'); };
|
104 | wa.onerror = console.error;
|
105 | document.head.appendChild(wa);
|
106 | }
|
107 | </script>
|
108 | ```
|
109 |
|
110 | **my-app.ts**
|
111 |
|
112 | ```ts
|
113 | /**
|
114 | * Say you've already installed the element via NPM, simply import the package to your application.
|
115 | * Here I'm using `lit-element` for developing my application.
|
116 | */
|
117 | import { css, customElement, html, LitElement } from 'lit-element';
|
118 | import 'app-datepicker';
|
119 |
|
120 | @customElement(MyApp.is)
|
121 | export class MyApp extends LitElement {
|
122 | static is() { return 'my-app'; }
|
123 |
|
124 | static styles = [
|
125 | css`
|
126 | :host {
|
127 | display: block;
|
128 | }
|
129 |
|
130 | * {
|
131 | box-sizing: border-box;
|
132 | }
|
133 | `
|
134 | ];
|
135 |
|
136 | protected render() {
|
137 | return html`<app-datepicker></app-datepicker>`;
|
138 | }
|
139 | }
|
140 | ```
|
141 |
|
142 | **index.html**
|
143 |
|
144 | ```html
|
145 | <!doctype html>
|
146 | <html>
|
147 | <!-- Using ES modules to load the app -->
|
148 | <script type="module" src="/my-app.js"></script>
|
149 | ...
|
150 | <body>
|
151 | <my-app>
|
152 | <!-- <AppDatepicker> will be rendered when <MyApp> loads. -->
|
153 | </my-app>
|
154 | </body>
|
155 | ...
|
156 | </html>
|
157 | ```
|
158 |
|
159 | ## Browser compatibility
|
160 |
|
161 | Both `app-datepicker` and `app-datepicker-dialog` works in last 2 versions of all evergreen browsers (Chrome, Firefox, Edge, and Safari). Internet Explorer 11 is no longer supported in favor of the [new Microsoft Edge].
|
162 |
|
163 | Tested on the following browsers:
|
164 |
|
165 | | Name | OS |
|
166 | | --- | --- |
|
167 | | Chrome 79 | Windows 10 |
|
168 | | Edge 18 | Windows 10 |
|
169 | | Firefox 72 | Windows 10 |
|
170 | | Safari 13 | mac 10.13 |
|
171 |
|
172 |
|
173 |
|
174 | | Edge 15 | Windows 10 |
|
175 | | Edge 17 | Windows 10 |
|
176 | | Firefox 62 (w/o native Shadow DOM) | macOS Mojave (10.14) |
|
177 | | Internet Explorer 11 | Windows 10 |
|
178 | | Safari 10.1 | Mac OS 10.12 |
|
179 | | Safari 9 | Mac OS X 10.11 | -->
|
180 |
|
181 | ## Q&A
|
182 |
|
183 | 1. Does it work well with [material-components-web-components]?
|
184 |
|
185 | For [material-components-web-components] users, you can create your own custom date picker element by wrapping `app-datepicker` inside [mwc-dialog].
|
186 |
|
187 | <!-- Feasible source code can be viewed [here][mwc-date-picker-url]. -->
|
188 |
|
189 | ```ts
|
190 | // Simplified code snippet
|
191 |
|
192 | class MWCDatePicker extends LitElement {
|
193 | render() {
|
194 | return html`
|
195 | <mwc-dialog>
|
196 | <app-datepicker></app-datepicker>
|
197 |
|
198 | <mwc-button slot="secondaryAction" dialogAction="cancel">cancel</mwc-button>
|
199 | <mwc-button slot="primaryAction" dialogAction="set">set</mwc-button>
|
200 | </mwc-dialog>
|
201 | `;
|
202 | }
|
203 | }
|
204 | ```
|
205 |
|
206 | 2. How can I hide the focus outline?
|
207 |
|
208 | For a11y reason, focus outline is shown when a calendar day is being focused. However, this can be modified via [CSS Shadow Parts].
|
209 |
|
210 | ```css
|
211 | /**
|
212 | * Hide focus ring.
|
213 | *
|
214 | * NOTE: It is recommended to come up with alternative styling for focus state
|
215 | * instead of just hiding the focus ring.
|
216 | */
|
217 | app-datepicker::part(calendar-day):focus {
|
218 | outline: none;
|
219 | }
|
220 | ```
|
221 |
|
222 | ## API references
|
223 |
|
224 | - [AppDatepicker][app-datepicker-api-reference-url]
|
225 | - [AppDatepickerDialog][app-datepicker-dialog-api-reference-url]
|
226 |
|
227 | ## Demo
|
228 |
|
229 | [Configurable demo powered by Firebase]
|
230 |
|
231 | ## Older versions
|
232 |
|
233 | Meantime, feel free to check the older version out at:
|
234 |
|
235 | 1. [`2.x` branch][2-x-url] - Built with Material Design and [Polymer 2][polymer-2-url], published at Bower.
|
236 | 2. [`3.x` branch][3-x-url] - Built with Material Design and [Polymer 3][polymer-3-url], published at NPM.
|
237 |
|
238 | ## License
|
239 |
|
240 | [MIT License](http://motss.mit-license.org/) © Rong Sen Ng
|
241 |
|
242 |
|
243 | [2-x-url]: https://github.com/motss/app-datepicker/tree/2.x?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
244 | [3-x-url]: https://github.com/motss/app-datepicker/tree/3.x?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
245 | [app-datepicker-api-reference-url]: /api-references.md#appdatepicker
|
246 | [app-datepicker-dialog-api-reference-url]: /api-references.md#appdatepickerdialog
|
247 | [Array.prototype.find]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
|
248 | [Configurable demo powered by Firebase]: https://motss-app.web.app/demo/app-datepicker.html
|
249 | [Intl.DateTimeFormat]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
|
250 | [jsdelivr-url]: https://www.jsdelivr.com/package/npm/app-datepicker?version=latest&utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
251 | [lit-element-url]: https://github.com/Polymer/lit-element?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
252 | [material-design-2-url]: https://material.io/design/?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
253 | [polymer-2-url]: https://polymer-library.polymer-project.org/2.0/docs/devguide/feature-overview?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
254 | [polymer-3-url]: https://polymer-library.polymer-project.org/3.0/docs/devguide/feature-overview?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
255 | [TypeScript]: https://github.com/Microsoft/TypeScript?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
256 | [unpkg-url]: https://unpkg.com/app-datepicker@latest/?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
257 | [web-components-community-url]: https://www.webcomponents.org?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
258 | [wre-2019-url]: https://www.deepcrawl.com/blog/news/what-version-of-chrome-is-google-actually-using-for-rendering
|
259 | [wre-url]: https://developers.google.com/search/docs/guides/rendering
|
260 | [new Microsoft Edge]: https://blogs.windows.com/msedgedev/2020/01/15/upgrading-new-microsoft-edge-79-chromium
|
261 | [ES2019]: https://kangax.github.io/compat-table/es2016plus/#test-Object.fromEntries
|
262 | [awesome-lit-html]: https://github.com/web-padawan/awesome-lit-html#individual-components
|
263 | [material-components-web-components]: https://github.com/material-components/material-components-web-components
|
264 | [mwc-dialog]: https://github.com/material-components/material-components-web-components/tree/master/packages/dialog
|
265 | [mwc-date-picker-url]: https://motss-app.web.app/demo/app-datepicker/mwc-date-picker.js
|
266 | [CSS Shadow Parts]: https://developer.mozilla.org/en-US/docs/Web/CSS/::part
|
267 |
|
268 |
|
269 | [ie-img-url]: https://cdn.jsdelivr.net/npm/@browser-logos/internet-explorer_9-11@1.1.3/internet-explorer_9-11_64x64.png
|
270 |
|
271 |
|
272 | [map-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map?utm_source=github.com&utm_medium=referral
|
273 | [string-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String?utm_source=github.com&utm_medium=referral
|
274 | [object-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object?utm_source=github.com&utm_medium=referral
|
275 | [number-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number?utm_source=github.com&utm_medium=referral
|
276 | [boolean-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean?utm_source=github.com&utm_medium=referral
|
277 | [html-style-element-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement?utm_source=github.com&utm_medium=referral
|
278 | [promise-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise?utm_source=github.com&utm_medium=referral
|
279 |
|
280 |
|
281 | [tippin-me-badge]: https://badgen.net/badge/%E2%9A%A1%EF%B8%8Ftippin.me/@igarshmyb/F0918E
|
282 | [follow-me-badge]: https://flat.badgen.net/twitter/follow/igarshmyb?icon=twitter
|
283 |
|
284 | [version-badge]: https://flat.badgen.net/npm/v/app-datepicker/latest?icon=npm
|
285 | [lit-element-version-badge]: https://flat.badgen.net/npm/v/lit-element/latest?icon=npm&label=lit-element
|
286 | [node-version-badge]: https://flat.badgen.net/npm/node/app-datepicker
|
287 | [mit-license-badge]: https://flat.badgen.net/npm/license/app-datepicker
|
288 |
|
289 | [downloads-badge]: https://flat.badgen.net/npm/dm/app-datepicker
|
290 | [total-downloads-badge]: https://flat.badgen.net/npm/dt/app-datepicker?label=total%20downloads
|
291 | [packagephobia-badge]: https://flat.badgen.net/packagephobia/install/app-datepicker%40latest
|
292 | [bundlephobia-badge]: https://flat.badgen.net/bundlephobia/minzip/app-datepicker@latest
|
293 |
|
294 | [ga-ci-badge]: https://github.com/motss/app-datepicker/workflows/ci/badge.svg
|
295 | [ga-sl-badge]: https://github.com/motss/app-datepicker/workflows/Sauce%20Labs/badge.svg
|
296 | [daviddm-badge]: https://flat.badgen.net/david/dep/motss/app-datepicker
|
297 |
|
298 | [codebeat-badge]: https://codebeat.co/badges/3a212108-43cd-4a1f-ab2c-fe890ad734b6
|
299 | [lgtm-badge]: https://flat.badgen.net/lgtm/grade/javascript/g/motss/app-datepicker?icon=lgtm
|
300 | [coc-badge]: https://flat.badgen.net/badge/code%20of/conduct/pink
|
301 |
|
302 |
|
303 | [tippin-me-url]: https://tippin.me/@igarshmyb
|
304 | [follow-me-url]: https://twitter.com/igarshmyb?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
305 |
|
306 | [version-url]: https://www.npmjs.com/package/app-datepicker/v/latest?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
307 | [node-version-url]: https://nodejs.org/en/download?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
308 | [mit-license-url]: https://github.com/motss/app-datepicker/blob/master/LICENSE?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
309 |
|
310 | [downloads-url]: http://www.npmtrends.com/app-datepicker?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
311 | [packagephobia-url]: https://packagephobia.now.sh/result?p=app-datepicker%40latest&utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
312 | [bundlephobia-url]: https://bundlephobia.com/result?p=app-datepicker@latest&utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
313 |
|
314 | [ga-ci-url]: https://github.com/motss/app-datepicker/actions?query=workflow%3Aci
|
315 | [ga-sl-url]: https://github.com/motss/app-datepicker/actions?query=workflow%3A%22Sauce+Labs%22
|
316 | [daviddm-url]: https://david-dm.org/motss/app-datepicker?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
317 |
|
318 | [codebeat-url]: https://codebeat.co/projects/github-com-motss-app-datepicker-master-68699d41-3539-4c5f-81df-c9202be34919?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
319 | [lgtm-url]: https://lgtm.com/projects/g/motss/app-datepicker/context:javascript?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
320 | [coc-url]: https://github.com/motss/app-datepicker/blob/master/code-of-conduct.md?utm_source=github.com&utm_medium=referral&utm_content=motss/app-datepicker
|
321 |
|
322 |
|
323 |
|
324 |
|