@punch-in/buffet-modern-core 3.3.11
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/README.md +50 -0
- package/babel.config.js +18 -0
- package/build/bundle.development.js +850 -0
- package/build/bundle.production.js +1 -0
- package/build/esm/components/AttributeIcon/Div.js +51 -0
- package/build/esm/components/AttributeIcon/index.js +53 -0
- package/build/esm/components/Button/index.js +75 -0
- package/build/esm/components/Checkbox/index.js +78 -0
- package/build/esm/components/Count/Wrapper.js +32 -0
- package/build/esm/components/Count/index.js +27 -0
- package/build/esm/components/DatePicker/index.js +206 -0
- package/build/esm/components/DatePicker/reducer.js +42 -0
- package/build/esm/components/Enumeration/index.js +54 -0
- package/build/esm/components/Error/index.js +137 -0
- package/build/esm/components/Error/reducer.js +23 -0
- package/build/esm/components/Flex/index.js +29 -0
- package/build/esm/components/HeaderActions/index.js +41 -0
- package/build/esm/components/HeaderTitle/index.js +45 -0
- package/build/esm/components/Icon/index.js +26 -0
- package/build/esm/components/IconLinks/index.js +36 -0
- package/build/esm/components/InputNumber/index.js +70 -0
- package/build/esm/components/InputText/PrefixIcon.js +32 -0
- package/build/esm/components/InputText/index.js +89 -0
- package/build/esm/components/Label/index.js +40 -0
- package/build/esm/components/List/index.js +50 -0
- package/build/esm/components/ListHeader/BaselineAlignement.js +5 -0
- package/build/esm/components/ListHeader/index.js +52 -0
- package/build/esm/components/ListRow/index.js +30 -0
- package/build/esm/components/ListRow/tests/index.tests.js +21 -0
- package/build/esm/components/NavTabs/index.js +38 -0
- package/build/esm/components/Option/RemoveButton.js +5 -0
- package/build/esm/components/Option/index.js +32 -0
- package/build/esm/components/Padded/index.js +56 -0
- package/build/esm/components/Paging/index.js +57 -0
- package/build/esm/components/Picker/PickerButton.js +61 -0
- package/build/esm/components/Picker/PickerSection.js +48 -0
- package/build/esm/components/Picker/PickerWrapper.js +5 -0
- package/build/esm/components/Picker/index.js +50 -0
- package/build/esm/components/PrefixIcon/index.js +7 -0
- package/build/esm/components/Select/index.js +82 -0
- package/build/esm/components/Separator/index.js +44 -0
- package/build/esm/components/Table/ActionCollapse.js +40 -0
- package/build/esm/components/Table/index.js +140 -0
- package/build/esm/components/Table/tests/index.js +130 -0
- package/build/esm/components/TableHeader/index.js +88 -0
- package/build/esm/components/TableRow/index.js +93 -0
- package/build/esm/components/Text/index.js +67 -0
- package/build/esm/components/Textarea/index.js +16 -0
- package/build/esm/components/TimePicker/index.js +288 -0
- package/build/esm/components/Toggle/index.js +72 -0
- package/build/esm/components/UnknownInput/index.js +19 -0
- package/build/esm/index.js +33 -0
- package/build/esm/theme/colors.js +48 -0
- package/build/index.js +8 -0
- package/package.json +123 -0
- package/src/components/AttributeIcon/Div.js +63 -0
- package/src/components/AttributeIcon/index.js +72 -0
- package/src/components/Button/index.js +95 -0
- package/src/components/Checkbox/index.js +86 -0
- package/src/components/Checkbox/tests/Checkbox.test.js +49 -0
- package/src/components/Count/Wrapper.js +36 -0
- package/src/components/Count/index.js +30 -0
- package/src/components/DatePicker/index.js +213 -0
- package/src/components/DatePicker/reducer.js +27 -0
- package/src/components/DatePicker/tests/__snapshots__/index.test.js.snap +301 -0
- package/src/components/DatePicker/tests/index.test.js +111 -0
- package/src/components/Enumeration/index.js +71 -0
- package/src/components/Enumeration/tests/index.test.js +41 -0
- package/src/components/Error/index.js +118 -0
- package/src/components/Error/reducer.js +14 -0
- package/src/components/Flex/index.js +25 -0
- package/src/components/Flex/tests/__snapshots__/index.test.js.snap +28 -0
- package/src/components/Flex/tests/index.test.js +11 -0
- package/src/components/HeaderActions/index.js +52 -0
- package/src/components/HeaderActions/tests/index.test.js +15 -0
- package/src/components/HeaderTitle/index.js +59 -0
- package/src/components/HeaderTitle/tests/index.test.js +15 -0
- package/src/components/Icon/index.js +50 -0
- package/src/components/Icon/tests/Icon.test.js +33 -0
- package/src/components/IconLinks/index.js +39 -0
- package/src/components/IconLinks/tests/index.test.js +27 -0
- package/src/components/InputNumber/index.js +74 -0
- package/src/components/InputText/PrefixIcon.js +38 -0
- package/src/components/InputText/index.js +88 -0
- package/src/components/Label/index.js +53 -0
- package/src/components/Label/tests/Label.test.js +38 -0
- package/src/components/List/index.js +56 -0
- package/src/components/List/tests/index.test.js +19 -0
- package/src/components/ListHeader/BaselineAlignement.js +7 -0
- package/src/components/ListHeader/index.js +58 -0
- package/src/components/ListHeader/tests/index.test.js +11 -0
- package/src/components/ListRow/index.js +34 -0
- package/src/components/ListRow/tests/index.tests.js +32 -0
- package/src/components/NavTabs/index.js +51 -0
- package/src/components/Option/RemoveButton.js +18 -0
- package/src/components/Option/index.js +32 -0
- package/src/components/Padded/index.js +47 -0
- package/src/components/Padded/tests/__snapshots__/index.test.js.snap +8 -0
- package/src/components/Padded/tests/index.test.js +11 -0
- package/src/components/Paging/index.js +66 -0
- package/src/components/Picker/PickerButton.js +84 -0
- package/src/components/Picker/PickerSection.js +41 -0
- package/src/components/Picker/PickerWrapper.js +7 -0
- package/src/components/Picker/index.js +44 -0
- package/src/components/Picker/tests/__snapshots__/pickerButton.test.js.snap +54 -0
- package/src/components/Picker/tests/__snapshots__/pickerSection.test.js.snap +20 -0
- package/src/components/Picker/tests/pickerButton.test.js +11 -0
- package/src/components/Picker/tests/pickerSection.test.js +11 -0
- package/src/components/PrefixIcon/index.js +11 -0
- package/src/components/Select/index.js +110 -0
- package/src/components/Select/tests/index.test.js +85 -0
- package/src/components/Separator/index.js +49 -0
- package/src/components/Table/ActionCollapse.js +53 -0
- package/src/components/Table/index.js +172 -0
- package/src/components/Table/tests/index.js +146 -0
- package/src/components/TableHeader/index.js +103 -0
- package/src/components/TableHeader/tests/index.test.js +85 -0
- package/src/components/TableRow/index.js +116 -0
- package/src/components/TableRow/tests/index.test.js +89 -0
- package/src/components/Text/index.js +62 -0
- package/src/components/Text/tests/__snapshots__/index.test.js.snap +19 -0
- package/src/components/Text/tests/index.test.js +11 -0
- package/src/components/Textarea/index.js +19 -0
- package/src/components/Textarea/tests/index.test.js +23 -0
- package/src/components/TimePicker/index.js +328 -0
- package/src/components/TimePicker/tests/index.test.js +95 -0
- package/src/components/Toggle/index.js +83 -0
- package/src/components/Toggle/tests/index.test.js +40 -0
- package/src/components/UnknownInput/index.js +20 -0
- package/src/index.js +33 -0
- package/src/theme/colors.js +48 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import Text from '../Text';
|
|
6
|
+
import colors from '../../theme/colors';
|
|
7
|
+
|
|
8
|
+
const PickerButton = styled(props => (
|
|
9
|
+
<Text
|
|
10
|
+
as="button"
|
|
11
|
+
fontWeight="semiBold"
|
|
12
|
+
color={props.isActive ? 'mediumBlue' : 'greyDark'}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
))`
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
height: 30px;
|
|
19
|
+
padding: 0 10px;
|
|
20
|
+
background-color: ${({ theme }) => theme.main.colors.white};
|
|
21
|
+
border: 1px solid ${({ theme }) => theme.main.colors.darkGrey};
|
|
22
|
+
border-radius: ${({ theme }) => theme.main.sizes.borderRadius};
|
|
23
|
+
&:active,
|
|
24
|
+
&:focus {
|
|
25
|
+
outline: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
> svg + span,
|
|
29
|
+
> span + svg {
|
|
30
|
+
margin-left: 10px;
|
|
31
|
+
}
|
|
32
|
+
> svg g {
|
|
33
|
+
stroke: ${({ theme }) => theme.main.colors.greyDark};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
${({ isActive, theme }) =>
|
|
37
|
+
isActive
|
|
38
|
+
? `
|
|
39
|
+
background-color: ${theme.main.colors.lightBlue};
|
|
40
|
+
border: 1px solid ${theme.main.colors.darkBlue};
|
|
41
|
+
color: ${theme.main.colors.mediumBlue};
|
|
42
|
+
> svg g {
|
|
43
|
+
stroke: ${theme.main.colors.mediumBlue};
|
|
44
|
+
}
|
|
45
|
+
`
|
|
46
|
+
: `
|
|
47
|
+
&:hover {
|
|
48
|
+
background-color: ${theme.main.colors.lightestGrey};
|
|
49
|
+
}
|
|
50
|
+
`}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
PickerButton.defaultProps = {
|
|
54
|
+
isActive: false,
|
|
55
|
+
type: 'button',
|
|
56
|
+
// TODO : This is temporary
|
|
57
|
+
theme: {
|
|
58
|
+
main: {
|
|
59
|
+
colors,
|
|
60
|
+
sizes: {
|
|
61
|
+
borderRadius: '2px',
|
|
62
|
+
fonts: {
|
|
63
|
+
xs: '11px',
|
|
64
|
+
sm: '12px',
|
|
65
|
+
md: '13px',
|
|
66
|
+
lg: '18px',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
fontWeights: {
|
|
70
|
+
regular: 400,
|
|
71
|
+
semiBold: 500,
|
|
72
|
+
bold: 600,
|
|
73
|
+
black: 900,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
PickerButton.propTypes = {
|
|
80
|
+
isActive: PropTypes.bool,
|
|
81
|
+
type: PropTypes.string,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default PickerButton;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
const PickerSection = styled.div`
|
|
5
|
+
display: none;
|
|
6
|
+
position: absolute;
|
|
7
|
+
top: 38px;
|
|
8
|
+
left: ${({ position }) => (position === 'left' ? '0' : 'auto')};
|
|
9
|
+
right: ${({ position }) => (position === 'right' ? '0' : 'auto')};
|
|
10
|
+
z-index: 1046;
|
|
11
|
+
background-color: ${({ theme }) => theme.main.colors.white};
|
|
12
|
+
border-radius: ${({ theme }) => theme.main.sizes.borderRadius};
|
|
13
|
+
border: 1px solid ${({ theme }) => theme.main.colors.darkGrey};
|
|
14
|
+
box-shadow: 0 2px 4px ${({ theme }) => theme.main.colors.greyAlpha};
|
|
15
|
+
${({ isOpen }) => isOpen && 'display: block;'}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
PickerSection.defaultProps = {
|
|
19
|
+
isOpen: false,
|
|
20
|
+
position: 'left',
|
|
21
|
+
// TODO : This is temporary
|
|
22
|
+
theme: {
|
|
23
|
+
main: {
|
|
24
|
+
colors: {
|
|
25
|
+
white: '#ffffff',
|
|
26
|
+
darkGrey: '#e3e9f3',
|
|
27
|
+
greyAlpha: 'rgba(227, 233, 243, 0.5)',
|
|
28
|
+
},
|
|
29
|
+
sizes: {
|
|
30
|
+
borderRadius: '2px',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
PickerSection.propTypes = {
|
|
37
|
+
isOpen: PropTypes.bool,
|
|
38
|
+
position: PropTypes.oneOf(['left', 'right']),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default PickerSection;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { useState, useRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import { useClickAwayListener } from '@punch-in/buffet-modern-hooks';
|
|
5
|
+
|
|
6
|
+
import PickerButton from './PickerButton';
|
|
7
|
+
import PickerSection from './PickerSection';
|
|
8
|
+
import PickerWrapper from './PickerWrapper';
|
|
9
|
+
|
|
10
|
+
const Picker = ({ position, renderButtonContent, renderSectionContent }) => {
|
|
11
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
12
|
+
const dropdownRef = useRef();
|
|
13
|
+
|
|
14
|
+
useClickAwayListener(dropdownRef, () => setIsOpen(false));
|
|
15
|
+
|
|
16
|
+
const handleToggle = () => {
|
|
17
|
+
setIsOpen(v => !v);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<PickerWrapper ref={dropdownRef}>
|
|
22
|
+
<PickerButton onClick={handleToggle} isActive={isOpen}>
|
|
23
|
+
{renderButtonContent(isOpen)}
|
|
24
|
+
</PickerButton>
|
|
25
|
+
<PickerSection isOpen={isOpen} position={position}>
|
|
26
|
+
{renderSectionContent(handleToggle)}
|
|
27
|
+
</PickerSection>
|
|
28
|
+
</PickerWrapper>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
Picker.defaultProps = {
|
|
33
|
+
position: 'left',
|
|
34
|
+
renderButtonContent: () => {},
|
|
35
|
+
renderSectionContent: () => {},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Picker.propTypes = {
|
|
39
|
+
position: PropTypes.oneOf(['left', 'right']),
|
|
40
|
+
renderButtonContent: PropTypes.func,
|
|
41
|
+
renderSectionContent: PropTypes.func,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default Picker;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`<PickerButton /> should match snapshot 1`] = `
|
|
4
|
+
.c0 {
|
|
5
|
+
margin: 0;
|
|
6
|
+
line-height: normal;
|
|
7
|
+
color: #292b2c;
|
|
8
|
+
font-size: 13px;
|
|
9
|
+
font-weight: 500;
|
|
10
|
+
text-transform: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.c1 {
|
|
14
|
+
display: -webkit-box;
|
|
15
|
+
display: -webkit-flex;
|
|
16
|
+
display: -ms-flexbox;
|
|
17
|
+
display: flex;
|
|
18
|
+
-webkit-align-items: center;
|
|
19
|
+
-webkit-box-align: center;
|
|
20
|
+
-ms-flex-align: center;
|
|
21
|
+
align-items: center;
|
|
22
|
+
height: 30px;
|
|
23
|
+
padding: 0 10px;
|
|
24
|
+
background-color: #ffffff;
|
|
25
|
+
border: 1px solid #e3e9f3;
|
|
26
|
+
border-radius: 2px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.c1:active,
|
|
30
|
+
.c1:focus {
|
|
31
|
+
outline: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.c1 > svg + span,
|
|
35
|
+
.c1 > span + svg {
|
|
36
|
+
margin-left: 10px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.c1 > svg g {
|
|
40
|
+
stroke: #292b2c;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.c1:hover {
|
|
44
|
+
background-color: #fbfbfb;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
<button
|
|
48
|
+
className="c0 c1"
|
|
49
|
+
color="greyDark"
|
|
50
|
+
fontSize="md"
|
|
51
|
+
fontWeight="semiBold"
|
|
52
|
+
type="button"
|
|
53
|
+
/>
|
|
54
|
+
`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`<PickerSection /> should match snapshot 1`] = `
|
|
4
|
+
.c0 {
|
|
5
|
+
display: none;
|
|
6
|
+
position: absolute;
|
|
7
|
+
top: 38px;
|
|
8
|
+
left: 0;
|
|
9
|
+
right: auto;
|
|
10
|
+
z-index: 1046;
|
|
11
|
+
background-color: #ffffff;
|
|
12
|
+
border-radius: 2px;
|
|
13
|
+
border: 1px solid #e3e9f3;
|
|
14
|
+
box-shadow: 0 2px 4px rgba(227,233,243,0.5);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
<div
|
|
18
|
+
className="c0"
|
|
19
|
+
/>
|
|
20
|
+
`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
import PickerButton from '../PickerButton';
|
|
4
|
+
|
|
5
|
+
describe('<PickerButton />', () => {
|
|
6
|
+
it('should match snapshot', () => {
|
|
7
|
+
const tree = renderer.create(<PickerButton />).toJSON();
|
|
8
|
+
|
|
9
|
+
expect(tree).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
import PickerSection from '../PickerSection';
|
|
4
|
+
|
|
5
|
+
describe('<PickerSection />', () => {
|
|
6
|
+
it('should match snapshot', () => {
|
|
7
|
+
const tree = renderer.create(<PickerSection />).toJSON();
|
|
8
|
+
|
|
9
|
+
expect(tree).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Select
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import invariant from 'invariant';
|
|
10
|
+
import { Select as StyledSelect } from '@punch-in/buffet-modern';
|
|
11
|
+
|
|
12
|
+
function Select({
|
|
13
|
+
autoFocus,
|
|
14
|
+
id,
|
|
15
|
+
name,
|
|
16
|
+
onChange,
|
|
17
|
+
options,
|
|
18
|
+
tabIndex,
|
|
19
|
+
value,
|
|
20
|
+
...rest
|
|
21
|
+
}) {
|
|
22
|
+
const lengthOfReactElementsInOptions = options.filter(option =>
|
|
23
|
+
React.isValidElement(option)
|
|
24
|
+
).length;
|
|
25
|
+
|
|
26
|
+
const formatOptions = () =>
|
|
27
|
+
options.map(option => {
|
|
28
|
+
let optionValue = option;
|
|
29
|
+
|
|
30
|
+
// Type check
|
|
31
|
+
// Use option.value if it is defined (ie. even when it is an empty string)
|
|
32
|
+
if (option && typeof option.value !== 'undefined') {
|
|
33
|
+
optionValue = option.value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<option key={JSON.stringify(optionValue)} value={optionValue}>
|
|
38
|
+
{option.label || option}
|
|
39
|
+
</option>
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
const renderOptions = () => {
|
|
43
|
+
const areOptionsValidReactElements = options.every(option =>
|
|
44
|
+
React.isValidElement(option)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return areOptionsValidReactElements ? options : formatOptions();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (lengthOfReactElementsInOptions > 0) {
|
|
51
|
+
invariant(
|
|
52
|
+
lengthOfReactElementsInOptions === options.length,
|
|
53
|
+
'You have mixed up React Elements and non React Elements in your options array '
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<StyledSelect
|
|
59
|
+
autoFocus={autoFocus}
|
|
60
|
+
id={id || name}
|
|
61
|
+
name={name}
|
|
62
|
+
onChange={onChange}
|
|
63
|
+
tabIndex={tabIndex}
|
|
64
|
+
value={value}
|
|
65
|
+
{...rest}
|
|
66
|
+
>
|
|
67
|
+
{renderOptions()}
|
|
68
|
+
</StyledSelect>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Select.defaultProps = {
|
|
73
|
+
autoComplete: 'off',
|
|
74
|
+
autoFocus: false,
|
|
75
|
+
id: null,
|
|
76
|
+
options: [],
|
|
77
|
+
placeholder: null,
|
|
78
|
+
tabIndex: '0',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
Select.propTypes = {
|
|
82
|
+
autoComplete: PropTypes.string,
|
|
83
|
+
autoFocus: PropTypes.bool,
|
|
84
|
+
id: PropTypes.string,
|
|
85
|
+
name: PropTypes.string.isRequired,
|
|
86
|
+
onChange: PropTypes.func.isRequired,
|
|
87
|
+
options: PropTypes.arrayOf(
|
|
88
|
+
PropTypes.oneOfType([
|
|
89
|
+
PropTypes.shape({
|
|
90
|
+
label: PropTypes.string,
|
|
91
|
+
value: PropTypes.oneOfType([
|
|
92
|
+
PropTypes.string,
|
|
93
|
+
PropTypes.number,
|
|
94
|
+
PropTypes.object,
|
|
95
|
+
]),
|
|
96
|
+
}),
|
|
97
|
+
PropTypes.string,
|
|
98
|
+
PropTypes.node,
|
|
99
|
+
])
|
|
100
|
+
),
|
|
101
|
+
placeholder: PropTypes.string,
|
|
102
|
+
tabIndex: PropTypes.string,
|
|
103
|
+
value: PropTypes.oneOfType([
|
|
104
|
+
PropTypes.string,
|
|
105
|
+
PropTypes.number,
|
|
106
|
+
PropTypes.object,
|
|
107
|
+
]).isRequired,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default Select;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from 'enzyme';
|
|
3
|
+
|
|
4
|
+
import Select from '../index';
|
|
5
|
+
|
|
6
|
+
const initProps = {
|
|
7
|
+
name: 'inputSelect',
|
|
8
|
+
onChange: jest.fn(),
|
|
9
|
+
value: '',
|
|
10
|
+
};
|
|
11
|
+
let renderedComponent;
|
|
12
|
+
const renderComponent = (props = initProps) => mount(<Select {...props} />);
|
|
13
|
+
|
|
14
|
+
describe('<Select />', () => {
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
renderedComponent.unmount();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('Should render the component with no errors', () => {
|
|
20
|
+
renderedComponent = renderComponent();
|
|
21
|
+
const wrapper = renderedComponent.find(Select);
|
|
22
|
+
|
|
23
|
+
expect(wrapper.exists()).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Testing options prop with an array of string', () => {
|
|
27
|
+
const options = ['option 1', 'option 2'];
|
|
28
|
+
|
|
29
|
+
renderedComponent = renderComponent({ ...initProps, options });
|
|
30
|
+
|
|
31
|
+
const wrapper = renderedComponent.find(Select);
|
|
32
|
+
const optionsElements = wrapper.find('option');
|
|
33
|
+
|
|
34
|
+
expect(optionsElements).toHaveLength(2);
|
|
35
|
+
expect(optionsElements.first().text()).toBe('option 1');
|
|
36
|
+
expect(optionsElements.last().text()).toBe('option 2');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('Testing options prop with an array of objects [{ label, value }]', () => {
|
|
40
|
+
const options = [
|
|
41
|
+
{
|
|
42
|
+
label: 'option 1',
|
|
43
|
+
value: 'option1',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: 'option 2',
|
|
47
|
+
value: 'option2',
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
renderedComponent = renderComponent({ ...initProps, options });
|
|
52
|
+
|
|
53
|
+
const wrapper = renderedComponent.find(Select);
|
|
54
|
+
const optionsElements = wrapper.find('option');
|
|
55
|
+
|
|
56
|
+
expect(optionsElements).toHaveLength(2);
|
|
57
|
+
expect(optionsElements.first().text()).toBe('option 1');
|
|
58
|
+
expect(optionsElements.last().text()).toBe('option 2');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('Should render the options with an array of React Nodes', () => {
|
|
62
|
+
const first = (
|
|
63
|
+
<option key="first" value="first">
|
|
64
|
+
First
|
|
65
|
+
</option>
|
|
66
|
+
);
|
|
67
|
+
const second = (
|
|
68
|
+
<option key="second" value="second">
|
|
69
|
+
Second
|
|
70
|
+
</option>
|
|
71
|
+
);
|
|
72
|
+
const options = [first, second];
|
|
73
|
+
|
|
74
|
+
renderedComponent = renderComponent({ ...initProps, options });
|
|
75
|
+
|
|
76
|
+
const wrapper = renderedComponent.find(Select);
|
|
77
|
+
const optionsElements = wrapper.find('option');
|
|
78
|
+
|
|
79
|
+
expect(wrapper.find(first)).toBeDefined();
|
|
80
|
+
expect(wrapper.find(second)).toBeDefined();
|
|
81
|
+
expect(optionsElements).toHaveLength(2);
|
|
82
|
+
expect(optionsElements.first().text()).toBe('First');
|
|
83
|
+
expect(optionsElements.last().text()).toBe('Second');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import Flex from '../Flex';
|
|
5
|
+
import Padded from '../Padded';
|
|
6
|
+
import Text from '../Text';
|
|
7
|
+
import colors from '../../theme/colors';
|
|
8
|
+
|
|
9
|
+
const BorderTop = styled.div`
|
|
10
|
+
border-top: 1px solid ${({ theme }) => theme.main.colors.border};
|
|
11
|
+
width: 100%;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
BorderTop.defaultProps = {
|
|
15
|
+
theme: {
|
|
16
|
+
main: {
|
|
17
|
+
colors,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
BorderTop.propTypes = {
|
|
22
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
23
|
+
theme: PropTypes.object,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const Separator = ({ label }) => (
|
|
27
|
+
<Flex justifyContent="center" alignItems="center">
|
|
28
|
+
{label ? (
|
|
29
|
+
<>
|
|
30
|
+
<BorderTop />
|
|
31
|
+
<Padded left right size="sm">
|
|
32
|
+
<Text color="grey">{label}</Text>
|
|
33
|
+
</Padded>
|
|
34
|
+
<BorderTop />
|
|
35
|
+
</>
|
|
36
|
+
) : (
|
|
37
|
+
<BorderTop />
|
|
38
|
+
)}
|
|
39
|
+
</Flex>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
Separator.defaultProps = {
|
|
43
|
+
label: null,
|
|
44
|
+
};
|
|
45
|
+
Separator.propTypes = {
|
|
46
|
+
label: PropTypes.string,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default Separator;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Icon from '../Icon';
|
|
4
|
+
|
|
5
|
+
function ActionCollapse({
|
|
6
|
+
colSpan,
|
|
7
|
+
translatedNumberOfEntry,
|
|
8
|
+
translatedNumberOfEntries,
|
|
9
|
+
translatedAction,
|
|
10
|
+
icon,
|
|
11
|
+
numberOfSelectedEntries,
|
|
12
|
+
onConfirm,
|
|
13
|
+
}) {
|
|
14
|
+
return (
|
|
15
|
+
<tr className="deleteRow">
|
|
16
|
+
<td colSpan={colSpan}>
|
|
17
|
+
<p>
|
|
18
|
+
{numberOfSelectedEntries}
|
|
19
|
+
|
|
20
|
+
{numberOfSelectedEntries > 1
|
|
21
|
+
? translatedNumberOfEntries
|
|
22
|
+
: translatedNumberOfEntry}
|
|
23
|
+
selected -
|
|
24
|
+
<button onClick={onConfirm} type="button">
|
|
25
|
+
<p>{translatedAction}</p>
|
|
26
|
+
{icon && <Icon icon={icon} />}
|
|
27
|
+
</button>
|
|
28
|
+
</p>
|
|
29
|
+
</td>
|
|
30
|
+
</tr>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ActionCollapse.defaultProps = {
|
|
35
|
+
icon: 'trash',
|
|
36
|
+
translatedNumberOfEntry: 'entry',
|
|
37
|
+
translatedNumberOfEntries: 'entries',
|
|
38
|
+
translatedAction: 'Delete all',
|
|
39
|
+
numberOfSelectedEntries: 0,
|
|
40
|
+
onConfirm: () => {},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
ActionCollapse.propTypes = {
|
|
44
|
+
colSpan: PropTypes.number.isRequired,
|
|
45
|
+
icon: PropTypes.string,
|
|
46
|
+
numberOfSelectedEntries: PropTypes.number,
|
|
47
|
+
onConfirm: PropTypes.func,
|
|
48
|
+
translatedAction: PropTypes.string,
|
|
49
|
+
translatedNumberOfEntries: PropTypes.string,
|
|
50
|
+
translatedNumberOfEntry: PropTypes.string,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default ActionCollapse;
|