@dtdot/lego 2.0.0-25 → 2.0.0-28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/Input/Input.component.d.ts +1 -0
- package/build/components/Input/Input.component.js +16 -3
- package/build/components/Loader/Loader.component.d.ts +5 -1
- package/build/components/Loader/Loader.component.js +27 -8
- package/build/components/Modal/Modal.component.d.ts +6 -5
- package/build/components/Modal/Modal.component.js +2 -2
- package/package.json +5 -12
|
@@ -15,6 +15,7 @@ export interface IInputProps {
|
|
|
15
15
|
'onBlur'?: () => void;
|
|
16
16
|
'data-testid'?: string;
|
|
17
17
|
'suggestions'?: SelectOption[];
|
|
18
|
+
'loading'?: boolean;
|
|
18
19
|
}
|
|
19
20
|
declare const Input: React.ForwardRefExoticComponent<IInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
20
21
|
export default Input;
|
|
@@ -9,6 +9,7 @@ import ControlLabel from '../../shared/ControlLabel';
|
|
|
9
9
|
import { ControlStyles } from '../../shared/ControlStyles';
|
|
10
10
|
import useFormNode, { getValue } from '../Form/useFormNode.hook';
|
|
11
11
|
import { OptionsPopper } from '../common/Options.component';
|
|
12
|
+
import Loader from '../Loader/Loader.component';
|
|
12
13
|
const InputContainer = styled.div `
|
|
13
14
|
position: relative;
|
|
14
15
|
border-radius: 2px;
|
|
@@ -52,6 +53,16 @@ const ErrorInner = styled.div `
|
|
|
52
53
|
align-items: center;
|
|
53
54
|
cursor: pointer;
|
|
54
55
|
`;
|
|
56
|
+
const LoadingContainer = styled.div `
|
|
57
|
+
position: absolute;
|
|
58
|
+
top: 0;
|
|
59
|
+
right: 0;
|
|
60
|
+
height: 100%;
|
|
61
|
+
width: 40px;
|
|
62
|
+
display: flex;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
align-items: center;
|
|
65
|
+
`;
|
|
55
66
|
const errorVariants = {
|
|
56
67
|
show: { opacity: 1, x: 10 },
|
|
57
68
|
};
|
|
@@ -63,7 +74,7 @@ const messageVariants = {
|
|
|
63
74
|
errorFocus: { opacity: 1, y: -4 },
|
|
64
75
|
};
|
|
65
76
|
const Input = React.forwardRef(function ForwardRefInput(props, ref) {
|
|
66
|
-
const { label, name, description, placeholder, disabled, type = 'text', autoFocus, value, 'error': propsError, onChange, onFocus, onBlur, 'data-testid': dataTestId, suggestions, } = props;
|
|
77
|
+
const { label, name, description, placeholder, disabled, type = 'text', autoFocus, value, 'error': propsError, onChange, onFocus, onBlur, 'data-testid': dataTestId, suggestions, loading, } = props;
|
|
67
78
|
const [isOpen, setIsOpen] = useState(false);
|
|
68
79
|
const [isFocused, setIsFocused] = useState(false);
|
|
69
80
|
const [referenceElement, setReferenceElement] = useState();
|
|
@@ -111,8 +122,10 @@ const Input = React.forwardRef(function ForwardRefInput(props, ref) {
|
|
|
111
122
|
React.createElement(ErrorContainer, { animate: error ? 'show' : undefined, style: { opacity: 0 }, variants: errorVariants, transition: { type: 'spring', duration: 0.3 }, "data-testid": 'error-indicator' },
|
|
112
123
|
React.createElement(ErrorInner, null,
|
|
113
124
|
React.createElement(FontAwesomeIcon, { icon: faExclamationCircle }))),
|
|
114
|
-
error && (React.createElement(ErrorMessage, { style: { opacity: 0, y: 0 }, animate: animationVariant, variants: messageVariants, transition: { type: 'spring', duration: 0.3 }, "data-testid": 'error-message' }, error))
|
|
115
|
-
|
|
125
|
+
error && (React.createElement(ErrorMessage, { style: { opacity: 0, y: 0 }, animate: animationVariant, variants: messageVariants, transition: { type: 'spring', duration: 0.3 }, "data-testid": 'error-message' }, error)),
|
|
126
|
+
loading && (React.createElement(LoadingContainer, null,
|
|
127
|
+
React.createElement(Loader, { size: 'sm' })))),
|
|
128
|
+
splitDescription && (React.createElement(ControlDescription, null, splitDescription.map((line, index) => (React.createElement("span", { key: index },
|
|
116
129
|
index !== 0 && React.createElement("br", null),
|
|
117
130
|
line))))),
|
|
118
131
|
filteredOptions && isOpen && (React.createElement(OptionsPopper, { referenceElement: referenceElement, options: filteredOptions, onSelect: handleSetSuggestion, onClose: () => setIsOpen(false) }))));
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
export interface BaseLoaderProps {
|
|
3
|
+
size: 'sm' | 'md';
|
|
4
|
+
}
|
|
2
5
|
export interface LoaderProps {
|
|
3
6
|
variant?: 'page-loader' | 'default';
|
|
7
|
+
size?: 'sm' | 'md';
|
|
4
8
|
}
|
|
5
|
-
declare const Loader: ({ variant }: LoaderProps) => JSX.Element;
|
|
9
|
+
declare const Loader: ({ variant, size }: LoaderProps) => JSX.Element;
|
|
6
10
|
export default Loader;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
import { motion } from 'framer-motion';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import colours from '../../colours/colours';
|
|
@@ -47,15 +47,34 @@ const loadingCircleTransition = {
|
|
|
47
47
|
repeatType: 'reverse',
|
|
48
48
|
ease: 'easeInOut',
|
|
49
49
|
}; // Framer motion isn't accepting 'repeatType' but animation breaks without it
|
|
50
|
-
const BaseLoader = () =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
const BaseLoader = ({ size }) => {
|
|
51
|
+
const loadingCircleWithSize = useMemo(() => {
|
|
52
|
+
const sizePx = size === 'md' ? '10px' : '5px';
|
|
53
|
+
return {
|
|
54
|
+
...loadingCircle,
|
|
55
|
+
width: sizePx,
|
|
56
|
+
height: sizePx,
|
|
57
|
+
};
|
|
58
|
+
}, [size]);
|
|
59
|
+
const loadingContainerWithSize = useMemo(() => {
|
|
60
|
+
const widthPx = size === 'md' ? '40px' : '20px';
|
|
61
|
+
const heightPx = size === 'md' ? '26px' : '13px';
|
|
62
|
+
return {
|
|
63
|
+
...loadingContainer,
|
|
64
|
+
width: widthPx,
|
|
65
|
+
height: heightPx,
|
|
66
|
+
};
|
|
67
|
+
}, [size]);
|
|
68
|
+
return (React.createElement(motion.div, { style: loadingContainerWithSize, variants: loadingContainerVariants, initial: 'start', animate: 'end', "data-testid": 'loader' },
|
|
69
|
+
React.createElement(motion.span, { style: loadingCircleWithSize, variants: loadingCircleVariants, transition: loadingCircleTransition }),
|
|
70
|
+
React.createElement(motion.span, { style: loadingCircleWithSize, variants: loadingCircleVariants, transition: loadingCircleTransition }),
|
|
71
|
+
React.createElement(motion.span, { style: loadingCircleWithSize, variants: loadingCircleVariants, transition: loadingCircleTransition })));
|
|
72
|
+
};
|
|
73
|
+
const Loader = ({ variant = 'default', size = 'md' }) => {
|
|
55
74
|
if (variant === 'page-loader') {
|
|
56
75
|
return (React.createElement(PageLoaderContainer, null,
|
|
57
|
-
React.createElement(BaseLoader,
|
|
76
|
+
React.createElement(BaseLoader, { size: size })));
|
|
58
77
|
}
|
|
59
|
-
return React.createElement(BaseLoader,
|
|
78
|
+
return React.createElement(BaseLoader, { size: size });
|
|
60
79
|
};
|
|
61
80
|
export default Loader;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export type ModalSize = 'sm' | 'md' | 'lg';
|
|
3
3
|
export interface ModalProps {
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
size?: ModalSize;
|
|
6
|
-
loading?: boolean;
|
|
7
|
-
onClose: () => void;
|
|
4
|
+
'children': React.ReactNode;
|
|
5
|
+
'size'?: ModalSize;
|
|
6
|
+
'loading'?: boolean;
|
|
7
|
+
'onClose': () => void;
|
|
8
|
+
'data-testid'?: string;
|
|
8
9
|
}
|
|
9
10
|
declare const Modal: {
|
|
10
|
-
({ children, size, loading, onClose }: ModalProps): React.ReactPortal;
|
|
11
|
+
({ children, size, loading, onClose, "data-testid": dataTestId }: ModalProps): React.ReactPortal;
|
|
11
12
|
Body: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
12
13
|
Header: ({ header, subHeader }: import("./_ModalHeader.component").ModalHeaderProps) => JSX.Element;
|
|
13
14
|
};
|
|
@@ -76,7 +76,7 @@ const SpinnerContainer = styled.div `
|
|
|
76
76
|
justify-content: center;
|
|
77
77
|
align-items: center;
|
|
78
78
|
`;
|
|
79
|
-
const Modal = ({ children, size, loading, onClose }) => {
|
|
79
|
+
const Modal = ({ children, size, loading, onClose, 'data-testid': dataTestId }) => {
|
|
80
80
|
const handleModalClick = (event) => {
|
|
81
81
|
event.modalClicked = true;
|
|
82
82
|
};
|
|
@@ -90,7 +90,7 @@ const Modal = ({ children, size, loading, onClose }) => {
|
|
|
90
90
|
React.createElement(ScrollContainer, null,
|
|
91
91
|
React.createElement(ModalContext.Provider, { value: { onClose } },
|
|
92
92
|
React.createElement(ModalWrapper, { size: size || 'md' },
|
|
93
|
-
React.createElement(ModalOuter, { transition: { type: 'spring', bounce: 0, duration: 0.6 }, initial: { height: loading ? loadingHeight : 'auto' }, animate: { height: loading ? loadingHeight : 'auto' }, size: size || 'md', onClick: handleModalClick, "data-testid": 'modal' },
|
|
93
|
+
React.createElement(ModalOuter, { transition: { type: 'spring', bounce: 0, duration: 0.6 }, initial: { height: loading ? loadingHeight : 'auto' }, animate: { height: loading ? loadingHeight : 'auto' }, size: size || 'md', onClick: handleModalClick, "data-testid": dataTestId || 'modal' },
|
|
94
94
|
!loading && children,
|
|
95
95
|
loading && (React.createElement(SpinnerContainer, null,
|
|
96
96
|
React.createElement(Loader, null))))))))), document.body);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtdot/lego",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-28",
|
|
4
4
|
"description": "Some reusable components for building my applications",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
8
8
|
"start": "start-storybook -p 6006 --no-open",
|
|
9
9
|
"watch": "npm run build -- --watch",
|
|
10
|
-
"lint": "eslint
|
|
10
|
+
"lint": "eslint src",
|
|
11
11
|
"storybook": "start-storybook -p 6006",
|
|
12
12
|
"build-storybook": "build-storybook",
|
|
13
13
|
"pretty": "prettier --write \"./**/*.{js,jsx,ts,tsx,json}\""
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@babel/core": "^7.20.7",
|
|
23
23
|
"@babel/preset-react": "^7.18.6",
|
|
24
24
|
"@babel/preset-typescript": "^7.18.6",
|
|
25
|
-
"@dtdot/eslint-config": "^0.0.
|
|
25
|
+
"@dtdot/eslint-config": "^0.0.9-15",
|
|
26
26
|
"@storybook/addon-actions": "^6.5.15",
|
|
27
27
|
"@storybook/addon-essentials": "^6.5.15",
|
|
28
28
|
"@storybook/addon-interactions": "^6.5.15",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"@storybook/manager-webpack5": "^6.5.15",
|
|
32
32
|
"@storybook/react": "^6.5.15",
|
|
33
33
|
"@storybook/testing-library": "^0.0.13",
|
|
34
|
-
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
|
35
34
|
"@types/identicon.js": "^2.3.1",
|
|
36
35
|
"@types/qrcode": "^1.5.0",
|
|
37
36
|
"@types/react": "^18.0.26",
|
|
@@ -40,15 +39,9 @@
|
|
|
40
39
|
"@types/styled-components": "^5.1.26",
|
|
41
40
|
"@types/tinycolor2": "^1.4.3",
|
|
42
41
|
"@types/uuid": "^9.0.0",
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^5.47.0",
|
|
44
|
-
"@typescript-eslint/parser": "^5.47.0",
|
|
45
42
|
"babel-loader": "^9.1.0",
|
|
46
|
-
"eslint": "^8.
|
|
47
|
-
"
|
|
48
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
49
|
-
"eslint-plugin-react": "^7.31.11",
|
|
50
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
|
-
"prettier": "^2.8.1",
|
|
43
|
+
"eslint": "^8.57.0",
|
|
44
|
+
"prettier": "^3.2.5",
|
|
52
45
|
"react": "^18.2.0",
|
|
53
46
|
"react-dom": "^18.2.0",
|
|
54
47
|
"styled-components": "^5.3.5",
|