Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(UI): The form verification border should be marked red normally. #628

Open
wants to merge 12 commits into
base: feature
Choose a base branch
from
37 changes: 20 additions & 17 deletions packages/ui/src/DateRanger/Ranger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import {
} from './constant';
import type { RangeOption } from './typing';
import InternalPickerPanel, { Rule } from './PickerPanel';
import { getMergedStatus, getStatusClassNames } from 'antd/es/_util/statusUtils';
import { FormItemInputContext } from 'antd/es/form/context';

import zhCN from './locale/zh-CN';
import enUS from './locale/en-US';
import './index.less';
Expand Down Expand Up @@ -103,12 +106,16 @@ const Ranger = (props: DateRangerProps) => {
isMoment: isMomentProps,
rules,
tip,
status: customStatus,
...rest
} = props;

console.log(locale, 'locale');
const { token } = theme.useToken();

// =================== Form =====================
const { status: contextStatus, hasFeedback } = React.useContext(FormItemInputContext);
const mergedStatus = getMergedStatus(contextStatus, customStatus);

// 是否为 moment 时间对象
const isMoment =
moment.isMoment(defaultValue?.[0]) ||
Expand All @@ -124,9 +131,10 @@ const Ranger = (props: DateRangerProps) => {
const [innerValue, setInnerValue] = useState<RangeValue>(
value ??
defaultValue ??
(selects
.find(item => item.name === defaultRangeName)
?.range(isMoment ? moment() : dayjs()) as RangeValue)
// 兼容一下匹配不上 defaultRangeName
((selects.find(item => item.name === defaultRangeName) || selects[0])?.range(
isMoment ? moment() : dayjs()
) as RangeValue)
);

const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -295,7 +303,10 @@ const Ranger = (props: DateRangerProps) => {
: selects[rangeNameIndex + 1];

return (
<Space className={classNames(prefix)} style={rest.style}>
<Space
className={classNames(prefix, getStatusClassNames(prefix, mergedStatus, hasFeedback))}
style={rest.style}
>
<Space size={0}>
<div className={`${prefix}-wrapper`}>
<Dropdown
Expand Down Expand Up @@ -338,8 +349,9 @@ const Ranger = (props: DateRangerProps) => {
label:
item.name === CUSTOMIZE ? (
<Tooltip
overlayClassName={`${prefix}-panel-wrapper`}
open={tooltipOpen}
arrow={false}
arrow={true}
onOpenChange={o => {
if (o) {
setTooltipOpen(true);
Expand All @@ -352,9 +364,6 @@ const Ranger = (props: DateRangerProps) => {
...tooltipProps?.overlayStyle,
}}
overlayInnerStyle={{
background: '#fff',
maxHeight: 'none',
margin: 16,
...tooltipProps?.overlayInnerStyle,
}}
title={
Expand Down Expand Up @@ -400,14 +409,7 @@ const Ranger = (props: DateRangerProps) => {
}}
>
<Space size={0}>
<span
className={`${prefix}-label`}
style={{
marginLeft: 8,
}}
>
{rangeLabel}
</span>
<div className={`${prefix}-label`}>{rangeLabel}</div>
{isPlay && <div className={`${prefix}-play`}>{label}</div>}
</Space>
</Dropdown>
Expand All @@ -430,6 +432,7 @@ const Ranger = (props: DateRangerProps) => {
}}
// @ts-ignore
value={innerValue}
// @ts-ignore
onChange={datePickerChange}
allowClear={false}
size={size}
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/DateRanger/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ export const NEAR_TIME_LIST = [
LAST_3_DAYS,
TODAY,
YESTERDAY,
THIS_WEEK,
LAST_WEEK,
THIS_MONTH,
LAST_MONTH,
THIS_YEAR,
Expand Down
10 changes: 10 additions & 0 deletions packages/ui/src/DateRanger/demo/default-quick-value.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { DateRanger } from '@oceanbase/ui';
import dayjs from 'dayjs';

export default () => (
<DateRanger
defaultQuickValue={DateRanger.THIS_WEEK.name}
selects={[DateRanger.YESTERDAY, DateRanger.TODAY, DateRanger.THIS_WEEK, DateRanger.THIS_MONTH]}
/>
);
59 changes: 38 additions & 21 deletions packages/ui/src/DateRanger/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../variable.less';
@import '~@oceanbase/design/es/theme/index.less';

@prefix: ob-date-ranger;

Expand All @@ -8,9 +9,9 @@
border-radius: 4px 0 0 4px;
box-sizing: border-box;
display: flex;
// FIXED: 存在不生效情况

.@{prefix}-picker {
padding-left: 0px;
padding-left: 2px;
border: 0px;
pointer-events: none;
input {
Expand Down Expand Up @@ -41,41 +42,57 @@
z-index: 1;
}
}
}

.@{prefix}-show-range {
.@{prefix}-quick-picker.@{prefix}-quick-picker-select {
margin-right: -1px;

.@{prefixCls}-select-selector {
border-top-right-radius: 0;
border-bottom-right-radius: 0;

&:hover {
z-index: 1;
}
}
.@{prefix}-playback-control {
display: flex;

.@{prefixCls}-select-arrow {
z-index: 1;
.@{prefixCls}-radio-button-wrapper {
padding-inline: 8px;
}
}
}

.@{prefix}-playback-control {
margin-left: 8px;
.@{prefix}-status-error {
.@{prefix}-wrapper {
border-color: @colorError;
}
}

.@{prefixCls}-radio-button-wrapper {
padding-inline: 8px;
.@{prefix}-panel-wrapper {
.ant-tooltip-arrow {
margin-inline: 16px;
&:before {
background-color: #fff;
}
}
.ant-tooltip-inner {
background: #fff;
margin: 16px;
max-height: none;
}
.ant-picker-cell-today {
.ant-picker-cell-inner {
border: 0;
}
}
}

.@{prefix}-time-wrapper {
.ant-picker-ok {
display: none;
}
}

.@{prefix}-label {
background-color: rgb(226, 229, 237);
display: inline-block;
width: 60px;
margin-left: 8px;
padding: 4px 0;
border-radius: 4px;
line-height: 1;
text-align: center;
}
.@{prefix}-play {
white-space: nowrap;
}
2 changes: 2 additions & 0 deletions packages/ui/src/DateRanger/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ nav:

<code src="./demo/default-value.tsx" title="指定默认值"></code>

<code src="./demo/default-quick-value.tsx" title="指定快速选择的默认值"></code>

## API

| 参数 | 说明 | 类型 | 默认值 | 版本 |
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/src/Ranger/Ranger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,15 @@ const Ranger = (props: RangerProps) => {
/>
)}
{showRange && (
// @ts-ignore
<DatePicker.RangePicker
// @ts-ignore
disabledDate={pastOnly ? disabledFuture : disabledDate}
format={DATE_TIME_FORMAT}
// @ts-ignore
defaultValue={defaultValue as [Dayjs, Dayjs]}
// @ts-ignore
value={(innerValue || defaultInternalValue) as [Dayjs, Dayjs]}
// @ts-ignore
onChange={datePickerChange}
showTime={true}
className={`${prefix}-range-picker`}
Expand Down
Loading