@dtdot/lego 2.0.0-11 → 2.0.0-13

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.
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ export interface ControlLineProps {
3
+ children: React.ReactNode;
4
+ variant?: 'action' | 'spaced';
5
+ }
6
+ declare const ControlLine: ({ children, variant }: ControlLineProps) => JSX.Element | null;
7
+ export default ControlLine;
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ const ActionContainer = styled.div `
4
+ display: flex;
5
+ width: 100%;
6
+
7
+ > :first-child {
8
+ flex-grow: 1;
9
+ padding-right: 3px;
10
+ }
11
+ `;
12
+ const SpacedContainer = styled.div `
13
+ display: flex;
14
+
15
+ > * {
16
+ flex-grow: 1;
17
+ padding-right: 3px;
18
+ }
19
+
20
+ > *:last-child {
21
+ padding-right: 0;
22
+ }
23
+ `;
24
+ const ControlLine = ({ children, variant = 'action' }) => {
25
+ if (variant === 'action') {
26
+ return React.createElement(ActionContainer, null, children);
27
+ }
28
+ if (variant === 'spaced') {
29
+ return React.createElement(SpacedContainer, null, children);
30
+ }
31
+ return null;
32
+ };
33
+ export default ControlLine;
@@ -10,7 +10,7 @@ import { ControlStyles } from '../../shared/ControlStyles';
10
10
  import useFormNode, { getValue } from '../Form/useFormNode.hook';
11
11
  const InputContainer = styled.div `
12
12
  position: relative;
13
- margin: 2px 0;
13
+ border-radius: 2px;
14
14
 
15
15
  background-color: ${(props) => props.theme.colours.controlBackground};
16
16
  `;
@@ -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, null,
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 && (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)))))),
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)))))));
package/build/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export { default as Card } from './components/Card/Card.component';
12
12
  export { default as CardGroup } from './components/Card/CardGroup.component';
13
13
  export { default as Checklist } from './components/Checklist/Checklist.component';
14
14
  export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
15
+ export { default as ControlLine } from './components/ControlLine/ControlLine.component';
15
16
  export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
16
17
  export { default as Form } from './components/Form/Form.component';
17
18
  export { default as Notification } from './components/Notification/Notification.component';
package/build/index.js CHANGED
@@ -12,6 +12,7 @@ export { default as Card } from './components/Card/Card.component';
12
12
  export { default as CardGroup } from './components/Card/CardGroup.component';
13
13
  export { default as Checklist } from './components/Checklist/Checklist.component';
14
14
  export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
15
+ export { default as ControlLine } from './components/ControlLine/ControlLine.component';
15
16
  export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
16
17
  export { default as Form } from './components/Form/Form.component';
17
18
  export { default as Notification } from './components/Notification/Notification.component';
@@ -16,7 +16,7 @@ export const ControlStyles = css `
16
16
  color: ${(props) => getThemeControlColours(props.theme).font};
17
17
  background-color: ${(props) => getThemeControlColours(props.theme).background};
18
18
 
19
- border: 1px solid ${(props) => getThemeControlColours(props.theme).border};
19
+ border: 1px solid ${(props) => getThemeControlColours(props.theme).background};
20
20
  border-radius: 2px;
21
21
 
22
22
  &:hover {
@@ -35,9 +35,11 @@ const darkTheme = {
35
35
  faintBorder: '#cccccc1f',
36
36
  controlBackground: '#5e6167',
37
37
  controlBackgroundDisabled: '#47494d',
38
- controlBorder: '#565656',
38
+ controlBorder: '#595b5e',
39
+ // controlBorder: '#565656',
39
40
  controlBorderFocus: '#4289de',
40
- controlBorderHover: '#4a4949',
41
+ controlBorderHover: '#686c74',
42
+ // controlBorderHover: '#4a4949',
41
43
  controlPlaceholder: '#949494',
42
44
  controlDescriptionColour: '#cbcbcb',
43
45
  uploadBackground: '#5e6167',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "2.0.0-11",
3
+ "version": "2.0.0-13",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {