Skip to content

Commit

Permalink
release: 7.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mako3577 committed Jan 8, 2024
1 parent ee3d7c5 commit 02524ae
Show file tree
Hide file tree
Showing 30 changed files with 885 additions and 807 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 7.0.0
Version: FREE 7.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": "7.0.0",
"version": "7.1.0",
"main": "index.js",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions app/src/free/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { DropdownProvider } from './contexts/DropdownContext';
import { DropdownBody } from './DropdownBody/DropdownBody';
import type { DropdownProps } from './types';

const MDBDropdown = ({ animation, onClose, onOpen, ...props }: DropdownProps) => {
const MDBDropdown = ({ animation, onClose, onOpen, wrapper = true, ...props }: DropdownProps) => {
return (
<DropdownProvider animation={animation} onClose={onClose} onOpen={onOpen} {...props}>
<DropdownBody {...props} />
<DropdownBody wrapper={wrapper} {...props} />
</DropdownProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const DropdownBody = ({
dropup,
dropright,
dropleft,
wrapper,
...props
}: DropdownProps) => {
useClickOutside();
Expand All @@ -25,9 +26,11 @@ export const DropdownBody = ({
className
);

return (
return wrapper ? (
<Tag className={classes} {...props}>
{children}
</Tag>
) : (
<>{children}</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const MDBDropdownMenu = ({
>
{Children.map(children, (child, idx) =>
cloneElement(child, {
tabIndex: 1,
tabIndex: 0,
'data-active': activeIndex === idx && true,
className: clsx(activeIndex === idx ? 'active' : '', child.props.className),
})
Expand Down
2 changes: 1 addition & 1 deletion app/src/free/components/Dropdown/contexts/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Dropdown {
}

export interface DropdownProviderProps {
children: ReactNode;
children?: ReactNode;
isOpen?: boolean;
options?: Record<string, unknown>;
animation?: boolean;
Expand Down
1 change: 1 addition & 0 deletions app/src/free/components/Dropdown/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface DropdownProps extends BaseComponent {
tag?: ComponentProps<any>;
onClose?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
onOpen?: (e: MouseEvent | SyntheticEvent | KeyboardEvent) => any;
wrapper?: boolean;
}
36 changes: 21 additions & 15 deletions app/src/free/forms/File/File.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import clsx from 'clsx';
import React from 'react';
import React, { useRef, forwardRef, useImperativeHandle } from 'react';
import type { FileProps } from './types';

const MDBFile: React.FC<FileProps> = ({ className, labelClass, labelStyle, inputRef, size, label, id, ...props }) => {
const inputClasses = clsx('form-control', `form-control-${size}`, className);
const labelClasses = clsx('form-label', labelClass);
const MDBFile: React.FC<FileProps> = forwardRef<HTMLInputElement, FileProps>(
({ className, labelClass, labelStyle, inputRef: inputRefProp, size, label, id, ...props }, ref) => {
const inputClasses = clsx('form-control', `form-control-${size}`, className);
const labelClasses = clsx('form-label', labelClass);
const inputRef = useRef<HTMLInputElement>(null);

return (
<>
{label && (
<label className={labelClasses} style={labelStyle} htmlFor={id}>
{label}
</label>
)}
<input className={inputClasses} type='file' id={id} ref={inputRef} {...props} />
</>
);
};
useImperativeHandle(ref, () => inputRef.current || inputRefProp?.current);

return (
<>
{label && (
<label className={labelClasses} style={labelStyle} htmlFor={id}>
{label}
</label>
)}
<input className={inputClasses} type='file' id={id} ref={inputRef} {...props} />
</>
);
}
);

MDBFile.displayName = 'MDBFile';
export default MDBFile;
75 changes: 36 additions & 39 deletions app/src/free/forms/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
'use client';

import clsx from 'clsx';
import React, { useState, useEffect, useRef, FocusEvent, ChangeEvent, useCallback, useImperativeHandle } from 'react';
import React, {
useState,
useEffect,
useRef,
FocusEvent,
ChangeEvent,
useCallback,
useImperativeHandle,
useMemo,
} from 'react';
import type { InputProps } from './types';
import { useOnScreen } from '../../../utils/hooks';

Expand All @@ -11,7 +20,7 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP
className,
size,
contrast,
value,
value: valueProp,
defaultValue,
id,
labelClass,
Expand All @@ -31,20 +40,24 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP
},
ref
) => {
const [newValue, setNewValue] = useState(value || defaultValue);
const [valueState, setValueState] = useState(defaultValue);
const value = useMemo(() => {
if (valueProp !== undefined) {
return valueProp;
}
return valueState;
}, [valueProp, valueState]);

const [labelWidth, setLabelWidth] = useState(0);
const [active, setActive] = useState(false);
const [counter, setCounter] = useState(0);

const innerRef = useRef<HTMLInputElement>(null);
const isVisible = useOnScreen(innerRef);

useImperativeHandle(ref, () => innerRef.current as HTMLInputElement);

const labelEl = useRef<HTMLLabelElement>(null);

const labelReference = labelRef ? labelRef : labelEl;

useImperativeHandle(ref, () => innerRef.current as HTMLInputElement);

const wrapperClasses = clsx('form-outline', contrast && 'form-white', wrapperClass);
const inputClasses = clsx(
'form-control',
Expand All @@ -55,58 +68,42 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP
);
const labelClasses = clsx('form-label', labelClass);

useEffect(() => {
if (!innerRef.current) return;

const { value } = innerRef.current;

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

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

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

const setWidth = useCallback(() => {
if (labelReference.current?.clientWidth) {
setLabelWidth(labelReference.current.clientWidth * 0.8 + 8);
}
}, [labelReference]);

useEffect(() => {
setWidth();
}, [labelReference.current?.clientWidth, setWidth, isVisible]);

const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
setNewValue(e.target.value);
setValueState(e.target.value);
showCounter && setCounter(e.target.value.length);
onChange?.(e);
};

const handleBlur = useCallback(
(e: FocusEvent<HTMLInputElement, Element>) => {
if (!innerRef.current) return;

if (
(newValue !== undefined && newValue != '') ||
(value !== undefined && value != '') ||
innerRef.current.value != ''
) {
if (value) {
setActive(true);
} else {
setActive(false);
}
onBlur && onBlur(e);
},
[newValue, value, onBlur]
[value, onBlur]
);

useEffect(() => {
setWidth();
}, [labelReference.current?.clientWidth, setWidth, isVisible]);

useEffect(() => {
if (value) {
return setActive(true);
}
setActive(false);
}, [value]);

return (
<WrapperTag className={wrapperClasses} style={wrapperStyle}>
<input
Expand All @@ -116,7 +113,7 @@ const MDBInput: React.FC<InputProps> = React.forwardRef<HTMLInputElement, InputP
onBlur={handleBlur}
onChange={handleChange}
onFocus={setWidth}
value={value}
value={valueProp}
defaultValue={defaultValue}
id={id}
ref={innerRef}
Expand Down
120 changes: 63 additions & 57 deletions app/src/free/forms/InputTemplate/InputTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,74 @@
import clsx from 'clsx';
import React from 'react';
import React, { forwardRef } from 'react';
import type { InputTemplateProps } from './types';

const InputTemplate: React.FC<InputTemplateProps> = ({
className,
inputRef,
labelClass,
wrapperClass,
labelStyle,
wrapperTag: WrapperTag = 'div',
wrapperStyle,
label,
inline,
btn,
id,
btnColor,
disableWrapper,
toggleSwitch,
...props
}) => {
let inputStyle = 'form-check-input';
let labelClassName = 'form-check-label';
const InputTemplate: React.FC<InputTemplateProps> = forwardRef(
(
{
className,
inputRef,
labelClass,
wrapperClass,
labelStyle,
wrapperTag: WrapperTag = 'div',
wrapperStyle,
label,
inline,
btn,
id,
btnColor,
disableWrapper,
toggleSwitch,
...props
},
ref
) => {
let inputStyle = 'form-check-input';
let labelClassName = 'form-check-label';

if (btn) {
inputStyle = 'btn-check';
if (btn) {
inputStyle = 'btn-check';

if (btnColor) {
labelClassName = `btn btn-${btnColor}`;
} else {
labelClassName = 'btn btn-primary';
if (btnColor) {
labelClassName = `btn btn-${btnColor}`;
} else {
labelClassName = 'btn btn-primary';
}
}
}

const wrapperClasses = clsx(
label && !btn && 'form-check',
inline && !btn && 'form-check-inline',
toggleSwitch && 'form-switch',
wrapperClass
);
const inputClasses = clsx(inputStyle, className);
const labelClasses = clsx(labelClassName, labelClass);
const wrapperClasses = clsx(
label && !btn && 'form-check',
inline && !btn && 'form-check-inline',
toggleSwitch && 'form-switch',
wrapperClass
);
const inputClasses = clsx(inputStyle, className);
const labelClasses = clsx(labelClassName, labelClass);

const inputBody = (
<>
<input className={inputClasses} id={id} ref={inputRef} {...props} />
{label && (
<label className={labelClasses} style={labelStyle} htmlFor={id}>
{label}
</label>
)}
</>
);
const inputBody = (
<>
<input className={inputClasses} id={id} ref={inputRef} {...props} />
{label && (
<label className={labelClasses} style={labelStyle} htmlFor={id}>
{label}
</label>
)}
</>
);

return (
<>
{disableWrapper ? (
inputBody
) : (
<WrapperTag style={wrapperStyle} className={wrapperClasses}>
{inputBody}
</WrapperTag>
)}
</>
);
};
return (
<>
{disableWrapper ? (
inputBody
) : (
<WrapperTag style={wrapperStyle} className={wrapperClasses} ref={ref}>
{inputBody}
</WrapperTag>
)}
</>
);
}
);

InputTemplate.displayName = 'InputTemplate';
export default InputTemplate;
Loading

0 comments on commit 02524ae

Please sign in to comment.