index.tsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React from 'react';
  2. import { forwardStatics } from '@douyinfe/semi-foundation/utils/object';
  3. import { numbers, strings } from '@douyinfe/semi-foundation/datePicker/constants';
  4. import DatePicker, { DatePickerProps } from './datePicker';
  5. import ConfigContext from '../configProvider/context';
  6. import LocaleConsumer from '../locale/localeConsumer';
  7. import { Locale } from '../locale/interface';
  8. export { DateInputProps } from './dateInput';
  9. export { DatePickerProps } from './datePicker';
  10. export { MonthProps } from './month';
  11. export { MonthsGridProps } from './monthsGrid';
  12. export { QuickControlProps } from './quickControl';
  13. export { YearAndMonthProps } from './yearAndMonth';
  14. export default forwardStatics(
  15. React.forwardRef<DatePicker, DatePickerProps>((props, ref) => {
  16. const propsObj = { ...props };
  17. const { type, format, rangeSeparator } = propsObj;
  18. if (typeof format === 'string' && format) {
  19. if (!/[Hhms]+/.test(format)) {
  20. if (type === 'dateTime') {
  21. propsObj.type = 'date';
  22. } else if (type === 'dateTimeRange') {
  23. propsObj.type = 'dateRange';
  24. }
  25. }
  26. }
  27. // Add spaces at both ends to prevent conflicts with characters in the date when separating
  28. if (rangeSeparator && typeof rangeSeparator === 'string') {
  29. propsObj.rangeSeparator = ` ${rangeSeparator.trim()} `;
  30. }
  31. if (propsObj.insetInput) {
  32. if (!propsObj.position) {
  33. propsObj.position = strings.POSITION_INLINE_INPUT;
  34. }
  35. /**
  36. * When insetInput is `true` and `position` includes `over`, use 1px `spacing` to solve the problem of border-radius leakage in the upper left corner
  37. *
  38. * @see https://user-images.githubusercontent.com/26477537/158817185-126a5f33-41f7-414a-8e36-8d1be2dda5cd.png
  39. */
  40. if (propsObj.position.includes('Over') && !propsObj.spacing) {
  41. propsObj.spacing = numbers.SPACING_INSET_INPUT;
  42. }
  43. }
  44. return (
  45. <ConfigContext.Consumer>
  46. {({ timeZone }: { timeZone?: string | number }) => (
  47. <LocaleConsumer componentName={'DatePicker'}>
  48. {(locale: Locale['DatePicker'], localeCode: string, dateFnsLocale: Locale['dateFnsLocale']) => (
  49. <DatePicker
  50. timeZone={timeZone}
  51. localeCode={localeCode}
  52. locale={locale}
  53. dateFnsLocale={dateFnsLocale}
  54. {...propsObj}
  55. ref={ref}
  56. />
  57. )}
  58. </LocaleConsumer>
  59. )}
  60. </ConfigContext.Consumer>
  61. );
  62. }),
  63. DatePicker
  64. );
  65. export {
  66. BaseValueType,
  67. DayStatusType,
  68. DisabledDateOptions,
  69. DisabledDateType,
  70. DisabledTimeType,
  71. InputSize,
  72. Position,
  73. PresetType,
  74. PresetsType,
  75. TriggerRenderProps,
  76. ValidateStatus,
  77. ValueType,
  78. } from '@douyinfe/semi-foundation/datePicker/foundation';