@dtdot/lego 2.0.0-10 → 2.0.0-12
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/ActionMenu/ActionMenu.component.js +1 -1
- package/build/components/Button/Button.component.js +11 -9
- package/build/components/Button/Button.context.d.ts +1 -0
- package/build/components/Button/Button.context.js +1 -0
- package/build/components/Card/_CardHeader.component.js +4 -2
- package/build/components/Select/Select.component.js +22 -4
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ const ActionMenu = ({ children, variant, size, icon, text, 'data-cy': dataCy })
|
|
|
36
36
|
return (React.createElement(React.Fragment, null,
|
|
37
37
|
React.createElement(Button, { variant: variant, size: size, icon: icon || faEllipsisV, "data-cy": dataCy || 'action-menu-button', ref: setReferenceElement, onClick: () => setShown(true) }, text),
|
|
38
38
|
shown &&
|
|
39
|
-
ReactDOM.createPortal(React.createElement("div", { ref: setPopperElement, style: styles.popper, ...attributes.popper },
|
|
39
|
+
ReactDOM.createPortal(React.createElement("div", { ref: setPopperElement, style: { ...styles.popper, zIndex: 999 }, ...attributes.popper },
|
|
40
40
|
React.createElement(ActionMenuContext.Provider, { value: { closeActionMenu: () => setShown(false) } },
|
|
41
41
|
React.createElement(ActionMenuPanel, null, children))), document.querySelector('body'))));
|
|
42
42
|
};
|
|
@@ -33,9 +33,11 @@ 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) => props.
|
|
37
|
-
?
|
|
38
|
-
:
|
|
36
|
+
background-color: ${(props) => props.noBackground
|
|
37
|
+
? 'transparent'
|
|
38
|
+
: props.iconOnly
|
|
39
|
+
? getThemeVariantColours(props.variant, props.theme).main
|
|
40
|
+
: getThemeVariantColours(props.variant, props.theme).darker};
|
|
39
41
|
|
|
40
42
|
height: ${(props) => props.height || getIconContainerSizePx(props.size).height};
|
|
41
43
|
width: ${(props) => getIconContainerSizePx(props.size).width};
|
|
@@ -51,8 +53,8 @@ const StyledButton = styled.button `
|
|
|
51
53
|
font-size: ${(props) => props.theme.fonts.default.size};
|
|
52
54
|
font-family: ${(props) => props.theme.fonts.default.family};
|
|
53
55
|
|
|
54
|
-
color: ${(props) => getThemeVariantColours(props.variant, props.theme).contrastText};
|
|
55
|
-
background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).main};
|
|
56
|
+
color: ${(props) => getThemeVariantColours(props.noBackground ? 'secondary' : props.variant, props.theme).contrastText};
|
|
57
|
+
background-color: ${(props) => props.noBackground ? 'transparent' : getThemeVariantColours(props.variant, props.theme).main};
|
|
56
58
|
|
|
57
59
|
border-radius: 2px;
|
|
58
60
|
|
|
@@ -63,7 +65,7 @@ const StyledButton = styled.button `
|
|
|
63
65
|
margin-top: ${(props) => props.marginTop};
|
|
64
66
|
|
|
65
67
|
&:hover {
|
|
66
|
-
background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).hover};
|
|
68
|
+
background-color: ${(props) => props.noBackground ? 'transparent' : getThemeVariantColours(props.variant, props.theme).hover};
|
|
67
69
|
|
|
68
70
|
${IconOuter} {
|
|
69
71
|
background-color: ${(props) => props.iconOnly
|
|
@@ -109,11 +111,11 @@ const ButtonSpinner = styled.div `
|
|
|
109
111
|
`;
|
|
110
112
|
const Button = React.forwardRef(function Button(props, ref) {
|
|
111
113
|
const { children, loading, variant = 'primary', size = 'md', type = 'button', icon, onClick, 'data-cy': dataCy, } = props;
|
|
112
|
-
const { width, height, alignSelf, marginTop } = useContext(ButtonContext);
|
|
113
|
-
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,
|
|
114
|
+
const { width, height, alignSelf, marginTop, noBackground } = useContext(ButtonContext);
|
|
115
|
+
return (React.createElement(StyledButton, { ref: ref, width: width, height: height, alignSelf: alignSelf, marginTop: marginTop, noBackground: noBackground, variant: variant, size: size, type: type, onClick: onClick, "data-cy": dataCy || 'button', iconOnly: !children }, loading ? (React.createElement(SpinnerContainer, null,
|
|
114
116
|
React.createElement(ButtonSpinner, { "data-cy": 'button-loading-spinner', variant: variant, size: size, iconOnly: !children }))) : (React.createElement(ButtonInner, null,
|
|
115
117
|
children && React.createElement(ButtonTextContainer, { size: size }, children),
|
|
116
|
-
icon && (React.createElement(IconOuter, { variant: variant, size: size, height: height, iconOnly: !children },
|
|
118
|
+
icon && (React.createElement(IconOuter, { noBackground: noBackground, variant: variant, size: size, height: height, iconOnly: !children },
|
|
117
119
|
React.createElement(FontAwesomeIcon, { icon: icon })))))));
|
|
118
120
|
});
|
|
119
121
|
export default Button;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
3
|
import { Text } from '../..';
|
|
4
|
+
import ButtonContext from '../Button/Button.context';
|
|
4
5
|
const HeaderRow = styled.div `
|
|
5
6
|
display: flex;
|
|
6
7
|
justify-content: space-between;
|
|
7
8
|
padding: 8px 16px;
|
|
8
9
|
margin-bottom: 8px;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
background-color: ${(props) => props.theme.colours.cardBackgroundSecondary};
|
|
11
12
|
`;
|
|
12
13
|
const LeftContainer = styled.div `
|
|
13
14
|
display: flex;
|
|
@@ -43,6 +44,7 @@ const CardHeader = ({ image, heading, subHeading, meta }) => {
|
|
|
43
44
|
React.createElement(Text, null, heading)),
|
|
44
45
|
React.createElement("div", null,
|
|
45
46
|
React.createElement(Text, { variant: 'secondary' }, subHeading)))),
|
|
46
|
-
meta && React.createElement(MetaContainer, null,
|
|
47
|
+
meta && (React.createElement(MetaContainer, null,
|
|
48
|
+
React.createElement(ButtonContext.Provider, { value: { height: '24px', width: '24px', noBackground: true } }, meta)))));
|
|
47
49
|
};
|
|
48
50
|
export default CardHeader;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
2
|
-
import React, { useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import { usePopper } from 'react-popper';
|
|
3
5
|
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
|
|
4
6
|
import { motion } from 'framer-motion';
|
|
5
7
|
import styled, { useTheme } from 'styled-components';
|
|
@@ -37,7 +39,7 @@ const ValueText = styled.div `
|
|
|
37
39
|
`;
|
|
38
40
|
const OptionsContainer = styled.div `
|
|
39
41
|
width: 100%;
|
|
40
|
-
position: absolute;
|
|
42
|
+
/* position: absolute; */
|
|
41
43
|
background-color: ${(props) => props.theme.colours.controlBackground};
|
|
42
44
|
z-index: 10000;
|
|
43
45
|
|
|
@@ -55,8 +57,11 @@ const Option = styled(motion.div) `
|
|
|
55
57
|
const Select = (props) => {
|
|
56
58
|
const theme = useTheme();
|
|
57
59
|
const [isOpen, setIsOpen] = useState(false);
|
|
60
|
+
const [referenceElement, setReferenceElement] = useState();
|
|
61
|
+
const [popperElement, setPopperElement] = useState();
|
|
58
62
|
const { label, name, description, placeholder, 'value': propsValue, 'data-cy': dataCy, options } = props;
|
|
59
63
|
const { value: contextValue, onChange: contextOnChange } = useFormNode(name);
|
|
64
|
+
const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: 'bottom-start' });
|
|
60
65
|
const value = getValue(propsValue, contextValue);
|
|
61
66
|
const splitDescription = description ? description.split('\\n').map((str) => str.trim()) : undefined;
|
|
62
67
|
const selectValue = (option) => {
|
|
@@ -69,16 +74,29 @@ const Select = (props) => {
|
|
|
69
74
|
}
|
|
70
75
|
};
|
|
71
76
|
const valueLabel = value && options.find((o) => o.value === value)?.label;
|
|
77
|
+
const handleGlobalClick = useCallback((event) => {
|
|
78
|
+
if (!popperElement?.contains(event.target)) {
|
|
79
|
+
setIsOpen(false);
|
|
80
|
+
}
|
|
81
|
+
}, [setIsOpen, popperElement]);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
document.addEventListener('mouseup', handleGlobalClick);
|
|
84
|
+
return () => {
|
|
85
|
+
document.removeEventListener('mouseup', handleGlobalClick);
|
|
86
|
+
};
|
|
87
|
+
}, [handleGlobalClick, popperElement]);
|
|
72
88
|
return (React.createElement("div", null,
|
|
73
89
|
label && React.createElement(ControlLabel, { htmlFor: name }, label),
|
|
74
|
-
React.createElement(ControlOuter,
|
|
90
|
+
React.createElement(ControlOuter, { ref: setReferenceElement },
|
|
75
91
|
React.createElement(SelectControl, { "data-cy": dataCy, onClick: () => setIsOpen(!isOpen) },
|
|
76
92
|
React.createElement(TextContainer, null,
|
|
77
93
|
!value && placeholder && React.createElement(PlaceholderText, null, placeholder),
|
|
78
94
|
value && React.createElement(ValueText, null, valueLabel)),
|
|
79
95
|
React.createElement(IconContainer, null,
|
|
80
96
|
React.createElement(FontAwesomeIcon, { icon: isOpen ? faChevronUp : faChevronDown }))),
|
|
81
|
-
isOpen &&
|
|
97
|
+
isOpen &&
|
|
98
|
+
ReactDOM.createPortal(React.createElement("div", { ref: setPopperElement, style: { ...styles.popper, zIndex: 999, width: referenceElement?.offsetWidth }, ...attributes.popper },
|
|
99
|
+
React.createElement(OptionsContainer, null, options.map((option) => (React.createElement(Option, { whileHover: { backgroundColor: theme.colours.controlBorder }, transition: { type: 'spring', duration: 0.2 }, key: option.value, onClick: () => selectValue(option) }, option.label))))), document.querySelector('body'))),
|
|
82
100
|
splitDescription && (React.createElement(ControlDescription, null, splitDescription.map((line, index) => (React.createElement(React.Fragment, null,
|
|
83
101
|
index !== 0 && React.createElement("br", null),
|
|
84
102
|
line)))))));
|