Skip to content

Commit

Permalink
release: 6.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mako3577 committed May 29, 2023
1 parent 4dc0332 commit da743a6
Show file tree
Hide file tree
Showing 184 changed files with 6,405 additions and 4,537 deletions.
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MDB 5 React

Version: FREE 6.0.0
Version: FREE 6.1.0

Documentation:
https://mdbootstrap.com/docs/b5/react/
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdb-react-ui-kit-demo",
"version": "6.0.0",
"version": "6.1.0",
"main": "index.js",
"repository": {
"type": "git",
Expand Down
11 changes: 8 additions & 3 deletions app/src/components/Collapse/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import type { CollapseProps } from './types';
const MDBCollapse: React.FC<CollapseProps> = ({
className,
children,
show,
show = false,
id,
navbar,
tag: Tag,
collapseRef,
style,
onShow,
onHide,
...props
}): JSX.Element => {
const [showCollapse, setShowCollapse] = useState<boolean | undefined>(false);
Expand Down Expand Up @@ -39,7 +41,10 @@ const MDBCollapse: React.FC<CollapseProps> = ({
}, [collapseHeight, showCollapse, refCollapse]);

useEffect(() => {
setShowCollapse(show);
if (showCollapse !== show) {
show ? onShow?.() : onHide?.();
setShowCollapse(show);
}

if (showCollapse) {
setTransition(true);
Expand All @@ -52,7 +57,7 @@ const MDBCollapse: React.FC<CollapseProps> = ({
return () => {
clearTimeout(timer);
};
}, [show, showCollapse]);
}, [show, showCollapse, onShow, onHide]);

useEffect(() => {
if (showCollapse) {
Expand Down
11 changes: 7 additions & 4 deletions app/src/components/Dropdown/DropdownItem/DropdownItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ const MDBDropdownItem = ({
preventCloseOnClick,
...props
}: DropdownItemProps) => {
const { setIsOpenState, onHide } = useDropdownContext();
const { setIsOpenState, onHide, setActiveIndex } = useDropdownContext();

const handleClose = (e: MouseEvent<HTMLElement>) => {
if (disabled || preventCloseOnClick) return;
onHide?.(e);
onClick?.(e);
if (disabled || preventCloseOnClick || e.defaultPrevented) {
return;
}

onHide?.();
setTimeout(() => setActiveIndex(-1), 300);
setIsOpenState(false);
onClick?.(e);
};

return (
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/Dropdown/DropdownMenu/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const MDBDropdownMenu = ({
return 'left-start';
}

const isEnd = popperElement && getComputedStyle(popperElement).getPropertyValue('--bs-position').trim() === 'end';
const isEnd = popperElement && getComputedStyle(popperElement).getPropertyValue('--mdb-position').trim() === 'end';

if (dropup) {
return isEnd ? 'top-end' : 'top-start';
Expand Down
7 changes: 5 additions & 2 deletions app/src/components/Dropdown/DropdownToggle/DropdownToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ const MDBDropdownToggle = ({
const classes = clsx('dropdown-toggle', split && 'dropdown-toggle-split', className);

const handleOpenToggle = (e: MouseEvent<HTMLElement>) => {
isOpenState ? onHide?.() : onShow?.();
onClick?.(e);
isOpenState ? onHide?.(e) : onShow?.(e);

if (e.defaultPrevented) {
return;
}
setIsOpenState((prev) => !prev);
onClick?.(e);

setTimeout(() => setActiveIndex(-1), 300);
};
Expand Down
10 changes: 5 additions & 5 deletions app/src/components/Dropdown/contexts/types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, SetStateAction, ReactNode } from 'react';
import { Dispatch, SetStateAction, ReactNode, SyntheticEvent } from 'react';

export interface Dropdown {
activeIndex: number;
Expand All @@ -10,8 +10,8 @@ export interface Dropdown {
setActiveIndex: Dispatch<SetStateAction<number>>;
setPopperElement: Dispatch<SetStateAction<HTMLElement | null>>;
setReferenceElement: Dispatch<SetStateAction<HTMLElement | null>>;
onHide?: () => any;
onShow?: () => any;
onHide?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
onShow?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
dropup?: boolean;
dropright?: boolean;
dropleft?: boolean;
Expand All @@ -26,6 +26,6 @@ export interface DropdownProviderProps {
dropup?: boolean;
dropright?: boolean;
dropleft?: boolean;
onHide?: () => any;
onShow?: () => any;
onHide?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
onShow?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
}
18 changes: 10 additions & 8 deletions app/src/components/Dropdown/hooks/useClickOutside.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { useCallback, useEffect } from 'react';
import { ReactPropTypes, SyntheticEvent, useCallback, useEffect } from 'react';
import { isNode } from '../helpers/typeguards';
import { useDropdownContext } from './useDropdownContext';

export const useClickOutside = () => {
const { isOpenState, setIsOpenState, setActiveIndex, popperElement, referenceElement, onHide } = useDropdownContext();

const handleClickOutside = useCallback(
({ target }: MouseEvent) => {
(e: MouseEvent | SyntheticEvent) => {
onHide?.(e);
if (
!isOpenState ||
!isNode(target) ||
(popperElement && popperElement.contains(target)) ||
(referenceElement && referenceElement.contains(target))
)
!isNode(e.target) ||
(popperElement && popperElement.contains(e.target)) ||
(referenceElement && referenceElement.contains(e.target)) ||
e.defaultPrevented
) {
return;

}
setIsOpenState(false);
onHide?.();

setTimeout(() => setActiveIndex(-1), 300);
},
[isOpenState, setIsOpenState, setActiveIndex, popperElement, referenceElement, onHide]
Expand Down
17 changes: 14 additions & 3 deletions app/src/components/Dropdown/hooks/useKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,27 @@ export const useKeyboard = (children: ReactElement[] | ReactElement) => {
if (e.key === 'Enter') {
const el: HTMLElement | null = document.querySelector('[data-active="true"]');
const child = el?.firstElementChild as HTMLElement | null | undefined;
child?.click();

if (child) {
return child.click();
}

onHide?.(e);

if (e.defaultPrevented) {
return;
}
setIsOpenState(false);
setTimeout(() => setActiveIndex(-1), 300);
}

if (e.key === 'Escape') {
setIsOpenState(false);
onHide?.();
onHide?.(e);
if (e.defaultPrevented) {
return;
}

setIsOpenState(false);
setTimeout(() => setActiveIndex(-1), 300);
}
},
Expand Down
6 changes: 3 additions & 3 deletions app/src/components/Dropdown/types.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseComponent } from '../../types/baseComponent';
import { ReactNode, ComponentProps } from 'react';
import { ReactNode, ComponentProps, SyntheticEvent } from 'react';

export interface DropdownProps extends BaseComponent {
animation?: boolean;
Expand All @@ -11,6 +11,6 @@ export interface DropdownProps extends BaseComponent {
dropleft?: boolean;
children?: ReactNode;
tag?: ComponentProps<any>;
onHide?: () => any;
onShow?: () => any;
onHide?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
onShow?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
}
30 changes: 19 additions & 11 deletions app/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const MDBModal: React.FC<ModalProps> = ({

const modalInnerRef = useRef<HTMLElement>(null);
const modalReference = modalRef ? modalRef : modalInnerRef;

const classes = clsx(
'modal',
staticModal && 'modal-static',
Expand All @@ -44,8 +43,10 @@ const MDBModal: React.FC<ModalProps> = ({
const backdropClasses = clsx('modal-backdrop', 'fade', isOpenBackdrop && 'show');

const closeModal = useCallback(() => {
setIsOpenModal(false);
isOpenModal && onHide?.();
setIsOpenModal((isCurrentlyShown) => {
isCurrentlyShown && onHide?.();
return false;
});

setTimeout(() => {
setIsOpenBackrop(false);
Expand All @@ -59,6 +60,10 @@ const MDBModal: React.FC<ModalProps> = ({

const handleClickOutside = useCallback(
(event: MouseEvent) => {
if (nonInvasive) {
return;
}

if (isOpenModal && event.target === modalReference.current) {
if (!staticBackdrop) {
closeModal();
Expand All @@ -71,7 +76,7 @@ const MDBModal: React.FC<ModalProps> = ({
}
}
},
[isOpenModal, modalReference, staticBackdrop, closeModal, onHidePrevented]
[isOpenModal, modalReference, staticBackdrop, closeModal, onHidePrevented, nonInvasive]
);

const handleKeydown = useCallback(
Expand Down Expand Up @@ -177,16 +182,19 @@ const MDBModal: React.FC<ModalProps> = ({
}, [show, closeModal, setShow, onShow]);

useEffect(() => {
if (!nonInvasive) {
window.addEventListener('click', handleClickOutside);
window.addEventListener('keydown', handleKeydown);
}
const addMouseUpListener = (e: MouseEvent) => {
if (!(e.target as HTMLElement).closest('.modal-dialog')) {
window.addEventListener('mouseup', handleClickOutside, { once: true });
}
};
window.addEventListener('mousedown', addMouseUpListener);
window.addEventListener('keydown', handleKeydown);

return () => {
window.removeEventListener('click', handleClickOutside);
window.removeEventListener('mousedown', addMouseUpListener);
window.removeEventListener('keydown', handleKeydown);
};
}, [handleKeydown, handleClickOutside, nonInvasive]);
}, [handleKeydown, handleClickOutside]);

const appendToBodyTemplate = (
<>
Expand Down Expand Up @@ -224,7 +232,7 @@ const MDBModal: React.FC<ModalProps> = ({
{children}
</Tag>
{ReactDOM.createPortal(
backdrop && innerShow && !nonInvasive && <div className={backdropClasses}></div>,
backdrop && innerShow && !nonInvasive && <div onClick={closeModal} className={backdropClasses}></div>,
document.body
)}
</>
Expand Down
18 changes: 9 additions & 9 deletions app/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback } from 'react';
import React, { useState, useEffect, useCallback, SyntheticEvent } from 'react';
import ReactDOM from 'react-dom';
import clsx from 'clsx';
import { usePopper } from 'react-popper';
Expand Down Expand Up @@ -58,16 +58,16 @@ const MDBTooltip: React.FC<TooltipProps> = ({
};
}, [isOpenState, isClicked]);

const handleOnMouseEnter = (e: any) => {
setIsOpenState(true);
onShow?.();
onMouseEnter && onMouseEnter(e);
const handleOnMouseEnter = (e: SyntheticEvent) => {
onShow?.(e);
!e.defaultPrevented && setIsOpenState(true);
onMouseEnter?.(e);
};

const handleOnMouseLeave = (e: any) => {
setIsOpenState(false);
onHide?.();
onMouseLeave && onMouseLeave(e);
const handleOnMouseLeave = (e: SyntheticEvent) => {
onHide?.(e);
!e.defaultPrevented && setIsOpenState(false);
onMouseLeave?.(e);
};

const handleClick = useCallback(
Expand Down
7 changes: 5 additions & 2 deletions app/src/components/Tooltip/types.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MouseEventHandler, SyntheticEvent } from 'react';
import { BaseComponent } from '../../types/baseComponent';
import { placement } from '../../types/placement';

Expand All @@ -10,8 +11,10 @@ interface TooltipProps extends BaseComponent {
title?: React.ReactNode;
wrapperProps?: Record<string, unknown>;
wrapperClass?: string;
onShow?: () => any;
onHide?: () => any;
onShow?: (e: SyntheticEvent) => any;
onHide?: (e: SyntheticEvent) => any;
onMouseEnter?: (e: SyntheticEvent) => any;
onMouseLeave?: (e: SyntheticEvent) => any;
}

export { TooltipProps };
12 changes: 6 additions & 6 deletions app/src/forms/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP

const { value } = innerRef.current;

value.length > 0 ? setActive(true) : setActive(false);
value != '' ? setActive(true) : setActive(false);
}, [innerRef.current?.value]);

useEffect(() => {
if (value === undefined) return;
value.toString().length > 0 ? setActive(true) : setActive(false);
value != '' ? setActive(true) : setActive(false);
}, [value]);

useEffect(() => {
if (defaultValue === undefined) return;
defaultValue.toString().length > 0 ? setActive(true) : setActive(false);
defaultValue != '' ? setActive(true) : setActive(false);
}, [defaultValue]);

const setWidth = useCallback(() => {
Expand All @@ -87,9 +87,9 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP
if (!innerRef.current) return;

if (
(newValue !== undefined && newValue.toString().length > 0) ||
(value !== undefined && value.toString().length > 0) ||
innerRef.current.value.length > 0
(newValue !== undefined && newValue != '') ||
(value !== undefined && value != '') ||
innerRef.current.value != ''
) {
setActive(true);
} else {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit da743a6

Please sign in to comment.