@basic-ui/dates 0.0.47 → 0.0.49

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.
@@ -1 +1 @@
1
- {"version":3,"file":"RangeDatePicker.js","names":["forwardRef","useRef","useState","assignMultipleRefs","adjustDates","RangeDatePickerProvider","RangeDatePicker","ref","as","Comp","minDate","propMinDate","Date","maxDate","propMaxDate","dayNames","monthNames","onChange","controlledFrom","from","controlledTo","to","defaultFrom","defaultTo","rest","isControlled","undefined","rangeDatePickerRef","stateFrom","stateTo","setDates","innerHasFocus","setInnerHasFocus","onChangeFrom","nextFrom","nextTo","onChangeTo","contextValue"],"sources":["../../../src/DatePicker/RangeDatePicker.tsx"],"sourcesContent":["import type { ElementType, HTMLAttributes, ReactNode } from 'react';\r\nimport { forwardRef, useRef, useState } from 'react';\r\nimport { assignMultipleRefs } from '@basic-ui/core';\r\n\r\nimport type { MonthNames, DayNames } from './dateTypes';\r\nimport { adjustDates } from './adjustDates';\r\nimport type { RangeDatePickerContextProps } from './contexts';\r\nimport { RangeDatePickerProvider } from './contexts';\r\n\r\nexport type RangeDatePickerProps = Omit<\r\n HTMLAttributes<HTMLDivElement>,\r\n 'onChange'\r\n> & {\r\n as?: ElementType<any>;\r\n minDate?: Date;\r\n maxDate?: Date;\r\n dayNames: DayNames;\r\n monthNames: MonthNames;\r\n children?: ReactNode[];\r\n onChange?: (from: Date | null, to: Date | null) => void;\r\n from?: Date | null;\r\n to?: Date | null;\r\n defaultFrom?: Date | null;\r\n defaultTo?: Date | null;\r\n};\r\n\r\nexport const RangeDatePicker = forwardRef<HTMLDivElement, RangeDatePickerProps>(\r\n function RangeDatePicker(\r\n {\r\n as: Comp = 'div',\r\n minDate: propMinDate = new Date(0),\r\n maxDate: propMaxDate = new Date(),\r\n dayNames,\r\n monthNames,\r\n onChange,\r\n from: controlledFrom,\r\n to: controlledTo,\r\n defaultFrom,\r\n defaultTo,\r\n ...rest\r\n },\r\n ref\r\n ) {\r\n const isControlled =\r\n controlledFrom !== undefined && controlledTo !== undefined;\r\n\r\n const minDate = propMinDate,\r\n maxDate = propMaxDate;\r\n\r\n const rangeDatePickerRef = useRef<HTMLDivElement | null>(null);\r\n const [{ from: stateFrom, to: stateTo }, setDates] = useState({\r\n from: (defaultFrom || null) as Date | null,\r\n to: (defaultTo || null) as Date | null,\r\n });\r\n const [innerHasFocus, setInnerHasFocus] = useState(false);\r\n\r\n const onChangeFrom = (from: Date | null) => {\r\n const to = stateTo;\r\n const { from: nextFrom, to: nextTo } = adjustDates(from, to, 'from');\r\n\r\n onChange && onChange(nextFrom, nextTo);\r\n setDates({ from: nextFrom, to: nextTo });\r\n };\r\n\r\n const onChangeTo = (to: Date | null) => {\r\n const from = stateFrom;\r\n const { from: nextFrom, to: nextTo } = adjustDates(from, to, 'to');\r\n\r\n onChange && onChange(nextFrom, nextTo);\r\n setDates({ from: nextFrom, to: nextTo });\r\n };\r\n\r\n const from = isControlled ? controlledFrom : stateFrom;\r\n const to = isControlled ? controlledTo : stateTo;\r\n\r\n const contextValue: RangeDatePickerContextProps = {\r\n rangeDatePickerRef,\r\n innerHasFocus,\r\n setInnerHasFocus,\r\n minDate,\r\n maxDate,\r\n from,\r\n to,\r\n dayNames,\r\n monthNames,\r\n onChangeFrom,\r\n onChangeTo,\r\n };\r\n\r\n return (\r\n <RangeDatePickerProvider value={contextValue}>\r\n <Comp\r\n ref={assignMultipleRefs(ref, rangeDatePickerRef)}\r\n data-has-focus={innerHasFocus ? '' : undefined}\r\n {...rest}\r\n />\r\n </RangeDatePickerProvider>\r\n );\r\n }\r\n);\r\n"],"mappings":";;;;AACA,SAASA,UAAT,EAAqBC,MAArB,EAA6BC,QAA7B,QAA6C,OAA7C;AACA,SAASC,kBAAT,QAAmC,gBAAnC;AAGA,SAASC,WAAT,QAA4B,eAA5B;AAEA,SAASC,uBAAT,QAAwC,YAAxC;;AAmBA,OAAO,IAAMC,eAAe,gBAAGN,UAAU,CACvC,SAAS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EsC,CAAlC"}
1
+ {"version":3,"file":"RangeDatePicker.js","names":["forwardRef","useRef","useState","assignMultipleRefs","adjustDates","RangeDatePickerProvider","jsx","_jsx","RangeDatePicker","_ref","ref","as","Comp","minDate","propMinDate","Date","maxDate","propMaxDate","dayNames","monthNames","onChange","from","controlledFrom","to","controlledTo","defaultFrom","defaultTo","rest","isControlled","undefined","rangeDatePickerRef","stateFrom","stateTo","setDates","innerHasFocus","setInnerHasFocus","onChangeFrom","nextFrom","nextTo","onChangeTo","contextValue","value","children"],"sources":["../../../src/DatePicker/RangeDatePicker.tsx"],"sourcesContent":["import type { ElementType, HTMLAttributes, ReactNode } from 'react';\nimport { forwardRef, useRef, useState } from 'react';\nimport { assignMultipleRefs } from '@basic-ui/core';\n\nimport type { MonthNames, DayNames } from './dateTypes';\nimport { adjustDates } from './adjustDates';\nimport type { RangeDatePickerContextProps } from './contexts';\nimport { RangeDatePickerProvider } from './contexts';\n\nexport type RangeDatePickerProps = Omit<\n HTMLAttributes<HTMLDivElement>,\n 'onChange'\n> & {\n as?: ElementType<any>;\n minDate?: Date;\n maxDate?: Date;\n dayNames: DayNames;\n monthNames: MonthNames;\n children?: ReactNode[];\n onChange?: (from: Date | null, to: Date | null) => void;\n from?: Date | null;\n to?: Date | null;\n defaultFrom?: Date | null;\n defaultTo?: Date | null;\n};\n\nexport const RangeDatePicker = forwardRef<HTMLDivElement, RangeDatePickerProps>(\n function RangeDatePicker(\n {\n as: Comp = 'div',\n minDate: propMinDate = new Date(0),\n maxDate: propMaxDate = new Date(),\n dayNames,\n monthNames,\n onChange,\n from: controlledFrom,\n to: controlledTo,\n defaultFrom,\n defaultTo,\n ...rest\n },\n ref\n ) {\n const isControlled =\n controlledFrom !== undefined && controlledTo !== undefined;\n\n const minDate = propMinDate,\n maxDate = propMaxDate;\n\n const rangeDatePickerRef = useRef<HTMLDivElement | null>(null);\n const [{ from: stateFrom, to: stateTo }, setDates] = useState({\n from: (defaultFrom || null) as Date | null,\n to: (defaultTo || null) as Date | null,\n });\n const [innerHasFocus, setInnerHasFocus] = useState(false);\n\n const onChangeFrom = (from: Date | null) => {\n const to = stateTo;\n const { from: nextFrom, to: nextTo } = adjustDates(from, to, 'from');\n\n onChange && onChange(nextFrom, nextTo);\n setDates({ from: nextFrom, to: nextTo });\n };\n\n const onChangeTo = (to: Date | null) => {\n const from = stateFrom;\n const { from: nextFrom, to: nextTo } = adjustDates(from, to, 'to');\n\n onChange && onChange(nextFrom, nextTo);\n setDates({ from: nextFrom, to: nextTo });\n };\n\n const from = isControlled ? controlledFrom : stateFrom;\n const to = isControlled ? controlledTo : stateTo;\n\n const contextValue: RangeDatePickerContextProps = {\n rangeDatePickerRef,\n innerHasFocus,\n setInnerHasFocus,\n minDate,\n maxDate,\n from,\n to,\n dayNames,\n monthNames,\n onChangeFrom,\n onChangeTo,\n };\n\n return (\n <RangeDatePickerProvider value={contextValue}>\n <Comp\n ref={assignMultipleRefs(ref, rangeDatePickerRef)}\n data-has-focus={innerHasFocus ? '' : undefined}\n {...rest}\n />\n </RangeDatePickerProvider>\n );\n }\n);\n"],"mappings":"AACA,SAASA,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACpD,SAASC,kBAAkB,QAAQ,gBAAgB;AAGnD,SAASC,WAAW,QAAQ,eAAe;AAE3C,SAASC,uBAAuB,QAAQ,YAAY;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAmBrD,OAAO,MAAMC,eAAe,gBAAGR,UAAU,CACvC,SAASQ,eAAeA,CAAAC,IAAA,EActBC,GAAG,EACH;EAAA,IAdA;IACEC,EAAE,EAAEC,IAAI,GAAG,KAAK;IAChBC,OAAO,EAAEC,WAAW,GAAG,IAAIC,IAAI,CAAC,CAAC,CAAC;IAClCC,OAAO,EAAEC,WAAW,GAAG,IAAIF,IAAI,CAAC,CAAC;IACjCG,QAAQ;IACRC,UAAU;IACVC,QAAQ;IACRC,IAAI,EAAEC,cAAc;IACpBC,EAAE,EAAEC,YAAY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AAQ;MAAEd,EAAE,EAAEe;IAAO,CAAC,CAAC;EAC1C,CAAC;EAED,MAAMjB,IAAI,GAAGO,YAAY,GAAGN,cAAc,GAAGS,SAAS;EACtD,MAAMR,EAAE,GAAGK,YAAY,GAAGJ,YAAY,GAAGQ,OAAO;EAEhD,MAAMQ,YAAyC,GAAG;IAChDV,kBAAkB;IAClBI,aAAa;IACbC,gBAAgB;IAChBtB,OAAO;IACPG,OAAO;IACPK,IAAI;IACJE,EAAE;IACFL,QAAQ;IACRC,UAAU;IACViB,YAAY;IACZG;EACF,CAAC;EAED,oBACEhC,IAAA,CAACF,uBAAuB;IAACoC,KAAK,EAAED,YAAa;IAAAE,QAAA,eAC3CnC,IAAA,CAACK,IAAI;MACHF,GAAG,EAAEP,kBAAkB,CAACO,GAAG,EAAEoB,kBAAkB,CAAE;MACjD,kBAAgBI,aAAa,GAAG,EAAE,GAAGL,SAAU;MAAA,GAC3CF;IAAI,CACT;EAAC,CACqB,CAAC;AAE9B,CACF,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- export declare function adjustDates(from: Date | null, to: Date | null, frozenParam: 'from' | 'to'): {
2
- from: Date | null;
3
- to: Date | null;
4
- };
1
+ export declare function adjustDates(from: Date | null, to: Date | null, frozenParam: 'from' | 'to'): {
2
+ from: Date | null;
3
+ to: Date | null;
4
+ };
@@ -9,10 +9,9 @@ export function adjustDates(from, to, frozenParam) {
9
9
  }
10
10
  }
11
11
  }
12
-
13
12
  return {
14
- from: from,
15
- to: to
13
+ from,
14
+ to
16
15
  };
17
16
  }
18
17
  //# sourceMappingURL=adjustDates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"adjustDates.js","names":["addDays","isValid","differenceInDays","adjustDates","from","to","frozenParam"],"sources":["../../../src/DatePicker/adjustDates.ts"],"sourcesContent":["import { addDays, isValid, differenceInDays } from 'date-fns';\r\n\r\nexport function adjustDates(\r\n from: Date | null,\r\n to: Date | null,\r\n frozenParam: 'from' | 'to'\r\n) {\r\n if (to && isValid(to) && from && isValid(from)) {\r\n if (differenceInDays(to, from) < 1) {\r\n if (frozenParam === 'from') {\r\n to = addDays(from, 1); // add one day\r\n } else {\r\n from = addDays(from, -1); // remove one day\r\n }\r\n }\r\n }\r\n\r\n return { from, to };\r\n}\r\n"],"mappings":"AAAA,SAASA,OAAT,EAAkBC,OAAlB,EAA2BC,gBAA3B,QAAmD,UAAnD;AAEA,OAAO,SAASC,WAAT,CACLC,IADK,EAELC,EAFK,EAGLC,WAHK,EAIL;EACA,IAAID,EAAE,IAAIJ,OAAO,CAACI,EAAD,CAAb,IAAqBD,IAArB,IAA6BH,OAAO,CAACG,IAAD,CAAxC,EAAgD;IAC9C,IAAIF,gBAAgB,CAACG,EAAD,EAAKD,IAAL,CAAhB,GAA6B,CAAjC,EAAoC;MAClC,IAAIE,WAAW,KAAK,MAApB,EAA4B;QAC1BD,EAAE,GAAGL,OAAO,CAACI,IAAD,EAAO,CAAP,CAAZ,CAD0B,CACH;MACxB,CAFD,MAEO;QACLA,IAAI,GAAGJ,OAAO,CAACI,IAAD,EAAO,CAAC,CAAR,CAAd,CADK,CACqB;MAC3B;IACF;EACF;;EAED,OAAO;IAAEA,IAAI,EAAJA,IAAF;IAAQC,EAAE,EAAFA;EAAR,CAAP;AACD"}
1
+ {"version":3,"file":"adjustDates.js","names":["addDays","isValid","differenceInDays","adjustDates","from","to","frozenParam"],"sources":["../../../src/DatePicker/adjustDates.ts"],"sourcesContent":["import { addDays, isValid, differenceInDays } from 'date-fns';\n\nexport function adjustDates(\n from: Date | null,\n to: Date | null,\n frozenParam: 'from' | 'to'\n) {\n if (to && isValid(to) && from && isValid(from)) {\n if (differenceInDays(to, from) < 1) {\n if (frozenParam === 'from') {\n to = addDays(from, 1); // add one day\n } else {\n from = addDays(from, -1); // remove one day\n }\n }\n }\n\n return { from, to };\n}\n"],"mappings":"AAAA,SAASA,OAAO,EAAEC,OAAO,EAAEC,gBAAgB,QAAQ,UAAU;AAE7D,OAAO,SAASC,WAAWA,CACzBC,IAAiB,EACjBC,EAAe,EACfC,WAA0B,EAC1B;EACA,IAAID,EAAE,IAAIJ,OAAO,CAACI,EAAE,CAAC,IAAID,IAAI,IAAIH,OAAO,CAACG,IAAI,CAAC,EAAE;IAC9C,IAAIF,gBAAgB,CAACG,EAAE,EAAED,IAAI,CAAC,GAAG,CAAC,EAAE;MAClC,IAAIE,WAAW,KAAK,MAAM,EAAE;QAC1BD,EAAE,GAAGL,OAAO,CAACI,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;MACzB,CAAC,MAAM;QACLA,IAAI,GAAGJ,OAAO,CAACI,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;MAC5B;IACF;EACF;EAEA,OAAO;IAAEA,IAAI;IAAEC;EAAG,CAAC;AACrB","ignoreList":[]}
@@ -1,31 +1,31 @@
1
- import type { MutableRefObject } from 'react';
2
- import type { MonthNames, DayNames } from './dateTypes';
3
- import type { ReducerState, ReducerActions } from './hooks';
4
- export interface RangeDatePickerContextProps {
5
- rangeDatePickerRef: MutableRefObject<HTMLDivElement | null>;
6
- innerHasFocus: boolean;
7
- setInnerHasFocus: (hasFocus: boolean) => void;
8
- minDate: Date;
9
- maxDate: Date;
10
- from?: Date | null;
11
- to?: Date | null;
12
- onChangeFrom: (d: Date | null) => void;
13
- onChangeTo: (d: Date | null) => void;
14
- dayNames: DayNames;
15
- monthNames: MonthNames;
16
- }
17
- export declare const RangeDatePickerProvider: import("react").Provider<RangeDatePickerContextProps | null>;
18
- export declare const useRangeDatePickerContext: () => RangeDatePickerContextProps | null;
19
- export interface DatePickerContextProps {
20
- minDate: Date;
21
- maxDate: Date;
22
- dayNames: DayNames;
23
- monthNames: MonthNames;
24
- datePickerRef: MutableRefObject<HTMLDivElement | null>;
25
- state: ReducerState;
26
- dispatch: (value: ReducerActions) => void;
27
- controlledValueRef: MutableRefObject<Date | null | undefined>;
28
- onChangeRef: MutableRefObject<((from: Date | null) => void) | undefined>;
29
- }
30
- export declare const useDatePickerContext: () => DatePickerContextProps;
31
- export declare const DatePickerProvider: import("react").Provider<DatePickerContextProps>;
1
+ import type { MutableRefObject } from 'react';
2
+ import type { MonthNames, DayNames } from './dateTypes';
3
+ import type { ReducerState, ReducerActions } from './hooks';
4
+ export interface RangeDatePickerContextProps {
5
+ rangeDatePickerRef: MutableRefObject<HTMLDivElement | null>;
6
+ innerHasFocus: boolean;
7
+ setInnerHasFocus: (hasFocus: boolean) => void;
8
+ minDate: Date;
9
+ maxDate: Date;
10
+ from?: Date | null;
11
+ to?: Date | null;
12
+ onChangeFrom: (d: Date | null) => void;
13
+ onChangeTo: (d: Date | null) => void;
14
+ dayNames: DayNames;
15
+ monthNames: MonthNames;
16
+ }
17
+ export declare const RangeDatePickerProvider: import("react").Provider<RangeDatePickerContextProps | null>;
18
+ export declare const useRangeDatePickerContext: () => RangeDatePickerContextProps | null;
19
+ export interface DatePickerContextProps {
20
+ minDate: Date;
21
+ maxDate: Date;
22
+ dayNames: DayNames;
23
+ monthNames: MonthNames;
24
+ datePickerRef: MutableRefObject<HTMLDivElement | null>;
25
+ state: ReducerState;
26
+ dispatch: (value: ReducerActions) => void;
27
+ controlledValueRef: MutableRefObject<Date | null | undefined>;
28
+ onChangeRef: MutableRefObject<((from: Date | null) => void) | undefined>;
29
+ }
30
+ export declare const useDatePickerContext: () => DatePickerContextProps;
31
+ export declare const DatePickerProvider: import("react").Provider<DatePickerContextProps>;
@@ -1,15 +1,18 @@
1
1
  import { createContext, useContext } from 'react';
2
- var rangeContext = /*#__PURE__*/createContext(null);
3
- var RangeDatePickerProvider = rangeContext.Provider;
4
- export { RangeDatePickerProvider };
5
- export var useRangeDatePickerContext = function useRangeDatePickerContext() {
6
- return useContext(rangeContext);
7
- }; // DatePicker
8
-
9
- var datePickerContext = /*#__PURE__*/createContext(null);
10
- export var useDatePickerContext = function useDatePickerContext() {
11
- return useContext(datePickerContext);
12
- };
13
- var DatePickerProvider = datePickerContext.Provider;
14
- export { DatePickerProvider };
2
+
3
+ // RangeDatePicker
4
+
5
+ const rangeContext = /*#__PURE__*/createContext(null);
6
+ export const {
7
+ Provider: RangeDatePickerProvider
8
+ } = rangeContext;
9
+ export const useRangeDatePickerContext = () => useContext(rangeContext);
10
+
11
+ // DatePicker
12
+
13
+ const datePickerContext = /*#__PURE__*/createContext(null);
14
+ export const useDatePickerContext = () => useContext(datePickerContext);
15
+ export const {
16
+ Provider: DatePickerProvider
17
+ } = datePickerContext;
15
18
  //# sourceMappingURL=contexts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contexts.js","names":["createContext","useContext","rangeContext","RangeDatePickerProvider","Provider","useRangeDatePickerContext","datePickerContext","useDatePickerContext","DatePickerProvider"],"sources":["../../../src/DatePicker/contexts.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\r\nimport { createContext, useContext } from 'react';\r\n\r\nimport type { MonthNames, DayNames } from './dateTypes';\r\nimport type { ReducerState, ReducerActions } from './hooks';\r\n\r\n// RangeDatePicker\r\nexport interface RangeDatePickerContextProps {\r\n rangeDatePickerRef: MutableRefObject<HTMLDivElement | null>;\r\n innerHasFocus: boolean;\r\n setInnerHasFocus: (hasFocus: boolean) => void;\r\n minDate: Date;\r\n maxDate: Date;\r\n from?: Date | null;\r\n to?: Date | null;\r\n onChangeFrom: (d: Date | null) => void;\r\n onChangeTo: (d: Date | null) => void;\r\n dayNames: DayNames;\r\n monthNames: MonthNames;\r\n}\r\n\r\nconst rangeContext = createContext<RangeDatePickerContextProps | null>(null);\r\nexport const { Provider: RangeDatePickerProvider } = rangeContext;\r\nexport const useRangeDatePickerContext = () => useContext(rangeContext);\r\n\r\n// DatePicker\r\nexport interface DatePickerContextProps {\r\n minDate: Date;\r\n maxDate: Date;\r\n dayNames: DayNames;\r\n monthNames: MonthNames;\r\n datePickerRef: MutableRefObject<HTMLDivElement | null>;\r\n state: ReducerState;\r\n dispatch: (value: ReducerActions) => void;\r\n controlledValueRef: MutableRefObject<Date | null | undefined>;\r\n onChangeRef: MutableRefObject<((from: Date | null) => void) | undefined>;\r\n}\r\nconst datePickerContext = createContext<DatePickerContextProps>(null as any);\r\nexport const useDatePickerContext = () => useContext(datePickerContext);\r\nexport const { Provider: DatePickerProvider } = datePickerContext;\r\n"],"mappings":"AACA,SAASA,aAAT,EAAwBC,UAAxB,QAA0C,OAA1C;AAoBA,IAAMC,YAAY,gBAAGF,aAAa,CAAqC,IAArC,CAAlC;AACO,IAAkBG,uBAAlB,GAA8CD,YAA9C,CAAQE,QAAR;;AACP,OAAO,IAAMC,yBAAyB,GAAG,SAA5BA,yBAA4B;EAAA,OAAMJ,UAAU,CAACC,YAAD,CAAhB;AAAA,CAAlC,C,CAEP;;AAYA,IAAMI,iBAAiB,gBAAGN,aAAa,CAAyB,IAAzB,CAAvC;AACA,OAAO,IAAMO,oBAAoB,GAAG,SAAvBA,oBAAuB;EAAA,OAAMN,UAAU,CAACK,iBAAD,CAAhB;AAAA,CAA7B;AACA,IAAkBE,kBAAlB,GAAyCF,iBAAzC,CAAQF,QAAR"}
1
+ {"version":3,"file":"contexts.js","names":["createContext","useContext","rangeContext","Provider","RangeDatePickerProvider","useRangeDatePickerContext","datePickerContext","useDatePickerContext","DatePickerProvider"],"sources":["../../../src/DatePicker/contexts.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { createContext, useContext } from 'react';\n\nimport type { MonthNames, DayNames } from './dateTypes';\nimport type { ReducerState, ReducerActions } from './hooks';\n\n// RangeDatePicker\nexport interface RangeDatePickerContextProps {\n rangeDatePickerRef: MutableRefObject<HTMLDivElement | null>;\n innerHasFocus: boolean;\n setInnerHasFocus: (hasFocus: boolean) => void;\n minDate: Date;\n maxDate: Date;\n from?: Date | null;\n to?: Date | null;\n onChangeFrom: (d: Date | null) => void;\n onChangeTo: (d: Date | null) => void;\n dayNames: DayNames;\n monthNames: MonthNames;\n}\n\nconst rangeContext = createContext<RangeDatePickerContextProps | null>(null);\nexport const { Provider: RangeDatePickerProvider } = rangeContext;\nexport const useRangeDatePickerContext = () => useContext(rangeContext);\n\n// DatePicker\nexport interface DatePickerContextProps {\n minDate: Date;\n maxDate: Date;\n dayNames: DayNames;\n monthNames: MonthNames;\n datePickerRef: MutableRefObject<HTMLDivElement | null>;\n state: ReducerState;\n dispatch: (value: ReducerActions) => void;\n controlledValueRef: MutableRefObject<Date | null | undefined>;\n onChangeRef: MutableRefObject<((from: Date | null) => void) | undefined>;\n}\nconst datePickerContext = createContext<DatePickerContextProps>(null as any);\nexport const useDatePickerContext = () => useContext(datePickerContext);\nexport const { Provider: DatePickerProvider } = datePickerContext;\n"],"mappings":"AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;;AAKjD;;AAeA,MAAMC,YAAY,gBAAGF,aAAa,CAAqC,IAAI,CAAC;AAC5E,OAAO,MAAM;EAAEG,QAAQ,EAAEC;AAAwB,CAAC,GAAGF,YAAY;AACjE,OAAO,MAAMG,yBAAyB,GAAGA,CAAA,KAAMJ,UAAU,CAACC,YAAY,CAAC;;AAEvE;;AAYA,MAAMI,iBAAiB,gBAAGN,aAAa,CAAyB,IAAW,CAAC;AAC5E,OAAO,MAAMO,oBAAoB,GAAGA,CAAA,KAAMN,UAAU,CAACK,iBAAiB,CAAC;AACvE,OAAO,MAAM;EAAEH,QAAQ,EAAEK;AAAmB,CAAC,GAAGF,iBAAiB","ignoreList":[]}
@@ -1,15 +1,15 @@
1
- export declare type DayNames = [string, string, string, string, string, string, string];
2
- export declare type MonthNames = [
3
- string,
4
- string,
5
- string,
6
- string,
7
- string,
8
- string,
9
- string,
10
- string,
11
- string,
12
- string,
13
- string,
14
- string
15
- ];
1
+ export type DayNames = [string, string, string, string, string, string, string];
2
+ export type MonthNames = [
3
+ string,
4
+ string,
5
+ string,
6
+ string,
7
+ string,
8
+ string,
9
+ string,
10
+ string,
11
+ string,
12
+ string,
13
+ string,
14
+ string
15
+ ];
@@ -1 +1 @@
1
- {"version":3,"file":"dateTypes.js","names":[],"sources":["../../../src/DatePicker/dateTypes.ts"],"sourcesContent":["export type DayNames = [string, string, string, string, string, string, string];\r\n\r\nexport type MonthNames = [\r\n string,\r\n string,\r\n string,\r\n string,\r\n string,\r\n string,\r\n string,\r\n string,\r\n string,\r\n string,\r\n string,\r\n string\r\n];\r\n"],"mappings":""}
1
+ {"version":3,"file":"dateTypes.js","names":[],"sources":["../../../src/DatePicker/dateTypes.ts"],"sourcesContent":["export type DayNames = [string, string, string, string, string, string, string];\n\nexport type MonthNames = [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string\n];\n"],"mappings":"","ignoreList":[]}
@@ -1,36 +1,36 @@
1
- export declare const FOCUS = "FOCUS";
2
- export declare const BLUR = "BLUR";
3
- export declare const NAVIGATE = "NAVIGATE";
4
- export declare const SET_DATE = "SET_DATE";
5
- export declare type ActionTypes = typeof FOCUS | typeof BLUR | typeof NAVIGATE | typeof SET_DATE;
6
- export interface ReducerState {
7
- isFocused: boolean;
8
- navigationYear: number;
9
- navigationMonth: number;
10
- navigationDay: number;
11
- selectedDate: Date | null;
12
- }
13
- interface FocusAction {
14
- type: typeof FOCUS;
15
- }
16
- interface NavigateAction {
17
- type: typeof NAVIGATE;
18
- year: number;
19
- month: number;
20
- day: number;
21
- }
22
- interface SetDateAction {
23
- type: typeof SET_DATE;
24
- selectedDate: Date | null;
25
- }
26
- interface BlurAction {
27
- type: typeof BLUR;
28
- selectedDate: Date | null;
29
- }
30
- export declare type ReducerActions = FocusAction | BlurAction | NavigateAction | SetDateAction;
31
- export declare function reducer(currentState: Readonly<ReducerState>, action: ReducerActions): ReducerState;
32
- export declare function useInnerFocus(): {
33
- handleFocus: () => void;
34
- handleBlur: () => void;
35
- };
36
- export {};
1
+ export declare const FOCUS = "FOCUS";
2
+ export declare const BLUR = "BLUR";
3
+ export declare const NAVIGATE = "NAVIGATE";
4
+ export declare const SET_DATE = "SET_DATE";
5
+ export type ActionTypes = typeof FOCUS | typeof BLUR | typeof NAVIGATE | typeof SET_DATE;
6
+ export interface ReducerState {
7
+ isFocused: boolean;
8
+ navigationYear: number;
9
+ navigationMonth: number;
10
+ navigationDay: number;
11
+ selectedDate: Date | null;
12
+ }
13
+ interface FocusAction {
14
+ type: typeof FOCUS;
15
+ }
16
+ interface NavigateAction {
17
+ type: typeof NAVIGATE;
18
+ year: number;
19
+ month: number;
20
+ day: number;
21
+ }
22
+ interface SetDateAction {
23
+ type: typeof SET_DATE;
24
+ selectedDate: Date | null;
25
+ }
26
+ interface BlurAction {
27
+ type: typeof BLUR;
28
+ selectedDate: Date | null;
29
+ }
30
+ export type ReducerActions = FocusAction | BlurAction | NavigateAction | SetDateAction;
31
+ export declare function reducer(currentState: Readonly<ReducerState>, action: ReducerActions): ReducerState;
32
+ export declare function useInnerFocus(): {
33
+ handleFocus: () => void;
34
+ handleBlur: () => void;
35
+ };
36
+ export {};
@@ -1,72 +1,78 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import { useRangeDatePickerContext, useDatePickerContext } from './contexts'; ////////////////////////////////////////////////////////////////////////////////
1
+ import { useRangeDatePickerContext, useDatePickerContext } from './contexts';
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
3
4
  // Actions
4
5
 
5
- export var FOCUS = 'FOCUS';
6
- export var BLUR = 'BLUR';
7
- export var NAVIGATE = 'NAVIGATE';
8
- export var SET_DATE = 'SET_DATE';
6
+ export const FOCUS = 'FOCUS';
7
+ export const BLUR = 'BLUR';
8
+ export const NAVIGATE = 'NAVIGATE';
9
+ export const SET_DATE = 'SET_DATE';
10
+
11
+ ////////////////////////////////////////////////////////////////////////////////
12
+ // Reducer
13
+
9
14
  export function reducer(currentState, action) {
10
15
  switch (action.type) {
11
16
  case FOCUS:
12
- return _extends(_extends({}, currentState), {}, {
17
+ return {
18
+ ...currentState,
13
19
  isFocused: true
14
- });
15
-
20
+ };
16
21
  case BLUR:
17
- return _extends(_extends({}, currentState), {}, {
22
+ return {
23
+ ...currentState,
18
24
  navigationYear: -1,
19
25
  navigationMonth: -1,
20
26
  navigationDay: -1,
21
27
  selectedDate: action.selectedDate,
22
28
  isFocused: false
23
- });
24
-
29
+ };
25
30
  case NAVIGATE:
26
- return _extends(_extends({}, currentState), {}, {
31
+ return {
32
+ ...currentState,
27
33
  navigationYear: action.year,
28
34
  navigationMonth: action.month,
29
35
  navigationDay: action.day
30
- });
31
-
36
+ };
32
37
  case SET_DATE:
33
38
  {
34
- return _extends(_extends({}, currentState), {}, {
39
+ return {
40
+ ...currentState,
35
41
  navigationYear: -1,
36
42
  navigationMonth: -1,
37
43
  navigationDay: -1,
38
44
  selectedDate: action.selectedDate
39
- });
45
+ };
40
46
  }
41
47
  }
42
- } ////////////////////////////////////////////////////////////////////////////////
48
+ }
49
+
50
+ ////////////////////////////////////////////////////////////////////////////////
43
51
  // Hooks
44
52
 
45
53
  export function useInnerFocus() {
46
- var _useDatePickerContext = useDatePickerContext(),
47
- dispatch = _useDatePickerContext.dispatch,
48
- onChangeRef = _useDatePickerContext.onChangeRef,
49
- datePickerRef = _useDatePickerContext.datePickerRef,
50
- _useDatePickerContext2 = _useDatePickerContext.state,
51
- selectedDate = _useDatePickerContext2.selectedDate,
52
- navigationMonth = _useDatePickerContext2.navigationMonth,
53
- navigationYear = _useDatePickerContext2.navigationYear,
54
- navigationDay = _useDatePickerContext2.navigationDay;
55
-
56
- var rangeCtx = useRangeDatePickerContext();
57
-
58
- var handleFocus = function handleFocus() {
54
+ const {
55
+ dispatch,
56
+ onChangeRef,
57
+ datePickerRef,
58
+ state: {
59
+ selectedDate,
60
+ navigationMonth,
61
+ navigationYear,
62
+ navigationDay
63
+ }
64
+ } = useDatePickerContext();
65
+ const rangeCtx = useRangeDatePickerContext();
66
+ const handleFocus = () => {
59
67
  dispatch({
60
68
  type: FOCUS
61
69
  });
62
-
63
70
  if (rangeCtx) {
64
71
  rangeCtx.setInnerHasFocus(true);
65
72
  }
66
73
  };
67
-
68
- var handleBlur = function handleBlur() {
69
- requestAnimationFrame(function () {
74
+ const handleBlur = () => {
75
+ requestAnimationFrame(() => {
70
76
  // we on want to close only if focus rests outside the datepicker
71
77
  if (datePickerRef.current && !datePickerRef.current.contains(document.activeElement)) {
72
78
  if (selectedDate && navigationYear >= 0 && navigationMonth >= 0 && navigationDay === -1) {
@@ -79,20 +85,18 @@ export function useInnerFocus() {
79
85
  } else {
80
86
  dispatch({
81
87
  type: BLUR,
82
- selectedDate: selectedDate
88
+ selectedDate
83
89
  });
84
90
  }
85
91
  }
86
-
87
92
  if (rangeCtx && rangeCtx.rangeDatePickerRef.current && !rangeCtx.rangeDatePickerRef.current.contains(document.activeElement)) {
88
93
  rangeCtx.setInnerHasFocus(false);
89
94
  }
90
95
  });
91
96
  };
92
-
93
97
  return {
94
- handleFocus: handleFocus,
95
- handleBlur: handleBlur
98
+ handleFocus,
99
+ handleBlur
96
100
  };
97
101
  }
98
102
  //# sourceMappingURL=hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","names":["useRangeDatePickerContext","useDatePickerContext","FOCUS","BLUR","NAVIGATE","SET_DATE","reducer","currentState","action","type","isFocused","navigationYear","navigationMonth","navigationDay","selectedDate","year","month","day","useInnerFocus","dispatch","onChangeRef","datePickerRef","state","rangeCtx","handleFocus","setInnerHasFocus","handleBlur","requestAnimationFrame","current","contains","document","activeElement","rangeDatePickerRef"],"sources":["../../../src/DatePicker/hooks.tsx"],"sourcesContent":["import { useRangeDatePickerContext, useDatePickerContext } from './contexts';\r\n\r\n////////////////////////////////////////////////////////////////////////////////\r\n// Actions\r\n\r\nexport const FOCUS = 'FOCUS';\r\n\r\nexport const BLUR = 'BLUR';\r\n\r\nexport const NAVIGATE = 'NAVIGATE';\r\n\r\nexport const SET_DATE = 'SET_DATE';\r\n\r\nexport type ActionTypes =\r\n | typeof FOCUS\r\n | typeof BLUR\r\n | typeof NAVIGATE\r\n | typeof SET_DATE;\r\n\r\n////////////////////////////////////////////////////////////////////////////////\r\n// Reducer\r\n\r\nexport interface ReducerState {\r\n isFocused: boolean;\r\n navigationYear: number;\r\n navigationMonth: number;\r\n navigationDay: number;\r\n selectedDate: Date | null;\r\n}\r\n\r\ninterface FocusAction {\r\n type: typeof FOCUS;\r\n}\r\n\r\ninterface NavigateAction {\r\n type: typeof NAVIGATE;\r\n year: number;\r\n month: number;\r\n day: number;\r\n}\r\ninterface SetDateAction {\r\n type: typeof SET_DATE;\r\n selectedDate: Date | null;\r\n}\r\n\r\ninterface BlurAction {\r\n type: typeof BLUR;\r\n selectedDate: Date | null;\r\n}\r\n\r\nexport type ReducerActions =\r\n | FocusAction\r\n | BlurAction\r\n | NavigateAction\r\n | SetDateAction;\r\n\r\nexport function reducer(\r\n currentState: Readonly<ReducerState>,\r\n action: ReducerActions\r\n): ReducerState {\r\n switch (action.type) {\r\n case FOCUS:\r\n return {\r\n ...currentState,\r\n isFocused: true,\r\n };\r\n case BLUR:\r\n return {\r\n ...currentState,\r\n navigationYear: -1,\r\n navigationMonth: -1,\r\n navigationDay: -1,\r\n selectedDate: action.selectedDate,\r\n isFocused: false,\r\n };\r\n case NAVIGATE:\r\n return {\r\n ...currentState,\r\n navigationYear: action.year,\r\n navigationMonth: action.month,\r\n navigationDay: action.day,\r\n };\r\n case SET_DATE: {\r\n return {\r\n ...currentState,\r\n navigationYear: -1,\r\n navigationMonth: -1,\r\n navigationDay: -1,\r\n selectedDate: action.selectedDate,\r\n };\r\n }\r\n }\r\n}\r\n\r\n////////////////////////////////////////////////////////////////////////////////\r\n// Hooks\r\n\r\nexport function useInnerFocus() {\r\n const {\r\n dispatch,\r\n onChangeRef,\r\n datePickerRef,\r\n state: { selectedDate, navigationMonth, navigationYear, navigationDay },\r\n } = useDatePickerContext();\r\n const rangeCtx = useRangeDatePickerContext();\r\n\r\n const handleFocus = () => {\r\n dispatch({ type: FOCUS });\r\n if (rangeCtx) {\r\n rangeCtx.setInnerHasFocus(true);\r\n }\r\n };\r\n\r\n const handleBlur = () => {\r\n requestAnimationFrame(() => {\r\n // we on want to close only if focus rests outside the datepicker\r\n if (\r\n datePickerRef.current &&\r\n !datePickerRef.current.contains(document.activeElement)\r\n ) {\r\n if (\r\n selectedDate &&\r\n navigationYear >= 0 &&\r\n navigationMonth >= 0 &&\r\n navigationDay === -1\r\n ) {\r\n // user started picking a new day, but haven't finished :(\r\n onChangeRef.current && onChangeRef.current(null);\r\n dispatch({ type: BLUR, selectedDate: null });\r\n } else {\r\n dispatch({ type: BLUR, selectedDate });\r\n }\r\n }\r\n\r\n if (\r\n rangeCtx &&\r\n rangeCtx.rangeDatePickerRef.current &&\r\n !rangeCtx.rangeDatePickerRef.current.contains(document.activeElement)\r\n ) {\r\n rangeCtx.setInnerHasFocus(false);\r\n }\r\n });\r\n };\r\n\r\n return { handleFocus, handleBlur };\r\n}\r\n"],"mappings":";AAAA,SAASA,yBAAT,EAAoCC,oBAApC,QAAgE,YAAhE,C,CAEA;AACA;;AAEA,OAAO,IAAMC,KAAK,GAAG,OAAd;AAEP,OAAO,IAAMC,IAAI,GAAG,MAAb;AAEP,OAAO,IAAMC,QAAQ,GAAG,UAAjB;AAEP,OAAO,IAAMC,QAAQ,GAAG,UAAjB;AA6CP,OAAO,SAASC,OAAT,CACLC,YADK,EAELC,MAFK,EAGS;EACd,QAAQA,MAAM,CAACC,IAAf;IACE,KAAKP,KAAL;MACE,6BACKK,YADL;QAEEG,SAAS,EAAE;MAFb;;IAIF,KAAKP,IAAL;MACE,6BACKI,YADL;QAEEI,cAAc,EAAE,CAAC,CAFnB;QAGEC,eAAe,EAAE,CAAC,CAHpB;QAIEC,aAAa,EAAE,CAAC,CAJlB;QAKEC,YAAY,EAAEN,MAAM,CAACM,YALvB;QAMEJ,SAAS,EAAE;MANb;;IAQF,KAAKN,QAAL;MACE,6BACKG,YADL;QAEEI,cAAc,EAAEH,MAAM,CAACO,IAFzB;QAGEH,eAAe,EAAEJ,MAAM,CAACQ,KAH1B;QAIEH,aAAa,EAAEL,MAAM,CAACS;MAJxB;;IAMF,KAAKZ,QAAL;MAAe;QACb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;UACLK,QAAQ,CAAC;YAAEV,IAAI,EAAEN,IAAR;YAAcW,YAAY,EAAZA;UAAd,CAAD,CAAR;QACD;MACF;;MAED,IACES,QAAQ,IACRA,QAAQ,CAACS,kBAAT,CAA4BJ,OAD5B,IAEA,CAACL,QAAQ,CAACS,kBAAT,CAA4BJ,OAA5B,CAAoCC,QAApC,CAA6CC,QAAQ,CAACC,aAAtD,CAHH,EAIE;QACAR,QAAQ,CAACE,gBAAT,CAA0B,KAA1B;MACD;IACF,CA3BoB,CAArB;EA4BD,CA7BD;;EA+BA,OAAO;IAAED,WAAW,EAAXA,WAAF;IAAeE,UAAU,EAAVA;EAAf,CAAP;AACD"}
1
+ {"version":3,"file":"hooks.js","names":["useRangeDatePickerContext","useDatePickerContext","FOCUS","BLUR","NAVIGATE","SET_DATE","reducer","currentState","action","type","isFocused","navigationYear","navigationMonth","navigationDay","selectedDate","year","month","day","useInnerFocus","dispatch","onChangeRef","datePickerRef","state","rangeCtx","handleFocus","setInnerHasFocus","handleBlur","requestAnimationFrame","current","contains","document","activeElement","rangeDatePickerRef"],"sources":["../../../src/DatePicker/hooks.tsx"],"sourcesContent":["import { useRangeDatePickerContext, useDatePickerContext } from './contexts';\n\n////////////////////////////////////////////////////////////////////////////////\n// Actions\n\nexport const FOCUS = 'FOCUS';\n\nexport const BLUR = 'BLUR';\n\nexport const NAVIGATE = 'NAVIGATE';\n\nexport const SET_DATE = 'SET_DATE';\n\nexport type ActionTypes =\n | typeof FOCUS\n | typeof BLUR\n | typeof NAVIGATE\n | typeof SET_DATE;\n\n////////////////////////////////////////////////////////////////////////////////\n// Reducer\n\nexport interface ReducerState {\n isFocused: boolean;\n navigationYear: number;\n navigationMonth: number;\n navigationDay: number;\n selectedDate: Date | null;\n}\n\ninterface FocusAction {\n type: typeof FOCUS;\n}\n\ninterface NavigateAction {\n type: typeof NAVIGATE;\n year: number;\n month: number;\n day: number;\n}\ninterface SetDateAction {\n type: typeof SET_DATE;\n selectedDate: Date | null;\n}\n\ninterface BlurAction {\n type: typeof BLUR;\n selectedDate: Date | null;\n}\n\nexport type ReducerActions =\n | FocusAction\n | BlurAction\n | NavigateAction\n | SetDateAction;\n\nexport function reducer(\n currentState: Readonly<ReducerState>,\n action: ReducerActions\n): ReducerState {\n switch (action.type) {\n case FOCUS:\n return {\n ...currentState,\n isFocused: true,\n };\n case BLUR:\n return {\n ...currentState,\n navigationYear: -1,\n navigationMonth: -1,\n navigationDay: -1,\n selectedDate: action.selectedDate,\n isFocused: false,\n };\n case NAVIGATE:\n return {\n ...currentState,\n navigationYear: action.year,\n navigationMonth: action.month,\n navigationDay: action.day,\n };\n case SET_DATE: {\n return {\n ...currentState,\n navigationYear: -1,\n navigationMonth: -1,\n navigationDay: -1,\n selectedDate: action.selectedDate,\n };\n }\n }\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// Hooks\n\nexport function useInnerFocus() {\n const {\n dispatch,\n onChangeRef,\n datePickerRef,\n state: { selectedDate, navigationMonth, navigationYear, navigationDay },\n } = useDatePickerContext();\n const rangeCtx = useRangeDatePickerContext();\n\n const handleFocus = () => {\n dispatch({ type: FOCUS });\n if (rangeCtx) {\n rangeCtx.setInnerHasFocus(true);\n }\n };\n\n const handleBlur = () => {\n requestAnimationFrame(() => {\n // we on want to close only if focus rests outside the datepicker\n if (\n datePickerRef.current &&\n !datePickerRef.current.contains(document.activeElement)\n ) {\n if (\n selectedDate &&\n navigationYear >= 0 &&\n navigationMonth >= 0 &&\n navigationDay === -1\n ) {\n // user started picking a new day, but haven't finished :(\n onChangeRef.current && onChangeRef.current(null);\n dispatch({ type: BLUR, selectedDate: null });\n } else {\n dispatch({ type: BLUR, selectedDate });\n }\n }\n\n if (\n rangeCtx &&\n rangeCtx.rangeDatePickerRef.current &&\n !rangeCtx.rangeDatePickerRef.current.contains(document.activeElement)\n ) {\n rangeCtx.setInnerHasFocus(false);\n }\n });\n };\n\n return { handleFocus, handleBlur };\n}\n"],"mappings":"AAAA,SAASA,yBAAyB,E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E5C,MAAMwB,WAAW,GAAGA,CAAA,KAAM;IACxBL,QAAQ,CAAC;MAAEV,IAAI,EAAEP;IAAM,CAAC,CAAC;IACzB,IAAIqB,QAAQ,EAAE;MACZA,QAAQ,CAACE,gBAAgB,CAAC,IAAI,CAAC;IACjC;EACF,CAAC;EAED,MAAMC,UAAU,GAAGA,CAAA,KAAM;IACvBC,qBAAqB,CAAC,MAAM;MAC1B;MACA,IACEN,aAAa,CAACO,OAAO,IACrB,CAACP,aAAa,CAACO,OAAO,CAACC,QAAQ,CAACC,QAAQ,CAACC,aAAa,CAAC,EACvD;QACA,IACEjB,YAAY,IACZH,cAAc,IAAI,CAAC,IACnBC,eAAe,IAAI,CAAC,IACpBC,aAAa,KAAK,CAAC,CAAC,EACpB;UACA;UACAO,WAAW,CAACQ,OAAO,IAAIR,WAAW,CAACQ,OAAO,CAAC,IAAI,CAAC;UAChDT,QAAQ,CAAC;YAAEV,IAAI,EAAEN,IAAI;YAAEW,YAAY,EAAE;UAAK,CAAC,CAAC;QAC9C,CAAC,MAAM;UACLK,QAAQ,CAAC;YAAEV,IAAI,EAAEN,IAAI;YAAEW;UAAa,CAAC,CAAC;QACxC;MACF;MAEA,IACES,QAAQ,IACRA,QAAQ,CAACS,kBAAkB,CAACJ,OAAO,IACnC,CAACL,QAAQ,CAACS,kBAAkB,CAACJ,OAAO,CAACC,QAAQ,CAACC,QAAQ,CAACC,aAAa,CAAC,EACrE;QACAR,QAAQ,CAACE,gBAAgB,CAAC,KAAK,CAAC;MAClC;IACF,CAAC,CAAC;EACJ,CAAC;EAED,OAAO;IAAED,WAAW;IAAEE;EAAW,CAAC;AACpC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- export * from './DatePicker';
2
- export * from './RangeDatePicker';
3
- export * from './DatePickerSelect';
4
- export * from './dateTypes';
5
- export * from './contexts';
1
+ export * from './DatePicker';
2
+ export * from './RangeDatePicker';
3
+ export * from './DatePickerSelect';
4
+ export * from './dateTypes';
5
+ export * from './contexts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/DatePicker/index.tsx"],"sourcesContent":["export * from './DatePicker';\r\nexport * from './RangeDatePicker';\r\nexport * from './DatePickerSelect';\r\nexport * from './dateTypes';\r\nexport * from './contexts';\r\n"],"mappings":"AAAA,cAAc,cAAd;AACA,cAAc,mBAAd;AACA,cAAc,oBAAd;AACA,cAAc,aAAd;AACA,cAAc,YAAd"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/DatePicker/index.tsx"],"sourcesContent":["export * from './DatePicker';\nexport * from './RangeDatePicker';\nexport * from './DatePickerSelect';\nexport * from './dateTypes';\nexport * from './contexts';\n"],"mappings":"AAAA,cAAc,cAAc;AAC5B,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,aAAa;AAC3B,cAAc,YAAY","ignoreList":[]}
@@ -1 +1 @@
1
- export * from './DatePicker';
1
+ export * from './DatePicker';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from './DatePicker';\r\n"],"mappings":"AAAA,cAAc,cAAd"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from './DatePicker';\n"],"mappings":"AAAA,cAAc,cAAc","ignoreList":[]}