@dtdot/lego 2.0.0-7 → 2.0.0-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/Form/Form.component.d.ts +4 -1
- package/build/components/Form/Form.component.js +2 -0
- package/build/components/Form/_NestedFormArray.d.ts +8 -0
- package/build/components/Form/_NestedFormArray.js +25 -0
- package/build/components/Loader/Loader.component.d.ts +4 -1
- package/build/components/Loader/Loader.component.js +17 -5
- package/build/components/Spacer/Spacer.component.d.ts +1 -1
- package/build/components/Spacer/Spacer.component.js +2 -0
- package/package.json +1 -1
|
@@ -6,5 +6,8 @@ interface FormProps {
|
|
|
6
6
|
onSubmit?: () => void;
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
}
|
|
9
|
-
declare const Form:
|
|
9
|
+
declare const Form: {
|
|
10
|
+
({ value, errors, onChange, onSubmit, children }: FormProps): JSX.Element;
|
|
11
|
+
NestedFormArray: ({ name, index, children }: import("./_NestedFormArray").NestedFormArrayProps) => JSX.Element;
|
|
12
|
+
};
|
|
10
13
|
export default Form;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import FormStateContext from './FormState.context';
|
|
4
|
+
import NestedFormArray from './_NestedFormArray';
|
|
4
5
|
const Form = ({ value, errors = {}, onChange, onSubmit, children }) => {
|
|
5
6
|
const onChangeFn = (key, fieldValue) => {
|
|
6
7
|
onChange({
|
|
@@ -22,4 +23,5 @@ const Form = ({ value, errors = {}, onChange, onSubmit, children }) => {
|
|
|
22
23
|
return (React.createElement(FormStateContext.Provider, { value: contextValue },
|
|
23
24
|
React.createElement("form", { onSubmit: onSubmitFn }, children)));
|
|
24
25
|
};
|
|
26
|
+
Form.NestedFormArray = NestedFormArray;
|
|
25
27
|
export default Form;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface NestedFormArrayProps {
|
|
3
|
+
name: string;
|
|
4
|
+
index: number;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare const NestedFormArray: ({ name, index, children }: NestedFormArrayProps) => JSX.Element;
|
|
8
|
+
export default NestedFormArray;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormStateContext from './FormState.context';
|
|
3
|
+
import useFormNode from './useFormNode.hook';
|
|
4
|
+
const NestedFormArray = ({ name, index, children }) => {
|
|
5
|
+
const { value, error, onChange } = useFormNode(name);
|
|
6
|
+
const safeValue = Array.from(Array(index + 1)).map((_, i) => value?.[i] || {});
|
|
7
|
+
const safeError = Array.from(Array(index + 1)).map((_, i) => error?.[i] || {});
|
|
8
|
+
const nestedValue = safeValue[index];
|
|
9
|
+
const nestedErrors = safeError[index];
|
|
10
|
+
console.log('safe', safeValue);
|
|
11
|
+
const onChangeFn = (key, fieldValue) => {
|
|
12
|
+
const newValue = [
|
|
13
|
+
...safeValue.map((item, i) => (i === index ? { ...item, [key]: fieldValue } : item)),
|
|
14
|
+
];
|
|
15
|
+
console.log(newValue);
|
|
16
|
+
onChange && onChange(newValue);
|
|
17
|
+
};
|
|
18
|
+
const contextValue = {
|
|
19
|
+
value: nestedValue,
|
|
20
|
+
errors: nestedErrors,
|
|
21
|
+
onChange: onChangeFn,
|
|
22
|
+
};
|
|
23
|
+
return React.createElement(FormStateContext.Provider, { value: contextValue }, children);
|
|
24
|
+
};
|
|
25
|
+
export default NestedFormArray;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { motion } from 'framer-motion';
|
|
3
|
+
import styled from 'styled-components';
|
|
3
4
|
import colours from '../../colours/colours';
|
|
5
|
+
const PageLoaderContainer = styled.div `
|
|
6
|
+
display: flex;
|
|
7
|
+
height: 300px;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
align-items: center;
|
|
10
|
+
`;
|
|
4
11
|
const loadingContainer = {
|
|
5
12
|
width: '40px',
|
|
6
13
|
height: '26px',
|
|
@@ -40,10 +47,15 @@ const loadingCircleTransition = {
|
|
|
40
47
|
repeatType: 'reverse',
|
|
41
48
|
ease: 'easeInOut',
|
|
42
49
|
}; // Framer motion isn't accepting 'repeatType' but animation breaks without it
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
const BaseLoader = () => (React.createElement(motion.div, { style: loadingContainer, variants: loadingContainerVariants, initial: 'start', animate: 'end', "data-cy": 'loader' },
|
|
51
|
+
React.createElement(motion.span, { style: loadingCircle, variants: loadingCircleVariants, transition: loadingCircleTransition }),
|
|
52
|
+
React.createElement(motion.span, { style: loadingCircle, variants: loadingCircleVariants, transition: loadingCircleTransition }),
|
|
53
|
+
React.createElement(motion.span, { style: loadingCircle, variants: loadingCircleVariants, transition: loadingCircleTransition })));
|
|
54
|
+
const Loader = ({ variant = 'default' }) => {
|
|
55
|
+
if (variant === 'page-loader') {
|
|
56
|
+
return (React.createElement(PageLoaderContainer, null,
|
|
57
|
+
React.createElement(BaseLoader, null)));
|
|
58
|
+
}
|
|
59
|
+
return React.createElement(BaseLoader, null);
|
|
48
60
|
};
|
|
49
61
|
export default Loader;
|