@dtdot/lego 2.0.0-6 → 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/Button/Button.component.js +9 -5
- 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/build/components/Table/Table.component.d.ts +3 -1
- package/build/components/Table/Table.component.js +14 -0
- package/build/components/Table/_TableAction.d.ts +6 -2
- package/build/components/Table/_TableAction.js +6 -3
- package/package.json +1 -1
|
@@ -33,7 +33,9 @@ const IconOuter = styled.span `
|
|
|
33
33
|
justify-content: center;
|
|
34
34
|
|
|
35
35
|
color: ${(props) => getThemeVariantColours(props.variant, props.theme).contrastText};
|
|
36
|
-
background-color: ${(props) =>
|
|
36
|
+
background-color: ${(props) => props.iconOnly
|
|
37
|
+
? getThemeVariantColours(props.variant, props.theme).main
|
|
38
|
+
: getThemeVariantColours(props.variant, props.theme).darker};
|
|
37
39
|
|
|
38
40
|
height: ${(props) => props.height || getIconContainerSizePx(props.size).height};
|
|
39
41
|
width: ${(props) => getIconContainerSizePx(props.size).width};
|
|
@@ -64,7 +66,9 @@ const StyledButton = styled.button `
|
|
|
64
66
|
background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).hover};
|
|
65
67
|
|
|
66
68
|
${IconOuter} {
|
|
67
|
-
background-color: ${(props) =>
|
|
69
|
+
background-color: ${(props) => props.iconOnly
|
|
70
|
+
? getThemeVariantColours(props.variant, props.theme).hover
|
|
71
|
+
: getThemeVariantColours(props.variant, props.theme).darkerHover};
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
`;
|
|
@@ -105,10 +109,10 @@ const ButtonSpinner = styled.div `
|
|
|
105
109
|
const Button = React.forwardRef(function Button(props, ref) {
|
|
106
110
|
const { children, loading, variant = 'primary', size = 'md', type = 'button', icon, onClick, 'data-cy': dataCy, } = props;
|
|
107
111
|
const { width, height, alignSelf, marginTop } = useContext(ButtonContext);
|
|
108
|
-
return (React.createElement(StyledButton, { ref: ref, width: width, height: height, alignSelf: alignSelf, marginTop: marginTop, variant: variant, size: size, type: type, onClick: onClick, "data-cy": dataCy || 'button' }, loading ? (React.createElement(SpinnerContainer, null,
|
|
109
|
-
React.createElement(ButtonSpinner, { "data-cy": 'button-loading-spinner', variant: variant, size: size }))) : (React.createElement(ButtonInner, null,
|
|
112
|
+
return (React.createElement(StyledButton, { ref: ref, width: width, height: height, alignSelf: alignSelf, marginTop: marginTop, variant: variant, size: size, type: type, onClick: onClick, "data-cy": dataCy || 'button', iconOnly: !children }, loading ? (React.createElement(SpinnerContainer, null,
|
|
113
|
+
React.createElement(ButtonSpinner, { "data-cy": 'button-loading-spinner', variant: variant, size: size, iconOnly: !children }))) : (React.createElement(ButtonInner, null,
|
|
110
114
|
children && React.createElement(ButtonTextContainer, { size: size }, children),
|
|
111
|
-
icon && (React.createElement(IconOuter, { variant: variant, size: size, height: height },
|
|
115
|
+
icon && (React.createElement(IconOuter, { variant: variant, size: size, height: height, iconOnly: !children },
|
|
112
116
|
React.createElement(FontAwesomeIcon, { icon: icon })))))));
|
|
113
117
|
});
|
|
114
118
|
export default Button;
|
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableVariant } from './_Table.context';
|
|
3
|
+
import { TableActionProps } from './_TableAction';
|
|
3
4
|
export type TableCellVariant = 'tight';
|
|
4
5
|
export interface TableProps {
|
|
5
6
|
children: React.ReactNode;
|
|
@@ -13,7 +14,8 @@ declare const Table: {
|
|
|
13
14
|
Row: ({ children, "data-cy": dataCy }: import("./_TableRow.component").TableRowProps) => JSX.Element;
|
|
14
15
|
Cell: import("styled-components").StyledComponent<"td", import("styled-components").DefaultTheme, TableCellProps, never>;
|
|
15
16
|
ActionContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
16
|
-
Action: ({ text, onClick, "data-cy": dataCy }:
|
|
17
|
+
Action: ({ text, variant, icon, onClick, "data-cy": dataCy }: TableActionProps) => JSX.Element;
|
|
17
18
|
ActionMenu: ({ items, "data-cy": dataCy }: import("./_TableActionMenu").TableActionMenuProps) => JSX.Element;
|
|
19
|
+
HiddenAction: (props: TableActionProps) => JSX.Element;
|
|
18
20
|
};
|
|
19
21
|
export default Table;
|
|
@@ -9,6 +9,10 @@ import TableRow from './_TableRow.component';
|
|
|
9
9
|
const StyledTable = styled.table `
|
|
10
10
|
width: 100%;
|
|
11
11
|
`;
|
|
12
|
+
const TableHiddenActionSpan = styled.span `
|
|
13
|
+
visibility: none;
|
|
14
|
+
opacity: 0;
|
|
15
|
+
`;
|
|
12
16
|
const TableCell = styled.td `
|
|
13
17
|
font-family: ${(props) => props.theme.fonts.default.family};
|
|
14
18
|
font-size: ${(props) => props.theme.fonts.default.size};
|
|
@@ -18,7 +22,16 @@ const TableCell = styled.td `
|
|
|
18
22
|
|
|
19
23
|
padding: ${(props) => (props.variant === 'tight' ? '0' : '0 16px')};
|
|
20
24
|
height: 36px;
|
|
25
|
+
|
|
26
|
+
&:hover {
|
|
27
|
+
${TableHiddenActionSpan} {
|
|
28
|
+
visibility: visible;
|
|
29
|
+
opacity: 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
21
32
|
`;
|
|
33
|
+
const TableHiddenAction = (props) => (React.createElement(TableHiddenActionSpan, null,
|
|
34
|
+
React.createElement(TableAction, { ...props })));
|
|
22
35
|
const Table = ({ children, variant = 'regular' }) => {
|
|
23
36
|
return (React.createElement(TableContext.Provider, { value: { variant } },
|
|
24
37
|
React.createElement(ButtonContext.Provider, { value: { height: '24px' } },
|
|
@@ -30,4 +43,5 @@ Table.Cell = TableCell;
|
|
|
30
43
|
Table.ActionContainer = TableActionContainer;
|
|
31
44
|
Table.Action = TableAction;
|
|
32
45
|
Table.ActionMenu = TableActionMenu;
|
|
46
|
+
Table.HiddenAction = TableHiddenAction;
|
|
33
47
|
export default Table;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
|
3
|
+
import { ColourVariant } from '../../theme/theme.types';
|
|
2
4
|
export interface TableActionProps {
|
|
3
|
-
'text'
|
|
5
|
+
'text'?: string;
|
|
6
|
+
'variant'?: ColourVariant;
|
|
7
|
+
'icon'?: IconProp;
|
|
4
8
|
'onClick': () => void;
|
|
5
9
|
'data-cy'?: string;
|
|
6
10
|
}
|
|
7
|
-
declare const TableAction: ({ text, onClick, "data-cy": dataCy }: TableActionProps) => JSX.Element;
|
|
11
|
+
declare const TableAction: ({ text, variant, icon, onClick, "data-cy": dataCy }: TableActionProps) => JSX.Element;
|
|
8
12
|
export default TableAction;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
2
|
import Button from '../Button/Button.component';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import ButtonContext from '../Button/Button.context';
|
|
4
|
+
const TableAction = ({ text, variant, icon, onClick, 'data-cy': dataCy }) => {
|
|
5
|
+
const buttonContextVal = useContext(ButtonContext);
|
|
6
|
+
return (React.createElement(ButtonContext.Provider, { value: { ...buttonContextVal, ...(!text && icon && { width: '32px' }) } },
|
|
7
|
+
React.createElement(Button, { variant: variant || 'tertiary', icon: icon, onClick: onClick, "data-cy": dataCy || 'button-table-action' }, text)));
|
|
5
8
|
};
|
|
6
9
|
export default TableAction;
|