UNPKG

@mui/x-date-pickers

Version:

The community edition of the MUI X Date and Time Picker components.

151 lines (149 loc) 5.62 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["localeText"]; import * as React from 'react'; import PropTypes from 'prop-types'; import { useThemeProps } from '@mui/material/styles'; import { jsx as _jsx } from "react/jsx-runtime"; export const PickerAdapterContext = /*#__PURE__*/React.createContext(null); // TODO v9: Remove this public export /** * The context that provides the date adapter and default dates to the pickers. * @deprecated Use `usePickersAdapter` hook if you need access to the adapter instead. */ if (process.env.NODE_ENV !== "production") PickerAdapterContext.displayName = "PickerAdapterContext"; export const MuiPickersAdapterContext = PickerAdapterContext; /** * Demos: * * - [Date format and localization](https://mui.com/x/react-date-pickers/adapters-locale/) * - [Calendar systems](https://mui.com/x/react-date-pickers/calendar-systems/) * - [Translated components](https://mui.com/x/react-date-pickers/localization/) * - [UTC and timezones](https://mui.com/x/react-date-pickers/timezone/) * * API: * * - [LocalizationProvider API](https://mui.com/x/api/date-pickers/localization-provider/) */ export const LocalizationProvider = function LocalizationProvider(inProps) { const { localeText: inLocaleText } = inProps, otherInProps = _objectWithoutPropertiesLoose(inProps, _excluded); const { adapter: parentAdapter, localeText: parentLocaleText } = React.useContext(PickerAdapterContext) ?? { utils: undefined, adapter: undefined, localeText: undefined }; const props = useThemeProps({ // We don't want to pass the `localeText` prop to the theme, that way it will always return the theme value, // We will then merge this theme value with our value manually props: otherInProps, name: 'MuiLocalizationProvider' }); const { children, dateAdapter: DateAdapter, dateFormats, dateLibInstance, adapterLocale, localeText: themeLocaleText } = props; const localeText = React.useMemo(() => _extends({}, themeLocaleText, parentLocaleText, inLocaleText), [themeLocaleText, parentLocaleText, inLocaleText]); const adapter = React.useMemo(() => { if (!DateAdapter) { if (parentAdapter) { return parentAdapter; } return null; } const dateAdapter = new DateAdapter({ locale: adapterLocale, formats: dateFormats, instance: dateLibInstance }); if (!dateAdapter.isMUIAdapter) { throw new Error(['MUI X: The date adapter should be imported from `@mui/x-date-pickers` or `@mui/x-date-pickers-pro`, not from `@date-io`', "For example, `import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'` instead of `import AdapterDayjs from '@date-io/dayjs'`", 'More information on the installation documentation: https://mui.com/x/react-date-pickers/quickstart/#installation'].join(`\n`)); } return dateAdapter; }, [DateAdapter, adapterLocale, dateFormats, dateLibInstance, parentAdapter]); const defaultDates = React.useMemo(() => { if (!adapter) { return null; } return { minDate: adapter.date('1900-01-01T00:00:00.000'), maxDate: adapter.date('2099-12-31T00:00:00.000') }; }, [adapter]); const contextValue = React.useMemo(() => { return { utils: adapter, adapter, defaultDates, localeText }; }, [defaultDates, adapter, localeText]); return /*#__PURE__*/_jsx(PickerAdapterContext.Provider, { value: contextValue, children: children }); }; if (process.env.NODE_ENV !== "production") LocalizationProvider.displayName = "LocalizationProvider"; process.env.NODE_ENV !== "production" ? LocalizationProvider.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "pnpm proptypes" | // ---------------------------------------------------------------------- /** * Locale for the date library you are using */ adapterLocale: PropTypes.any, children: PropTypes.node, /** * Date library adapter class function. * @see See the localization provider {@link https://mui.com/x/react-date-pickers/quickstart/#integrate-provider-and-adapter date adapter setup section} for more details. */ dateAdapter: PropTypes.func, /** * Formats that are used for any child pickers */ dateFormats: PropTypes.shape({ dayOfMonth: PropTypes.string, dayOfMonthFull: PropTypes.string, fullDate: PropTypes.string, fullTime12h: PropTypes.string, fullTime24h: PropTypes.string, hours12h: PropTypes.string, hours24h: PropTypes.string, keyboardDate: PropTypes.string, keyboardDateTime12h: PropTypes.string, keyboardDateTime24h: PropTypes.string, meridiem: PropTypes.string, minutes: PropTypes.string, month: PropTypes.string, monthShort: PropTypes.string, normalDate: PropTypes.string, normalDateWithWeekday: PropTypes.string, seconds: PropTypes.string, shortDate: PropTypes.string, weekday: PropTypes.string, weekdayShort: PropTypes.string, year: PropTypes.string }), /** * Date library instance you are using, if it has some global overrides * ```jsx * dateLibInstance={momentTimeZone} * ``` */ dateLibInstance: PropTypes.any, /** * Locale for components texts */ localeText: PropTypes.object } : void 0;