@dtdot/lego 2.0.0-7 → 2.0.0-9

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.
@@ -6,5 +6,8 @@ interface FormProps {
6
6
  onSubmit?: () => void;
7
7
  children: React.ReactNode;
8
8
  }
9
- declare const Form: ({ value, errors, onChange, onSubmit, children }: FormProps) => JSX.Element;
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(Math.max(index + 1, value?.length || 0))).map((_, i) => value?.[i] || {});
7
+ const safeError = Array.from(Array(Math.max(index + 1, value?.length || 0))).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,3 +1,6 @@
1
1
  /// <reference types="react" />
2
- declare const Loader: () => JSX.Element;
2
+ export interface LoaderProps {
3
+ variant?: 'page-loader' | 'default';
4
+ }
5
+ declare const Loader: ({ variant }: LoaderProps) => JSX.Element;
3
6
  export default Loader;
@@ -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 Loader = () => {
44
- return (React.createElement(motion.div, { style: loadingContainer, variants: loadingContainerVariants, initial: 'start', animate: 'end', "data-cy": 'loader' },
45
- React.createElement(motion.span, { style: loadingCircle, variants: loadingCircleVariants, transition: loadingCircleTransition }),
46
- React.createElement(motion.span, { style: loadingCircle, variants: loadingCircleVariants, transition: loadingCircleTransition }),
47
- React.createElement(motion.span, { style: loadingCircle, variants: loadingCircleVariants, transition: loadingCircleTransition })));
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;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export type SpacerSize = '0.5x' | '1x' | '2x' | '4x' | '6x';
2
+ export type SpacerSize = '0.5x' | '1x' | '2x' | '4x' | '6x' | '8x';
3
3
  export interface SpacerProps {
4
4
  size: SpacerSize;
5
5
  }
@@ -12,6 +12,8 @@ const getSpacing = (size) => {
12
12
  return '32px';
13
13
  case '6x':
14
14
  return '48px';
15
+ case '8x':
16
+ return '64px';
15
17
  default:
16
18
  return 0;
17
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "2.0.0-7",
3
+ "version": "2.0.0-9",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {