rsuite 5.83.0 → 5.83.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [5.83.1](https://github.com/rsuite/rsuite/compare/v5.83.0...v5.83.1) (2025-06-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * allow TimePicker and TimeRangePicker locale prop to override global locale ([#4333](https://github.com/rsuite/rsuite/issues/4333)) ([6f66dfd](https://github.com/rsuite/rsuite/commit/6f66dfdc570c930b99e2954bc339446707947b92))
7
+
8
+
9
+
1
10
  # [5.83.0](https://github.com/rsuite/rsuite/compare/v5.82.0...v5.83.0) (2025-06-19)
2
11
 
3
12
 
@@ -16,12 +16,29 @@ var _excluded = ["locale"];
16
16
  function getDefaultRTL() {
17
17
  return typeof document !== 'undefined' && (document.body.getAttribute('dir') || document.dir) === 'rtl';
18
18
  }
19
- function toLocaleKey(componentName) {
20
- var Picker = ['Cascader', 'CheckTreePicker', 'MultiCascader', 'SelectPicker', 'TreePicker', 'CheckPicker', 'CheckTreePicker'];
21
- if (Picker.includes(componentName)) {
22
- return 'Combobox';
23
- }
24
- return componentName;
19
+
20
+ /**
21
+ * Maps a component name to its corresponding locale key
22
+ * @param componentName - The name of the component
23
+ * @returns The locale key for the component
24
+ */
25
+ function getComponentLocaleKey(componentName) {
26
+ // Define mappings for components that share locale keys
27
+ var localeKeyMappings = {
28
+ // All picker components use the Combobox locale
29
+ Cascader: 'Combobox',
30
+ CheckTreePicker: 'Combobox',
31
+ MultiCascader: 'Combobox',
32
+ SelectPicker: 'Combobox',
33
+ TreePicker: 'Combobox',
34
+ CheckPicker: 'Combobox',
35
+ // Time components use date components locales
36
+ TimePicker: 'DatePicker',
37
+ TimeRangePicker: 'DateRangePicker'
38
+ };
39
+
40
+ // Return the mapped locale key or the component name itself if no mapping exists
41
+ return localeKeyMappings[componentName] || componentName;
25
42
  }
26
43
 
27
44
  /**
@@ -69,7 +86,7 @@ function useCustom(componentName, componentProps) {
69
86
  //Memoize the global default props based on component name
70
87
  var globalDefaultProps = ((_components$component = components[componentName]) === null || _components$component === void 0 ? void 0 : _components$component.defaultProps) || {};
71
88
  var mergedProps = (0, _assign.default)({}, globalDefaultProps, restProps);
72
- var localeKey = toLocaleKey(componentName);
89
+ var localeKey = getComponentLocaleKey(componentName);
73
90
 
74
91
  // If the default locale has the component name, then merge the locale.
75
92
  if (Object.keys(_en_GB.default).includes(localeKey)) {
package/dist/rsuite.js CHANGED
@@ -2325,7 +2325,7 @@ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/he
2325
2325
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
2326
2326
 
2327
2327
  "use strict";
2328
- eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports[\"default\"] = void 0;\nexports.useCustom = useCustom;\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\nvar _react = __webpack_require__(/*! react */ \"react\");\nvar _assign = _interopRequireDefault(__webpack_require__(/*! lodash/assign */ \"./node_modules/lodash/assign.js\"));\nvar _en_GB = _interopRequireDefault(__webpack_require__(/*! ../locales/en_GB */ \"./src/locales/en_GB.ts\"));\nvar _date = __webpack_require__(/*! ../internals/utils/date */ \"./src/internals/utils/date/index.ts\");\nvar _CustomContext = __webpack_require__(/*! ./CustomContext */ \"./src/CustomProvider/CustomContext.tsx\");\nvar _excluded = [\"locale\"];\nfunction getDefaultRTL() {\n return typeof document !== 'undefined' && (document.body.getAttribute('dir') || document.dir) === 'rtl';\n}\nfunction toLocaleKey(componentName) {\n var Picker = ['Cascader', 'CheckTreePicker', 'MultiCascader', 'SelectPicker', 'TreePicker', 'CheckPicker', 'CheckTreePicker'];\n if (Picker.includes(componentName)) {\n return 'Combobox';\n }\n return componentName;\n}\n\n/**\n * A hook to get custom configuration of `<CustomProvider>`\n * @param componentName - The name of the component\n * @param componentProps - The props of the component\n */\nfunction useCustom(componentName, componentProps) {\n var _globalLocale$DateTim;\n var _useContext = (0, _react.useContext)(_CustomContext.CustomContext),\n _useContext$component = _useContext.components,\n components = _useContext$component === void 0 ? {} : _useContext$component,\n _useContext$locale = _useContext.locale,\n globalLocale = _useContext$locale === void 0 ? _en_GB.default : _useContext$locale,\n _useContext$rtl = _useContext.rtl,\n rtl = _useContext$rtl === void 0 ? getDefaultRTL() : _useContext$rtl,\n formatDate = _useContext.formatDate,\n parseDate = _useContext.parseDate,\n classPrefix = _useContext.classPrefix,\n toasters = _useContext.toasters,\n disableRipple = _useContext.disableRipple;\n var _ref = componentProps || {},\n componentLocale = _ref.locale,\n restProps = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);\n var dateLocale = globalLocale === null || globalLocale === void 0 || (_globalLocale$DateTim = globalLocale.DateTimeFormats) === null || _globalLocale$DateTim === void 0 ? void 0 : _globalLocale$DateTim.dateLocale;\n var code = globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale.code;\n var getLocale = (0, _react.useCallback)(function (key, overrideLocale) {\n // Initialize with common locale\n var publicLocale = (globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale.common) || {};\n\n // Merge component-specific locale(s) based on key type\n var specificLocale = typeof key === 'string' ? globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale[key] : Array.isArray(key) ? _assign.default.apply(void 0, [{}].concat(key.map(function (k) {\n return globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale[k];\n }))) : {};\n\n // Merge all parts: public locale, specific locale, custom component locale\n return (0, _assign.default)({}, publicLocale, specificLocale, componentLocale, overrideLocale);\n }, [globalLocale, componentLocale]);\n var propsWithDefaults = (0, _react.useMemo)(function () {\n var _components$component;\n if (!componentName) {\n return;\n }\n\n //Memoize the global default props based on component name\n var globalDefaultProps = ((_components$component = components[componentName]) === null || _components$component === void 0 ? void 0 : _components$component.defaultProps) || {};\n var mergedProps = (0, _assign.default)({}, globalDefaultProps, restProps);\n var localeKey = toLocaleKey(componentName);\n\n // If the default locale has the component name, then merge the locale.\n if (Object.keys(_en_GB.default).includes(localeKey)) {\n return (0, _extends2.default)({}, mergedProps, {\n locale: getLocale(localeKey)\n });\n }\n return mergedProps;\n }, [componentName, components, getLocale, restProps]);\n var _formatDate = (0, _react.useCallback)(function (date, formatStr, options) {\n try {\n if (formatDate) {\n return formatDate(date, formatStr, options);\n }\n return (0, _date.format)((0, _date.isValid)(date) ? date : new Date(), formatStr, (0, _extends2.default)({\n locale: dateLocale\n }, options));\n } catch (error) {\n if (true) {\n console.error('Error: Invalid date format', error);\n }\n return 'Error: Invalid date format';\n }\n }, [dateLocale, formatDate]);\n var _parseDate = (0, _react.useCallback)(function (dateString, formatString, referenceDate, options) {\n if (parseDate) {\n return parseDate(dateString, formatString, referenceDate, options);\n }\n return (0, _date.parse)(dateString, formatString, referenceDate || new Date(), (0, _extends2.default)({\n locale: dateLocale\n }, options));\n }, [parseDate, dateLocale]);\n return {\n code: code,\n rtl: rtl,\n toasters: toasters,\n disableRipple: disableRipple,\n classPrefix: classPrefix,\n propsWithDefaults: propsWithDefaults,\n getLocale: getLocale,\n formatDate: _formatDate,\n parseDate: _parseDate\n };\n}\nvar _default = exports[\"default\"] = useCustom;\n\n//# sourceURL=webpack://rsuite/./src/CustomProvider/useCustom.ts?");
2328
+ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports[\"default\"] = void 0;\nexports.useCustom = useCustom;\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\nvar _react = __webpack_require__(/*! react */ \"react\");\nvar _assign = _interopRequireDefault(__webpack_require__(/*! lodash/assign */ \"./node_modules/lodash/assign.js\"));\nvar _en_GB = _interopRequireDefault(__webpack_require__(/*! ../locales/en_GB */ \"./src/locales/en_GB.ts\"));\nvar _date = __webpack_require__(/*! ../internals/utils/date */ \"./src/internals/utils/date/index.ts\");\nvar _CustomContext = __webpack_require__(/*! ./CustomContext */ \"./src/CustomProvider/CustomContext.tsx\");\nvar _excluded = [\"locale\"];\nfunction getDefaultRTL() {\n return typeof document !== 'undefined' && (document.body.getAttribute('dir') || document.dir) === 'rtl';\n}\n\n/**\n * Maps a component name to its corresponding locale key\n * @param componentName - The name of the component\n * @returns The locale key for the component\n */\nfunction getComponentLocaleKey(componentName) {\n // Define mappings for components that share locale keys\n var localeKeyMappings = {\n // All picker components use the Combobox locale\n Cascader: 'Combobox',\n CheckTreePicker: 'Combobox',\n MultiCascader: 'Combobox',\n SelectPicker: 'Combobox',\n TreePicker: 'Combobox',\n CheckPicker: 'Combobox',\n // Time components use date components locales\n TimePicker: 'DatePicker',\n TimeRangePicker: 'DateRangePicker'\n };\n\n // Return the mapped locale key or the component name itself if no mapping exists\n return localeKeyMappings[componentName] || componentName;\n}\n\n/**\n * A hook to get custom configuration of `<CustomProvider>`\n * @param componentName - The name of the component\n * @param componentProps - The props of the component\n */\nfunction useCustom(componentName, componentProps) {\n var _globalLocale$DateTim;\n var _useContext = (0, _react.useContext)(_CustomContext.CustomContext),\n _useContext$component = _useContext.components,\n components = _useContext$component === void 0 ? {} : _useContext$component,\n _useContext$locale = _useContext.locale,\n globalLocale = _useContext$locale === void 0 ? _en_GB.default : _useContext$locale,\n _useContext$rtl = _useContext.rtl,\n rtl = _useContext$rtl === void 0 ? getDefaultRTL() : _useContext$rtl,\n formatDate = _useContext.formatDate,\n parseDate = _useContext.parseDate,\n classPrefix = _useContext.classPrefix,\n toasters = _useContext.toasters,\n disableRipple = _useContext.disableRipple;\n var _ref = componentProps || {},\n componentLocale = _ref.locale,\n restProps = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);\n var dateLocale = globalLocale === null || globalLocale === void 0 || (_globalLocale$DateTim = globalLocale.DateTimeFormats) === null || _globalLocale$DateTim === void 0 ? void 0 : _globalLocale$DateTim.dateLocale;\n var code = globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale.code;\n var getLocale = (0, _react.useCallback)(function (key, overrideLocale) {\n // Initialize with common locale\n var publicLocale = (globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale.common) || {};\n\n // Merge component-specific locale(s) based on key type\n var specificLocale = typeof key === 'string' ? globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale[key] : Array.isArray(key) ? _assign.default.apply(void 0, [{}].concat(key.map(function (k) {\n return globalLocale === null || globalLocale === void 0 ? void 0 : globalLocale[k];\n }))) : {};\n\n // Merge all parts: public locale, specific locale, custom component locale\n return (0, _assign.default)({}, publicLocale, specificLocale, componentLocale, overrideLocale);\n }, [globalLocale, componentLocale]);\n var propsWithDefaults = (0, _react.useMemo)(function () {\n var _components$component;\n if (!componentName) {\n return;\n }\n\n //Memoize the global default props based on component name\n var globalDefaultProps = ((_components$component = components[componentName]) === null || _components$component === void 0 ? void 0 : _components$component.defaultProps) || {};\n var mergedProps = (0, _assign.default)({}, globalDefaultProps, restProps);\n var localeKey = getComponentLocaleKey(componentName);\n\n // If the default locale has the component name, then merge the locale.\n if (Object.keys(_en_GB.default).includes(localeKey)) {\n return (0, _extends2.default)({}, mergedProps, {\n locale: getLocale(localeKey)\n });\n }\n return mergedProps;\n }, [componentName, components, getLocale, restProps]);\n var _formatDate = (0, _react.useCallback)(function (date, formatStr, options) {\n try {\n if (formatDate) {\n return formatDate(date, formatStr, options);\n }\n return (0, _date.format)((0, _date.isValid)(date) ? date : new Date(), formatStr, (0, _extends2.default)({\n locale: dateLocale\n }, options));\n } catch (error) {\n if (true) {\n console.error('Error: Invalid date format', error);\n }\n return 'Error: Invalid date format';\n }\n }, [dateLocale, formatDate]);\n var _parseDate = (0, _react.useCallback)(function (dateString, formatString, referenceDate, options) {\n if (parseDate) {\n return parseDate(dateString, formatString, referenceDate, options);\n }\n return (0, _date.parse)(dateString, formatString, referenceDate || new Date(), (0, _extends2.default)({\n locale: dateLocale\n }, options));\n }, [parseDate, dateLocale]);\n return {\n code: code,\n rtl: rtl,\n toasters: toasters,\n disableRipple: disableRipple,\n classPrefix: classPrefix,\n propsWithDefaults: propsWithDefaults,\n getLocale: getLocale,\n formatDate: _formatDate,\n parseDate: _parseDate\n };\n}\nvar _default = exports[\"default\"] = useCustom;\n\n//# sourceURL=webpack://rsuite/./src/CustomProvider/useCustom.ts?");
2329
2329
 
2330
2330
  /***/ }),
2331
2331