@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.
Files changed (131) hide show
  1. package/README.md +50 -0
  2. package/babel.config.js +18 -0
  3. package/build/bundle.development.js +850 -0
  4. package/build/bundle.production.js +1 -0
  5. package/build/esm/components/AttributeIcon/Div.js +51 -0
  6. package/build/esm/components/AttributeIcon/index.js +53 -0
  7. package/build/esm/components/Button/index.js +75 -0
  8. package/build/esm/components/Checkbox/index.js +78 -0
  9. package/build/esm/components/Count/Wrapper.js +32 -0
  10. package/build/esm/components/Count/index.js +27 -0
  11. package/build/esm/components/DatePicker/index.js +206 -0
  12. package/build/esm/components/DatePicker/reducer.js +42 -0
  13. package/build/esm/components/Enumeration/index.js +54 -0
  14. package/build/esm/components/Error/index.js +137 -0
  15. package/build/esm/components/Error/reducer.js +23 -0
  16. package/build/esm/components/Flex/index.js +29 -0
  17. package/build/esm/components/HeaderActions/index.js +41 -0
  18. package/build/esm/components/HeaderTitle/index.js +45 -0
  19. package/build/esm/components/Icon/index.js +26 -0
  20. package/build/esm/components/IconLinks/index.js +36 -0
  21. package/build/esm/components/InputNumber/index.js +70 -0
  22. package/build/esm/components/InputText/PrefixIcon.js +32 -0
  23. package/build/esm/components/InputText/index.js +89 -0
  24. package/build/esm/components/Label/index.js +40 -0
  25. package/build/esm/components/List/index.js +50 -0
  26. package/build/esm/components/ListHeader/BaselineAlignement.js +5 -0
  27. package/build/esm/components/ListHeader/index.js +52 -0
  28. package/build/esm/components/ListRow/index.js +30 -0
  29. package/build/esm/components/ListRow/tests/index.tests.js +21 -0
  30. package/build/esm/components/NavTabs/index.js +38 -0
  31. package/build/esm/components/Option/RemoveButton.js +5 -0
  32. package/build/esm/components/Option/index.js +32 -0
  33. package/build/esm/components/Padded/index.js +56 -0
  34. package/build/esm/components/Paging/index.js +57 -0
  35. package/build/esm/components/Picker/PickerButton.js +61 -0
  36. package/build/esm/components/Picker/PickerSection.js +48 -0
  37. package/build/esm/components/Picker/PickerWrapper.js +5 -0
  38. package/build/esm/components/Picker/index.js +50 -0
  39. package/build/esm/components/PrefixIcon/index.js +7 -0
  40. package/build/esm/components/Select/index.js +82 -0
  41. package/build/esm/components/Separator/index.js +44 -0
  42. package/build/esm/components/Table/ActionCollapse.js +40 -0
  43. package/build/esm/components/Table/index.js +140 -0
  44. package/build/esm/components/Table/tests/index.js +130 -0
  45. package/build/esm/components/TableHeader/index.js +88 -0
  46. package/build/esm/components/TableRow/index.js +93 -0
  47. package/build/esm/components/Text/index.js +67 -0
  48. package/build/esm/components/Textarea/index.js +16 -0
  49. package/build/esm/components/TimePicker/index.js +288 -0
  50. package/build/esm/components/Toggle/index.js +72 -0
  51. package/build/esm/components/UnknownInput/index.js +19 -0
  52. package/build/esm/index.js +33 -0
  53. package/build/esm/theme/colors.js +48 -0
  54. package/build/index.js +8 -0
  55. package/package.json +123 -0
  56. package/src/components/AttributeIcon/Div.js +63 -0
  57. package/src/components/AttributeIcon/index.js +72 -0
  58. package/src/components/Button/index.js +95 -0
  59. package/src/components/Checkbox/index.js +86 -0
  60. package/src/components/Checkbox/tests/Checkbox.test.js +49 -0
  61. package/src/components/Count/Wrapper.js +36 -0
  62. package/src/components/Count/index.js +30 -0
  63. package/src/components/DatePicker/index.js +213 -0
  64. package/src/components/DatePicker/reducer.js +27 -0
  65. package/src/components/DatePicker/tests/__snapshots__/index.test.js.snap +301 -0
  66. package/src/components/DatePicker/tests/index.test.js +111 -0
  67. package/src/components/Enumeration/index.js +71 -0
  68. package/src/components/Enumeration/tests/index.test.js +41 -0
  69. package/src/components/Error/index.js +118 -0
  70. package/src/components/Error/reducer.js +14 -0
  71. package/src/components/Flex/index.js +25 -0
  72. package/src/components/Flex/tests/__snapshots__/index.test.js.snap +28 -0
  73. package/src/components/Flex/tests/index.test.js +11 -0
  74. package/src/components/HeaderActions/index.js +52 -0
  75. package/src/components/HeaderActions/tests/index.test.js +15 -0
  76. package/src/components/HeaderTitle/index.js +59 -0
  77. package/src/components/HeaderTitle/tests/index.test.js +15 -0
  78. package/src/components/Icon/index.js +50 -0
  79. package/src/components/Icon/tests/Icon.test.js +33 -0
  80. package/src/components/IconLinks/index.js +39 -0
  81. package/src/components/IconLinks/tests/index.test.js +27 -0
  82. package/src/components/InputNumber/index.js +74 -0
  83. package/src/components/InputText/PrefixIcon.js +38 -0
  84. package/src/components/InputText/index.js +88 -0
  85. package/src/components/Label/index.js +53 -0
  86. package/src/components/Label/tests/Label.test.js +38 -0
  87. package/src/components/List/index.js +56 -0
  88. package/src/components/List/tests/index.test.js +19 -0
  89. package/src/components/ListHeader/BaselineAlignement.js +7 -0
  90. package/src/components/ListHeader/index.js +58 -0
  91. package/src/components/ListHeader/tests/index.test.js +11 -0
  92. package/src/components/ListRow/index.js +34 -0
  93. package/src/components/ListRow/tests/index.tests.js +32 -0
  94. package/src/components/NavTabs/index.js +51 -0
  95. package/src/components/Option/RemoveButton.js +18 -0
  96. package/src/components/Option/index.js +32 -0
  97. package/src/components/Padded/index.js +47 -0
  98. package/src/components/Padded/tests/__snapshots__/index.test.js.snap +8 -0
  99. package/src/components/Padded/tests/index.test.js +11 -0
  100. package/src/components/Paging/index.js +66 -0
  101. package/src/components/Picker/PickerButton.js +84 -0
  102. package/src/components/Picker/PickerSection.js +41 -0
  103. package/src/components/Picker/PickerWrapper.js +7 -0
  104. package/src/components/Picker/index.js +44 -0
  105. package/src/components/Picker/tests/__snapshots__/pickerButton.test.js.snap +54 -0
  106. package/src/components/Picker/tests/__snapshots__/pickerSection.test.js.snap +20 -0
  107. package/src/components/Picker/tests/pickerButton.test.js +11 -0
  108. package/src/components/Picker/tests/pickerSection.test.js +11 -0
  109. package/src/components/PrefixIcon/index.js +11 -0
  110. package/src/components/Select/index.js +110 -0
  111. package/src/components/Select/tests/index.test.js +85 -0
  112. package/src/components/Separator/index.js +49 -0
  113. package/src/components/Table/ActionCollapse.js +53 -0
  114. package/src/components/Table/index.js +172 -0
  115. package/src/components/Table/tests/index.js +146 -0
  116. package/src/components/TableHeader/index.js +103 -0
  117. package/src/components/TableHeader/tests/index.test.js +85 -0
  118. package/src/components/TableRow/index.js +116 -0
  119. package/src/components/TableRow/tests/index.test.js +89 -0
  120. package/src/components/Text/index.js +62 -0
  121. package/src/components/Text/tests/__snapshots__/index.test.js.snap +19 -0
  122. package/src/components/Text/tests/index.test.js +11 -0
  123. package/src/components/Textarea/index.js +19 -0
  124. package/src/components/Textarea/tests/index.test.js +23 -0
  125. package/src/components/TimePicker/index.js +328 -0
  126. package/src/components/TimePicker/tests/index.test.js +95 -0
  127. package/src/components/Toggle/index.js +83 -0
  128. package/src/components/Toggle/tests/index.test.js +40 -0
  129. package/src/components/UnknownInput/index.js +20 -0
  130. package/src/index.js +33 -0
  131. package/src/theme/colors.js +48 -0
package/package.json ADDED
@@ -0,0 +1,123 @@
1
+ {
2
+ "name": "@punch-in/buffet-modern-core",
3
+ "version": "3.3.11",
4
+ "description": "Buffetjs Core Components",
5
+ "main": "build",
6
+ "module": "build/esm/index.js",
7
+ "sideEffects": [
8
+ "*.css"
9
+ ],
10
+ "scripts": {
11
+ "prebuild": "rimraf build",
12
+ "build": "npm run build:development && npm run build:production && npm run build:esm && npm run create:index",
13
+ "build:analyze": "cross-env NODE_ENV=production webpack-cli --json > build/stats.production.json && webpack-bundle-analyzer build/stats.production.json",
14
+ "build:development": "cross-env NODE_ENV=development webpack-cli",
15
+ "build:esm": "cross-env BABEL_ENV=esm babel ./src --out-dir ./build/esm --ignore \"**/*.test.js\" --ignore \"**/test.js\"",
16
+ "build:production": "cross-env NODE_ENV=production webpack-cli",
17
+ "build:watch": "npm run create:index && cross-env NODE_ENV=development webpack-cli -w",
18
+ "build:watch:esm": "cross-env BABEL_ENV=esm babel ./src --out-dir ./build/esm --ignore \"**/*.test.js\" --ignore \"**/test.js\" --watch",
19
+ "create:index": "node ./createBuildIndex.js",
20
+ "test": "cross-env NODE_ENV=development npm run test:lint && npm run test:style && npm run test:jest",
21
+ "test:jest": "jest --runInBand --no-cache --config=jest.config.js",
22
+ "test:jest:watch": "jest --config=jest.config.js --watchAll",
23
+ "test:jest:update": "jest --runInBand --no-cache --config=jest.config.js -u",
24
+ "test:lint": "eslint .",
25
+ "test:lint:quiet": "eslint . --quiet",
26
+ "test:prettier": "echo \"Error: no test specified\"",
27
+ "test:prettiers": "prettier-check \"**/*.js\"",
28
+ "test:style": "stylelint src/components/**/*.js",
29
+ "test:style:quiet": "stylelint src/components/**/*.js --quiet",
30
+ "lint:fix": "eslint . --fix",
31
+ "prepublishOnly": "npm run build"
32
+ },
33
+ "dependencies": {
34
+ "@fortawesome/fontawesome-svg-core": "^1.2.25",
35
+ "@fortawesome/free-regular-svg-icons": "^5.11.2",
36
+ "@fortawesome/free-solid-svg-icons": "^5.11.2",
37
+ "@fortawesome/react-fontawesome": "^0.1.4",
38
+ "@punch-in/buffet-modern": "^3.3.11",
39
+ "@punch-in/buffet-modern-hooks": "^3.3.11",
40
+ "@punch-in/buffet-modern-icons": "^3.3.11",
41
+ "@punch-in/buffet-modern-utils": "^3.3.11",
42
+ "invariant": "^2.2.4",
43
+ "lodash": "4.17.21",
44
+ "moment": "^2.24.0",
45
+ "prop-types": "^15.7.2",
46
+ "rc-input-number": "^4.5.0",
47
+ "react": "^16.14.0",
48
+ "react-dates": "^21.5.1",
49
+ "react-moment-proptypes": "^1.7.0",
50
+ "react-router-dom": "^5.2.0",
51
+ "react-with-direction": "^1.3.1",
52
+ "reactstrap": "^8.5.1",
53
+ "styled-components": "^5.3.10"
54
+ },
55
+ "devDependencies": {
56
+ "@babel/cli": "^7.1.5",
57
+ "@babel/core": "^7.1.6",
58
+ "@babel/eslint-parser": "^7.22.0",
59
+ "@babel/plugin-proposal-export-default-from": "^7.0.0",
60
+ "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
61
+ "@babel/plugin-proposal-function-bind": "^7.0.0",
62
+ "@babel/plugin-transform-class-properties": "^7.1.0",
63
+ "@babel/plugin-transform-flow-strip-types": "^7.1.6",
64
+ "@babel/preset-env": "^7.1.6",
65
+ "@babel/preset-flow": "^7.0.0",
66
+ "@babel/preset-react": "^7.0.0",
67
+ "@testing-library/jest-dom": "^5.1.1",
68
+ "@testing-library/react": "^9.4.0",
69
+ "@testing-library/react-hooks": "^3.2.1",
70
+ "babel-jest": "^23.6.0",
71
+ "babel-loader": "^8.0.4",
72
+ "babel-plugin-module-resolver": "3.0.0",
73
+ "bundlesize": "^0.17.0",
74
+ "cross-env": "^5.1.4",
75
+ "enzyme": "^3.11.0",
76
+ "enzyme-adapter-react-16": "^1.15.2",
77
+ "enzyme-to-json": "^3.5.0",
78
+ "eslint": "^7.5.0",
79
+ "eslint-config-airbnb": "^18.2.0",
80
+ "eslint-config-prettier": "^6.11.0",
81
+ "eslint-import-resolver-lerna": "^1.1.0",
82
+ "eslint-import-resolver-webpack": "^0.12.2",
83
+ "eslint-plugin-import": "^2.22.0",
84
+ "eslint-plugin-jest": "^23.19.0",
85
+ "eslint-plugin-jsx-a11y": "^6.3.1",
86
+ "eslint-plugin-react": "^7.20.5",
87
+ "eslint-plugin-react-hooks": "^4.0.8",
88
+ "jest-styled-components": "^7.0.0",
89
+ "mini-css-extract-plugin": "^0.4.0",
90
+ "react-dom": "^16.14.0",
91
+ "react-test-renderer": "^16.13.1",
92
+ "rimraf": "^3.0.2",
93
+ "stylelint": "^13.6.1",
94
+ "stylelint-config-prettier": "^8.0.2",
95
+ "stylelint-config-rational-order": "^0.1.2",
96
+ "stylelint-config-standard": "^20.0.0",
97
+ "stylelint-config-styled-components": "^0.1.1",
98
+ "stylelint-processor-styled-components": "^1.10.0",
99
+ "url-loader": "^1.0.1",
100
+ "webpack": "^4.44.0",
101
+ "webpack-bundle-analyzer": "^3.8.0",
102
+ "webpack-cli": "^3.3.12"
103
+ },
104
+ "peerDependencies": {
105
+ "react": "^16.9.0",
106
+ "react-dom": "^16.9.0",
107
+ "styled-components": "^5.0.0"
108
+ },
109
+ "keywords": [
110
+ "Buffetjs",
111
+ "React"
112
+ ],
113
+ "author": "Strapi team",
114
+ "license": "MIT",
115
+ "publishConfig": {
116
+ "access": "public"
117
+ },
118
+ "repository": {
119
+ "type": "git",
120
+ "url": "https://github.com/strapi/buffet"
121
+ },
122
+ "gitHead": "63c6c13e0fd7feed8e0ea89f751b68b02ef767ea"
123
+ }
@@ -0,0 +1,63 @@
1
+ import styled from 'styled-components';
2
+
3
+ const Div = styled.div`
4
+ display: flex;
5
+ flex-direction: column;
6
+ justify-content: center;
7
+ height: 20px;
8
+ width: 35px;
9
+
10
+ > svg {
11
+ align-self: center;
12
+ }
13
+
14
+ background-color: ${({ type }) => {
15
+ switch (type) {
16
+ case 'boolean':
17
+ return '#69ba05';
18
+ case 'date':
19
+ case 'datetime':
20
+ case 'time':
21
+ case 'timestamp':
22
+ return '#1c8ee2';
23
+ case 'component':
24
+ return '#666666';
25
+ case 'contentType':
26
+ return '#ff6458';
27
+ case 'dynamiczone':
28
+ return '#333333';
29
+ case 'email':
30
+ return '#ff6400';
31
+ case 'enumeration':
32
+ case 'enum':
33
+ return '#f8b295';
34
+ case 'json':
35
+ case 'JSON':
36
+ return '#3C8C98';
37
+ case 'media':
38
+ case 'file':
39
+ case 'files':
40
+ return '#b981d5';
41
+ case 'number':
42
+ return '#e8442f';
43
+ case 'password':
44
+ return '#ff9900';
45
+ case 'string':
46
+ case 'text':
47
+ return '#ffb500';
48
+ case 'relation':
49
+ return '#1c5de7';
50
+ case 'richtext':
51
+ return '#ff9200';
52
+ case 'singleType':
53
+ return '#F4A7B4';
54
+ case 'uid':
55
+ return '#c3814f';
56
+ default:
57
+ return '';
58
+ }
59
+ }};
60
+ border-radius: 2px;
61
+ `;
62
+
63
+ export default Div;
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {
4
+ Bool,
5
+ Calendar,
6
+ Component,
7
+ ContentType,
8
+ DynamicZone,
9
+ Email,
10
+ Enumeration,
11
+ Json,
12
+ Media,
13
+ NumberIcon,
14
+ Password,
15
+ Relation,
16
+ RichText,
17
+ SingleType,
18
+ Text,
19
+ Uid,
20
+ } from '@punch-in/buffet-modern-icons';
21
+ import Div from './Div';
22
+
23
+ const types = {
24
+ biginteger: NumberIcon,
25
+ boolean: Bool,
26
+ component: Component,
27
+ contentType: ContentType,
28
+ date: Calendar,
29
+ datetime: Calendar,
30
+ decimal: NumberIcon,
31
+ dynamiczone: DynamicZone,
32
+ email: Email,
33
+ enum: Enumeration,
34
+ enumeration: Enumeration,
35
+ file: Media,
36
+ files: Media,
37
+ float: NumberIcon,
38
+ integer: NumberIcon,
39
+ json: Json,
40
+ JSON: Json,
41
+ media: Media,
42
+ number: NumberIcon,
43
+ password: Password,
44
+ relation: Relation,
45
+ richtext: RichText,
46
+ singleType: SingleType,
47
+ string: Text,
48
+ text: Text,
49
+ time: Calendar,
50
+ timestamp: Calendar,
51
+ uid: Uid,
52
+ };
53
+
54
+ const AttributeIcon = ({ type, ...rest }) => {
55
+ const Compo = types[type];
56
+
57
+ if (!types[type]) {
58
+ return null;
59
+ }
60
+
61
+ return (
62
+ <Div {...rest} type={type}>
63
+ <Compo />
64
+ </Div>
65
+ );
66
+ };
67
+
68
+ AttributeIcon.propTypes = {
69
+ type: PropTypes.string.isRequired,
70
+ };
71
+
72
+ export default AttributeIcon;
@@ -0,0 +1,95 @@
1
+ /**
2
+ *
3
+ * Button
4
+ *
5
+ */
6
+
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import {
10
+ LoadingIndicator,
11
+ Button as StyledButton,
12
+ colors,
13
+ } from '@punch-in/buffet-modern';
14
+ import { Plus } from '@punch-in/buffet-modern-icons';
15
+ import Flex from '../Flex';
16
+ import PrefixIcon from '../PrefixIcon';
17
+
18
+ function Button({
19
+ children,
20
+ color,
21
+ disabled,
22
+ icon,
23
+ label,
24
+ isLoading,
25
+ ...rest
26
+ }) {
27
+ const content = label || children;
28
+
29
+ const img =
30
+ icon === true ? (
31
+ <Plus height="11px" width="11px" fill={`${colors.button[color].color}`} />
32
+ ) : (
33
+ <PrefixIcon icon={icon} />
34
+ );
35
+
36
+ if (isLoading) {
37
+ return (
38
+ <StyledButton
39
+ color={color}
40
+ disabled={disabled}
41
+ {...rest}
42
+ onClick={e => {
43
+ // Preventing the user from clicking the button when loading
44
+ e.preventDefault();
45
+ }}
46
+ >
47
+ <Flex justifyContent="space-around">
48
+ <LoadingIndicator
49
+ animationTime="0.6s"
50
+ borderWidth="2px"
51
+ borderColor="#f7f5f0"
52
+ borderTopColor="#d1cec7"
53
+ size="1.3rem"
54
+ />
55
+ </Flex>
56
+ </StyledButton>
57
+ );
58
+ }
59
+
60
+ return (
61
+ <StyledButton color={color} disabled={disabled} {...rest}>
62
+ {img}
63
+ {content}
64
+ </StyledButton>
65
+ );
66
+ }
67
+
68
+ Button.defaultProps = {
69
+ children: null,
70
+ color: 'primary',
71
+ disabled: false,
72
+ icon: false,
73
+ isLoading: false,
74
+ label: null,
75
+ type: 'button',
76
+ };
77
+
78
+ Button.propTypes = {
79
+ children: PropTypes.node,
80
+ color: PropTypes.oneOf([
81
+ 'primary',
82
+ 'secondary',
83
+ 'cancel',
84
+ 'success',
85
+ 'delete',
86
+ 'none',
87
+ ]),
88
+ disabled: PropTypes.bool,
89
+ icon: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),
90
+ isLoading: PropTypes.bool,
91
+ label: PropTypes.string,
92
+ type: PropTypes.oneOf(['submit', 'reset', 'button', 'menu']),
93
+ };
94
+
95
+ export default Button;
@@ -0,0 +1,86 @@
1
+ /**
2
+ *
3
+ * Checkbox
4
+ *
5
+ */
6
+
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+
10
+ import {
11
+ Checkbox as StyledCheckbox,
12
+ CheckboxWrapper,
13
+ } from '@punch-in/buffet-modern';
14
+ import Label from '../Label';
15
+
16
+ function Checkbox({
17
+ autoFocus,
18
+ className,
19
+ id,
20
+ message,
21
+ name,
22
+ onChange,
23
+ tabIndex,
24
+ value,
25
+ ...rest
26
+ }) {
27
+ const handleChange = () => {
28
+ const target = {
29
+ name,
30
+ type: 'checkbox',
31
+ value: !value,
32
+ };
33
+
34
+ onChange({ target });
35
+ };
36
+
37
+ return (
38
+ <CheckboxWrapper className={className} disabled={rest.disabled}>
39
+ <StyledCheckbox
40
+ {...rest}
41
+ autoFocus={autoFocus}
42
+ id={id || name}
43
+ name={name}
44
+ onChange={handleChange}
45
+ tabIndex={tabIndex}
46
+ checked={value}
47
+ />
48
+ <Label htmlFor={id || name} message={message} />
49
+ </CheckboxWrapper>
50
+ );
51
+ }
52
+
53
+ Checkbox.defaultProps = {
54
+ autoComplete: 'off',
55
+ autoFocus: false,
56
+ className: null,
57
+ disabled: false,
58
+ id: null,
59
+ message: null,
60
+ onChange: () => {},
61
+ placeholder: null,
62
+ tabIndex: '0',
63
+ value: false,
64
+ };
65
+ Checkbox.propTypes = {
66
+ autoComplete: PropTypes.string,
67
+ autoFocus: PropTypes.bool,
68
+ className: PropTypes.string,
69
+ disabled: PropTypes.bool,
70
+ id: PropTypes.string,
71
+ message: PropTypes.oneOfType([
72
+ PropTypes.func,
73
+ PropTypes.string,
74
+ PropTypes.shape({
75
+ id: PropTypes.string,
76
+ params: PropTypes.object,
77
+ }),
78
+ ]),
79
+ name: PropTypes.string.isRequired,
80
+ onChange: PropTypes.func,
81
+ placeholder: PropTypes.string,
82
+ tabIndex: PropTypes.string,
83
+ value: PropTypes.bool,
84
+ };
85
+
86
+ export default Checkbox;
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { mount } from 'enzyme';
3
+
4
+ import Checkbox from '../index';
5
+
6
+ const defaultProps = {
7
+ type: 'checkbox',
8
+ name: 'checkbox',
9
+ onChange: jest.fn(),
10
+ };
11
+ const renderComponent = (props = defaultProps) =>
12
+ mount(<Checkbox {...props} />);
13
+
14
+ describe('<Checkbox />', () => {
15
+ // eslint-disable-next-line jest/expect-expect
16
+ it('should not crash', () => {
17
+ renderComponent();
18
+ });
19
+
20
+ it('should send a boolean', () => {
21
+ const onChange = jest.fn();
22
+ const value = false;
23
+ const renderedComponent = renderComponent({
24
+ ...defaultProps,
25
+ onChange,
26
+ value,
27
+ });
28
+ const element = renderedComponent.find('input');
29
+
30
+ element.simulate('change');
31
+ const expected = {
32
+ target: {
33
+ name: 'checkbox',
34
+ type: 'checkbox',
35
+ value: true,
36
+ },
37
+ };
38
+ expect(onChange).toHaveBeenLastCalledWith(expected);
39
+ });
40
+
41
+ it('should use the defaultProps', () => {
42
+ const {
43
+ defaultProps: { onChange },
44
+ } = Checkbox;
45
+
46
+ expect(onChange).toBeDefined();
47
+ expect(onChange({ preventDefault: jest.fn() })).toBe(undefined);
48
+ });
49
+ });
@@ -0,0 +1,36 @@
1
+ import styled from 'styled-components';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import Flex from '../Flex';
5
+ import colors from '../../theme/colors';
6
+
7
+ const Wrapper = styled(Flex)`
8
+ width: fit-content;
9
+ height: 1.4rem;
10
+ min-width: 1.4rem;
11
+ padding: 0 0.2rem;
12
+ border-radius: ${({ theme }) => theme.main.sizes.borderRadius};
13
+ background-color: ${({ theme, isActive }) =>
14
+ isActive ? theme.main.colors.lightBlue : '#e9eaeb'};
15
+ `;
16
+
17
+ Wrapper.defaultProps = {
18
+ theme: {
19
+ main: {
20
+ colors,
21
+ sizes: {
22
+ borderRadius: '2px',
23
+ paddings: {
24
+ xs: '5px',
25
+ },
26
+ },
27
+ },
28
+ },
29
+ };
30
+
31
+ Wrapper.propTypes = {
32
+ isActive: PropTypes.bool,
33
+ theme: PropTypes.object,
34
+ };
35
+
36
+ export default Wrapper;
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import Text from '../Text';
5
+ import Wrapper from './Wrapper';
6
+
7
+ const Count = ({ count, isActive }) => (
8
+ <Wrapper isActive={isActive} justifyContent="center" alignItems="center">
9
+ <Text
10
+ lineHeight="none"
11
+ fontWeight="bold"
12
+ color={isActive ? 'mediumBlue' : 'grey'}
13
+ fontSize="xs"
14
+ >
15
+ {count}
16
+ </Text>
17
+ </Wrapper>
18
+ );
19
+
20
+ Count.propTypes = {
21
+ count: PropTypes.number,
22
+ isActive: PropTypes.bool,
23
+ };
24
+
25
+ Count.defaultProps = {
26
+ count: 0,
27
+ isActive: false,
28
+ };
29
+
30
+ export default Count;