Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor(design): refactor DatePicker (#5622)

白熱587a07c8d264
diff --git a/packages/design/package.json b/packages/design/package.json
index 9d70183c96..72615bdd1f 100644
--- a/packages/design/package.json
+++ b/packages/design/package.json
@@ -83,7 +83,6 @@
"dayjs": "^1.11.13",
"rc-dropdown": "^4.2.1",
"rc-menu": "^9.16.0",
- "rc-picker": "^4.9.0",
"rc-virtual-list": "^3.16.1",
"react-grid-layout": "^1.5.1",
"react-transition-group": "^4.4.5",
diff --git a/packages/design/src/components/calendar/Calendar.tsx b/packages/design/src/components/calendar/Calendar.tsx
index e9b49c16cd..126e6ca1a8 100644
--- a/packages/design/src/components/calendar/Calendar.tsx
+++ b/packages/design/src/components/calendar/Calendar.tsx
@@ -47,13 +47,15 @@ function DayButton(props: ButtonHTMLAttributes<HTMLButtonElement>) {
interface ICalendarProps {
className?: string;
+ showTime?: boolean;
+ max?: Date;
+ min?: Date;
value?: Date;
onValueChange?: (date: Date) => void;
- showTime?: boolean;
}
export function Calendar(props: ICalendarProps) {
- const { className, value, onValueChange, showTime = false } = props;
+ const { className, max, min, showTime = false, value, onValueChange } = props;
const { locale } = useContext(ConfigContext);
@@ -109,7 +111,19 @@ export function Calendar(props: ICalendarProps) {
return day && currentYear === today.getFullYear() && currentMonth === today.getMonth() && day === today.getDate();
}
+ function isDisabled(day: number) {
+ if (!day) return false;
+ const hours = value?.getHours() ?? today.getHours();
+ const minutes = value?.getMinutes() ?? today.getMinutes();
+ const seconds = value?.getSeconds() ?? today.getSeconds();
+ const d = new Date(currentYear, currentMonth, day, hours, minutes, seconds);
+ if (min && d < min) return true;
+ if (max && d > max) return true;
+ return false;
+ }
+
function handleChangeDate(day: number) {
+ if (isDisabled(day)) return;
const hours = value?.getHours() ?? today.getHours();
const minutes = value?.getMinutes() ?? today.getMinutes();
const seconds = value?.getSeconds() ?? today.getSeconds();
@@ -187,11 +201,13 @@ export function Calendar(props: ICalendarProps) {
key={idx}
className={clsx({
'!univer-bg-primary-600 univer-font-bold univer-text-white': isSelected(day),
- 'univer-hover:bg-primary-100 univer-cursor-pointer univer-text-gray-800': !isSelected(day),
+ 'univer-hover:bg-primary-100 univer-cursor-pointer univer-text-gray-800': !isSelected(day) && !isDisabled(day),
'dark:!univer-text-white': !isToday(day) && !isSelected(day),
'univer-font-semibold univer-text-primary-600 dark:!univer-text-primary-500': isToday(day),
+ 'univer-cursor-not-allowed univer-opacity-40': isDisabled(day),
})}
onClick={() => handleChangeDate(day)}
+ disabled={isDisabled(day)}
>
{day}
</DayButton>
diff --git a/packages/design/src/components/date-picker/DatePicker.stories.tsx b/packages/design/src/components/date-picker/DatePicker.stories.tsx
index 83ae04356b..f3fe8d664e 100644
--- a/packages/design/src/components/date-picker/DatePicker.stories.tsx
+++ b/packages/design/src/components/date-picker/DatePicker.stories.tsx
@@ -15,7 +15,6 @@
*/
import type { Meta } from '@storybook/react';
-import { dayjs } from '@univerjs/core';
import { useState } from 'react';
import { DatePicker } from './DatePicker';
@@ -32,10 +31,10 @@ export default meta;
export const DatePickerBasic = {
render() {
- const [value, setValue] = useState<dayjs.Dayjs>(dayjs());
+ const [value, setValue] = useState(new Date());
return (
- <DatePicker value={value} onChange={setValue} />
+ <DatePicker value={value} onValueChange={setValue} />
);
},
};
diff --git a/packages/design/src/components/date-picker/DatePicker.tsx b/packages/design/src/components/date-picker/DatePicker.tsx
index f889d36991..dae26c7ae5 100644
--- a/packages/design/src/components/date-picker/DatePicker.tsx
+++ b/packages/design/src/components/date-picker/DatePicker.tsx
@@ -14,49 +14,70 @@
* limitations under the License.
*/
-import type { dayjs } from '@univerjs/core';
-import type { PickerProps } from 'rc-picker';
import { CalendarIcon } from '@univerjs/icons';
-import RcPicker from 'rc-picker';
-import generateConfig from 'rc-picker/lib/generate/dayjs';
-import { useContext } from 'react';
-import { ConfigContext } from '../config-provider/ConfigProvider';
-import './index.css';
-
-/** @deprecated */
-export interface IDatePickerProps extends Omit<PickerProps<dayjs.Dayjs>, 'value' | 'onChange' | 'locale' | 'generateConfig' | 'prefixCls'> {
+import dayjs from 'dayjs';
+import { useState } from 'react';
+import { borderClassName } from '../../helper/class-utilities';
+import { clsx } from '../../helper/clsx';
+import { Calendar } from '../calendar/Calendar';
+import { Dropdown } from '../dropdown/Dropdown';
+
+interface IDatePickerProps {
+ /**
+ * Additional CSS classes for the date picker.
+ */
+ className?: string;
+
/**
* The value of the date picker.
*/
- value: dayjs.Dayjs;
+ value?: Date;
/**
* Callback when the value of the date picker changes.
*/
- onChange: (date: dayjs.Dayjs, dateString: string) => void;
+ onValueChange?: (date: Date) => void;
}
-/** @deprecated */
export function DatePicker(props: IDatePickerProps) {
- const { value, onChange, ...ext } = props;
+ const { value, onValueChange, className } = props;
- const { locale } = useContext(ConfigContext);
+ const [open, setOpen] = useState(false);
- function handleChange(date: dayjs.Dayjs | dayjs.Dayjs[], dateString: string | string[]) {
- if (!Array.isArray(date) && !Array.isArray(dateString)) {
- onChange(date, dateString);
- }
+ function handleValueChange(date: Date) {
+ onValueChange?.(date);
+ setOpen(false);
}
return (
- <RcPicker<dayjs.Dayjs>
- {...ext}
- value={value}
- prefixCls="univer-date-picker"
- generateConfig={generateConfig}
- locale={locale?.Picker!}
- suffixIcon={<CalendarIcon className="univer-date-picker-suffix-icon" />}
- onChange={handleChange}
- />
+ <Dropdown
+ align="start"
+ overlay={(
+ <div className="univer-p-2">
+ <Calendar value={value} onValueChange={handleValueChange} />
+ </div>
+ )}
+ open={open}
+ onOpenChange={setOpen}
+ >
+ <button
+ className={clsx(`
+ univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md
+ univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all
+ hover:univer-border-primary-600
+ dark:!univer-text-white
+ `, borderClassName, className)}
+ type="button"
+ >
+ {dayjs(value).format('YYYY-MM-DD')}
+
+ <CalendarIcon
+ className={`
+ univer-text-gray-600
+ dark:!univer-text-gray-400
+ `}
+ />
+ </button>
+ </Dropdown>
);
}
diff --git a/packages/design/src/components/date-picker/index.css b/packages/design/src/components/date-picker/index.css
deleted file mode 100644
index a8dc117e30..0000000000
--- a/packages/design/src/components/date-picker/index.css
+++ /dev/null
@@ -1,337 +0,0 @@
-.univer-date-picker {
- position: relative;
- width: 200px;
- height: 32px;
- border-radius: 4px;
- box-sizing: border-box;
- display: inline-flex;
- @apply univer-bg-white univer-border univer-border-solid univer-border-gray-200;
- @apply univer-text-gray-900;
-}
-.univer-dark .univer-date-picker {
- @apply univer-text-white univer-bg-gray-900 univer-border-gray-600;
-}
-
-.univer-date-picker-rtl {
- direction: rtl;
-}
-
-.univer-date-picker-invalid {
- box-shadow: 0 0 2px red;
-}
-
-.univer-date-picker-panel {
- display: inline-block;
- vertical-align: top;
-}
-
-.univer-date-picker-panel-focused {
- border-color: blue;
-}
-
-.univer-date-picker-panel-rtl {
- direction: rtl;
-}
-
-.univer-date-picker-suffix-icon {
- position: absolute;
- top: 50%;
- right: 0;
- bottom: 0;
- display: flex;
- align-items: center;
- padding: 0 8px;
- transform: translateY(-50%);
- cursor: pointer;
- @apply univer-text-gray-600;
-}
-.univer-dark .univer-date-picker-suffix-icon {
- @apply univer-text-gray-200;
-}
-
-.univer-date-picker-decade-panel,
-.univer-date-picker-year-panel,
-.univer-date-picker-month-panel,
-.univer-date-picker-week-panel,
-.univer-date-picker-date-panel,
-.univer-date-picker-time-panel {
- display: flex;
- flex-direction: column;
-}
-
-.univer-date-picker-decade-panel table,
-.univer-date-picker-year-panel table,
-.univer-date-picker-month-panel table,
-.univer-date-picker-week-panel table,
-.univer-date-picker-date-panel table,
-.univer-date-picker-time-panel table {
- text-align: center;
- border-collapse: collapse;
-}
-
-/* Header */
-.univer-date-picker-header {
- margin-bottom: 12px;
- display: flex;
- align-items: center;
-}
-
-.univer-date-picker-header > * {
- flex: none;
-}
-
-.univer-date-picker-header-view {
- height: 16px;
- flex: auto;
- display: flex;
- justify-content: center;
- align-items: center;
- gap: 8px;
-}
-
-.univer-date-picker-header-view > button {
- padding: 0;
- border: 0;
- background-color: transparent;
- cursor: pointer;
- @apply univer-text-gray-900;
-}
-.univer-dark .univer-date-picker-header-view > button {
- @apply univer-text-white;
-}
-
-.univer-date-picker-header-super-prev-btn,
-.univer-date-picker-header-super-next-btn,
-.univer-date-picker-header-prev-btn,
-.univer-date-picker-header-next-btn {
- width: 16px;
- height: 16px;
- padding: 0;
- line-height: 16px;
- font-size: 16px;
- border: none;
- background-color: transparent;
- cursor: pointer;
- @apply univer-text-gray-600;
-}
-.univer-dark .univer-date-picker-header-super-prev-btn,
-.univer-dark .univer-date-picker-header-super-next-btn,
-.univer-dark .univer-date-picker-header-prev-btn,
-.univer-dark .univer-date-picker-header-next-btn {
- @apply univer-text-gray-200;
-}
-
-/* Content */
-.univer-date-picker-cell {
- @apply univer-text-gray-600;
-}
-.univer-dark .univer-date-picker-cell {
- @apply univer-text-gray-200;
-}
-
-.univer-date-picker-cell-disabled {
- opacity: 0.2;
-}
-
-.univer-date-picker-cell-inner {
- display: inline-block;
- box-sizing: border-box;
- width: 100%;
- height: 24px;
- margin: 0;
- padding: 0;
- font-size: 12px;
- line-height: 24px;
- background: transparent;
- border: 0;
- border-radius: 4px;
- outline: none;
- cursor: pointer;
- transition: background 0.3s;
- @apply univer-px-1.5;
-}
-
-.univer-date-picker-cell-in-view {
- color: #333;
-}
-
-.univer-date-picker-cell-in-range > .univer-date-picker-cell-inner {
- background: rgba(0, 0, 255, 0.05);
-}
-
-.univer-date-picker-cell-hover > .univer-date-picker-cell-inner {
- @apply hover:univer-bg-gray-100;
-}
-
-.univer-date-picker-cell-range-hover-start::after,
-.univer-date-picker-cell-range-hover-end::after,
-.univer-date-picker-cell-range-hover::after {
- position: absolute;
- top: 3px;
- right: 0;
- bottom: 0;
- left: 0;
- border: 1px solid green;
- border-right: 0;
- border-left: 0;
- content: '';
- pointer-events: none;
-}
-
-.univer-date-picker-cell-range-hover-start::after {
- border-left: 1px solid green !important;
-}
-
-.univer-date-picker-cell-range-hover-end::after {
- border-right: 1px solid green !important;
-}
-
-.univer-date-picker-cell-today > .univer-date-picker-cell-inner {
- @apply univer-border univer-border-solid univer-border-primary-600;
-}
-
-.univer-date-picker-cell-range-start > .univer-date-picker-cell-inner,
-.univer-date-picker-cell-range-end > .univer-date-picker-cell-inner,
-.univer-date-picker-cell-selected > .univer-date-picker-cell-inner {
- color: #fff;
- @apply univer-bg-primary-600;
-}
-
-/* Preset */
-.univer-date-picker-presets {
- background: #ccccff;
-}
-
-.univer-date-picker-presets ul {
- margin: 0;
- padding: 0;
- list-style: none;
-}
-
-/* Now Button */
-.univer-date-picker-now {
- padding-top: 12px;
-}
-
-.univer-date-picker-now-btn {
- font-size: 13px;
- cursor: pointer;
- @apply univer-text-primary-600;
-}
-
-/* Footer */
-.univer-date-picker-footer,
-.univer-date-picker-picker-footer {
- margin-top: 12px;
- @apply univer-border-0 univer-border-t univer-border-solid univer-border-t-gray-200;
-}
-
-.univer-date-picker-ranges {
- @apply univer-list-none univer-m-0 univer-p-0 univer-flex univer-items-center univer-justify-center;
-}
-
-/* Clear Button */
-.univer-date-picker-clear {
- position: absolute;
- top: 7px;
- right: 8px;
- cursor: pointer;
-}
-
-.univer-date-picker-clear-btn {
- width: 16px;
- height: 16px;
- text-align: center;
- line-height: 16px;
- border-radius: 50%;
- display: block;
- @apply univer-bg-gray-500;
-}
-
-.univer-date-picker-clear-btn::before {
- content: '×';
- position: absolute;
- top: -1px;
- left: 0;
- right: 0;
- bottom: 0;
- color: white;
- font-size: 16px;
- line-height: 16px;
-}
-
-/* Dropdown */
-.univer-date-picker-dropdown {
- position: absolute;
- pointer-events: none;
-}
-
-.univer-date-picker-dropdown-range {
- padding: 10px 0;
-}
-
-.univer-date-picker-dropdown-hidden {
- display: none;
-}
-
-/* Range Picker */
-.univer-date-picker-range {
- position: relative;
- display: inline-flex;
-}
-
-.univer-date-picker-range-wrapper {
- display: flex;
-}
-
-.univer-date-picker-active-bar {
- bottom: 0;
- height: 3px;
- background: green;
- opacity: 0;
- transition: all 0.3s;
- pointer-events: none;
-}
-
-.univer-date-picker-focused .univer-date-picker-active-bar {
- opacity: 1;
-}
-
-/* Panel Container */
-.univer-date-picker-panel-container {
- display: inline-block;
- vertical-align: top;
- transition: margin 0.3s;
- pointer-events: all;
-}
-
-.univer-date-picker-panel-layout {
- display: flex;
- flex-wrap: nowrap;
- align-items: stretch;
- overflow: hidden;
- @apply univer-bg-white univer-border univer-border-solid univer-border-gray-200 univer-rounded univer-shadow univer-p-4;
-}
-.univer-dark .univer-date-picker-panel-layout {
- @apply univer-bg-gray-900 univer-border-gray-600;
-}
-
-/* Input */
-.univer-date-picker-input {
- position: relative;
- display: inline-flex;
- width: 100%;
-}
-
-.univer-date-picker-input > input {
- width: 100%;
- padding-left: 12px;
- border: none;
- border-radius: 4px;
- box-sizing: border-box;
- @apply univer-bg-transparent;
-}
-
-.univer-date-picker-input > input:focus {
- outline: none;
-}
diff --git a/packages/design/src/components/date-picker/index.ts b/packages/design/src/components/date-picker/index.ts
deleted file mode 100644
index ce5dbd14f4..0000000000
--- a/packages/design/src/components/date-picker/index.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/** @deprecated */
-export { DatePicker, type IDatePickerProps } from './DatePicker';
diff --git a/packages/design/src/components/date-range-picker/DateRangePicker.stories.tsx b/packages/design/src/components/date-range-picker/DateRangePicker.stories.tsx
index 2b2aaed8a0..1e830f49a0 100644
--- a/packages/design/src/components/date-range-picker/DateRangePicker.stories.tsx
+++ b/packages/design/src/components/date-range-picker/DateRangePicker.stories.tsx
@@ -16,8 +16,6 @@
import type { Meta } from '@storybook/react';
-import type { NoUndefinedRangeValueType } from 'rc-picker/lib/PickerInput/RangePicker';
-import { dayjs } from '@univerjs/core';
import { useState } from 'react';
import { DateRangePicker } from './DateRangePicker';
@@ -34,10 +32,10 @@ export default meta;
export const DateRangePickerBasic = {
render() {
- const [value, setValue] = useState<NoUndefinedRangeValueType<dayjs.Dayjs>>([dayjs(), dayjs().add(7, 'day')]);
+ const [value, setValue] = useState<[Date, Date]>([new Date(), new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)]);
return (
- <DateRangePicker value={value} onChange={setValue} />
+ <DateRangePicker value={value} onValueChange={setValue} />
);
},
};
diff --git a/packages/design/src/components/date-range-picker/DateRangePicker.tsx b/packages/design/src/components/date-range-picker/DateRangePicker.tsx
index 15a3514bb9..ff231ff453 100644
--- a/packages/design/src/components/date-range-picker/DateRangePicker.tsx
+++ b/packages/design/src/components/date-range-picker/DateRangePicker.tsx
@@ -14,50 +14,94 @@
* limitations under the License.
*/
-import type { dayjs } from '@univerjs/core';
-import type { NoUndefinedRangeValueType, RangePickerProps } from 'rc-picker/lib/PickerInput/RangePicker';
-import { CalendarIcon, GuideIcon } from '@univerjs/icons';
-import { RangePicker } from 'rc-picker';
-import generateConfig from 'rc-picker/lib/generate/dayjs';
-import { useContext } from 'react';
-import { ConfigContext } from '../config-provider/ConfigProvider';
-import './index.css';
-
-/** @deprecated */
-export interface IDateRangePickerProps extends Omit<RangePickerProps<dayjs.Dayjs>, 'value' | 'onChange' | 'locale' | 'generateConfig' | 'prefixCls'> {
+import { CalendarIcon } from '@univerjs/icons';
+import dayjs from 'dayjs';
+import { useState } from 'react';
+import { borderClassName } from '../../helper/class-utilities';
+import { clsx } from '../../helper/clsx';
+import { Calendar } from '../calendar/Calendar';
+import { Dropdown } from '../dropdown/Dropdown';
+
+interface IDateRangePickerProps {
+ /**
+ * Additional CSS classes for the date picker.
+ */
+ className?: string;
+
/**
* The value of the date picker.
*/
- value: NoUndefinedRangeValueType<dayjs.Dayjs>;
+ value?: [Date, Date];
/**
* Callback when the value of the date picker changes.
*/
- onChange: (date: NoUndefinedRangeValueType<dayjs.Dayjs>, dateString: [string, string]) => void;
+ onValueChange?: (date: [Date, Date]) => void;
}
-/** @deprecated */
export function DateRangePicker(props: IDateRangePickerProps) {
- const { value, onChange, ...ext } = props;
+ const { value = [new Date(), new Date()], onValueChange, className } = props;
+
+ const [open, setOpen] = useState(false);
- const { locale } = useContext(ConfigContext);
+ function handleValueChange(date: [Date, Date]) {
+ let [start, end] = date;
- function handleChange(date: NoUndefinedRangeValueType<dayjs.Dayjs> | null, dateString: [string, string]) {
- if (Array.isArray(date) && Array.isArray(dateString)) {
- onChange(date, dateString);
+ // Ensure start date is before end date
+ if (start > end) {
+ // Swap the dates if they are in the wrong order
+ [start, end] = [end, start];
}
+ onValueChange?.([start, end]);
+ setOpen(false);
}
return (
- <RangePicker<dayjs.Dayjs>
- {...ext}
- value={value}
- prefixCls="univer-date-range-picker"
- generateConfig={generateConfig}
- locale={locale?.Picker!}
- separator={<GuideIcon />}
- suffixIcon={<CalendarIcon className="univer-date-range-picker-suffix-icon" />}
- onChange={handleChange}
- />
+ <Dropdown
+ align="start"
+ overlay={(
+ <div className="univer-grid univer-grid-cols-2 univer-gap-2 univer-p-2">
+ <Calendar
+ value={value[0]}
+ max={value[1]}
+ onValueChange={(date) => {
+ handleValueChange([date, value[1]]);
+ }}
+ />
+ <Calendar
+ value={value[1]}
+ min={value[0]}
+ onValueChange={(date) => {
+ handleValueChange([value[0], date]);
+ }}
+ />
+ </div>
+ )}
+ open={open}
+ onOpenChange={setOpen}
+ >
+ <button
+ className={clsx(`
+ univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md
+ univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all
+ hover:univer-border-primary-600
+ dark:!univer-text-white
+ `, borderClassName, className)}
+ type="button"
+ >
+ <span className="univer-flex univer-gap-1">
+ <span>{dayjs(value[0]).format('YYYY-MM-DD')}</span>
+ <span>-</span>
+ <span>{dayjs(value[1]).format('YYYY-MM-DD')}</span>
+ </span>
+
+ <CalendarIcon
+ className={`
+ univer-text-gray-600
+ dark:!univer-text-gray-400
+ `}
+ />
+ </button>
+ </Dropdown>
);
}
diff --git a/packages/design/src/components/date-range-picker/index.css b/packages/design/src/components/date-range-picker/index.css
deleted file mode 100644
index 65858a554d..0000000000
--- a/packages/design/src/components/date-range-picker/index.css
+++ /dev/null
@@ -1,295 +0,0 @@
-.univer-date-range-picker {
- position: relative;
- width: 280px;
- height: 32px;
- border-radius: 4px;
- box-sizing: border-box;
- display: inline-flex;
- @apply univer-border univer-border-solid univer-border-gray-200;
- @apply univer-text-gray-900;
-}
-.univer-dark .univer-date-range-picker {
- @apply univer-text-white univer-bg-gray-900 univer-border-gray-600;
-}
-
-.univer-date-range-picker-rtl {
- direction: rtl;
-}
-
-.univer-date-range-picker-invalid {
- box-shadow: 0 0 2px red;
-}
-
-.univer-date-range-picker-panel {
- display: inline-block;
- vertical-align: top;
-}
-
-.univer-date-range-picker-panel-focused {
- border-color: blue;
-}
-
-.univer-date-range-picker-panel-rtl {
- direction: rtl;
-}
-
-.univer-date-range-picker-suffix-icon {
- position: absolute;
- top: 50%;
- right: 0;
- bottom: 0;
- display: flex;
- align-items: center;
- padding: 0 8px;
- transform: translateY(-50%);
- cursor: pointer;
- @apply univer-text-gray-600;
-}
-
-/* Shared Panels */
-.univer-date-range-picker-decade-panel,
-.univer-date-range-picker-year-panel,
-.univer-date-range-picker-month-panel,
-.univer-date-range-picker-week-panel,
-.univer-date-range-picker-date-panel,
-.univer-date-range-picker-time-panel {
- display: flex;
- flex-direction: column;
-}
-
-.univer-date-range-picker-decade-panel table,
-.univer-date-range-picker-year-panel table,
-.univer-date-range-picker-month-panel table,
-.univer-date-range-picker-week-panel table,
-.univer-date-range-picker-date-panel table,
-.univer-date-range-picker-time-panel table {
- text-align: center;
- border-collapse: collapse;
-}
-
-/* Header */
-.univer-date-range-picker-header {
- margin-bottom: 12px;
- display: flex;
- align-items: center;
-}
-
-.univer-date-range-picker-header > * {
- flex: none;
-}
-
-.univer-date-range-picker-header-view {
- height: 16px;
- flex: auto;
- display: flex;
- justify-content: center;
- align-items: center;
- gap: 8px;
-}
-
-.univer-date-range-picker-header-view > button {
- padding: 0;
- border: 0;
- background-color: transparent;
- cursor: pointer;
-}
-
-.univer-date-range-picker-header-super-prev-btn,
-.univer-date-range-picker-header-super-next-btn,
-.univer-date-range-picker-header-prev-btn,
-.univer-date-range-picker-header-next-btn {
- width: 16px;
- height: 16px;
- padding: 0;
- line-height: 16px;
- font-size: 16px;
- border: none;
- background-color: transparent;
- cursor: pointer;
- @apply univer-text-gray-600;
-}
-.univer-dark .univer-date-range-picker-header-super-prev-btn,
-.univer-dark .univer-date-range-picker-header-super-next-btn,
-.univer-dark .univer-date-range-picker-header-prev-btn,
-.univer-dark .univer-date-range-picker-header-next-btn {
- @apply univer-text-gray-400;
-}
-
-/* Content */
-.univer-date-range-picker-cell {
- @apply univer-text-gray-600;
-}
-.univer-dark .univer-date-range-picker-cell {
- @apply univer-text-gray-400;
-}
-
-.univer-date-range-picker-cell-disabled {
- opacity: 0.2;
-}
-
-.univer-date-range-picker-cell-inner {
- display: inline-block;
- box-sizing: border-box;
- width: 100%;
- height: 24px;
- margin: 0;
- padding: 0;
- font-size: 12px;
- line-height: 24px;
- background: transparent;
- border: 0;
- border-radius: 4px;
- outline: none;
- cursor: pointer;
- transition: background 0.3s;
-}
-
-.univer-date-range-picker-cell-in-view {
- color: #333;
-}
-
-.univer-date-range-picker-cell-in-range > .univer-date-range-picker-cell-inner {
- background: rgba(0, 0, 255, 0.05);
-}
-
-.univer-date-range-picker-cell-hover > .univer-date-range-picker-cell-inner {
- @apply univer-bg-gray-100;
-}
-
-.univer-date-range-picker-cell-range-hover-start::after,
-.univer-date-range-picker-cell-range-hover-end::after,
-.univer-date-range-picker-cell-range-hover::after {
- position: absolute;
- top: 3px;
- right: 0;
- bottom: 0;
- left: 0;
- border: 1px solid green;
- border-right: 0;
- border-left: 0;
- content: '';
- pointer-events: none;
-}
-
-.univer-date-range-picker-cell-range-hover-start::after {
- border-left: 1px solid green !important;
-}
-
-.univer-date-range-picker-cell-range-hover-end::after {
- border-right: 1px solid green !important;
-}
-
-.univer-date-range-picker-cell-today > .univer-date-range-picker-cell-inner {
- @apply univer-border univer-border-solid univer-border-primary-600;
-}
-
-.univer-date-range-picker-cell-range-start > .univer-date-range-picker-cell-inner,
-.univer-date-range-picker-cell-range-end > .univer-date-range-picker-cell-inner,
-.univer-date-range-picker-cell-selected > .univer-date-range-picker-cell-inner {
- color: #fff;
- @apply univer-bg-primary-600;
-}
-
-/* Preset */
-.univer-date-range-picker-presets {
- background: #ccccff;
-}
-
-.univer-date-range-picker-presets ul {
- margin: 0;
- padding: 0;
- list-style: none;
-}
-
-/* Now Button */
-.univer-date-range-picker-now {
- padding-top: 12px;
-}
-
-.univer-date-range-picker-now-btn {
- font-size: 13px;
- cursor: pointer;
- @apply univer-text-primary-600;
-}
-
-/* Footer */
-.univer-date-range-picker-footer,
-.univer-date-range-picker-picker-footer {
- margin-top: 12px;
- @apply univer-border-0 univer-border-t univer-border-solid univer-border-t-gray-200;
-}
-
-/* Dropdown */
-.univer-date-range-picker-dropdown {
- position: absolute;
- pointer-events: none;
-}
-
-.univer-date-range-picker-dropdown-range {
- padding: 10px 0;
-}
-
-.univer-date-range-picker-dropdown-hidden {
- display: none;
-}
-
-/* Range Picker */
-.univer-date-range-picker-range {
- position: relative;
- display: inline-flex;
-}
-
-.univer-date-range-picker-range-wrapper {
- display: flex;
-}
-
-.univer-date-range-picker-active-bar {
- bottom: 0;
- height: 3px;
- opacity: 0;
- transition: all 0.3s;
- pointer-events: none;
- @apply univer-bg-primary-600;
-}
-
-.univer-date-range-picker-focused .univer-date-range-picker-active-bar {
- opacity: 1;
-}
-
-.univer-date-range-picker-panel-container {
- display: inline-block;
- vertical-align: top;
- transition: margin 0.3s;
- pointer-events: all;
-}
-
-.univer-date-range-picker-panel-layout {
- display: flex;
- flex-wrap: nowrap;
- align-items: stretch;
- overflow: hidden;
- @apply univer-bg-white univer-border univer-border-solid univer-border-gray-200 univer-rounded univer-shadow univer-p-4;
-}
-.univer-dark .univer-date-range-picker-panel-layout {
- @apply univer-bg-gray-900 univer-border-gray-600;
-}
-
-/* Input */
-.univer-date-range-picker-input {
- position: relative;
- display: inline-flex;
- width: 100%;
-}
-
-.univer-date-range-picker-input > input {
- width: 100%;
- padding-left: 12px;
- border: none;
- border-radius: 4px;
- box-sizing: border-box;
- @apply univer-bg-transparent;
-}
-
-.univer-date-range-picker-input > input:focus {
- outline: none;
-}
diff --git a/packages/design/src/components/date-range-picker/index.ts b/packages/design/src/components/date-range-picker/index.ts
index e25178fb97..ac5fb93c4b 100644
--- a/packages/design/src/components/date-range-picker/index.ts
+++ b/packages/design/src/components/date-range-picker/index.ts
@@ -14,4 +14,4 @@
* limitations under the License.
*/
-export { DateRangePicker, type IDateRangePickerProps } from './DateRangePicker';
+export { DateRangePicker } from './DateRangePicker';
diff --git a/packages/design/src/components/dialog/DialogPrimitive.tsx b/packages/design/src/components/dialog/DialogPrimitive.tsx
index b6505f8ec2..2b123e5c76 100644
--- a/packages/design/src/components/dialog/DialogPrimitive.tsx
+++ b/packages/design/src/components/dialog/DialogPrimitive.tsx
@@ -70,7 +70,7 @@ const DialogContent = forwardRef<
data-[state=closed]:univer-slide-out-to-top-[48%]
univer-fixed univer-left-1/2 univer-top-1/2 univer-z-[1050] univer-box-border univer-grid
univer-w-full univer-max-w-lg -univer-translate-x-1/2 -univer-translate-y-1/2 univer-gap-4
- univer-bg-white univer-px-6 univer-py-4 univer-text-gray-500 univer-shadow-md univer-duration-200
+ univer-bg-white univer-p-4 univer-text-gray-500 univer-shadow-md univer-duration-200
sm:!univer-rounded-lg
dark:!univer-bg-gray-700 dark:!univer-text-gray-400
`,
diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts
index 1a7d5ba27f..59b261f671 100644
--- a/packages/design/src/index.ts
+++ b/packages/design/src/index.ts
@@ -28,7 +28,7 @@ export { Checkbox, type ICheckboxProps } from './components/checkbox/Checkbox';
export { ColorPicker, type IColorPickerProps } from './components/color-picker/ColorPicker';
export { ConfigContext, ConfigProvider, type IConfigProviderProps } from './components/config-provider/ConfigProvider';
export { Confirm, type IConfirmProps } from './components/confirm/Confirm';
-export { DatePicker, type IDatePickerProps } from './components/date-picker';
+export { DatePicker } from './components/date-picker/DatePicker';
export { DateRangePicker } from './components/date-range-picker';
export { Dialog, type IDialogProps } from './components/dialog/Dialog';
export { DraggableList, type IDraggableListProps, ReactGridLayout } from './components/draggable-list';
diff --git a/packages/design/src/locale/ca-ES.ts b/packages/design/src/locale/ca-ES.ts
index 7ca0fd5309..3f6548076a 100644
--- a/packages/design/src/locale/ca-ES.ts
+++ b/packages/design/src/locale/ca-ES.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsEsES from 'dayjs/locale/es';
-import PickerCaES from 'rc-picker/lib/locale/ca_ES';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: 'cancel·la',
confirm: 'ok',
},
- Picker: {
- ...dajsEsES,
- ...PickerCaES,
- },
CascaderList: {
empty: 'Cap',
},
diff --git a/packages/design/src/locale/en-US.ts b/packages/design/src/locale/en-US.ts
index 00d0f2f5b9..b6f578d929 100644
--- a/packages/design/src/locale/en-US.ts
+++ b/packages/design/src/locale/en-US.ts
@@ -14,19 +14,12 @@
* limitations under the License.
*/
-import dajsEnUS from 'dayjs/locale/en';
-import PickerEnUs from 'rc-picker/lib/locale/en_US';
-
const locale = {
design: {
Confirm: {
cancel: 'cancel',
confirm: 'ok',
},
- Picker: {
- ...dajsEnUS,
- ...PickerEnUs,
- },
CascaderList: {
empty: 'None',
},
diff --git a/packages/design/src/locale/es-ES.ts b/packages/design/src/locale/es-ES.ts
index ee6916945c..0156c5c4de 100644
--- a/packages/design/src/locale/es-ES.ts
+++ b/packages/design/src/locale/es-ES.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsEsES from 'dayjs/locale/es';
-import PickerEsES from 'rc-picker/lib/locale/es_ES';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: 'cancel·la',
confirm: 'ok',
},
- Picker: {
- ...dajsEsES,
- ...PickerEsES,
- },
CascaderList: {
empty: 'Cap',
},
diff --git a/packages/design/src/locale/fa-IR.ts b/packages/design/src/locale/fa-IR.ts
index 2857e46e90..e2cbbb3c90 100644
--- a/packages/design/src/locale/fa-IR.ts
+++ b/packages/design/src/locale/fa-IR.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsFaIR from 'dayjs/locale/fa';
-import PickerFaIR from 'rc-picker/lib/locale/fa_IR';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: 'لغو',
confirm: 'باشه',
},
- Picker: {
- ...dajsFaIR,
- ...PickerFaIR,
- },
CascaderList: {
empty: 'هیچ کدام',
},
diff --git a/packages/design/src/locale/fr-FR.ts b/packages/design/src/locale/fr-FR.ts
index d0001f83ef..eb856bec2a 100644
--- a/packages/design/src/locale/fr-FR.ts
+++ b/packages/design/src/locale/fr-FR.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsFrFR from 'dayjs/locale/fr';
-import PickerFrFR from 'rc-picker/lib/locale/fr_FR';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: 'annuler',
confirm: 'ok',
},
- Picker: {
- ...dajsFrFR,
- ...PickerFrFR,
- },
CascaderList: {
empty: 'Aucun',
},
diff --git a/packages/design/src/locale/ko-KR.ts b/packages/design/src/locale/ko-KR.ts
index 5192558de3..21d02c8da0 100644
--- a/packages/design/src/locale/ko-KR.ts
+++ b/packages/design/src/locale/ko-KR.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsKoKR from 'dayjs/locale/ko';
-import PickerKoKR from 'rc-picker/lib/locale/ko_KR';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: '취소',
confirm: '확인',
},
- Picker: {
- ...dajsKoKR,
- ...PickerKoKR,
- },
CascaderList: {
empty: '없음',
},
diff --git a/packages/design/src/locale/ru-RU.ts b/packages/design/src/locale/ru-RU.ts
index aa557d4289..d8ee51a38c 100644
--- a/packages/design/src/locale/ru-RU.ts
+++ b/packages/design/src/locale/ru-RU.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsRuRU from 'dayjs/locale/ru';
-import PickerRuRU from 'rc-picker/lib/locale/ru_RU';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: 'отмена',
confirm: 'ок',
},
- Picker: {
- ...dajsRuRU,
- ...PickerRuRU,
- },
CascaderList: {
empty: 'Нет',
},
diff --git a/packages/design/src/locale/vi-VN.ts b/packages/design/src/locale/vi-VN.ts
index 9a6d07c17f..87d98842eb 100644
--- a/packages/design/src/locale/vi-VN.ts
+++ b/packages/design/src/locale/vi-VN.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsViVN from 'dayjs/locale/vi';
-import PickerViVN from 'rc-picker/lib/locale/vi_VN';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: 'Hủy bỏ',
confirm: 'Xác nhận',
},
- Picker: {
- ...dajsViVN,
- ...PickerViVN,
- },
CascaderList: {
empty: 'Không có',
},
diff --git a/packages/design/src/locale/zh-CN.ts b/packages/design/src/locale/zh-CN.ts
index df0b9f8c40..d380289c2e 100644
--- a/packages/design/src/locale/zh-CN.ts
+++ b/packages/design/src/locale/zh-CN.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsZhCN from 'dayjs/locale/zh';
-import PickerZhCN from 'rc-picker/lib/locale/zh_CN';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: '取消',
confirm: '确定',
},
- Picker: {
- ...dajsZhCN,
- ...PickerZhCN,
- },
CascaderList: {
empty: '无',
},
diff --git a/packages/design/src/locale/zh-TW.ts b/packages/design/src/locale/zh-TW.ts
index b45ea4ab6b..b6a06f4dd3 100644
--- a/packages/design/src/locale/zh-TW.ts
+++ b/packages/design/src/locale/zh-TW.ts
@@ -15,8 +15,6 @@
*/
import type enUS from './en-US';
-import dajsZhTw from 'dayjs/locale/zh-tw';
-import PickerZhTw from 'rc-picker/lib/locale/zh_TW';
const locale: typeof enUS = {
design: {
@@ -24,10 +22,6 @@ const locale: typeof enUS = {
cancel: '取消',
confirm: '確定',
},
- Picker: {
- ...dajsZhTw,
- ...PickerZhTw,
- },
CascaderList: {
empty: '無',
},
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx b/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx
index 77769c4bd9..e389d729aa 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx
@@ -16,7 +16,7 @@
import type { ITableFilterItem } from '@univerjs/sheets-table';
import type { IConditionCompareTypeEnum, IConditionExpect, IConditionInfo, ITableConditionTypeEnumWithoutLogic } from './type';
-import { dayjs, Injector, LocaleService } from '@univerjs/core';
+import { Injector, LocaleService } from '@univerjs/core';
import { borderClassName, CascaderList, clsx, DatePicker, DateRangePicker, Dropdown, Input, InputNumber, Select } from '@univerjs/design';
import { MoreDownIcon } from '@univerjs/icons';
import { TableConditionTypeEnum, TableDateCompareTypeEnum, TableStringCompareTypeEnum } from '@univerjs/sheets-table';
@@ -152,36 +152,24 @@ export const SheetTableConditionPanel = (props: IConditionFilterProps) => {
{!!(subComponentType === ConditionSubComponentEnum.DatePicker) && (
<div id="univer-table-date-picker-wrapper">
<DatePicker
- value={dayjs(conditionInfo.info.date)}
- defaultPickerValue={dayjs()}
- onChange={(v) => handleConditionInfo({ date: v.toDate() })}
- getPopupContainer={() => {
- const wrapper = document.getElementById('univer-table-date-picker-wrapper');
- return wrapper || document.body;
- }}
className="univer-w-full"
- allowClear={false}
+ value={conditionInfo.info.date ?? new Date()}
+ onValueChange={(v) => handleConditionInfo({ date: v })}
/>
</div>
)}
{!!(subComponentType === ConditionSubComponentEnum.DateRange) && (
<div id="univer-table-date-range-wrapper">
<DateRangePicker
- value={[dayjs(conditionInfo.info.dateRange?.[0]) ?? dayjs(), dayjs(conditionInfo.info.dateRange?.[1]) ?? dayjs()]}
- defaultPickerValue={[dayjs(), dayjs()]}
- onChange={(v) => {
+ className="univer-w-full"
+ value={[conditionInfo.info.dateRange?.[0] ?? new Date(), conditionInfo.info.dateRange?.[1] ?? new Date()]}
+ onValueChange={(v) => {
if (v) {
- handleConditionInfo({ dateRange: v.map((i) => i?.toDate()) as [Date, Date] });
+ handleConditionInfo({ dateRange: v });
} else {
handleConditionInfo({});
}
}}
- getPopupContainer={() => {
- const wrapper = document.getElementById('univer-table-date-range-wrapper');
- return wrapper || document.body;
- }}
- classNames={{ popup: 'univer-w-[400px]' }}
- allowClear={false}
/>
</div>
)}
diff --git a/packages/sheets-table-ui/src/views/components/util.ts b/packages/sheets-table-ui/src/views/components/util.ts
index e5507919cc..86b26f2c23 100644
--- a/packages/sheets-table-ui/src/views/components/util.ts
+++ b/packages/sheets-table-ui/src/views/components/util.ts
@@ -334,11 +334,17 @@ export function getInitConditionInfo(tableFilter?: ITableFilterItem) {
const { conditionType, compareType } = filterInfo;
if (conditionType === TableConditionTypeEnum.Date) {
if (compareType === TableDateCompareTypeEnum.Between || compareType === TableDateCompareTypeEnum.NotBetween) {
+ // ensure expectedValue is an array of two dates
+ let dateRange: [Date, Date] | undefined;
+ if (Array.isArray(filterInfo.expectedValue)) {
+ dateRange = filterInfo.expectedValue.map((i) => (typeof i === 'string' ? new Date(i) : i)) as [Date, Date];
+ }
+
return {
type: conditionType,
compare: compareType,
info: {
- dateRange: filterInfo.expectedValue,
+ dateRange,
},
};
} else if (compareType === TableDateCompareTypeEnum.Today
@@ -360,11 +366,24 @@ export function getInitConditionInfo(tableFilter?: ITableFilterItem) {
info: {},
};
} else if (datePickerSet.has(compareType as TableDateCompareTypeEnum)) {
+ // ensure expectedValue is a date or an array of two dates
+ let date: Date | [Date, Date] | undefined;
+
+ if (typeof filterInfo.expectedValue === 'string') {
+ date = new Date(filterInfo.expectedValue);
+ } else if (Array.isArray(filterInfo.expectedValue)) {
+ for (let i = 0; i < filterInfo.expectedValue.length; i++) {
+ if (typeof filterInfo.expectedValue[i] === 'string') {
+ filterInfo.expectedValue[i] = new Date(filterInfo.expectedValue[i]);
+ }
+ }
+ }
+
return {
type: conditionType,
compare: compareType,
info: {
- date: filterInfo.expectedValue,
+ date,
},
};
} else {
diff --git a/packages/sheets-table/src/types/type.ts b/packages/sheets-table/src/types/type.ts
index b83009031e..944e926528 100644
--- a/packages/sheets-table/src/types/type.ts
+++ b/packages/sheets-table/src/types/type.ts
@@ -61,7 +61,8 @@ export interface ITableConditionFilterItem {
export interface ITableDateFilterInfo {
conditionType: TableConditionTypeEnum.Date;
compareType: TableDateCompareTypeEnum;
- expectedValue: Date | [Date, Date] | undefined;
+ // Date-like strings
+ expectedValue?: string | [string, string] | Date | [Date, Date];
anchorTime?: number;
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3de6d0b252..627510b355 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1228,9 +1228,6 @@ importers:
rc-menu:
specifier: ^9.16.0
- rc-picker:
- specifier: ^4.9.0
rc-virtual-list:
specifier: ^3.16.1
@@ -7000,9 +6997,6 @@ packages:
resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==}
engines: {node: '>= 0.4'}
- resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==}
-
resolution: {integrity: sha512-QGLawF3lq5NOqJ5+pIgvrmE1jL8W9iwwHPAdKyV6gydtmDPngty+87YpSpzMPk9lAMnBIXcf57OKSDEjfuyRyw==}
@@ -9886,26 +9880,6 @@ packages:
react: 19.1.1
react-dom: 19.1.1
- resolution: {integrity: sha512-MJ5teb7FlNE0NFHTncxXQ62Y5lytq6sh5nUw0iH8OkHL/TjARSEvSHpr940pWgjGANpjCwyMdvsEV55l5tYNSg==}
- engines: {node: '>=8.x'}
- peerDependencies:
- date-fns: '>= 2.x'
- dayjs: '>= 1.x'
- luxon: '>= 3.x'
- moment: '>= 2.x'
- react: 19.1.1
- react-dom: 19.1.1
- peerDependenciesMeta:
- date-fns:
- optional: true
- dayjs:
- optional: true
- luxon:
- optional: true
- moment:
- optional: true
-
resolution: {integrity: sha512-YZLjUbyIWox8E9i9C3Tm7ia+W7euPItNWSPX5sCcQTYbnwDb5uNpnLHQCG1f22oZWUhLw4Mv2tFmeWe68CDQRQ==}
peerDependencies:
@@ -14995,9 +14969,6 @@ snapshots:
es-errors: 1.3.0
is-data-view: 1.0.2
- optional: true
-
@@ -18357,20 +18328,6 @@ snapshots:
react: 19.1.1
react-dom: 19.1.1([email protected])
- dependencies:
- '@babel/runtime': 7.27.1
- '@rc-component/trigger': 2.2.6([email protected]([email protected]))([email protected])
- classnames: 2.5.1
- react: 19.1.1
- react-dom: 19.1.1([email protected])
- optionalDependencies:
- date-fns: 4.1.0
- dayjs: 1.11.13
-
dependencies:
'@babel/runtime': 7.27.1