Skip to content

Commit bff2457

Browse files
committed
feat(ui): add auto-complete component
1 parent ef0e55c commit bff2457

100 files changed

Lines changed: 1210 additions & 338 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/site/src/app/styles/_app.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ h3 {
226226
'Input': 'input',
227227
'Switch': 'switch',
228228
'Time-picker': 'time-picker',
229-
'Date-picker': 'date-picker'
229+
'Date-picker': 'date-picker',
230+
'Auto-complete': 'input'
230231
)
231232
{
232233
section[id^='#{$id}'] {

packages/ui/src/components/_alert-dialog/AlertDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface DAlertDialogProps extends React.HTMLAttributes<HTMLDivElement>
1010
onClose?: () => void;
1111
}
1212

13-
export function DAlertDialog(props: DAlertDialogProps) {
13+
export function DAlertDialog(props: DAlertDialogProps): JSX.Element | null {
1414
const {
1515
children,
1616
dDuration,

packages/ui/src/components/_base-design/BaseDesign.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface DBaseDesignProps {
1414
dFormControl?: DFormControl;
1515
}
1616

17-
export function DBaseDesign(props: DBaseDesignProps) {
17+
export function DBaseDesign(props: DBaseDesignProps): JSX.Element | null {
1818
const { children, dCompose, dFormControl } = props;
1919

2020
const composeContext = useContext(DComposeContext);

packages/ui/src/components/_base-input/BaseInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface DBaseInputProps extends React.InputHTMLAttributes<any> {
1212
dFor?: boolean;
1313
}
1414

15-
function BaseInput(props: DBaseInputProps, ref: React.ForwardedRef<any>) {
15+
function BaseInput(props: DBaseInputProps, ref: React.ForwardedRef<any>): JSX.Element | null {
1616
const { dFormControl, dTag = 'input', dFor = true, ...restProps } = props;
1717

1818
//#region Context

packages/ui/src/components/_date-input/DateInput.tsx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { DFormControl } from '../form';
33

44
import React, { useEffect, useId, useImperativeHandle, useRef, useState } from 'react';
55
import ReactDOM from 'react-dom';
6-
import { filter } from 'rxjs';
76

87
import {
98
usePrefixConfig,
@@ -43,14 +42,15 @@ export interface DDateInputProps extends Omit<React.HTMLAttributes<HTMLDivElemen
4342
dSize?: DSize;
4443
dRange?: boolean;
4544
dClearable?: boolean;
45+
dEscClosable?: boolean;
4646
dDisabled?: boolean;
4747
dInputProps?: [React.InputHTMLAttributes<HTMLInputElement>?, React.InputHTMLAttributes<HTMLInputElement>?];
4848
dInputRef?: [React.Ref<HTMLInputElement>?, React.Ref<HTMLInputElement>?];
4949
onVisibleChange?: (visible: boolean) => void;
5050
onClear?: () => void;
5151
}
5252

53-
function DateInput(props: DDateInputProps, ref: React.ForwardedRef<DDateInputRef>) {
53+
function DateInput(props: DDateInputProps, ref: React.ForwardedRef<DDateInputRef>): JSX.Element | null {
5454
const {
5555
children,
5656
dFormControl,
@@ -60,6 +60,7 @@ function DateInput(props: DDateInputProps, ref: React.ForwardedRef<DDateInputRef
6060
dSize,
6161
dRange,
6262
dClearable,
63+
dEscClosable = true,
6364
dDisabled,
6465
dInputProps,
6566
dInputRef,
@@ -169,25 +170,6 @@ function DateInput(props: DDateInputProps, ref: React.ForwardedRef<DDateInputRef
169170
}
170171
}, [asyncCapture, dVisible, uniqueId, updatePosition]);
171172

172-
useEffect(() => {
173-
if (dVisible) {
174-
const [asyncGroup, asyncId] = asyncCapture.createGroup();
175-
176-
asyncGroup
177-
.fromEvent<KeyboardEvent>(window, 'keydown')
178-
.pipe(filter((e) => e.code === 'Escape'))
179-
.subscribe({
180-
next: () => {
181-
onVisibleChange?.(false);
182-
},
183-
});
184-
185-
return () => {
186-
asyncCapture.deleteGroup(asyncId);
187-
};
188-
}
189-
}, [asyncCapture, onVisibleChange, dVisible]);
190-
191173
const preventBlur: React.MouseEventHandler = (e) => {
192174
if (e.target !== inputRefLeft.current && e.target !== inputRefRight.current && e.button === 0) {
193175
e.preventDefault();
@@ -236,7 +218,11 @@ function DateInput(props: DDateInputProps, ref: React.ForwardedRef<DDateInputRef
236218
onKeyDown={(e) => {
237219
inputProps?.onKeyDown?.(e);
238220

239-
if (!dVisible) {
221+
if (dVisible) {
222+
if (dEscClosable && e.code === 'Escape') {
223+
onVisibleChange?.(false);
224+
}
225+
} else {
240226
if (e.code === 'Space' || e.code === 'Enter') {
241227
e.preventDefault();
242228

packages/ui/src/components/_focus-visible/FocusVisible.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
import React, { useEffect, useRef } from 'react';
1+
import type React from 'react';
2+
3+
import { useEffect, useRef } from 'react';
24

35
import { useAsync } from '../../hooks';
46

57
const FOCUS_KEY = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'Enter', 'Space'];
68

9+
export interface DFocusVisibleRenderProps {
10+
fvOnFocus: React.FocusEventHandler;
11+
fvOnBlur: React.FocusEventHandler;
12+
fvOnKeyDown: React.KeyboardEventHandler;
13+
}
14+
715
export interface DFocusVisibleProps {
8-
children: React.ReactElement;
16+
children: (props: DFocusVisibleRenderProps) => JSX.Element | null;
917
onFocusVisibleChange?: (visible: boolean) => void;
1018
}
11-
export function DFocusVisible(props: DFocusVisibleProps) {
19+
20+
export function DFocusVisible(props: DFocusVisibleProps): JSX.Element | null {
1221
const { children, onFocusVisibleChange } = props;
1322

1423
const dataRef = useRef({
@@ -35,25 +44,18 @@ export function DFocusVisible(props: DFocusVisibleProps) {
3544
};
3645
}, [asyncCapture]);
3746

38-
return React.cloneElement<React.HTMLAttributes<HTMLElement>>(children, {
39-
...children.props,
40-
onFocus: (e) => {
41-
children.props.onFocus?.(e);
42-
47+
return children({
48+
fvOnFocus: () => {
4349
if (dataRef.current.focusByKeydown) {
4450
onFocusVisibleChange?.(true);
4551
dataRef.current.focusVisible = true;
4652
}
4753
},
48-
onBlur: (e) => {
49-
children.props.onBlur?.(e);
50-
54+
fvOnBlur: () => {
5155
onFocusVisibleChange?.(false);
5256
dataRef.current.focusVisible = false;
5357
},
54-
onKeyDown: (e) => {
55-
children.props.onKeyDown?.(e);
56-
58+
fvOnKeyDown: (e) => {
5759
if (!dataRef.current.focusVisible && FOCUS_KEY.includes(e.code)) {
5860
onFocusVisibleChange?.(true);
5961
}

packages/ui/src/components/_footer/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface DFooterProps extends Omit<React.HTMLAttributes<HTMLDivElement>,
1616
onClose?: () => void;
1717
}
1818

19-
export function DFooter(props: DFooterProps) {
19+
export function DFooter(props: DFooterProps): JSX.Element | null {
2020
const {
2121
dAlign = 'right',
2222
dActions = ['cancel', 'ok'],

packages/ui/src/components/_header/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface DHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
1010
onClose?: () => void;
1111
}
1212

13-
export function DHeader(props: DHeaderProps) {
13+
export function DHeader(props: DHeaderProps): JSX.Element | null {
1414
const {
1515
children,
1616
dActions = ['close'],

packages/ui/src/components/_mask/Mask.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface DMaskProps extends Omit<React.HTMLAttributes<HTMLDivElement>, '
1111
afterVisibleChange?: (visible: boolean) => void;
1212
}
1313

14-
export function DMask(props: DMaskProps) {
14+
export function DMask(props: DMaskProps): JSX.Element | null {
1515
const {
1616
dVisible,
1717
onClose,

packages/ui/src/components/_popup/Popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface DPopupProps {
3535
onUpdatePosition?: () => void;
3636
}
3737

38-
export function DPopup(props: DPopupProps) {
38+
export function DPopup(props: DPopupProps): JSX.Element | null {
3939
const {
4040
children,
4141
dVisible,

0 commit comments

Comments
 (0)