Repository: icehaunter/vue3-datepicker Branch: master Commit: a086dd68d245 Files: 28 Total size: 75.6 KB Directory structure: gitextract_cw1ibvv4/ ├── .github/ │ └── workflows/ │ ├── docs-autobuild.yml │ ├── formatting-check.yml │ └── npm-publish.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── LICENSE ├── README.md ├── docs/ │ ├── .vitepress/ │ │ ├── config.js │ │ └── theme/ │ │ ├── custom.css │ │ └── index.js │ ├── config.md │ ├── examples.md │ └── index.md ├── index.html ├── package.json ├── src/ │ ├── App.vue │ ├── datepicker/ │ │ ├── Datepicker.vue │ │ ├── DayPicker.vue │ │ ├── MonthPicker.vue │ │ ├── PickerPopup.vue │ │ ├── Timepicker.vue │ │ └── YearPicker.vue │ ├── index.css │ ├── main.js │ └── vue-shim.d.ts ├── tsconfig.json └── vite.config.ts ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/docs-autobuild.yml ================================================ name: Documentation release on: push: branches: [master] paths: - 'docs/**' - 'package.json' workflow_dispatch: jobs: build_documentation: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18 - name: Build documentation run: | npm ci npm run build:docs - name: Initialize repo with docs run: git init ./docs/.vitepress/dist - name: Commit updated docs run: | git config user.name "${{ github.actor }}" git config user.email "${{ github.actor }}@users.noreply.github.com" git add -A git commit -m "Updated docs from ${{ github.sha }}" git push --verbose -f "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" master:gh-pages working-directory: ./docs/.vitepress/dist ================================================ FILE: .github/workflows/formatting-check.yml ================================================ name: Verify the code on: pull_request: jobs: verify-formatting: name: Check formatting runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: mode-version: 18 cache: npm - run: npm ci - run: npx prettier --check . ================================================ FILE: .github/workflows/npm-publish.yml ================================================ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages name: Node.js Package on: release: types: [created] workflow_dispatch: jobs: publish-npm: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18 registry-url: https://registry.npmjs.org/ - run: npm ci - run: rm -rf dist/ - run: npm run build:component - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} ================================================ FILE: .gitignore ================================================ node_modules .DS_Store .idea dist *.local **/.vitepress/cache ================================================ FILE: .prettierignore ================================================ **/dist **/.vitepress/cache ================================================ FILE: .prettierrc ================================================ { "semi": false, "singleQuote": true, "vueIndentScriptAndStyle": false, "tabWidth": 2 } ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 Ilia Borovitinov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Vue 3 Datepicker Documentation: https://icehaunter.github.io/vue3-datepicker/ This is a basic (at least for now) reimplementation of https://github.com/icehaunter/vuejs-datepicker in Vue 3 and with greatly cleaned up code. All date manipulation and formatting are done via the amazing [`date-fns`](https://date-fns.org/) library, so it's a direct dependency of this picker. ## Installation Package is available on NPM: https://www.npmjs.com/package/vue3-datepicker ```sh npm i vue3-datepicker ``` The component is packaged mainly for use with bundlers, if you require a browser build - post an issue. ## Usage For more examples see https://icehaunter.github.io/vue3-datepicker/examples.html ```vue ``` ## Props and attributes Attribute fallthrough is enabled, so any attribute you apply to the component will be passed down to the input. All props which accept formatting strings for dates use [`date-fns` formatting function](https://date-fns.org/docs/format) under the hood, so see that function's documentation for patterns. Main interaction to date selection is done via `v-model` with `Date` as expected type of the value passed. Full props documentation is available at https://icehaunter.github.io/vue3-datepicker/config.html#props | ID | Type | Default | Description | | ------------------------ | -------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `upperLimit` | `Date` | | Upper limit for available dates for picking | | `lowerLimit` | `Date` | | Lower limit for available dates for picking | | `startingViewDate` | `Date` | `() => new Date()` | Date on which to focus when empty datepicker is opened. Default is "right now" | | `disabledDates` | `{ dates: Date[] }` | | Dates not available for picking | | `disabledTime` | `{ dates: Date[] }` | | Dates not available for time picking | | `startingView` | `'time' \| 'day' \| 'month' \| 'year'` | `'day'` | View on which the date picker should open. Can be either `year`, `month`, or `day` | | `minimumView` | `'time' \| 'day' \| 'month' \| 'year'` | `'day'` | If set, lower-level views won't show | | `dayPickerHeadingFormat` | `String` | `LLLL yyyy` | `date-fns`-type formatting for a day view heading | | `dayFormat` | `String` | `dd` | `date-fns`-type formatting for each day on the day view | | `weekdayFormat` | `String` | `EE` | `date-fns`-type formatting for a line of weekdays on day view | | `inputFormat` | `String` | `yyyy-MM-dd` | `date-fns`-type format in which the string in the input should be both parsed and displayed | | `locale` | [`Locale`](https://date-fns.org/v2.16.1/docs/I18n#usage) | `date-fns/locale/en` | [`date-fns` locale object](https://date-fns.org/v2.16.1/docs/I18n#usage). Used in string formatting (see default `dayPickerHeadingFormat`) | | `disabled` | `Boolean` | `false` | Disables datepicker and prevents it's opening | | `typeable` | `Boolean` | `false` | Allows user to input date manually | | `weekStartsOn` | `Number` | 1 | Day on which the week should start. Number from 0 to 6, where 0 is Sunday and 6 is Saturday. Week starts with a Monday (1) by default | | `clearable` | `Boolean` | `false` | Allows clearing the selected date and setting the value to `null` | | `allowOutsideInterval` | `Boolean` | `false` | Allows user to click dates outside of current interval | ### Events - `opened`: Emitted every time the popup opens, including on field focus - `closed`: Emitted every time the popup closes, including on field blur - `decadePageChanged`: Emitted when a page is changed on the year picker view, displaying a different decade. Has a date that is included in the shown decade as an argument. - `yearPageChanged`: Emitted when a page is changed on the month picker view, displaying a different year. Has a date that is included in the shown year as an argument. - `monthPageChanged`: Emitted when a page is changed on the day picker view, displaying a different month. Has a date that is included in the shown month as an argument. ## Compatibility Package is transpiled and should be usable for everyone with ES6 and above, but the styling of the datepicker itself uses CSS Grid and CSS variables. ## Example ```vue ``` ================================================ FILE: docs/.vitepress/config.js ================================================ module.exports = { title: 'Vue 3 Datepicker', description: 'Datepicker component suitable for Vue 3', base: '/vue3-datepicker/', themeConfig: { nav: [ { text: 'Getting Started', link: '/' }, { text: 'Configuration', link: '/config' }, { text: 'Examples', link: '/examples' }, ], editLink: { pattern: 'https://github.com/icehaunter/vue3-datepicker/edit/master/docs/:path', text: 'Edit this page on Github', }, socialLinks: [ { icon: 'github', link: 'https://github.com/icehaunter/vue3-datepicker' }, ], }, } ================================================ FILE: docs/.vitepress/theme/custom.css ================================================ .vp-doc input[type='text'] { border: 1px solid lightgray; padding: 4px 8px; } ================================================ FILE: docs/.vitepress/theme/index.js ================================================ import DefaultTheme from 'vitepress/theme' import './custom.css' export default DefaultTheme ================================================ FILE: docs/config.md ================================================ # Configuration ## Props ### `v-model` - Type: `Date` - Required: yes The actual date that will be selected. The component behaves as close to Vue 3 documentation on custom component inputs as possible, using `modelValue` prop and `update:modelValue` event pair. Use those if you want to have more control over your model binding. ### `upperLimit` - Type: `Date` - Required: no Upper limit (not inclusive) for available dates for picking. All dates above that limit will not be selectable. ### `lowerLimit` - Type: `Date` - Required: no Lower limit (not inclusive) for available dates for picking. All dates below that limit will not be selectable. ## `startingViewDate` - Type: `Date` - Default: `new Date()` (right now) When opening the empty datepicker, this date will be "focused": the month of this date will be shown on the day picker view, the year of this date will be shown in the month picker view, and the decade of this date will be shown in the year picker view. ### `disabledDates` - Type: `{ dates: Date[], predicate: (target: Date) => boolean }` - Required: no All dates listed in the `dates` array will not be selectable. Can also take in a function via the `predicate` key, which tests each date in the current view of the calendar, returning `true` if date should be disabled. ### `disabledTime` - Type: `{ dates: Date[], predicate: (target: Date) => boolean }` - Required: no All dates listed in the `dates` array will not be selectable in the timepicker view. Can also take in a function via the `predicate` key, which tests each date in the timepicker view, returning `true` if date should be disabled. ### `startingView` - Type: `'time' | 'day' | 'month' | 'year'` - Default: `'day'` View on which the date picker should open. Can be either `year`, `month`, `day` or `time`. If `startingView` is `time` and `minimumView` is `time` then only view of the calendar `time` will be available. ### `dayPickerHeadingFormat` - Type: `String` (date-fns [format string](https://date-fns.org/docs/format)) - Default: `LLLL yyyy` `date-fns`-type formatting for a day view heading. By default prints full month as text and selected year (e.g. January 2021). ### `weekdayFormat` - Type: `String` (date-fns [format string](https://date-fns.org/docs/format)) - Default: `EE` `date-fns`-type formatting for a line of weekdays on day view. By default uses three-letter representation (e.g. Fri). ### `dayFormat` - Type: `String` (date-fns [format string](https://date-fns.org/docs/format)) - Default: `dd` `date-fns`-type formatting for the day picker view. ### `inputFormat` - Type: `String` (date-fns [format string](https://date-fns.org/docs/format)) - Default: `yyyy-MM-dd` `date-fns`-type format in which the string in the input should be both parsed and displayed. By default uses ISO format (e.g. 2021-01-01). ### `locale` - Type: `Locale` [`date-fns` locale object](https://date-fns.org/v2.16.1/docs/I18n#usage) - Default: `date-fns/locale/en` Used in all date string formatting (e.g. see default `dayPickerHeadingFormat`) ### `weekStartsOn` - Type: `0 | 1 | 2 | 3 | 4 | 5 | 6` - Default: `1` Day on which the week should start. Number from 0 to 6, where 0 is Sunday and 6 is Saturday. Week starts with a Monday (1) by default. ### `clearable` - Type: `Boolean` - Default: `false` Allows clearing the selected date and setting the value to `null` ### `disabled` - Type: `Boolean` - Default: `false` Disables datepicker and prevents it's opening ### `typeable` - Type: `Boolean` - Default: `false` Allows user to input date manually ### `allowOutsideInterval` - Type: `Boolean` - Default: `false` Allows user to click dates outside of current interval. ## Styling The input itself can be styled via passing classes to it. [Attribute fallthrough](https://v3.vuejs.org/guide/component-attrs.html#disabling-attribute-inheritance) is enabled. Keep in mind that input itself is not a top-level element, as it is contained within the top-level `div`. :::warning Heavy restyling via variables has not been tested, as I am mostly using this component as-is. If you find any issues while adjusting the colors (e.g. some colors don't change or a setting is missing) please [file an issue on GitHub](https://github.com/icehaunter/vue3-datepicker/issues). ::: ### Variables Style can be altered significantly without editing CSS files of the components. This is done via CSS variables. Following variables are available: | Variable name | Default value | Type | | ---------------------------------- | -------------- | ------ | | `--vdp-bg-color` | `#fff` | color | | `--vdp-text-color` | `#000` | color | | `--vdp-box-shadow` | See source | shadow | | `--vdp-border-radius` | `3px` | size | | `--vdp-heading-size` | `2.5em` | size | | `--vdp-heading-weight` | `bold` | weight | | `--vdp-heading-hover-color` | `#eeeeee` | color | | `--vdp-arrow-color` | `currentColor` | color | | `--vdp-elem-color` | `currentColor` | color | | `--vdp-disabled-color` | `#d5d9e0` | color | | `--vdp-hover-color` | `#fff` | color | | `--vdp-hover-bg-color` | `#0baf74` | color | | `--vdp-selected-color` | `#fff` | color | | `--vdp-selected-bg-color` | `#0baf74` | color | | `--vdp-current-date-outline-color` | `#888888` | color | | `--vdp-current-date-font-weight` | `bold` | weight | | `--vdp-elem-font-size` | `0.8em` | size | | `--vdp-elem-border-radius` | `3px` | size | | `--vdp-divider-color` | `#d5d9e0` | color | ### Styling example and playground :::tip Note that variables affect only the datepicker popup. If you want to change styles for the input, just pass it in the `:style` prop or use classes. :::
{{ variable }}  
Copy serialized object with these settings
{{ styleObj }}
================================================ FILE: docs/examples.md ================================================ # Examples ## Styling For styling examples, see [Configuration section](/config#styling-example-and-playground). ## Basic usage
Code for this example ```vue ```
## Typeable input
Code for this example ```vue ```
## Upper and lower limits :::tip If limit is within the current "view" (e.g. a month), then view changing will be prohibited. ::: Settings: - Lower limit: - Upper limit: Result:
Code for this example ```vue ```
## Disabled dates Settings: - Disabled date: Result:
Code for this example ```vue ```
## Starting view Settings: - - - - Result: ## Mininimal view Settings: - - - - Result: ## Clearable
Code for this example ```vue ```
:::tip We can customize clearable view with `slot` for example: :::
Code for this example ```vue ```
================================================ FILE: docs/index.md ================================================ # Introduction This is a reimplementation of [vuejs-datepicker](https://github.com/icehaunter/vuejs-datepicker) in Vue 3 and with greatly cleaned up code. All date manipulation and formatting are done via the amazing [`date-fns`](https://date-fns.org/) library, so it's a direct dependency of this picker. ## Example Datepicker comes with styling, but input itself does not. Attributes fall through to the `input` element, so you can use classes and styles as you would on any input. ## Installation Package is available on NPM: [![npm](https://img.shields.io/npm/v/vue3-datepicker)](https://www.npmjs.com/package/vue3-datepicker) ```sh npm i vue3-datepicker ``` Then import it in your code and use as a usual component: ```vue ``` ## Compatibility Package is transpiled and should be usable for everyone with ES6 and above, but the styling of the datepicker itself uses CSS Grid and CSS variables. Package uses typescript and ships with TS declarations for its components. ## Props and attributes Attribute fallthrough is enabled, so any attribute you apply to the component will be passed down to the input. All props which accept formatting strings for dates use [`date-fns` formatting function](https://date-fns.org/docs/format) under the hood, so see that function's documentation for patterns. Main interaction to date selection is done via `v-model` with `Date` as expected type of the value passed. More in-depth documentation of the props, as well as examples, can be found in [Configuration](/config) | ID | Type | Default | Description | | ------------------------ | -------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `upperLimit` | `Date` | | Upper limit for available dates for picking | | `lowerLimit` | `Date` | | Lower limit for available dates for picking | | `startingViewDate` | `Date` | `() => new Date()` | Date on which to focus when empty datepicker is opened. Default is "right now" | | `disabledDates` | `{ dates: Date[] }` | | Dates not available for picking | | `disabledTime` | `{ dates: Date[] }` | | Dates not available for time picking | | `startingView` | `'time' \| `'day' \| 'month' \| 'year'` | `'day'` | View on which the date picker should open. Can be either `year`, `month`, or `day` | | `minimumView` | `'time' \| `'day' \| 'month' \| 'year'` | `'day'` | If set, lower-level views won't show | | `dayPickerHeadingFormat` | `String` | `LLLL yyyy` | `date-fns`-type formatting for a day view heading | | `dayFormat` | `String` | `dd` | `date-fns`-type formatting for each day on the day view | | `weekdayFormat` | `String` | `EE` | `date-fns`-type formatting for a line of weekdays on day view | | `inputFormat` | `String` | `yyyy-MM-dd` | `date-fns`-type format in which the string in the input should be both parsed and displayed | | `locale` | [`Locale`](https://date-fns.org/v2.16.1/docs/I18n#usage) | `date-fns/locale/en` | [`date-fns` locale object](https://date-fns.org/v2.16.1/docs/I18n#usage). Used in string formatting (see default `dayPickerHeadingFormat`) | | `disabled` | `Boolean` | `false` | Disables datepicker and prevents it's opening | | `typeable` | `Boolean` | `false` | Allows user to input date manually | | `weekStartsOn` | `Number` | 1 | Day on which the week should start. Number from 0 to 6, where 0 is Sunday and 6 is Saturday. Week starts with a Monday (1) by default | | `clearable` | `Boolean` | `false` | Allows clearing the selected date and setting the value to `null` | | `allowOutsideInterval` | `Boolean` | `false` | Allows user to click dates outside of current interval | ### Events - `opened`: Emitted every time the popup opens, including on field focus - `closed`: Emitted every time the popup closes, including on field blur - `decadePageChanged`: Emitted when a page is changed on the year picker view, displaying a different decade. Has a date that is included in the shown decade as an argument. - `yearPageChanged`: Emitted when a page is changed on the month picker view, displaying a different year. Has a date that is included in the shown year as an argument. - `monthPageChanged`: Emitted when a page is changed on the day picker view, displaying a different month. Has a date that is included in the shown month as an argument. ## Styling Styling is done via CSS variables, which control colors used in the popup. All variables, as well as styling example and playground can be found in [Configuration section](/config.html#styling-example-and-playground) ================================================ FILE: index.html ================================================ Vite App
================================================ FILE: package.json ================================================ { "author": { "email": "icehaunter@gmail.com", "name": "Ilya Borovitinov" }, "license": "MIT", "engines": { "node": ">=10.16.0" }, "repository": { "type": "git", "url": "https://github.com/icehaunter/vue3-datepicker.git" }, "bugs": { "url": "https://github.com/icehaunter/vue3-datepicker/issues" }, "private": false, "name": "vue3-datepicker", "version": "0.4.0", "publishConfig": { "access": "public" }, "description": "A simple Vue 3 datepicker component. Supports disabling of dates, translations. Dependent on date-fns.", "keywords": [ "vue", "vue 3", "component", "datepicker", "date-picker", "calendar", "date-fns" ], "main": "dist/vue3-datepicker.umd.js", "module": "dist/vue3-datepicker.mjs", "types": "./dist/types/Datepicker.vue.d.ts", "files": [ "src/datepicker", "dist" ], "scripts": { "dev": "vite", "dev:docs": "vitepress dev docs", "build:component": "vite build", "build:docs": "vitepress build docs", "preview:docs": "vitepress preview docs", "format": "prettier -w ." }, "devDependencies": { "@babel/types": "^7.22.4", "@types/node": "^20.2.5", "@vitejs/plugin-vue": "^4.2.3", "@vue/compiler-sfc": "^3.3.4", "prettier": "^2.8.8", "typescript": "^4.8.4", "vite": "^4.3.9", "vite-plugin-css-injected-by-js": "^3.1.1", "vite-plugin-dts": "^2.3.0", "vitepress": "^1.0.0-beta.1", "vue": "^3.3.4" }, "peerDependencies": { "vue": "^3.0.0" }, "dependencies": { "date-fns": "^2.22.1" } } ================================================ FILE: src/App.vue ================================================ ================================================ FILE: src/datepicker/Datepicker.vue ================================================ ================================================ FILE: src/datepicker/DayPicker.vue ================================================ ================================================ FILE: src/datepicker/MonthPicker.vue ================================================ ================================================ FILE: src/datepicker/PickerPopup.vue ================================================ ================================================ FILE: src/datepicker/Timepicker.vue ================================================ ================================================ FILE: src/datepicker/YearPicker.vue ================================================ ================================================ FILE: src/index.css ================================================ #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; /* text-align: center; */ color: #2c3e50; margin-top: 60px; } ================================================ FILE: src/main.js ================================================ import { createApp } from 'vue' import App from './App.vue' import './index.css' window.app = createApp(App).mount('#app') ================================================ FILE: src/vue-shim.d.ts ================================================ declare module '*.vue' { import { defineComponent } from 'vue' const Component: ReturnType export default Component } ================================================ FILE: tsconfig.json ================================================ { "compilerOptions": { "target": "ES2019", "module": "esnext", "lib": ["ESNext", "DOM"], // this enables stricter inference for data properties on `this` "strict": true, "jsx": "preserve", "moduleResolution": "node", "declaration": true }, "exclude": ["node_modules", "dist"] } ================================================ FILE: vite.config.ts ================================================ import { resolve } from 'path' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js' import dts from 'vite-plugin-dts' export default defineConfig({ build: { cssCodeSplit: true, lib: { // Could also be a dictionary or array of multiple entry points entry: resolve(__dirname, 'src/datepicker/Datepicker.vue'), name: 'Datepicker', formats: ['es', 'umd'], // the proper extensions will be added fileName: 'vue3-datepicker', }, rollupOptions: { // make sure to externalize deps that shouldn't be bundled // into your library external: ['vue', 'date-fns', 'date-fns/fp', 'date-fns/locale'], output: { // Provide global variables to use in the UMD build // for externalized deps globals: { vue: 'Vue', 'date-fns': 'date-fns', }, assetFileNames: (assetInfo) => { if (assetInfo.name === 'style.css') return 'vue3-datepicker.css' return assetInfo.name! }, }, }, }, plugins: [ vue(), cssInjectedByJsPlugin(), dts({ entryRoot: 'src/datepicker', outputDir: 'dist/types', }), ], optimizeDeps: { include: ['date-fns/locale', 'date-fns/fp'], }, })