@dtdot/lego 0.17.2 → 0.17.8
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/ImageUpload/ImageUpload.component.js +1 -1
- package/build/components/LiveList/LiveList.component.js +7 -4
- package/build/components/LiveList/LiveList.stories.d.ts +1 -0
- package/build/components/LiveList/LiveList.stories.js +7 -0
- package/build/components/LiveList/_FocusContext.js +1 -1
- package/build/components/LiveList/_LiveListRow.js +1 -1
- package/build/components/Notification/Notification.component.js +1 -1
- package/build/components/ProfileImage/ProfileImage.component.js +1 -1
- package/build/components/QrCode/QrCode.component.js +1 -1
- package/build/hooks/useKeyPress.js +2 -3
- package/package.json +31 -31
|
@@ -35,7 +35,7 @@ const addVariants = {
|
|
|
35
35
|
const defaultValue = [{ id: uuidv4(), value: '' }];
|
|
36
36
|
const LiveList = ({ value: inputValue, name, onChange: propsOnChange }) => {
|
|
37
37
|
const { getFocused, requestFocus } = useContext(FocusContext);
|
|
38
|
-
const { value: contextValue, error: contextError, onChange: contextOnChange } = useFormNode(name);
|
|
38
|
+
const { value: contextValue, error: contextError, onChange: contextOnChange, } = useFormNode(name);
|
|
39
39
|
const value = contextValue || inputValue || defaultValue;
|
|
40
40
|
const wrappedOnChange = useCallback((val) => {
|
|
41
41
|
if (propsOnChange) {
|
|
@@ -46,7 +46,7 @@ const LiveList = ({ value: inputValue, name, onChange: propsOnChange }) => {
|
|
|
46
46
|
}
|
|
47
47
|
}, [propsOnChange, contextOnChange]);
|
|
48
48
|
useEffect(() => {
|
|
49
|
-
if (!
|
|
49
|
+
if (!value?.length) {
|
|
50
50
|
wrappedOnChange([{ id: uuidv4(), value: '' }]);
|
|
51
51
|
}
|
|
52
52
|
}, [value, wrappedOnChange]);
|
|
@@ -65,10 +65,13 @@ const LiveList = ({ value: inputValue, name, onChange: propsOnChange }) => {
|
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
const focusedValue = value.find((val) => val.id === focusedId);
|
|
68
|
-
if (focusedValue
|
|
68
|
+
if (focusedValue?.value) {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
const focusedIndex = value.findIndex((val) => val.id === focusedId);
|
|
72
|
+
if (focusedIndex === 0) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
72
75
|
const prevId = focusedIndex > 0 ? value[focusedIndex - 1].id : undefined;
|
|
73
76
|
wrappedOnChange(value.filter((val) => val.id !== focusedId));
|
|
74
77
|
if (prevId) {
|
|
@@ -94,7 +97,7 @@ const LiveList = ({ value: inputValue, name, onChange: propsOnChange }) => {
|
|
|
94
97
|
const newItem = { id: uuidv4(), value: '' };
|
|
95
98
|
wrappedOnChange([...value, newItem]);
|
|
96
99
|
};
|
|
97
|
-
if (!
|
|
100
|
+
if (!value?.length) {
|
|
98
101
|
return null;
|
|
99
102
|
}
|
|
100
103
|
return (React.createElement("div", null,
|
|
@@ -3,5 +3,6 @@ import { Meta } from '@storybook/react/types-6-0';
|
|
|
3
3
|
export declare const Standard: () => JSX.Element;
|
|
4
4
|
export declare const InForm: () => JSX.Element;
|
|
5
5
|
export declare const WithValidation: () => JSX.Element;
|
|
6
|
+
export declare const EmptyList: () => JSX.Element;
|
|
6
7
|
declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
|
|
7
8
|
export default _default;
|
|
@@ -44,6 +44,13 @@ export const WithValidation = () => {
|
|
|
44
44
|
React.createElement(Button, { onClick: clear }, "Clear"),
|
|
45
45
|
React.createElement(Button, { onClick: validate }, "Set Errors"))));
|
|
46
46
|
};
|
|
47
|
+
export const EmptyList = () => {
|
|
48
|
+
const [value, setValue] = useState({});
|
|
49
|
+
return (React.createElement(React.Fragment, null,
|
|
50
|
+
React.createElement(Heading.FormHeading, null, "Ingredients"),
|
|
51
|
+
React.createElement(Spacer, { size: '1x' }),
|
|
52
|
+
React.createElement(LiveList, { value: value, onChange: setValue })));
|
|
53
|
+
};
|
|
47
54
|
export default {
|
|
48
55
|
title: 'Components/LiveList',
|
|
49
56
|
component: LiveList,
|
|
@@ -57,7 +57,7 @@ const FocusContextProvider = ({ children }) => {
|
|
|
57
57
|
function FocusContextProviderHOC(WrappedComponent) {
|
|
58
58
|
const HocComponent = (props) => {
|
|
59
59
|
return (React.createElement(FocusContextProvider, null,
|
|
60
|
-
React.createElement(WrappedComponent,
|
|
60
|
+
React.createElement(WrappedComponent, { ...props })));
|
|
61
61
|
};
|
|
62
62
|
return HocComponent;
|
|
63
63
|
}
|
|
@@ -60,7 +60,7 @@ const LiveListRow = ({ id, value, error, onChange, onRemove }) => {
|
|
|
60
60
|
onBlur(id);
|
|
61
61
|
};
|
|
62
62
|
return (React.createElement(InputContainer, { whileHover: 'hover' },
|
|
63
|
-
React.createElement(Input, { onFocus: handleFocus, onBlur: handleBlur, ref: inputRef, value: value, error: error, onChange: handleChange }),
|
|
63
|
+
React.createElement(Input, { onFocus: handleFocus, onBlur: handleBlur, ref: inputRef, value: value || '', error: error, onChange: handleChange }),
|
|
64
64
|
React.createElement(RemoveContainer, { animate: isFocused ? 'focus' : undefined, style: { opacity: 0 }, variants: removeVariants, transition: { type: 'spring', duration: 0.3 } },
|
|
65
65
|
React.createElement(RemoveInner, { onClick: onRemove },
|
|
66
66
|
React.createElement(FontAwesomeIcon, { icon: faTimes })))));
|
|
@@ -11,5 +11,5 @@ const NotificationContainer = styled.div `
|
|
|
11
11
|
}
|
|
12
12
|
`;
|
|
13
13
|
const Notification = (props) => (React.createElement(NotificationContainer, null,
|
|
14
|
-
React.createElement(Alert,
|
|
14
|
+
React.createElement(Alert, { ...props })));
|
|
15
15
|
export default Notification;
|
|
@@ -30,7 +30,7 @@ const Identicon = ({ value }) => {
|
|
|
30
30
|
const hexColours = [colours.red, colours.green, colours.blue, colours.yellow];
|
|
31
31
|
const convertedColours = hexColours.map((hex) => {
|
|
32
32
|
const rgb = hexToRgb(hex);
|
|
33
|
-
return [rgb
|
|
33
|
+
return [rgb?.r, rgb?.g, rgb?.b, 255];
|
|
34
34
|
});
|
|
35
35
|
const hash = SparkMD5.hash(value || 'unknown user');
|
|
36
36
|
const colourIndex = Math.floor(Math.random() * 4);
|
|
@@ -45,7 +45,7 @@ const QrCode = ({ value }) => {
|
|
|
45
45
|
if (hintTimeoutRef.current) {
|
|
46
46
|
window.clearTimeout(hintTimeoutRef.current);
|
|
47
47
|
}
|
|
48
|
-
if (inputRef
|
|
48
|
+
if (inputRef?.current) {
|
|
49
49
|
inputRef.current.select();
|
|
50
50
|
document.execCommand('copy');
|
|
51
51
|
}
|
|
@@ -4,14 +4,13 @@ const useKeypress = (key, handler) => {
|
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
eventListenerRef.current = (event) => {
|
|
6
6
|
if (key === event.key) {
|
|
7
|
-
handler
|
|
7
|
+
handler?.();
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
}, [key, handler]);
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const eventListener = (event) => {
|
|
13
|
-
|
|
14
|
-
(_a = eventListenerRef.current) === null || _a === void 0 ? void 0 : _a.call(eventListenerRef, event);
|
|
13
|
+
eventListenerRef.current?.(event);
|
|
15
14
|
};
|
|
16
15
|
window.addEventListener('keydown', eventListener);
|
|
17
16
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtdot/lego",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.8",
|
|
4
4
|
"description": "Some reusable components for building my applications",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,36 +17,36 @@
|
|
|
17
17
|
"build"
|
|
18
18
|
],
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/cli": "^7.
|
|
21
|
-
"@babel/core": "^7.
|
|
22
|
-
"@babel/preset-react": "^7.
|
|
23
|
-
"@babel/preset-typescript": "^7.
|
|
24
|
-
"@storybook/addon-actions": "^6.
|
|
25
|
-
"@storybook/addon-essentials": "^6.
|
|
26
|
-
"@storybook/addon-links": "^6.
|
|
27
|
-
"@storybook/react": "^6.
|
|
28
|
-
"@types/identicon.js": "^2.3.
|
|
29
|
-
"@types/qrcode": "^1.4.
|
|
30
|
-
"@types/react": "^17.0.
|
|
31
|
-
"@types/react-dom": "^17.0.
|
|
20
|
+
"@babel/cli": "^7.17.0",
|
|
21
|
+
"@babel/core": "^7.17.2",
|
|
22
|
+
"@babel/preset-react": "^7.16.7",
|
|
23
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
24
|
+
"@storybook/addon-actions": "^6.4.19",
|
|
25
|
+
"@storybook/addon-essentials": "^6.4.19",
|
|
26
|
+
"@storybook/addon-links": "^6.4.19",
|
|
27
|
+
"@storybook/react": "^6.4.19",
|
|
28
|
+
"@types/identicon.js": "^2.3.1",
|
|
29
|
+
"@types/qrcode": "^1.4.2",
|
|
30
|
+
"@types/react": "^17.0.39",
|
|
31
|
+
"@types/react-dom": "^17.0.11",
|
|
32
32
|
"@types/spark-md5": "^3.0.2",
|
|
33
|
-
"@types/styled-components": "^5.1.
|
|
33
|
+
"@types/styled-components": "^5.1.22",
|
|
34
34
|
"@types/uuid": "^8.3.4",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
36
|
-
"@typescript-eslint/parser": "^4.
|
|
37
|
-
"babel-loader": "^8.2.
|
|
38
|
-
"eslint": "^7.
|
|
39
|
-
"eslint-config-prettier": "^7.
|
|
40
|
-
"eslint-plugin-prettier": "^3.
|
|
41
|
-
"eslint-plugin-react": "^7.
|
|
42
|
-
"eslint-plugin-react-hooks": "^4.
|
|
43
|
-
"prettier": "^2.
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
36
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
37
|
+
"babel-loader": "^8.2.3",
|
|
38
|
+
"eslint": "^7.32.0",
|
|
39
|
+
"eslint-config-prettier": "^7.2.0",
|
|
40
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
41
|
+
"eslint-plugin-react": "^7.28.0",
|
|
42
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
43
|
+
"prettier": "^2.5.1",
|
|
44
44
|
"prettier-eslint": "^12.0.0",
|
|
45
|
-
"react": "^17.0.
|
|
46
|
-
"react-dom": "^17.0.
|
|
45
|
+
"react": "^17.0.2",
|
|
46
|
+
"react-dom": "^17.0.2",
|
|
47
47
|
"storybook-addon-styled-component-theme": "^1.3.0",
|
|
48
|
-
"styled-components": "^5.
|
|
49
|
-
"typescript": "^4.
|
|
48
|
+
"styled-components": "^5.3.3",
|
|
49
|
+
"typescript": "^4.5.5"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"react": "^17.0.1",
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
|
58
|
-
"@fortawesome/free-solid-svg-icons": "^5.15.
|
|
58
|
+
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
|
59
59
|
"@fortawesome/react-fontawesome": "^0.1.13",
|
|
60
|
-
"framer-motion": "^
|
|
60
|
+
"framer-motion": "^6.2.6",
|
|
61
61
|
"identicon.js": "^2.3.3",
|
|
62
|
-
"qrcode": "^1.
|
|
62
|
+
"qrcode": "^1.5.0",
|
|
63
63
|
"react-use-measure": "^2.1.1",
|
|
64
|
-
"spark-md5": "^3.0.
|
|
64
|
+
"spark-md5": "^3.0.2",
|
|
65
65
|
"uuid": "^8.3.2"
|
|
66
66
|
}
|
|
67
67
|
}
|