Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/dialog/AlertDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ export function useAlertDialog({ title, message, ...footerProps }) {
};
}

export function AlertDialog({ title, message, children, onClose, closeLabel }) {
export function AlertDialog({
title = 'Atention required',
message,
children,
onClose = () => {},
closeLabel = 'Close',
}) {
return (
<Dialog
title={title}
Expand All @@ -33,12 +39,6 @@ export function AlertDialog({ title, message, children, onClose, closeLabel }) {
);
}

AlertDialog.defaultProps = {
onClose: () => {},
title: 'Atention required',
closeLabel: 'Close',
};

AlertDialog.propTypes = {
children: PropTypes.node,
message: PropTypes.node,
Expand All @@ -47,17 +47,13 @@ AlertDialog.propTypes = {
closeLabel: PropTypes.node,
};

function AlertDialogFooter({ close, onClose, closeLabel }) {
function AlertDialogFooter({ close, onClose = () => {}, closeLabel = 'Close' }) {
return (
<button type="button" className="btn btn-primary" onClick={awaitForAsyncTask(onClose, close)}>
{closeLabel}
</button>
);
}
AlertDialogFooter.defaultProps = {
onClose: () => {},
closeLabel: 'Close',
};

AlertDialogFooter.propTypes = {
close: PropTypes.func,
Expand Down
23 changes: 10 additions & 13 deletions src/dialog/ConfirmationDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useConfirmationDialog({ title, message, ...footerProps }) {
};
}

export function ConfirmationDialog({ title, message, children, ...footerProps }) {
export function ConfirmationDialog({ title = 'Atention required', message, children, ...footerProps }) {
return (
<Dialog
title={title}
Expand All @@ -34,10 +34,6 @@ export function ConfirmationDialog({ title, message, children, ...footerProps })
);
}

ConfirmationDialog.defaultProps = {
title: 'Atention required',
};

ConfirmationDialog.propTypes = {
children: PropTypes.node,
message: PropTypes.node,
Expand All @@ -49,7 +45,14 @@ ConfirmationDialog.propTypes = {
proceedType: PropTypes.oneOf(['primary', 'danger', 'success']),
};

function ConfirmationDialogFooter({ close, onProceed, onCancel, cancelLabel, proceedLabel, proceedType }) {
function ConfirmationDialogFooter({
close,
onProceed = () => {},
onCancel = () => {},
cancelLabel = 'Cancel',
proceedLabel = 'Proceed',
proceedType = 'primary',
}) {
return (
<>
<button type="button" className="btn btn-secondary" onClick={safeClick(awaitForAsyncTask(onCancel, close))}>
Expand All @@ -65,13 +68,7 @@ function ConfirmationDialogFooter({ close, onProceed, onCancel, cancelLabel, pro
</>
);
}
ConfirmationDialogFooter.defaultProps = {
onProceed: () => {},
onCancel: () => {},
cancelLabel: 'Cancel',
proceedLabel: 'Proceed',
proceedType: 'primary',
};

ConfirmationDialogFooter.propTypes = {
close: PropTypes.func,
onCancel: PropTypes.func,
Expand Down
7 changes: 1 addition & 6 deletions src/dialog/Dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useDialog({ onlyRenderContentIfIsOpen = true, ...props }) {
};
}

export function Dialog({ children, onlyRenderContentIfIsOpen, onClose, ...props }) {
export function Dialog({ children, onlyRenderContentIfIsOpen = true, onClose = () => {}, ...props }) {
const { isOpen, open, close } = useOpenState();

const onCloseDialog = async () => {
Expand All @@ -53,11 +53,6 @@ export function Dialog({ children, onlyRenderContentIfIsOpen, onClose, ...props
);
}

Dialog.defaultProps = {
onClose: () => {},
onlyRenderContentIfIsOpen: true,
};

Dialog.propTypes = {
afterOpen: PropTypes.func,
children: PropTypes.node,
Expand Down
27 changes: 8 additions & 19 deletions src/dialog/Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import { formatClasses } from '../utils/attributes';
const ESCAPE_KEYCODE = 27;

export function Modal({
afterOpen,
afterOpen = () => {},
body,
centered,
centered = true,
contentClassName,
footer,
isOpen,
keyboard,
keyboard = true,
onClose,
scrollable,
size,
staticBackdrop,
scrollable = false,
size = '',
staticBackdrop = false,
title,
useTimesClose,
dialogBodyProps,
useTimesClose = true,
dialogBodyProps = {},
}) {
const modalRef = useRef(null);
const closeAndHide = useCallback(() => {
Expand Down Expand Up @@ -104,17 +104,6 @@ export function Modal({
);
}

Modal.defaultProps = {
afterOpen: () => {},
centered: true,
dialogBodyProps: {},
keyboard: true,
scrollable: false,
size: '',
staticBackdrop: false,
useTimesClose: true,
};

Modal.propTypes = {
afterOpen: PropTypes.func,
body: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
Expand Down
22 changes: 7 additions & 15 deletions src/forms/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { useForm } from './helpers/useForm';
import { FormActions } from './FormActions';

export function Form({
cancelLabel,
cancelLabel = 'Cancel',
children,
customValidation,
customValidation = false,
customActions,
initialValues,
onCancel,
onSubmit,
onChange,
submitLabel,
onCancel = () => {},
onSubmit = () => {},
onChange = () => {},
submitLabel = 'Submit',
validations,
transform,
transform = (data) => data,
}) {
const formState = useForm(initialValues, { validations, onChange, transform });
const formRef = useRef(null);
Expand Down Expand Up @@ -100,14 +100,6 @@ export function Form({
);
}

Form.defaultProps = {
cancelLabel: 'Cancel',
customValidation: false,
submitLabel: 'Submit',
onChange: () => {},
transform: (data) => data,
};

Form.propTypes = {
cancelLabel: PropTypes.string,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
Expand Down
25 changes: 7 additions & 18 deletions src/forms/FormAutocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Dropdown } from '../mixed/Dropdown';
import { useOpenState } from '../utils/useOpenState';
import { formatClasses } from '../utils/attributes';
import { getValueByPath } from '../utils/getters-setters';
import { defaultFilter } from '../utils/filter';

import {
booleanOrFunction,
Expand All @@ -16,6 +17,7 @@ import {
serializeValue,
} from './helpers/form-helpers';
import { useFormControl } from './helpers/useFormControl';
// eslint-disable-next-line import/max-dependencies
import { FormGroup } from './FormGroup';

function getSelectedItem(value, items, allowUnlistedValue, trackBy) {
Expand All @@ -34,17 +36,17 @@ export function FormAutocomplete({
afterChange,
allowUnlistedValue,
disabled: _disabled,
filter,
filter = defaultFilter,
id,
listContainerRef,
name,
onSearch,
onClearSearch,
openOnFocus,
onSearch = () => {},
onClearSearch = () => {},
openOnFocus = false,
options,
placeholder,
required: _required,
template,
template = (x) => x,
trackBy,
}) {
const {
Expand Down Expand Up @@ -262,19 +264,6 @@ export function FormAutocomplete({
);
}

FormAutocomplete.defaultProps = {
openOnFocus: false,
onSearch: () => {},
onClearSearch: () => {},
filter: (_searchValue) => (item) => {
const itemValue = JSON.stringify(item.label).toLowerCase();
const searchValue = _searchValue.toLowerCase();

return itemValue.includes(searchValue);
},
template: (x) => x,
};

FormAutocomplete.propTypes = {
afterChange: PropTypes.func,
allowUnlistedValue: PropTypes.bool,
Expand Down
41 changes: 11 additions & 30 deletions src/forms/FormAutocompleteTag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import { formatClasses } from '../utils/attributes';
import { useToasts } from '../toasts/useToasts';

import { getValueByPath, setValueByPath } from '../utils/getters-setters';
import { defaultFilter } from '../utils/filter';

import { booleanOrFunction, handleInputChange, normalizeOptions } from './helpers/form-helpers';
import { useFormControl } from './helpers/useFormControl';
// eslint-disable-next-line import/max-dependencies
import { FormGroup } from './FormGroup';

export function FormAutocompleteTag({
addButtonIcon,
addButtonIcon = <i className="bi bi-plus-lg" />,
afterChange,
repeatedTagErrorMessage,
allowUnlistedValue,
repeatedTagErrorMessage = 'Impossible to add repeated tag',
allowUnlistedValue = true,
disabled: _disabled,
filter,
filter = defaultFilter,
listContainerRef,
name,
onSearch,
openOnFocus,
onSearch = () => {},
openOnFocus = false,
options: _options,
placeholder,
required: _required,
template,
template = (x) => x,
trackBy,
}) {
const { showToast } = useToasts();
Expand Down Expand Up @@ -306,21 +307,6 @@ export function FormAutocompleteTag({
);
}

FormAutocompleteTag.defaultProps = {
allowUnlistedValue: true,
openOnFocus: false,
onSearch: () => {},
filter: (_searchValue) => (item) => {
const itemValue = JSON.stringify(item.label).toLowerCase();
const searchValue = _searchValue.toLowerCase();

return itemValue.includes(searchValue);
},
template: (x) => x,
repeatedTagErrorMessage: 'Impossible to add repeated tag',
addButtonIcon: <i className="bi bi-plus-lg" />,
};

FormAutocompleteTag.propTypes = {
addButtonIcon: PropTypes.node,
afterChange: PropTypes.func,
Expand All @@ -343,9 +329,9 @@ FormAutocompleteTag.propTypes = {
};

export function FormGroupAutocompleteTag({
addButtonIcon,
removeButtonIcon,
allowUnlistedValue,
addButtonIcon = <i className="bi bi-plus-lg" />,
removeButtonIcon = <i className="bi bi-x-lg" />,
allowUnlistedValue = true,
afterChange,
disabled,
filter,
Expand Down Expand Up @@ -432,11 +418,6 @@ export function FormGroupAutocompleteTag({
</FormGroup>
);
}
FormGroupAutocompleteTag.defaultProps = {
allowUnlistedValue: true,
addButtonIcon: <i className="bi bi-plus-lg" />,
removeButtonIcon: <i className="bi bi-x-lg" />,
};

FormGroupAutocompleteTag.propTypes = {
afterChange: PropTypes.func,
Expand Down
27 changes: 10 additions & 17 deletions src/forms/FormDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ export const FormDropdown = ({
childClassName,
disabled,
dropdownClassName,
includeEmptyItem,
includeEmptyItem = true,
itemClassName,
listContainerRef,
menuClassName,
menuClassName = 'p-0 w-100',
name,
options,
placeholder,
template,
toggleIcon,
template = (x) => x,
toggleIcon = function toggleIcon(isOpen) {
return (
<div className="d-flex align-items-center px-2">
<i className={`bi ${isOpen ? 'bi-chevron-up' : 'bi-chevron-down'}`}></i>
</div>
);
},
trackBy,
}) => {
const dropdownRef = useRef(null);
Expand Down Expand Up @@ -126,19 +132,6 @@ export const FormDropdown = ({
);
};

FormDropdown.defaultProps = {
includeEmptyItem: true,
menuClassName: 'p-0 w-100',
template: (x) => x,
toggleIcon: function toggleIcon(isOpen) {
return (
<div className="d-flex align-items-center px-2">
<i className={`bi ${isOpen ? 'bi-chevron-up' : 'bi-chevron-down'}`}></i>
</div>
);
},
};

FormDropdown.propTypes = {
afterChange: PropTypes.func,
childClassName: PropTypes.string,
Expand Down
Loading