nepali-datepicker-reactjs
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -56,4 +56,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var initialState = { | ||
currentLocale: NEPALI | ||
var initialState = function initialState(minYear, maxYear) { | ||
return { | ||
currentLocale: NEPALI, | ||
minYear: minYear != null ? minYear : 2000, | ||
maxYear: maxYear != null ? maxYear : 2100 | ||
}; | ||
}; | ||
@@ -63,3 +67,3 @@ | ||
if (state === void 0) { | ||
state = initialState; | ||
state = initialState(); | ||
} | ||
@@ -80,9 +84,11 @@ | ||
}, | ||
state: initialState | ||
state: initialState() | ||
}); | ||
var ConfigProvider = function ConfigProvider(_ref) { | ||
var children = _ref.children; | ||
var children = _ref.children, | ||
minYear = _ref.minYear, | ||
maxYear = _ref.maxYear; | ||
var _useReducer = React.useReducer(ConfigReducer, initialState), | ||
var _useReducer = React.useReducer(ConfigReducer, initialState(minYear, maxYear)), | ||
state = _useReducer[0], | ||
@@ -265,2 +271,18 @@ dispatch = _useReducer[1]; | ||
if (year === 2081 && month === 2) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex + 1]; | ||
} | ||
if (year === 2081 && month === 3) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex - 1]; | ||
} | ||
if (year === 2081 && month === 11) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex] - 1; | ||
} | ||
if (year === 2081 && month === 12) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex] + 1; | ||
} | ||
if (year === 2085 && month === 5 || year === 2088 && month === 5) { | ||
@@ -506,3 +528,3 @@ return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex] - 2; | ||
var years = React.useMemo(function () { | ||
return range(2000, 2080).reverse().map(function (year) { | ||
return range(getConfig("minYear"), getConfig("maxYear")).reverse().map(function (year) { | ||
return { | ||
@@ -693,2 +715,5 @@ label: numberTrans(year), | ||
var _useConfig = useConfig(), | ||
getConfig = _useConfig.getConfig; | ||
React.useEffect(function () { | ||
@@ -720,2 +745,6 @@ var parsedDateValue = parseBSDate(value); | ||
if (year < getConfig("minYear") || year > getConfig("maxYear")) { | ||
return date; | ||
} | ||
return parseBSDate(stitchDate({ | ||
@@ -957,3 +986,6 @@ day: date.bsDay, | ||
}, [props.options]); | ||
return React__default.createElement(ConfigProvider, null, React__default.createElement(NepaliDatePicker, Object.assign({}, _extends({}, props, { | ||
return React__default.createElement(ConfigProvider, { | ||
maxYear: props.maxYear, | ||
minYear: props.minYear | ||
}, React__default.createElement(NepaliDatePicker, Object.assign({}, _extends({}, props, { | ||
options: calenderOptions | ||
@@ -960,0 +992,0 @@ })))); |
@@ -53,4 +53,8 @@ import React, { createContext, useReducer, useContext, useLayoutEffect, useState, useMemo, useCallback, useEffect, Fragment, useRef } from 'react'; | ||
var initialState = { | ||
currentLocale: NEPALI | ||
var initialState = function initialState(minYear, maxYear) { | ||
return { | ||
currentLocale: NEPALI, | ||
minYear: minYear != null ? minYear : 2000, | ||
maxYear: maxYear != null ? maxYear : 2100 | ||
}; | ||
}; | ||
@@ -60,3 +64,3 @@ | ||
if (state === void 0) { | ||
state = initialState; | ||
state = initialState(); | ||
} | ||
@@ -77,9 +81,11 @@ | ||
}, | ||
state: initialState | ||
state: initialState() | ||
}); | ||
var ConfigProvider = function ConfigProvider(_ref) { | ||
var children = _ref.children; | ||
var children = _ref.children, | ||
minYear = _ref.minYear, | ||
maxYear = _ref.maxYear; | ||
var _useReducer = useReducer(ConfigReducer, initialState), | ||
var _useReducer = useReducer(ConfigReducer, initialState(minYear, maxYear)), | ||
state = _useReducer[0], | ||
@@ -262,2 +268,18 @@ dispatch = _useReducer[1]; | ||
if (year === 2081 && month === 2) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex + 1]; | ||
} | ||
if (year === 2081 && month === 3) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex - 1]; | ||
} | ||
if (year === 2081 && month === 11) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex] - 1; | ||
} | ||
if (year === 2081 && month === 12) { | ||
return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex] + 1; | ||
} | ||
if (year === 2085 && month === 5 || year === 2088 && month === 5) { | ||
@@ -503,3 +525,3 @@ return bsMonthMaxDays[month - 1][bsMonthUpperDaysIndex] - 2; | ||
var years = useMemo(function () { | ||
return range(2000, 2080).reverse().map(function (year) { | ||
return range(getConfig("minYear"), getConfig("maxYear")).reverse().map(function (year) { | ||
return { | ||
@@ -690,2 +712,5 @@ label: numberTrans(year), | ||
var _useConfig = useConfig(), | ||
getConfig = _useConfig.getConfig; | ||
useEffect(function () { | ||
@@ -717,2 +742,6 @@ var parsedDateValue = parseBSDate(value); | ||
if (year < getConfig("minYear") || year > getConfig("maxYear")) { | ||
return date; | ||
} | ||
return parseBSDate(stitchDate({ | ||
@@ -954,3 +983,6 @@ day: date.bsDay, | ||
}, [props.options]); | ||
return React.createElement(ConfigProvider, null, React.createElement(NepaliDatePicker, Object.assign({}, _extends({}, props, { | ||
return React.createElement(ConfigProvider, { | ||
maxYear: props.maxYear, | ||
minYear: props.minYear | ||
}, React.createElement(NepaliDatePicker, Object.assign({}, _extends({}, props, { | ||
options: calenderOptions | ||
@@ -957,0 +989,0 @@ })))); |
import { FunctionComponent } from "react"; | ||
declare const ConfigProvider: FunctionComponent; | ||
import { IContextProviderProps } from "../Types"; | ||
declare const ConfigProvider: FunctionComponent<IContextProviderProps>; | ||
export default ConfigProvider; |
import { ConfigAction, ConfigState } from "./ConfigTypes"; | ||
export declare const initialState: ConfigState; | ||
export declare const initialState: (minYear?: number | undefined, maxYear?: number | undefined) => ConfigState; | ||
declare const ConfigReducer: (state: ConfigState | undefined, action: ConfigAction) => ConfigState; | ||
export default ConfigReducer; |
@@ -5,2 +5,4 @@ import { localeType } from "../Types"; | ||
currentLocale: localeType; | ||
minYear: number; | ||
maxYear: number; | ||
} | ||
@@ -7,0 +9,0 @@ export declare type ConfigValue = localeType; |
@@ -13,2 +13,7 @@ import { HTMLAttributes } from "react"; | ||
} | ||
export interface IContextProviderProps { | ||
minYear?: number; | ||
children: React.ReactNode; | ||
maxYear?: number; | ||
} | ||
export interface INepaliDatePicker { | ||
@@ -21,2 +26,4 @@ value: string; | ||
options: NepaliDatePickerOptions; | ||
minYear?: number; | ||
maxYear?: number; | ||
} | ||
@@ -34,2 +41,4 @@ export interface NepaliDatePickerProps { | ||
}; | ||
minYear?: INepaliDatePicker["minYear"]; | ||
maxYear?: INepaliDatePicker["maxYear"]; | ||
} | ||
@@ -36,0 +45,0 @@ export interface NepaliDatepickerEvents { |
{ | ||
"name": "nepali-datepicker-reactjs", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "Nepali Datepicker (Bikram Sambat) as a ReactJS component", | ||
@@ -44,2 +44,5 @@ "keywords": [ | ||
"build": "microbundle-crl --no-compress --format modern,cjs --css-modules false", | ||
"prepare": "yarn build", | ||
"version": "git add -A src", | ||
"postversion": "git push && git push --tags", | ||
"predeploy": "cd example && yarn install && yarn run build", | ||
@@ -54,3 +57,3 @@ "deploy": "gh-pages -d example/build" | ||
"peerDependencies": { | ||
"react": "^16.8.0" | ||
"react": "^18.2.0" | ||
}, | ||
@@ -63,4 +66,4 @@ "devDependencies": { | ||
"@types/node": "^12.12.38", | ||
"@types/react": "^16.9.27", | ||
"@types/react-dom": "^16.9.7", | ||
"@types/react": "^16.9.49", | ||
"@types/react-dom": "^16.9.8", | ||
"@typescript-eslint/eslint-plugin": "^2.26.0", | ||
@@ -84,9 +87,9 @@ "@typescript-eslint/parser": "^2.26.0", | ||
"microbundle-crl": "^0.13.10", | ||
"node-sass": "^4.14.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.0.4", | ||
"prettier-stylelint": "^0.4.2", | ||
"react": "^16.13.1", | ||
"react-scripts": "^3.4.1", | ||
"react": "^18.2.0", | ||
"react-scripts": "^5.0.1", | ||
"rimraf": "^3.0.2", | ||
"sass": "^1.77.5", | ||
"stylelint": "^13.6.1", | ||
@@ -105,5 +108,5 @@ "stylelint-config-standard": "^20.0.0", | ||
"dependencies": { | ||
"bikram-sambat-js": "^1.0.1", | ||
"bikram-sambat-js": "^1.0.2", | ||
"nepali-number": "^1.0.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
259563
2208
+ Addedreact@18.3.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact@16.14.0(transitive)
- Removedreact-is@16.13.1(transitive)
Updatedbikram-sambat-js@^1.0.2