Skip to content

Commit

Permalink
fix: Overall Proptypes, linter error, circular dependencies, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-fx committed Nov 29, 2023
1 parent a1f8a11 commit f9dd999
Show file tree
Hide file tree
Showing 113 changed files with 3,334 additions and 2,324 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
],
"import/no-names-as-default": "off",
"import/prefer-default-export": "warn",
"no-param-reassign": "off"
"no-param-reassign": "off",
"radix": "off",
"no-unused-vars": "warn"
}
}
4 changes: 2 additions & 2 deletions merged_tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@
"y": "0",
"blur": "4",
"spread": "0",
"color": "rgba({button.background.color.primary.hover}, 0.80)",
"color": "{button.background.color.primary.hover}",
"type": "dropShadow"
},
"type": "boxShadow"
Expand Down Expand Up @@ -3174,7 +3174,7 @@
"y": "0",
"blur": "4",
"spread": "0",
"color": "rgba({buttonIcon.background.color.primary.hover}, 0.80)",
"color": "{buttonAction.background.color.primary.hover--reverse-transparent}",
"type": "dropShadow"
},
"type": "boxShadow"
Expand Down
17 changes: 9 additions & 8 deletions packages/components/src/ThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ export const BUBBLES_THEME = {

const THEME_PROVIDER_PROP_TYPES = {
theme: PropTypes.object,
children: PropTypes.node,
};
const THEME_PROVIDER_DEFAULT_PROPS = {
theme: BUBBLES_THEME,
};

const parseTheme = (theme) => {
if (isEmpty(theme.other)) return theme;
recursiveParse(theme.other);
return theme;
};

const recursiveParse = (object) => {
if (!isObject(object)) return;
for (const property in object) {
Object.keys(object).forEach((property) => {
if (object[property].value) {
object[property] = object[property].value;
} else {
recursiveParse(object[property]);
}
}
});
};

const parseTheme = (theme) => {
if (isEmpty(theme.other)) return theme;
recursiveParse(theme.other);
return theme;
};

const ThemeProvider = ({ children, theme }) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/dates/Calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const CALENDAR_PROP_TYPES = {
firstDayOfWeek: PropTypes.oneOf(CALENDAR_FIRST_DAYS),
minDate: PropTypes.instanceOf(Date),
maxDate: PropTypes.instanceOf(Date),
size: PropTypes.string,
};

const Calendar = forwardRef(({ range, size, locale, ...props }, ref) => {
Expand All @@ -105,6 +106,7 @@ const Calendar = forwardRef(({ range, size, locale, ...props }, ref) => {
return <Comp {...props} locale={currentLocale} ref={ref} classNames={classes} />;
});

Calendar.displayName = 'Calendar';
Calendar.defaultProps = CALENDAR_DEFAULT_PROPS;
Calendar.propTypes = CALENDAR_PROP_TYPES;

Expand Down
9 changes: 6 additions & 3 deletions packages/components/src/feedback/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
} from '@bubbles-ui/icons/solid';
import { RemoveIcon } from '@bubbles-ui/icons/outline';
import { AlertStyles } from './Alert.styles';
import { Button, ActionButton } from '../../form';
import { Button } from '../../form/Button';
import { ActionButton } from '../../form/ActionButton';

export const ALERT_SEVERITIES = ['info', 'success', 'warning', 'error'];
export const ALERT_VARIANTS = ['inline', 'block'];
Expand Down Expand Up @@ -38,9 +39,9 @@ const Alert = ({
severity = ALERT_SEVERITIES.includes(severity) ? severity : 'info';
const isCloseable = useMemo(
() => closeable && !isNil(closeable) && closeable !== '',
[closeable]
[closeable],
);
const { classes, cx } = AlertStyles({ variant, severity }, { name: 'Alert' });
const { classes } = AlertStyles({ variant, severity }, { name: 'Alert' });

return (
<MantineAlert
Expand Down Expand Up @@ -75,6 +76,7 @@ const Alert = ({
);
};

Alert.displayName = 'Alert';
Alert.defaultProps = {
variant: 'inline',
severity: 'info',
Expand All @@ -99,6 +101,7 @@ Alert.propTypes = {
onClose: PropTypes.func,
/** Controls if Alert uses aria role */
useAria: PropTypes.bool,
children: PropTypes.node,
};

export { Alert };
3 changes: 1 addition & 2 deletions packages/components/src/feedback/Loader/Loader.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { isString } from 'lodash';
import { Loader as MantineLoader, Box } from '@mantine/core';
import { Loader as MantineLoader } from '@mantine/core';
import { ContextContainer, CONTEXT_CONTAINER_PROP_TYPES } from '../../layout';
import { Text } from '../../typography';
import { LoaderStyles } from './Loader.styles';

export const LOADER_LABEL_POSITIONS = ['right', 'bottom'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Calification } from '../../informative';
import { ScoreFeedbackStyles } from './ScoreFeedback.styles';
import { SCORE_FEEDBACK_DEFAULT_PROPS, SCORE_FEEDBACK_PROP_TYPES } from './ScoreFeedback.constants';

const ScoreFeedback = ({ calification, children, styles, className, useAria, ...props }) => {
const ScoreFeedback = ({ calification, children, styles, className, useAria }) => {
const { classes, cx } = ScoreFeedbackStyles({ styles }, { name: 'ScoreFeedback' });

return (
// Role is left empty, it should be 'comment' but the role is proposed for WAI-ARIA 1.3, which is still being drafted.
<Box className={cx(classes.root, className)} role={useAria ? '' : ''}>
<Box className={cx(classes.root, className)} role={useAria ? 'comment' : ''}>
<Calification
{...calification}
inverted={true}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import { Box } from '../../layout';
import { Box } from '../../layout/Box';
import { Avatar } from '../../informative/Avatar';
import { ImageLoader } from '../../misc/ImageLoader';
import { TextClamp } from '../../typography/TextClamp';
import { ScoreFronstageStyles } from './ScoreFronstage.styles';
import {
SCORE_FRONSTAGE_DEFAULT_PROPS,
SCORE_FRONSTAGE_PROP_TYPES,
} from './ScoreFronstage.constants';
import { Average } from './Average';
import { Item } from './Item';
import { Avatar } from '../../informative';
import { ImageLoader } from '../../misc';
import { TextClamp } from '../../typography';

const ScoreFronstage = ({
title,
Expand All @@ -24,7 +24,7 @@ const ScoreFronstage = ({
locale,
...props
}) => {
const { classes, cx } = ScoreFronstageStyles({}, { name: 'ScoreFronstage' });
const { classes } = ScoreFronstageStyles({}, { name: 'ScoreFronstage' });

return (
<Box className={classes.root} {...props}>
Expand Down
18 changes: 10 additions & 8 deletions packages/components/src/form/FileUpload/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import React, { useMemo, useRef } from 'react';
import PropTypes from 'prop-types';
import { Group, Text } from '@mantine/core';
import { Dropzone as MantineDropzone } from '@mantine/dropzone';
import { FileUploadStyles } from './FileUpload.styles';
import { Stack, Box } from '../../layout/';
import { FileItemDisplay } from '../../informative/FileItemDisplay';
import { Alert } from '../../feedback/Alert';
import { InputWrapper, INPUT_WRAPPER_PROP_TYPES, ActionButton, Button } from '../../form';
import { DeleteBinIcon } from '@bubbles-ui/icons/solid/';
import { SynchronizeArrowIcon } from '@bubbles-ui/icons/outline';
import { isEmpty, isFunction } from 'lodash';
import { FileUploadStyles } from './FileUpload.styles';
import { Stack, Box } from '../../layout';
import { FileItemDisplay } from '../../informative/FileItemDisplay';
import { Alert } from '../../feedback/Alert';
import { InputWrapper, INPUT_WRAPPER_PROP_TYPES } from '../InputWrapper';
import { ActionButton } from '../ActionButton';
import { Button } from '../Button';

export const FILE_UPLOAD_DEFAULT_PROPS = {
disabled: false,
Expand Down Expand Up @@ -69,14 +71,14 @@ const FileUpload = ({

const onDropHandler = (acceptedFiles) => {
const newFiles = [...files, ...acceptedFiles];
isFunction(onChange) && onChange(newFiles.length === 1 ? newFiles[0] : newFiles);
if (isFunction(onChange)) onChange(newFiles.length === 1 ? newFiles[0] : newFiles);
setFiles(newFiles);
setError(false);
};

const removeFile = (index) => {
const newFiles = files.filter((file, fileIndex) => fileIndex !== index);
isFunction(onChange) && onChange(newFiles.length === 1 ? newFiles[0] : newFiles);
if (isFunction(onChange)) onChange(newFiles.length === 1 ? newFiles[0] : newFiles);
setFiles(newFiles);
};

Expand All @@ -94,7 +96,7 @@ const FileUpload = ({

const { classes, cx } = FileUploadStyles(
{ disabled, single, files, hasError },
{ name: 'FileUpload' }
{ name: 'FileUpload' },
);
return (
<Box className={classes.wrapper}>
Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/form/FileUpload/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { FileUpload } from './FileUpload';

export { FileUpload };
export * from './FileUpload';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { isFunction, isString, isNil } from 'lodash';
import { CloudUploadIcon, UndoIcon } from '@bubbles-ui/icons/outline/';
import { Box, Stack } from '../../layout';
import { Button } from '../../form';
import { Box } from '../../layout/Box';
import { Stack } from '../../layout/Stack';
import { Button } from '../Button';
import { ImageLoader } from '../../misc/ImageLoader';
import { ImagePreviewInputStyles } from './ImagePreviewInput.styles';

Expand All @@ -24,6 +25,9 @@ export const IMAGE_PREVIEW_INPUT_PROP_TYPES = {
previewStyle: PropTypes.object,
control: PropTypes.element,
onChange: PropTypes.func,
readonly: PropTypes.bool,
disabled: PropTypes.bool,
useAria: PropTypes.bool,
};

const ImagePreviewInput = ({
Expand All @@ -36,7 +40,6 @@ const ImagePreviewInput = ({
readonly,
disabled,
useAria,
...props
}) => {
const [imagePreview, setImagePreview] = useState(previewURL);
const [imageValue, setImageValue] = useState(value);
Expand All @@ -57,20 +60,20 @@ const ImagePreviewInput = ({
}, [value]);

const resetImage = () => {
isFunction(onChange) && onChange(null);
if (isFunction(onChange)) onChange(null);
setImagePreview(null);
setImageValue(null);
};

const openFileBrowser = () => {
let input = document.createElement('input');
const input = document.createElement('input');
input.type = 'file';
input.accept = 'image/*';
input.onchange = (e) => {
const file = e.target.files[0];
file.path = file.name;
setImageValue(file);
isFunction(onChange) && onChange(file);
if (isFunction(onChange)) onChange(file);
};
input.click();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import { Text } from '@mantine/core';
import { AlertInformationCircleIcon } from '@bubbles-ui/icons/solid';
import { Box } from '../../layout/Box';
import {
INPUT_DESCRIPTION_DEFAULT_PROPS,
INPUT_DESCRIPTION_PROP_TYPES,
} from './InputDescription.constants';
import { InputDescriptionStyles } from './InputDescription.styles';
import { AlertInformationCircleIcon } from '@bubbles-ui/icons/solid';
import { Box } from '../../layout';

const InputDescription = ({ message, withIcon, ...props }) => {
const { classes, cx } = InputDescriptionStyles({ withIcon });
const InputDescription = ({ message, withIcon }) => {
const { classes } = InputDescriptionStyles({ withIcon });

return (
<Box className={classes.container}>
Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/form/InputDescription/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { InputDescription } from './InputDescription';

export { InputDescription };
export * from './InputDescription';
10 changes: 5 additions & 5 deletions packages/components/src/form/InputLabel/InputLabel.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { isEmpty } from 'lodash';
import { Box } from '../../layout/Box';
import { Text } from '../../typography/Text';
import { InputDescription } from '../InputDescription';
import { InputLabelStyles } from './InputLabel.styles';
import { INPUT_LABEL_DEFAULT_PROPS, INPUT_LABEL_PROP_TYPES } from './InputLabel.constants';
import { Text } from '../../typography';
import { InputDescription } from '../InputDescription';
import { isEmpty } from 'lodash';
import { Box } from '../../layout';

const InputLabel = ({ label, description, withDescriptionIcon, required, ...props }) => {
const { classes, cx } = InputLabelStyles({}, { name: 'InputLabel' });
const { classes } = InputLabelStyles({}, { name: 'InputLabel' });

return (
<Box className={classes.container}>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/form/InputWrapper/InputWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Box } from '../../layout/Box';
import { Stack } from '../../layout/Stack';
import { InputError } from '../InputError';
import { InputHelp } from '../InputHelp';
import { InputLabel } from '../InputLabel';
import { InputWrapperStyles } from './InputWrapper.styles';
import {
INPUT_WRAPPER_DEFAULT_PROPS,
INPUT_WRAPPER_PROP_TYPES,
INPUT_WRAPPER_ORIENTATIONS,
INPUT_WRAPPER_SIZES,
} from './InputWrapper.constants';
import { InputLabel } from '../InputLabel';

const InputWrapper = ({
orientation: orientationProp,
Expand Down
Loading

0 comments on commit f9dd999

Please sign in to comment.