5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.storybook/main.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 |
3 | module.exports = {
4 | stories: ["../stories/**/*.stories.js"],
5 | logLevel: "debug",
6 | addons: [
7 | "@storybook/addon-actions",
8 | "@storybook/addon-links"
9 | ]
10 | };
11 |
--------------------------------------------------------------------------------
/.storybook/preview-head.html:
--------------------------------------------------------------------------------
1 |
5 |
9 |
--------------------------------------------------------------------------------
/.storybook/preview.js:
--------------------------------------------------------------------------------
1 | import { addParameters } from "@storybook/react";
2 |
3 | addParameters({
4 | options: {
5 | // Sort stories in numeric order
6 | storySort: function(a, b) {
7 | if (a > b) return 1;
8 | if (a < b) return -1;
9 | return 0;
10 | }
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 0.1.0-beta.0 (2020-07-23)
2 |
3 |
4 | ### Features
5 |
6 | * initial commit ([6c24341](https://github.com/mark-tate/use-date-input/commit/6c24341efc30d33d6248367ee6578831c7a975ad))
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 mark-tate
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # use-date-input
2 |
3 | This project is a React library to help compose your own date picker and calendar UI components.
4 |
5 | From simple to advanced, you can build your own date picker component in minutes.
6 |
7 | The key features of this projects
8 |
9 | - `Lightweight` - Optimized bundle size
10 | - `Control` - built with React hooks and the reducer pattern, the API gives you full control of the component's state
11 | - `Themeable` - built as a naked UI component, use the simple theming API to style
12 | - `Date Frameworks` - can be used with the date framework of your choice
13 | Either use the ready-made adapters ([dayjs](https://github.com/mark-tate/use-date-input/tree/master/packages/dayjs-adapter), [date-fns](https://github.com/mark-tate/use-date-input/tree/master/packages/date-fns-adapter), [luxon](https://github.com/mark-tate/use-date-input/tree/master/packages/luxon-adapter), [moment](https://github.com/mark-tate/use-date-input/tree/master/packages/moment-adapter)) or write your own adapter
14 | - `Composable` - can be used with any UI Framework
15 | Compose with your own UI components, to create date inputs, date dialogs or calendars with shortcut lists
16 | - `Accessible` - designed and tested for A11y, with full keyboard and screen-reader support
17 | - `Localisation` - customize region and labels
18 | - `Documentation` - fully documented with editable examples
19 |
20 | To get up and running quickly, refer to the [getting started](https://mark-tate.github.io/use-date-input/getting-started) guide.
21 |
22 | For the full documentation, refer to the [documentation](https://mark-tate.github.io/use-date-input/).
23 |
24 | ## Pay It Forward
25 | This project was built to give something back to the OpenSource community.
26 |
27 | Please raise a PR for this project or be inspired to create (or contribute) to another Open Source project.
28 |
29 |
30 | Building this component took alot of effort, so to show your appreciation, please let me know how you are using it, where you
31 | are using it and what themes you create.
32 |
33 | All feedback appreciated, message me on [Linked-In](https://twitter.com/mark.tate3).
34 |
35 | ## Credits
36 | When I started out, I wanted to create the Downshift of DatePickers.
37 | So a special mention to Kent, who inspired the journey.
38 |
39 | Documentation site built with [docz](https://www.docz.site/)
40 |
--------------------------------------------------------------------------------
/config/jest/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | collectCoverage: true,
3 | coveragePathIgnorePatterns: ["(tests/.*.mock).(jsx?|tsx?)$"],
4 | moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
5 | roots: ["/src"],
6 | setupFilesAfterEnv: ['../../config/jest/jest.setup.js'],
7 | testRegex: "(/__tests__/.*.(test|spec)).(jsx?|tsx?)$",
8 | transformIgnorePatterns: ["/node_modules/(?!@babel/runtime)"],
9 | verbose: true,
10 | };
11 |
--------------------------------------------------------------------------------
/config/jest/jest.setup.js:
--------------------------------------------------------------------------------
1 | // react-testing-library renders your components to document.body,
2 | // this adds jest-dom's custom assertions
3 | import '@testing-library/jest-dom/extend-expect';
4 |
5 | if (window.document) {
6 | window.document.createRange = () => ({
7 | setStart: () => {},
8 | setEnd: () => {},
9 | commonAncestorContainer: {
10 | nodeName: 'BODY',
11 | ownerDocument: document
12 | }
13 | });
14 | }
15 |
--------------------------------------------------------------------------------
/config/rollup/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from "@rollup/plugin-babel";
2 | import commonjs from "@rollup/plugin-commonjs";
3 | import filesize from "rollup-plugin-filesize";
4 | import resolve from "@rollup/plugin-node-resolve";
5 | import { terser } from "rollup-plugin-terser";
6 | import visualizer from "rollup-plugin-visualizer";
7 | import path from "path";
8 |
9 | const pkgRootPath = process.cwd();
10 | const pkg = require(path.join(pkgRootPath, "package.json"));
11 |
12 | const config = {
13 | input: "src/index.js",
14 | output: [
15 | {
16 | file: "dist/index.umd.js",
17 | format: "umd",
18 | name: 'useDateInput',
19 | plugins: [
20 | terser()
21 | ],
22 | sourcemap: true
23 | },
24 | {
25 | file: "dist/index.js",
26 | format: "cjs",
27 | plugins: [
28 | visualizer({
29 | filename: "dist/stat-cjs.html",
30 | sourcemap: false
31 | })
32 | ],
33 | sourcemap: true
34 | },
35 | {
36 | file: "dist/index.min.js",
37 | format: "cjs",
38 | plugins: [
39 | terser(),
40 | visualizer({
41 | filename: "dist/stat-cjs-min.html",
42 | sourcemap: false
43 | })
44 | ],
45 | sourcemap: true
46 | },
47 | {
48 | file: "dist/index.esm.js",
49 | format: "esm",
50 | plugins: [
51 | visualizer({
52 | filename: "dist/stat-esm.html",
53 | sourcemap: false
54 | })
55 | ],
56 | sourcemap: true
57 | }
58 | ],
59 | plugins: [
60 | resolve(),
61 | babel({
62 | exclude: "**/node_modules/**",
63 | babelHelpers: "runtime"
64 | }),
65 | commonjs(),
66 | filesize(),
67 | visualizer(),
68 | terser()
69 | ],
70 | external: [
71 | /@babel\/runtime/,
72 | "dayjs/plugin/weekday",
73 | "dayjs/plugin/advancedFormat",
74 | "dayjs/plugin/customParseFormat",
75 | "dayjs/plugin/isBetween",
76 | "dayjs/plugin/isSameOrAfter",
77 | "dayjs/plugin/isSameOrBefore",
78 | ...Object.keys(pkg.dependencies || {}),
79 | ...Object.keys(pkg.peerDependencies || {})
80 | ]
81 | };
82 |
83 | export default config;
84 |
--------------------------------------------------------------------------------
/docs/component---src-docs-home-mdx-1efa576e828372a01f78.js:
--------------------------------------------------------------------------------
1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[22],{Rs4b:function(e,t,o){"use strict";o.r(t),o.d(t,"_frontmatter",(function(){return f})),o.d(t,"default",(function(){return O}));var a=o("Fcif"),n=o("+I+c"),r=(o("mXGw"),o("/FXl")),i=o("TjRS"),p=o("0BI5"),s=o("Uf7D"),c=o("Jpf6"),b=o("+tan"),m=o("CPF+"),u=o("Wo/x"),d=o("jGq8"),l=o("bD26"),h=o("i28S"),f=(o("aD51"),{});void 0!==f&&f&&f===Object(f)&&Object.isExtensible(f)&&!f.hasOwnProperty("__filemeta")&&Object.defineProperty(f,"__filemeta",{configurable:!0,value:{name:"_frontmatter",filename:"src/docs/home.mdx"}});var j={_frontmatter:f},x=i.a;function O(e){var t=e.components,o=Object(n.a)(e,["components"]);return Object(r.b)(x,Object(a.a)({},j,o,{components:t,mdxType:"MDXLayout"}),Object(r.b)(s.a,{mdxType:"Heading"},"use-date-input"),Object(r.b)(p.a,{mdxType:"Carousel"},Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/calendar",linkText:"Show Me",title:"Calendar",description:"Use as a single or date range calendar component",showBackground:!0,mdxType:"HeroWrapper"},Object(r.b)(b.a,{mdxType:"Hero1"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/composition",linkText:"Show Me",title:"Composable",description:"Compose into your own UI component",showBackground:!0,mdxType:"HeroWrapper"},Object(r.b)(m.a,{mdxType:"Hero2"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/useDateInput",linkText:"Show Me",title:"useDateInput Hook",description:"Compose with an input for single dates",mdxType:"HeroWrapper"},Object(r.b)(u.a,{mdxType:"Hero3"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/useDateRangeInput",linkText:"Show Me",title:"useDateRangeInput Hook",description:"Compose with multiple inputs for date ranges",mdxType:"HeroWrapper"},Object(r.b)(d.a,{mdxType:"Hero4"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/theming",linkText:"Show Me",title:"Themable",description:"Style it with your own theme",mdxType:"HeroWrapper"},Object(r.b)(l.a,{mdxType:"Hero5"})),Object(r.b)(h.a,{mdxType:"Hero6"})))}void 0!==O&&O&&O===Object(O)&&Object.isExtensible(O)&&!O.hasOwnProperty("__filemeta")&&Object.defineProperty(O,"__filemeta",{configurable:!0,value:{name:"MDXContent",filename:"src/docs/home.mdx"}}),O.isMDXComponent=!0}}]);
2 | //# sourceMappingURL=component---src-docs-home-mdx-1efa576e828372a01f78.js.map
--------------------------------------------------------------------------------
/docs/component---src-docs-home-mdx-527d2d622f429217b0ce.js:
--------------------------------------------------------------------------------
1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[22],{Rs4b:function(e,t,o){"use strict";o.r(t),o.d(t,"_frontmatter",(function(){return f})),o.d(t,"default",(function(){return O}));var a=o("Fcif"),n=o("+I+c"),r=(o("mXGw"),o("/FXl")),i=o("TjRS"),p=o("0BI5"),s=o("Uf7D"),c=o("Jpf6"),b=o("+tan"),m=o("CPF+"),d=o("Wo/x"),u=o("jGq8"),h=o("bD26"),l=o("i28S"),f=(o("aD51"),{});void 0!==f&&f&&f===Object(f)&&Object.isExtensible(f)&&!f.hasOwnProperty("__filemeta")&&Object.defineProperty(f,"__filemeta",{configurable:!0,value:{name:"_frontmatter",filename:"src/docs/home.mdx"}});var j={_frontmatter:f},x=i.a;function O(e){var t=e.components,o=Object(n.a)(e,["components"]);return Object(r.b)(x,Object(a.a)({},j,o,{components:t,mdxType:"MDXLayout"}),Object(r.b)(s.a,{mdxType:"Heading"},"use-date-input"),Object(r.b)(p.a,{mdxType:"Carousel"},Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/calendar",linkText:"Show Me",title:"Calendar",description:"Use as a single or date range calendar component",showBackground:!0,mdxType:"HeroWrapper"},Object(r.b)(b.a,{mdxType:"Hero1"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/composition",linkText:"Show Me",title:"Composable",description:"Compose into your own UI component",showBackground:!0,mdxType:"HeroWrapper"},Object(r.b)(m.a,{mdxType:"Hero2"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/useDateInput",linkText:"Show Me",title:"useDateInput Hook",description:"Compose with an input for single dates",mdxType:"HeroWrapper"},Object(r.b)(d.a,{mdxType:"Hero3"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/useDateRangeInput",linkText:"Show Me",title:"useDateRangeInput Hook",description:"Compose with an input for date ranges",mdxType:"HeroWrapper"},Object(r.b)(u.a,{mdxType:"Hero4"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/theming",linkText:"Show Me",title:"Themable",description:"Style it with your own theme",mdxType:"HeroWrapper"},Object(r.b)(h.a,{mdxType:"Hero5"})),Object(r.b)(l.a,{mdxType:"Hero6"})))}void 0!==O&&O&&O===Object(O)&&Object.isExtensible(O)&&!O.hasOwnProperty("__filemeta")&&Object.defineProperty(O,"__filemeta",{configurable:!0,value:{name:"MDXContent",filename:"src/docs/home.mdx"}}),O.isMDXComponent=!0}}]);
2 | //# sourceMappingURL=component---src-docs-home-mdx-527d2d622f429217b0ce.js.map
--------------------------------------------------------------------------------
/docs/component---src-docs-home-mdx-b43c4f7d6a42573c7588.js:
--------------------------------------------------------------------------------
1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[22],{Rs4b:function(e,t,o){"use strict";o.r(t),o.d(t,"_frontmatter",(function(){return f})),o.d(t,"default",(function(){return O}));var a=o("Fcif"),n=o("+I+c"),r=(o("mXGw"),o("/FXl")),i=o("TjRS"),p=o("0BI5"),s=o("Uf7D"),c=o("Jpf6"),b=o("+tan"),m=o("CPF+"),u=o("Wo/x"),d=o("jGq8"),l=o("bD26"),h=o("i28S"),f=(o("aD51"),{});void 0!==f&&f&&f===Object(f)&&Object.isExtensible(f)&&!f.hasOwnProperty("__filemeta")&&Object.defineProperty(f,"__filemeta",{configurable:!0,value:{name:"_frontmatter",filename:"src/docs/home.mdx"}});var j={_frontmatter:f},x=i.a;function O(e){var t=e.components,o=Object(n.a)(e,["components"]);return Object(r.b)(x,Object(a.a)({},j,o,{components:t,mdxType:"MDXLayout"}),Object(r.b)(s.a,{mdxType:"Heading"},"use-date-input"),Object(r.b)(p.a,{mdxType:"Carousel"},Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/calendar",linkText:"Show Me",title:"Calendar",description:"Use as a single or date range calendar component",showBackground:!0,mdxType:"HeroWrapper"},Object(r.b)(b.a,{mdxType:"Hero1"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/composition",linkText:"Show Me",title:"Composable",description:"Compose into your own UI component",showBackground:!0,mdxType:"HeroWrapper"},Object(r.b)(m.a,{mdxType:"Hero2"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/useDateInput",linkText:"Show Me",title:"useDateInput Hook",description:"Compose with an input for single dates",mdxType:"HeroWrapper"},Object(r.b)(u.a,{mdxType:"Hero3"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/useDateRangeInput",linkText:"Show Me",title:"useDateRangeInput Hook",description:"Compose with multiple inputs for date ranges",mdxType:"HeroWrapper"},Object(r.b)(d.a,{mdxType:"Hero4"})),Object(r.b)(c.a,{href:"https://mark-tate.github.io/use-date-input/theming",linkText:"Show Me",title:"Themable",description:"Style it with your own theme",mdxType:"HeroWrapper"},Object(r.b)(l.a,{mdxType:"Hero5"})),Object(r.b)(h.a,{mdxType:"Hero6"})))}void 0!==O&&O&&O===Object(O)&&Object.isExtensible(O)&&!O.hasOwnProperty("__filemeta")&&Object.defineProperty(O,"__filemeta",{configurable:!0,value:{name:"MDXContent",filename:"src/docs/home.mdx"}}),O.isMDXComponent=!0}}]);
2 | //# sourceMappingURL=component---src-docs-home-mdx-b43c4f7d6a42573c7588.js.map
--------------------------------------------------------------------------------
/docs/component---src-docs-hooks-use-calendar-state-mdx-839708fa49fb1650d779.js:
--------------------------------------------------------------------------------
1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[25],{"8sOg":function(e,t,a){"use strict";a.r(t),a.d(t,"_frontmatter",(function(){return u})),a.d(t,"default",(function(){return D}));var n=a("Fcif"),r=a("+I+c"),o=a("mXGw"),d=a("/FXl"),c=a("TjRS"),s=a("ZFoC"),l=a("GYKu"),b=a("Tmbg"),i=a("9b5V"),u=(a("aD51"),{});void 0!==u&&u&&u===Object(u)&&Object.isExtensible(u)&&!u.hasOwnProperty("__filemeta")&&Object.defineProperty(u,"__filemeta",{configurable:!0,value:{name:"_frontmatter",filename:"src/docs/hooks/useCalendarState.mdx"}});m="DateLabel";var m,p={_frontmatter:u},f=c.a;function D(e){var t,a=e.components,m=Object(r.a)(e,["components"]);return Object(d.b)(f,Object(n.a)({},p,m,{components:a,mdxType:"MDXLayout"}),Object(d.b)("h1",{id:"usecalendarstate"},"useCalendarState"),Object(d.b)("p",null,Object(d.b)("inlineCode",{parentName:"p"},"useCalendarState")," is a hook which will provide the current state of your components."),Object(d.b)("h2",{id:"example"},"Example"),Object(d.b)(s.c,{__position:0,__code:"() => {\n const DateLabel = () => {\n const { format, getDateFormat } = useDateAPI()\n const { startDate: selectedDate } = useCalendarState()\n let dateLabel = 'Select A Date'\n if (selectedDate) {\n const formatter = getDateFormat(formatNames.ARIA_DAY_LABEL)\n dateLabel = format(selectedDate, formatter)\n }\n return
{dateLabel}
\n }\n return (\n \n \n \n \n )\n}",__scope:(t={props:m,DefaultLayout:c.a,useState:o.useState,Playground:s.c,useDateAPI:l.t,useCalendarState:l.s,Calendar:l.c,CalendarProvider:l.d,formatNames:b.a,dateAdapter:i.a},t.DefaultLayout=c.a,t._frontmatter=u,t),mdxType:"Playground"},(function(){return Object(d.b)(l.d,{adapter:i.a,mdxType:"CalendarProvider"},Object(d.b)((function(){var e=Object(l.t)(),t=e.format,a=e.getDateFormat,n=Object(l.s)().startDate,r="Select A Date";n&&(r=t(n,a(b.a.ARIA_DAY_LABEL)));return Object(d.b)("p",{style:{padding:"8px"}},r)}),{mdxType:"DateLabel"}),Object(d.b)(l.c,{mdxType:"Calendar"}))})))}void 0!==D&&D&&D===Object(D)&&Object.isExtensible(D)&&!D.hasOwnProperty("__filemeta")&&Object.defineProperty(D,"__filemeta",{configurable:!0,value:{name:"MDXContent",filename:"src/docs/hooks/useCalendarState.mdx"}}),D.isMDXComponent=!0}}]);
2 | //# sourceMappingURL=component---src-docs-hooks-use-calendar-state-mdx-839708fa49fb1650d779.js.map
--------------------------------------------------------------------------------
/docs/component---src-docs-hooks-use-calendar-state-mdx-d273907bc340e564fb12.js:
--------------------------------------------------------------------------------
1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[25],{"8sOg":function(e,t,a){"use strict";a.r(t),a.d(t,"_frontmatter",(function(){return u})),a.d(t,"default",(function(){return D}));var n=a("Fcif"),r=a("+I+c"),o=a("mXGw"),d=a("/FXl"),c=a("TjRS"),s=a("ZFoC"),l=a("GYKu"),b=a("Tmbg"),i=a("9b5V"),u=(a("aD51"),{});void 0!==u&&u&&u===Object(u)&&Object.isExtensible(u)&&!u.hasOwnProperty("__filemeta")&&Object.defineProperty(u,"__filemeta",{configurable:!0,value:{name:"_frontmatter",filename:"src/docs/hooks/useCalendarState.mdx"}});m="DateLabel";var m,p={_frontmatter:u},f=c.a;function D(e){var t,a=e.components,m=Object(r.a)(e,["components"]);return Object(d.b)(f,Object(n.a)({},p,m,{components:a,mdxType:"MDXLayout"}),Object(d.b)("h1",{id:"usecalendarstate"},"useCalendarState"),Object(d.b)("p",null,Object(d.b)("inlineCode",{parentName:"p"},"useCalendarState")," is a hook which will provide the current state of your components."),Object(d.b)("h2",{id:"example"},"Example"),Object(d.b)(s.c,{__position:0,__code:"() => {\n const DateLabel = () => {\n const { format, getDateFormat } = useDateAPI()\n const { startDate: selectedDate } = useCalendarState()\n let dateLabel = 'Select A Date'\n if (selectedDate) {\n const formatter = getDateFormat(formatNames.ARIA_DAY_LABEL)\n dateLabel = format(selectedDate, formatter)\n }\n return
{dateLabel}
\n }\n return (\n \n \n \n \n )\n}",__scope:(t={props:m,DefaultLayout:c.a,useState:o.useState,Playground:s.c,useDateAPI:l.t,useCalendarState:l.s,Calendar:l.c,CalendarProvider:l.d,formatNames:b.a,dateAdapter:i.a},t.DefaultLayout=c.a,t._frontmatter=u,t),mdxType:"Playground"},(function(){return Object(d.b)(l.d,{adapter:i.a,mdxType:"CalendarProvider"},Object(d.b)((function(){var e=Object(l.t)(),t=e.format,a=e.getDateFormat,n=Object(l.s)().startDate,r="Select A Date";n&&(r=t(n,a(b.a.ARIA_DAY_LABEL)));return Object(d.b)("p",{style:{padding:"8px"}},r)}),{mdxType:"DateLabel"}),Object(d.b)(l.c,{mdxType:"Calendar"}))})))}void 0!==D&&D&&D===Object(D)&&Object.isExtensible(D)&&!D.hasOwnProperty("__filemeta")&&Object.defineProperty(D,"__filemeta",{configurable:!0,value:{name:"MDXContent",filename:"src/docs/hooks/useCalendarState.mdx"}}),D.isMDXComponent=!0}}]);
2 | //# sourceMappingURL=component---src-docs-hooks-use-calendar-state-mdx-d273907bc340e564fb12.js.map
--------------------------------------------------------------------------------
/docs/component---src-docs-hooks-use-calendar-state-mdx-d3b2db02444906b5abb9.js:
--------------------------------------------------------------------------------
1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[25],{"8sOg":function(e,t,a){"use strict";a.r(t),a.d(t,"_frontmatter",(function(){return i})),a.d(t,"default",(function(){return D}));var n=a("Fcif"),r=a("+I+c"),o=a("mXGw"),c=a("/FXl"),d=a("TjRS"),l=a("ZFoC"),s=a("GYKu"),b=a("Tmbg"),u=a("9b5V"),i=(a("aD51"),{});void 0!==i&&i&&i===Object(i)&&Object.isExtensible(i)&&!i.hasOwnProperty("__filemeta")&&Object.defineProperty(i,"__filemeta",{configurable:!0,value:{name:"_frontmatter",filename:"src/docs/hooks/useCalendarState.mdx"}});m="DateLabel";var m,p={_frontmatter:i},f=d.a;function D(e){var t,a=e.components,m=Object(r.a)(e,["components"]);return Object(c.b)(f,Object(n.a)({},p,m,{components:a,mdxType:"MDXLayout"}),Object(c.b)("h1",{id:"usecalendarstate"},"useCalendarState"),Object(c.b)("p",null,Object(c.b)("inlineCode",{parentName:"p"},"useCalendarState")," is a hook which will provide the current state of your components."),Object(c.b)("h2",{id:"example"},"Example"),Object(c.b)(l.c,{__position:0,__code:"() => {\n const DateLabel = () => {\n const { format, getDateFormat } = useDateAPI()\n const { startDate: selectedDate } = useCalendarState()\n let dateLabel = 'Select A Date'\n if (selectedDate) {\n const formatter = getDateFormat(formatNames.ARIA_DAY_LABEL)\n dateLabel = format(selectedDate, formatter)\n }\n return
38 | );
39 | fireEvent.mouseDown(getByTestId("inside-child"));
40 | expect(onClickOutside).not.toHaveBeenCalled();
41 | fireEvent.mouseDown(getByTestId("ignored-outside-child"));
42 | expect(onClickOutside).not.toHaveBeenCalled();
43 | fireEvent.mouseDown(getByTestId("outside-child"));
44 | expect(onClickOutside).toHaveBeenCalled();
45 | });
46 | });
47 |
--------------------------------------------------------------------------------
/packages/popper/src/index.js:
--------------------------------------------------------------------------------
1 | export { default as Popper } from "./Popper";
2 | export { default as ClickOutside } from "./ClickOutside";
3 |
--------------------------------------------------------------------------------
/public/cross.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
--------------------------------------------------------------------------------
/src/docs/components/clickOutside.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: ClickOutside
3 | route: /clickOutside
4 | ---
5 | import { useRef } from "react";
6 | import { Playground } from "docz";
7 | import { ClickOutside } from "@use-date-input/popper";
8 | import { Button } from "../../gatsby-theme-docz/components/Button";
9 | import { ButtonBar } from "../../gatsby-theme-docz/components/ButtonBar";
10 |
11 | # ClickOutside
12 | The `ClickOutside` component is used to detect when the mouse is clicked outside the calendar.
13 |
14 | In the default implementation `ClickOutside` is used to determine when to close the `Calendar` when rendered inside a `Popper`.
15 | Clicks within the `Calender` or on the associated inputs should not close the `Calendar` but everywhere else should.
16 |
17 | ## Example
18 | In this example when you click the buttons they log whether or not it considers it a click outside the rendered tree.
19 | In addition an ignored list of refs can be provided which, when clicked, will not invoke `onClickOutside`.
20 |
21 |
22 | {() => {
23 | const ignoreRef = useRef();
24 | const ignoreListRefs=[ignoreRef];
25 | function handleClickOutside() {
26 | console.log('you clicked outside the component');
27 | }
28 | return (
29 | <>
30 |
31 |
32 |
33 |
34 |
38 |
39 |
40 | >
41 | );
42 | }}
43 |
44 |
45 | ## Props
46 | | Prop Name | Type | Is Required | Default Value | Description |
47 | |-|-|-|-|-|
48 | | children| `node`| optional| | children to monitor for click outside events|
49 | | ignoreClickOutsideRefs| `array`| optional| | Additional array of refs, will ignore click outside from|
50 | | onClickOutside| `func`| optional| | Callback called when the mouse is clicked outside|
51 |
--------------------------------------------------------------------------------
/src/docs/components/dayOfWeek.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: DayOfWeek
3 | route: /dayOfWeek
4 | ---
5 | import { Playground } from "docz";
6 | import { DayOfWeek } from "@use-date-input/core";
7 |
8 | # DayOfWeek
9 | The `DayOfWeek` components renders a day of the week.
10 |
11 | In the default implementation, [WeekHeader](https://mark-tate.github.io/use-date-input/weekHeader) is the parent of `DayOfWeek`.
12 |
13 | ## Example
14 |
15 | M
16 |
17 |
18 | ## Props
19 | | Prop Name | Type | Is Required | Default Value | Description |
20 | |-|-|-|-|-|
21 | | children| `node`| optional| | Day of week node|
22 | | className| `string`| optional| | Class name of root element|
23 | | description| `string`| optional| | Day of week expanded label|
24 |
25 | ## Importing
26 | It can be imported as either the base component
27 |
28 | ```javascript
29 | import { DayOfWeek } from "@use-date-input/core";
30 | ```
31 |
32 | or as an overridable component that can be replaced through the `components` prop in `CalendarProvider`.
33 | Refer to [How to replace UI components](https://mark-tate.github.io/use-date-input/theming#how-to-replace-ui-components).
34 |
35 | ```javascript
36 | import { CustomisableDayOfWeek } from "@use-date-input/core";
37 | ```
38 |
39 | If providing your own component, it can be useful to import the base component and use it within your composition.
40 |
--------------------------------------------------------------------------------
/src/docs/components/header.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Header
3 | route: /header
4 | ---
5 | import { Playground } from "docz";
6 | import { Header, CalendarProvider } from "@use-date-input/core";
7 | import { adapter as dateAdapter } from '@use-date-input/date-fns-adapter';
8 |
9 | # Header
10 | The `Header` component renders the `Calendar` header.
11 |
12 | In the default implementation, [Root](https://mark-tate.github.io/use-date-input/root) is the parent of `Header`.
13 | By default `Header` uses the visibleFromDate and renders the current year as it's title, alongside the navigation buttons.
14 |
15 | ## Example
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | ## Props
25 | | Prop Name | Type | Is Required | Default Value | Description |
26 | |-|-|-|-|-|
27 | | className| `string`| optional| | Class name of root element|
28 |
29 | ## Importing
30 | It can be imported as either the base component
31 |
32 | ```javascript
33 | import { Header } from "@use-date-input/core";
34 | ```
35 |
36 | or as an overridable component that can be replaced through the `components` prop in `CalendarProvider`.
37 | Refer to [How to replace UI components](https://mark-tate.github.io/use-date-input/theming#how-to-replace-ui-components).
38 |
39 | ```javascript
40 | import { CustomisableHeader } from "@use-date-input/core";
41 | ```
42 |
43 | If providing your own component, it can be useful to import the base component and use it within your composition.
44 |
--------------------------------------------------------------------------------
/src/docs/components/month.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Month
3 | route: /month
4 | ---
5 | import { Playground } from "docz";
6 | import { Month, CalendarProvider, useDateAPI } from "@use-date-input/core";
7 | import { adapter as dateAdapter } from "@use-date-input/date-fns-adapter";
8 |
9 | # Month
10 | The `Month` components renders a calendar month.
11 |
12 | In the default implementation, [MonthGroup](https://mark-tate.github.io/use-date-input/monthGroup) is the parent of `Month`.
13 |
14 | ## Example
15 |
16 | {() => {
17 | function MonthExample() {
18 | const { createDate } = useDateAPI();
19 | const month = createDate();
20 | return ();
21 | }
22 | return (
23 |
24 |
25 |
26 | );
27 | }}
28 |
29 |
30 | ## Props
31 | | Prop Name | Type | Is Required | Default Value | Description |
32 | |-|-|-|-|-|
33 | | className| `string`| optional| | Class name of root element|
34 | | month| `object`| optional| | Month |
35 |
36 | ## Importing
37 | It can be imported as either the base component
38 |
39 | ```javascript
40 | import { Month } from "@use-date-input/core";
41 | ```
42 |
43 | or as an overridable component that can be replaced through the `components` prop in `CalendarProvider`.
44 | Refer to [How to replace UI components](https://mark-tate.github.io/use-date-input/theming#how-to-replace-ui-components).
45 |
46 | ```javascript
47 | import { CustomisableMonth } from "@use-date-input/core";
48 | ```
49 |
50 | If providing your own component, it can be useful to import the base component and use it within your composition.
51 |
52 |
--------------------------------------------------------------------------------
/src/docs/components/monthGroup.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: MonthGroup
3 | route: /monthGroup
4 | ---
5 | import { Playground } from "docz";
6 | import { MonthGroup, CalendarProvider, useDateAPI } from "@use-date-input/core";
7 | import { adapter as dateAdapter } from '@use-date-input/date-fns-adapter';
8 |
9 | # MonthGroup
10 | The `MonthGroup` components renders all the visible calendar `Month` components.
11 |
12 | ## Example
13 |
14 | {() => {
15 | function MonthGroupExample() {
16 | const { createDate } = useDateAPI();
17 | const visibleFromDate = createDate();
18 | return ();
19 | }
20 | return (
21 |
22 |
23 |
24 | );
25 | }}
26 |
27 |
28 | ## Props
29 | | Prop Name | Type | Is Required | Default Value | Description |
30 | |-|-|-|-|-|
31 | | className| `string`| optional| | Class name of root element|
32 | | visibleFromDate| `object`| optional| | Visible from date |
33 |
34 | ## Importing
35 | It can be imported as either the base component
36 |
37 | ```javascript
38 | import { MonthGroup } from "@use-date-input/core";
39 | ```
40 |
41 | or as an overridable component that can be replaced through the `components` prop in `CalendarProvider`.
42 | Refer to [How to replace UI components](https://mark-tate.github.io/use-date-input/theming#how-to-replace-ui-components).
43 |
44 | ```javascript
45 | import { CustomisableMonthGroup } from "@use-date-input/core";
46 | ```
47 |
48 | If providing your own component, it can be useful to import the base component and use it within your composition.
49 |
--------------------------------------------------------------------------------
/src/docs/components/root.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Root
3 | route: /root
4 | ---
5 | import { Playground } from "docz";
6 | import useMediaQuery from "@material-ui/core/useMediaQuery/useMediaQuery";
7 | import { useTheme } from "@material-ui/core/styles";
8 | import { Calendar, CalendarProvider, Root } from "@use-date-input/core";
9 | import { adapter as dateAdapter } from "@use-date-input/date-fns-adapter";
10 | import { DemoContent, DemoContentSmall } from "../../gatsby-theme-docz/components/DemoContent";
11 |
12 | # Root
13 | The `Root` component is the root component of the `Calendar`.
14 |
15 | `Root` enables you to re-compose the Calendar with additional UI elements, such as shortcut lists or additional branding.
16 | Refer to [Composition](https://mark-tate.github.io/use-date-input/composition).
17 |
18 | ## Example
19 |
20 | {() => {
21 | const theme = useTheme();
22 | const isSmallBreakpoint = useMediaQuery(theme.breakpoints.down("sm"));
23 | const AddYourComponentHere = isSmallBreakpoint ? DemoContentSmall : DemoContent;
24 | function MyRoot(props) {
25 | return (
26 | <>
27 |
28 |
29 |
30 |
31 | >
32 | );
33 | }
34 | return (
35 |
36 |
37 |
38 | );
39 | }}
40 |
41 |
42 | ## Props
43 | | Prop Name | Type | Is Required | Default Value | Description |
44 | |-|-|-|-|-|
45 | | className| `string`| optional| | Class name of root element|
46 |
47 | ## Importing
48 | It can be imported as either the base component
49 |
50 | ```javascript
51 | import { Root } from "@use-date-input/core";
52 | ```
53 |
54 | or as an overridable component that can be replaced through the `components` prop in `CalendarProvider`.
55 | Refer to [How to replace UI components](https://mark-tate.github.io/use-date-input/theming#how-to-replace-ui-components).
56 |
57 | ```javascript
58 | import { CustomisableMonthRoot } from "@use-date-input/core";
59 | ```
60 |
61 | If providing your own component, it can be useful to import the base component and use it within your composition.
62 |
--------------------------------------------------------------------------------
/src/docs/components/week.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Week
3 | route: /week
4 | ---
5 | import { Playground } from "docz";
6 | import { CalendarProvider, Week } from "@use-date-input/core";
7 | import { adapter as dateAdapter } from "@use-date-input/date-fns-adapter";
8 |
9 | # Week
10 | The `Week` components renders a week, as a row of `Day` components based on the current `Calendar` state.
11 |
12 | ## Example
13 |
14 | {() => {
15 | const { addDays, createDate } = dateAdapter();
16 | const today = createDate();
17 | const days = Array(7).fill(0).reduce((result, day, dayIndex) => {
18 | return [ ...result, addDays(today, dayIndex)];
19 | }, []);
20 | return (
21 |
22 |
23 |
24 | );
25 | }}
26 |
27 |
28 | ## Props
29 | | Prop Name | Type | Is Required | Default Value | Description |
30 | |-|-|-|-|-|
31 | | className| `string`| optional| | Class name of root element |
32 | | days| `array`| required| | Array of dates to render |
33 | | parentMonth| `object`| required| | to determine days of weeks, which are outside of current month |
34 |
35 | ## Importing
36 | It can be imported as either the base component
37 |
38 | ```javascript
39 | import { Week } from "@use-date-input/core";
40 | ```
41 |
42 | or as an overridable component that can be replaced through the `components` prop in `CalendarProvider`.
43 | Refer to [How to replace UI components](https://mark-tate.github.io/use-date-input/theming#how-to-replace-ui-components).
44 |
45 | ```javascript
46 | import { Week } from "@use-date-input/core";
47 | ```
48 |
49 | If providing your own component, it can be useful to import the base component and use it within your composition.
50 |
--------------------------------------------------------------------------------
/src/docs/components/weekHeader.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: WeekHeader
3 | route: /weekHeader
4 | ---
5 | import { Playground } from "docz";
6 | import { CalendarProvider, WeekHeader } from "@use-date-input/core";
7 | import { adapter as dateAdapter } from '@use-date-input/date-fns-adapter';
8 |
9 | # WeekHeader
10 | The `WeekHeader` component renders the days of the week within the month header.
11 |
12 | ## Example
13 |
14 | {() => {
15 | return (
16 |
17 |
18 |
19 | );
20 | }}
21 |
22 |
23 | ## Props
24 | | Prop Name | Type | Is Required | Default Value | Description |
25 | |-|-|-|-|-|
26 | | className| `string`| optional| | Class name of root element |
27 |
28 | ## Importing
29 | It can be imported as either the base component
30 |
31 | ```javascript
32 | import { WeekHeader } from "@use-date-input/core";
33 | ```
34 |
35 | or as an overridable component that can be replaced through the `components` prop in `CalendarProvider`.
36 | Refer to [How to replace UI components](https://mark-tate.github.io/use-date-input/theming#how-to-replace-ui-components).
37 |
38 | ```javascript
39 | import { WeekHeader } from "@use-date-input/core";
40 | ```
41 |
42 | If providing your own component, it can be useful to import the base component and use it within your composition.
43 |
--------------------------------------------------------------------------------
/src/docs/home.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: Home
3 | route: /
4 | fullPage: true
5 | ---
6 |
7 | import { Carousel } from "../gatsby-theme-docz/components/Carousel";
8 | import { Heading } from "../gatsby-theme-docz/components/Heading";
9 | import { HeroWrapper } from "../gatsby-theme-docz/components/HeroWrapper";
10 | import { Hero1 } from "../gatsby-theme-docz/components/Hero1";
11 | import { Hero2 } from "../gatsby-theme-docz/components/Hero2";
12 | import { Hero3 } from "../gatsby-theme-docz/components/Hero3";
13 | import { Hero4 } from "../gatsby-theme-docz/components/Hero4";
14 | import { Hero5 } from "../gatsby-theme-docz/components/Hero5";
15 | import { Hero6 } from "../gatsby-theme-docz/components/Hero6";
16 |
17 | use-date-input
18 |
19 |
26 |
27 |
28 |
35 |
36 |
37 |
43 |
44 |
45 |
51 |
52 |
53 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/docs/hooks/useCalendarDispatch.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: useCalendarDispatch
3 | route: /useCalendarDispatch
4 | ---
5 | import { Playground } from 'docz'
6 | import { calendarActions, useCalendarDispatch, Calendar, CalendarProvider} from '@use-date-input/core';
7 | import { adapter as dateAdapter } from "@use-date-input/date-fns-adapter";
8 | import { Button } from "../../gatsby-theme-docz/components/Button";
9 | import { ButtonBar } from "../../gatsby-theme-docz/components/ButtonBar";
10 |
11 | # useCalendarDispatch
12 | `useCalendarDispatch` returns the configured reducers dispatcher, along with a helper API for common actions.
13 |
14 | ```javascript
15 | const {
16 | dispatch,
17 | mouseClickOutside,
18 | navigateNext,
19 | navigatePrevious,
20 | selectDate,
21 | setAnimating,
22 | setEnableKeyboardNavigation,
23 | setKeyboardCursor,
24 | setMouseCursor,
25 | setEndDate,
26 | setStartDate,
27 | setOpen,
28 | setKeyPress,
29 | setVisibleFromDate
30 | } = useCalendarDispatch();
31 | ```
32 |
33 | ## Using the dispatcher
34 | Using the dispatcher we can dispatch any action to the reducers.
35 |
36 |
37 | {() => {
38 | const MyPanel = () => {
39 | const { dispatch } = useCalendarDispatch();
40 | const handleClick = () => dispatch({ type: calendarActions.navigateNext });
41 | return (
42 |
43 |
44 |
45 | );
46 | };
47 | return (
48 |
49 |
50 |
51 |
52 | );
53 | }}
54 |
55 |
56 | ## Using the helper API
57 | Using the dispatcher we can dispatch the most common actions, through helper methods.
58 |
59 |
60 | {() => {
61 | function MyPanel() {
62 | const { navigateNext } = useCalendarDispatch();
63 | const handleClick = () =>navigateNext();
64 | return (
65 |
66 |
67 |
68 | );
69 | };
70 | return (
71 |
72 |
73 |
74 |
75 | );
76 | }}
77 |
78 |
--------------------------------------------------------------------------------
/src/docs/hooks/useCalendarProps.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: useCalendarProps
3 | route: /useCalendarProps
4 | ---
5 | import { useState } from 'react';
6 | import { Playground } from 'docz'
7 | import { useDateAPI, useCalendarProps, Calendar, CalendarProvider} from '@use-date-input/core';
8 | import { formatNames } from '@use-date-input/common';
9 | import { adapter as dateAdapter } from '@use-date-input/date-fns-adapter';
10 |
11 | # useCalendarProps
12 |
13 | `useCalendarProps` is a hook which will provide the props provided to `CalendarProvider`.
14 |
15 | This hook can be used to add yuor own props to the context.
16 |
17 | ## Example
18 |
19 | {() => {
20 | const [selectedDate, setSelectedDate] = useState();
21 | const DateLabel = ({ selectedDate }) => {
22 | const { format, getDateFormat } = useDateAPI();
23 | const props = useCalendarProps();
24 | let dateLabel = 'Select A Date';
25 | if (selectedDate) {
26 | const formatter = getDateFormat(formatNames.ARIA_DAY_LABEL);
27 | dateLabel = format(selectedDate, formatter);
28 | }
29 | return (
{props.myExtraLabel}
{dateLabel}
);
30 | };
31 | return (
32 |
37 |
38 |
39 |
40 | );
41 | }}
42 |
43 |
--------------------------------------------------------------------------------
/src/docs/hooks/useCalendarState.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: useCalendarState
3 | route: /useCalendarState
4 | ---
5 | import { useState } from 'react';
6 | import { Playground } from 'docz'
7 | import { useDateAPI, useCalendarState, Calendar, CalendarProvider} from '@use-date-input/core';
8 | import { formatNames } from '@use-date-input/common';
9 | import { adapter as dateAdapter } from '@use-date-input/date-fns-adapter';
10 |
11 | # useCalendarState
12 |
13 | `useCalendarState` is a hook which will provide the current state of your components.
14 |
15 | ## Example
16 |
17 | {() => {
18 | const DateLabel = () => {
19 | const { format, getDateFormat } = useDateAPI();
20 | const { startDate:selectedDate } = useCalendarState();
21 | let dateLabel = 'Select A Date';
22 | if (selectedDate) {
23 | const formatter = getDateFormat(formatNames.ARIA_DAY_LABEL);
24 | dateLabel = format(selectedDate, formatter);
25 | }
26 | return (
{dateLabel}
);
27 | };
28 | return (
29 |
32 |
33 |
34 |
35 | );
36 | }}
37 |
38 |
--------------------------------------------------------------------------------
/src/docs/hooks/useDateAPI.mdx:
--------------------------------------------------------------------------------
1 | ---
2 | name: useDateAPI
3 | route: /useDateAPI
4 | ---
5 | import { useState } from 'react';
6 | import { Playground } from 'docz'
7 | import { useDateAPI, Calendar, CalendarProvider} from '@use-date-input/core';
8 | import { formatNames } from '@use-date-input/common';
9 | import { adapter as dateAdapter } from "@use-date-input/date-fns-adapter";
10 |
11 | # useDateAPI
12 |
13 | `useDateAPI` is a hook which will provide the dateAPI to any child of `CalendarProvider`.
14 |
15 | ## Example
16 |
17 | {() => {
18 | // import { useState } from "react";
19 | // import { formatNames } from '@use-date-input/common';
20 | // import { adapter as dateAdapter } from "@use-date-input/date-fns-adapter";
21 | // import { CalendarProvider, calendar, useDateAPI } from "@use-date-input/core";
22 | const [selectedDate, setSelectedDate] = useState();
23 | const DateLabel = ({ selectedDate }) => {
24 | const { format, getDateFormat } = useDateAPI();
25 | let dateLabel = 'Select A Date';
26 | if (selectedDate) {
27 | const formatter = getDateFormat(formatNames.ARIA_DAY_LABEL);
28 | dateLabel = format(selectedDate, formatter);
29 | }
30 | return (