Skip to content

Commit

Permalink
feat(ui): popup components support dInitialVisible
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Jun 21, 2023
1 parent 8a4505d commit 82ef3d5
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/ui/src/components/auto-complete/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface DAutoCompleteItem {
export interface DAutoCompleteProps<T extends DAutoCompleteItem> extends React.HTMLAttributes<HTMLDivElement> {
dList: T[];
dVisible?: boolean;
dInitialVisible?: boolean;
dLoading?: boolean;
dVirtual?: boolean;
dCustomItem?: (item: T) => React.ReactNode;
Expand All @@ -49,6 +50,7 @@ function AutoComplete<T extends DAutoCompleteItem>(
children,
dList,
dVisible,
dInitialVisible = false,
dLoading = false,
dVirtual = false,
dCustomItem,
Expand Down Expand Up @@ -89,7 +91,7 @@ function AutoComplete<T extends DAutoCompleteItem>(

const canSelectItem = useCallback((item: T) => !item.disabled && !item.children, []);

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);

const [focusVisible, setFocusVisible] = useState(false);

Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/cascader/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface DCascaderProps<V extends DId, T extends DCascaderItem<V>> exten
dList: T[];
dModel?: V | null | V[];
dVisible?: boolean;
dInitialVisible?: boolean;
dPlaceholder?: string;
dSize?: DSize;
dLoading?: boolean;
Expand Down Expand Up @@ -86,6 +87,7 @@ function Cascader<V extends DId, T extends DCascaderItem<V>>(
dList,
dModel,
dVisible,
dInitialVisible = false,
dPlaceholder,
dSize,
dLoading = false,
Expand Down Expand Up @@ -163,7 +165,7 @@ function Cascader<V extends DId, T extends DCascaderItem<V>>(

const [searchValue, changeSearchValue] = useDValue<string>('', dSearchValue, onSearchValueChange);

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);
const formControlInject = useFormControl(dFormControl);
const [_select, changeSelect] = useDValue<V | null | V[]>(
dMultiple ? [] : null,
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface DDatePickerProps extends Omit<React.HTMLAttributes<HTMLDivEleme
dModel?: Date | null | [Date, Date];
dFormat?: string;
dVisible?: boolean;
dInitialVisible?: boolean;
dPlacement?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right';
dOrder?: 'ascend' | 'descend' | false;
dPlaceholder?: string | [string?, string?];
Expand Down Expand Up @@ -58,6 +59,7 @@ function DatePicker(props: DDatePickerProps, ref: React.ForwardedRef<DDateInputR
dModel,
dFormat,
dVisible,
dInitialVisible = false,
dPlacement = 'bottom-left',
dOrder = 'ascend',
dPlaceholder,
Expand Down Expand Up @@ -90,7 +92,7 @@ function DatePicker(props: DDatePickerProps, ref: React.ForwardedRef<DDateInputR

const [t] = useTranslation();

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);

const size = dSize ?? gSize;
const disabled = (dDisabled || gDisabled || dFormControl?.control.disabled) ?? false;
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { DDrawerHeader } from './DrawerHeader';

export interface DDrawerProps extends React.HTMLAttributes<HTMLDivElement> {
dVisible: boolean;
dInitialVisible?: boolean;
dContainer?: DRefExtra | false;
dPlacement?: 'top' | 'right' | 'bottom' | 'left';
dWidth?: number | string;
Expand Down Expand Up @@ -51,6 +52,7 @@ export const DDrawer: {
const {
children,
dVisible,
dInitialVisible = false,
dContainer,
dPlacement = 'right',
dWidth = 400,
Expand Down Expand Up @@ -127,7 +129,7 @@ export const DDrawer: {
: `translateX(${(distance[dPlacement] / 3) * 2}px)`,
};

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onClose);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onClose);

const isFixed = isUndefined(dContainer);

Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface DDropdownProps<ID extends DId, T extends DDropdownItem<ID>>
children: React.ReactElement;
dList: T[];
dVisible?: boolean;
dInitialVisible?: boolean;
dPlacement?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right';
dTrigger?: 'hover' | 'click';
dArrow?: boolean;
Expand All @@ -57,6 +58,7 @@ function Dropdown<ID extends DId, T extends DDropdownItem<ID>>(
children,
dList,
dVisible,
dInitialVisible = false,
dPlacement = 'bottom-right',
dTrigger = 'hover',
dArrow = false,
Expand Down Expand Up @@ -157,7 +159,7 @@ function Dropdown<ID extends DId, T extends DDropdownItem<ID>>(
setFocusIds(ids);
};

const [visible, _changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, _changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);
const changeVisible = (visible: boolean) => {
if (!visible) {
setPopupIds([]);
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DModalHeader } from './ModalHeader';

export interface DModalProps extends React.HTMLAttributes<HTMLDivElement> {
dVisible: boolean;
dInitialVisible?: boolean;
dWidth?: number | string;
dTop?: number | string;
dZIndex?: number | string;
Expand Down Expand Up @@ -48,6 +49,7 @@ export const DModal: {
const {
children,
dVisible,
dInitialVisible = false,
dWidth = 520,
dTop = 100,
dZIndex,
Expand Down Expand Up @@ -96,7 +98,7 @@ export const DModal: {

const topStyle = dTop + (isNumber(dTop) ? 'px' : '');

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onClose);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onClose);

const maxZIndex = useMaxIndex(visible);
const zIndex = (() => {
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface DPopoverRef {
export interface DPopoverProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
children: React.ReactElement;
dVisible?: boolean;
dInitialVisible?: boolean;
dTrigger?: 'hover' | 'click';
dContainer?: DRefExtra | false;
dPlacement?: DPopupPlacement;
Expand All @@ -51,6 +52,7 @@ function Popover(props: DPopoverProps, ref: React.ForwardedRef<DPopoverRef>): JS
const {
children,
dVisible,
dInitialVisible = false,
dTrigger = 'hover',
dContainer,
dPlacement = 'top',
Expand Down Expand Up @@ -112,7 +114,7 @@ function Popover(props: DPopoverProps, ref: React.ForwardedRef<DPopoverRef>): JS
const titleId = `${dPrefix}popover-title-${uniqueId}`;
const bodyId = `${dPrefix}popover-content-${uniqueId}`;

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);

const maxZIndex = useMaxIndex(visible);
const zIndex = (() => {
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface DSelectProps<V extends DId, T extends DSelectItem<V>> extends O
dList: T[];
dModel?: V | null | V[];
dVisible?: boolean;
dInitialVisible?: boolean;
dPlaceholder?: string;
dSize?: DSize;
dLoading?: boolean;
Expand Down Expand Up @@ -82,6 +83,7 @@ function Select<V extends DId, T extends DSelectItem<V>>(
dList,
dModel,
dVisible,
dInitialVisible = false,
dPlaceholder,
dSize,
dLoading = false,
Expand Down Expand Up @@ -147,7 +149,7 @@ function Select<V extends DId, T extends DSelectItem<V>>(

const [focusVisible, setFocusVisible] = useState(false);

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);
const formControlInject = useFormControl(dFormControl);
const [_select, changeSelect] = useDValue<V | null | V[]>(
dMultiple ? [] : null,
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/time-picker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface DTimePickerProps extends Omit<React.HTMLAttributes<HTMLDivEleme
dModel?: Date | null | [Date, Date];
dFormat?: string;
dVisible?: boolean;
dInitialVisible?: boolean;
dPlacement?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right';
dOrder?: 'ascend' | 'descend' | false;
dPlaceholder?: string | [string?, string?];
Expand Down Expand Up @@ -61,6 +62,7 @@ function TimePicker(props: DTimePickerProps, ref: React.ForwardedRef<DTimePicker
dModel,
dFormat,
dVisible,
dInitialVisible = false,
dPlacement = 'bottom-left',
dOrder = 'ascend',
dPlaceholder,
Expand Down Expand Up @@ -91,7 +93,7 @@ function TimePicker(props: DTimePickerProps, ref: React.ForwardedRef<DTimePicker

const [t] = useTranslation();

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);

const size = dSize ?? gSize;
const disabled = (dDisabled || gDisabled || dFormControl?.control.disabled) ?? false;
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface DTooltipRef {
export interface DTooltipProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
children: React.ReactElement;
dVisible?: boolean;
dInitialVisible?: boolean;
dTrigger?: 'hover' | 'click';
dContainer?: DRefExtra | false;
dPlacement?: DPopupPlacement;
Expand All @@ -43,6 +44,7 @@ function Tooltip(props: DTooltipProps, ref: React.ForwardedRef<DTooltipRef>): JS
const {
children,
dVisible,
dInitialVisible = false,
dTrigger = 'hover',
dContainer,
dPlacement = 'top',
Expand Down Expand Up @@ -91,7 +93,7 @@ function Tooltip(props: DTooltipProps, ref: React.ForwardedRef<DTooltipRef>): JS
const uniqueId = useId();
const id = restProps.id ?? `${dPrefix}tooltip-${uniqueId}`;

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);

const maxZIndex = useMaxIndex(visible);
const zIndex = (() => {
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/tree-select/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface DTreeSelectProps<V extends DId, T extends DTreeItem<V>> extends
dModel?: V | null | V[];
dExpands?: V[];
dVisible?: boolean;
dInitialVisible?: boolean;
dPlaceholder?: string;
dSize?: DSize;
dLoading?: boolean;
Expand Down Expand Up @@ -81,6 +82,7 @@ function TreeSelect<V extends DId, T extends DTreeItem<V>>(
dModel,
dExpands,
dVisible,
dInitialVisible = false,
dPlaceholder,
dSize,
dLoading = false,
Expand Down Expand Up @@ -134,7 +136,7 @@ function TreeSelect<V extends DId, T extends DTreeItem<V>>(

const [searchValue, changeSearchValue] = useDValue<string>('', dSearchValue, onSearchValueChange);

const [visible, changeVisible] = useDValue<boolean>(false, dVisible, onVisibleChange);
const [visible, changeVisible] = useDValue<boolean>(dInitialVisible, dVisible, onVisibleChange);

const renderNodes = useMemo<AbstractTreeNode<V, T>[]>(
() =>
Expand Down

0 comments on commit 82ef3d5

Please sign in to comment.