@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
@@ -0,0 +1,93 @@
1
+ /**
2
+ *
3
+ * TableRow
4
+ *
5
+ */
6
+
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import { isFunction, isObject } from 'lodash';
10
+ import { Checkbox, Links as StyledLinks } from '@punch-in/buffet-modern';
11
+ import Icon from '../Icon';
12
+ function TableRow(_ref) {
13
+ var headers = _ref.headers,
14
+ _onClick = _ref.onClick,
15
+ onSelect = _ref.onSelect,
16
+ row = _ref.row,
17
+ rowLinks = _ref.rowLinks,
18
+ withBulkAction = _ref.withBulkAction;
19
+ // const displayedCells = headers.map(header => ({ key: header.value, );
20
+
21
+ return /*#__PURE__*/React.createElement("tr", {
22
+ onClick: function onClick(e) {
23
+ e.preventDefault();
24
+ e.stopPropagation();
25
+ _onClick(e, row);
26
+ }
27
+ }, withBulkAction && /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(Checkbox, {
28
+ onClick: function onClick(e) {
29
+ e.stopPropagation();
30
+ },
31
+ onChange: onSelect,
32
+ checked: row._isChecked
33
+ })), headers.map(function (_ref2) {
34
+ var cellName = _ref2.value,
35
+ cellFormatter = _ref2.cellFormatter,
36
+ cellAdapter = _ref2.cellAdapter;
37
+ var displayedValue = !isObject(row[cellName]) ? row[cellName] : '-';
38
+ if (isFunction(cellFormatter)) {
39
+ displayedValue = cellFormatter(row[cellName], row);
40
+ }
41
+ var displayedContent = /*#__PURE__*/React.createElement("p", null, displayedValue || '-');
42
+ if (isFunction(cellAdapter)) {
43
+ displayedContent = cellAdapter(row);
44
+ }
45
+ return /*#__PURE__*/React.createElement("td", {
46
+ key: cellName,
47
+ className: "".concat(cellName, "-cell")
48
+ }, displayedContent);
49
+ }), rowLinks.length > 0 && /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("div", {
50
+ style: {
51
+ width: 'fit-content',
52
+ "float": 'right'
53
+ }
54
+ }, /*#__PURE__*/React.createElement(StyledLinks, null, rowLinks.map(function (icon, index) {
55
+ return /*#__PURE__*/React.createElement("button", {
56
+ // eslint-disable-next-line react/no-array-index-key
57
+ key: index + icon,
58
+ onClick: function onClick(e) {
59
+ e.preventDefault();
60
+ e.stopPropagation();
61
+ icon.onClick(row);
62
+ },
63
+ type: "button"
64
+ }, /*#__PURE__*/React.createElement(Icon, {
65
+ className: "link-icon",
66
+ icon: icon.icon
67
+ }));
68
+ })))));
69
+ }
70
+ TableRow.defaultProps = {
71
+ headers: [],
72
+ onClick: function onClick() {},
73
+ onSelect: function onSelect() {},
74
+ row: {},
75
+ rowLinks: [],
76
+ withBulkAction: false
77
+ };
78
+ TableRow.propTypes = {
79
+ headers: PropTypes.arrayOf(PropTypes.shape({
80
+ isSortEnabled: PropTypes.bool,
81
+ name: PropTypes.string,
82
+ value: PropTypes.string
83
+ })),
84
+ onClick: PropTypes.func,
85
+ onSelect: PropTypes.func,
86
+ // eslint-disable-next-line react/forbid-prop-types
87
+ row: PropTypes.object,
88
+ rowLinks: PropTypes.arrayOf(PropTypes.shape({
89
+ icon: PropTypes.node
90
+ })),
91
+ withBulkAction: PropTypes.bool
92
+ };
93
+ export default TableRow;
@@ -0,0 +1,67 @@
1
+ var _templateObject;
2
+ function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
3
+ import styled from 'styled-components';
4
+ import PropTypes from 'prop-types';
5
+ import colors from '../../theme/colors';
6
+ var Text = styled.p(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n margin: 0;\n line-height: ", ";\n color: ", ";\n font-size: ", ";\n font-weight: ", ";\n text-transform: ", ";\n ", "\n"])), function (_ref) {
7
+ var lineHeight = _ref.lineHeight;
8
+ return lineHeight;
9
+ }, function (_ref2) {
10
+ var theme = _ref2.theme,
11
+ color = _ref2.color;
12
+ return theme.main.colors[color] || color;
13
+ }, function (_ref3) {
14
+ var theme = _ref3.theme,
15
+ fontSize = _ref3.fontSize;
16
+ return theme.main.sizes.fonts[fontSize];
17
+ }, function (_ref4) {
18
+ var theme = _ref4.theme,
19
+ fontWeight = _ref4.fontWeight;
20
+ return theme.main.fontWeights[fontWeight];
21
+ }, function (_ref5) {
22
+ var textTransform = _ref5.textTransform;
23
+ return textTransform;
24
+ }, function (_ref6) {
25
+ var ellipsis = _ref6.ellipsis;
26
+ return ellipsis && "\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n ";
27
+ });
28
+ Text.defaultProps = {
29
+ color: 'greyDark',
30
+ ellipsis: false,
31
+ fontSize: 'md',
32
+ fontWeight: 'regular',
33
+ lineHeight: 'normal',
34
+ textTransform: 'none',
35
+ // TODO : This is temporary
36
+ theme: {
37
+ main: {
38
+ colors: colors,
39
+ sizes: {
40
+ fonts: {
41
+ xs: '11px',
42
+ sm: '12px',
43
+ md: '13px',
44
+ lg: '18px',
45
+ xl: '24px'
46
+ }
47
+ },
48
+ fontWeights: {
49
+ regular: 400,
50
+ semiBold: 500,
51
+ bold: 600,
52
+ black: 900
53
+ }
54
+ }
55
+ }
56
+ };
57
+ Text.propTypes = {
58
+ color: PropTypes.string,
59
+ ellipsis: PropTypes.bool,
60
+ fontSize: PropTypes.string,
61
+ fontWeight: PropTypes.string,
62
+ lineHeight: PropTypes.string,
63
+ textTransform: PropTypes.string,
64
+ // eslint-disable-next-line react/forbid-prop-types
65
+ theme: PropTypes.object
66
+ };
67
+ export default Text;
@@ -0,0 +1,16 @@
1
+ /**
2
+ *
3
+ * Textarea
4
+ *
5
+ */
6
+
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import { Textarea as StyledTextArea } from '@punch-in/buffet-modern';
10
+ function Textarea(props) {
11
+ return /*#__PURE__*/React.createElement(StyledTextArea, props);
12
+ }
13
+ Textarea.propTypes = {
14
+ name: PropTypes.string.isRequired
15
+ };
16
+ export default Textarea;
@@ -0,0 +1,288 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
8
+ /**
9
+ *
10
+ * TimePicker
11
+ *
12
+ */
13
+
14
+ import React, { useCallback, useEffect, useState, useRef, useMemo } from 'react';
15
+ import { isInteger, toNumber } from 'lodash';
16
+ import PropTypes from 'prop-types';
17
+ import { IconWrapper, TimePicker as StyledTimePicker, TimePickerWrapper, TimeList } from '@punch-in/buffet-modern';
18
+ import { useEventListener, useShortcutEffect } from '@punch-in/buffet-modern-hooks';
19
+ import Icon from '../Icon';
20
+ var MINUTES_IN_HOUR = 60;
21
+
22
+ // Returns string with two digits padded at start with 0
23
+ var pad = function pad(num) {
24
+ return "0".concat(num).substr(-2);
25
+ };
26
+
27
+ // Convert time array to formatted time string
28
+ export var timeFormatter = function timeFormatter(time) {
29
+ var newTime = Array(3).fill('00').concat(splitArray(time)).reverse();
30
+ newTime.length = 3;
31
+ return format(newTime).join(':');
32
+ };
33
+
34
+ // Convert time string to time array
35
+ var splitArray = function splitArray(string) {
36
+ if (isInteger(toNumber(string)) && string) {
37
+ var stringFormat = string.length === 3 ? "0".concat(string) : string;
38
+ return stringFormat.match(/.{1,2}/g).reverse();
39
+ }
40
+ var lowercase = string ? string.toLowerCase() : '0';
41
+ var array = lowercase.includes('h') ? lowercase.split('h') : lowercase.split(':');
42
+ return array.reverse().filter(function (v) {
43
+ return !!v;
44
+ });
45
+ };
46
+
47
+ // Ensure two-digit format for minutes and seconds
48
+ var format = function format(array) {
49
+ return array.map(function (string, i) {
50
+ if (string.length < 2) {
51
+ return i === 0 ? "0".concat(string) : "".concat(string, "0");
52
+ }
53
+ return string;
54
+ });
55
+ };
56
+
57
+ // Hide seconds if needed
58
+ var _short = function _short(hour) {
59
+ var array = hour.split(':');
60
+ if (array.length > 2) {
61
+ return array.slice(0, -1).join(':');
62
+ }
63
+ return hour;
64
+ };
65
+
66
+ // return array of minutes in hours with current step
67
+ var getMinutesArr = function getMinutesArr(step) {
68
+ var length = MINUTES_IN_HOUR / step;
69
+ return Array.from({
70
+ length: length
71
+ }, function (_v, i) {
72
+ return step * i;
73
+ });
74
+ };
75
+
76
+ // Generate options for TimeList display
77
+ var getOptions = function getOptions(step) {
78
+ var hours = Array.from({
79
+ length: 24
80
+ }, function (_, i) {
81
+ return i;
82
+ });
83
+ var minutes = getMinutesArr(step);
84
+ var options = hours.reduce(function (acc, cur) {
85
+ var hour = pad(cur);
86
+ var hourOptions = minutes.map(function (minute) {
87
+ var label = "".concat(hour, ":").concat(pad(minute));
88
+ return {
89
+ value: "".concat(label, ":00"),
90
+ label: label
91
+ };
92
+ });
93
+ return acc.concat(hourOptions);
94
+ }, []);
95
+ return options;
96
+ };
97
+
98
+ // Find the nearest time option to select a TimeList value
99
+ var roundHour = function roundHour(time, step) {
100
+ var arr = splitArray(time);
101
+ var minutesArr = getMinutesArr(step);
102
+ var nearMin = nearest(minutesArr.concat(MINUTES_IN_HOUR), parseInt(arr[1], 10));
103
+ arr[1] = minutesArr.includes(arr[1]) ? '00' : pad(nearMin);
104
+ arr[2] = nearMin === 60 ? "".concat(parseInt(arr[2], 10) + 1) : arr[2];
105
+ return format(arr.reverse()).join(':');
106
+ };
107
+
108
+ // Set the nearest option to select a TimeList value
109
+ var nearest = function nearest(arr, val) {
110
+ return arr.reduce(function (p, n) {
111
+ return Math.abs(p) > Math.abs(n - val) ? n - val : p;
112
+ }, Infinity) + val;
113
+ };
114
+ function TimePicker(props) {
115
+ var name = props.name,
116
+ onChange = props.onChange,
117
+ seconds = props.seconds,
118
+ tabIndex = props.tabIndex,
119
+ value = props.value,
120
+ step = props.step;
121
+ var _useState = useState(''),
122
+ _useState2 = _slicedToArray(_useState, 2),
123
+ inputVal = _useState2[0],
124
+ setInputVal = _useState2[1];
125
+ var _useState3 = useState(false),
126
+ _useState4 = _slicedToArray(_useState3, 2),
127
+ isOpen = _useState4[0],
128
+ setIsOpen = _useState4[1];
129
+ var options = useMemo(function () {
130
+ return getOptions(step);
131
+ }, [step]);
132
+ var inputRef = useRef();
133
+ var wrapperRef = useRef();
134
+ var listRef = useRef();
135
+ var listRefs = options.reduce(function (acc, curr) {
136
+ acc[curr.value] = useRef();
137
+ return acc;
138
+ }, {});
139
+ var currentTimeSelected = useMemo(function () {
140
+ return roundHour(timeFormatter(inputVal), step);
141
+ }, [inputVal, step]);
142
+
143
+ // Effect to set the time
144
+ useEffect(function () {
145
+ if (!isOpen) {
146
+ var time = seconds ? value : _short(value);
147
+ setInputVal(time);
148
+ }
149
+ }, [value, seconds, isOpen]);
150
+
151
+ // Effect to enable scrolling
152
+ useEffect(function () {
153
+ var currentRef = currentTimeSelected;
154
+ if (isOpen && listRefs[currentRef]) {
155
+ listRef.current.scrollTop = listRefs[currentRef].current.offsetTop;
156
+ }
157
+ }, [isOpen, currentTimeSelected, listRefs]);
158
+
159
+ // Custom hook to close the TimeList
160
+ useEventListener('click', function (event) {
161
+ if (!wrapperRef.current.contains(event.target)) {
162
+ setIsOpen(false);
163
+ }
164
+ }, isOpen);
165
+
166
+ // Custom hook to select a time using the keyboard's up arrow
167
+ useShortcutEffect('arrowUp', function () {
168
+ if (isOpen) {
169
+ var currentIndex = options.findIndex(function (o) {
170
+ return o.value === currentTimeSelected;
171
+ });
172
+ if (!currentIndex) return;
173
+ var nextIndex = currentIndex - 1;
174
+ var nextTime = options[nextIndex] || options[currentIndex];
175
+ updateTime(nextTime.value);
176
+ }
177
+ }, isOpen);
178
+
179
+ // Custom hook to select a time using the keyboard's down arrow
180
+ useShortcutEffect('arrowDown', function () {
181
+ if (isOpen) {
182
+ var currentIndex = options.findIndex(function (o) {
183
+ return o.value === currentTimeSelected;
184
+ });
185
+ var lastIndex = options.length - 1;
186
+ if (currentIndex >= lastIndex) return;
187
+ var nextIndex = currentIndex + 1;
188
+ var nextTime = options[nextIndex] || options[lastIndex];
189
+ updateTime(nextTime.value);
190
+ }
191
+ }, isOpen);
192
+
193
+ // Custom hook to close the time list
194
+ useShortcutEffect('enter', function () {
195
+ if (isOpen) {
196
+ setIsOpen(false);
197
+ inputRef.current.blur();
198
+ }
199
+ }, isOpen);
200
+ useShortcutEffect('tab', function () {
201
+ if (isOpen) {
202
+ setIsOpen(false);
203
+ inputRef.current.blur();
204
+ }
205
+ }, isOpen);
206
+ var handleChange = function handleChange(_ref) {
207
+ var target = _ref.target;
208
+ updateTime(target.value);
209
+ };
210
+ var handleChangeRadio = useCallback(function () {}, []);
211
+ var formatInputValue = function formatInputValue(time) {
212
+ if (!seconds) {
213
+ setInputVal(_short(time));
214
+ } else {
215
+ setInputVal(time);
216
+ }
217
+ };
218
+ var handleClick = function handleClick(_ref2) {
219
+ var target = _ref2.target;
220
+ updateTime(target.value);
221
+ setIsOpen(false);
222
+ };
223
+ var updateTime = function updateTime(time) {
224
+ formatInputValue(time);
225
+ onChange({
226
+ target: {
227
+ name: name,
228
+ type: 'time',
229
+ value: timeFormatter(time)
230
+ }
231
+ });
232
+ };
233
+ return /*#__PURE__*/React.createElement(TimePickerWrapper, {
234
+ ref: wrapperRef,
235
+ className: props.className
236
+ }, /*#__PURE__*/React.createElement(StyledTimePicker, _extends({}, props, {
237
+ autoComplete: "off",
238
+ onChange: handleChange,
239
+ onFocus: function onFocus() {
240
+ return setIsOpen(true);
241
+ },
242
+ ref: inputRef,
243
+ type: "text",
244
+ value: inputVal,
245
+ tabIndex: tabIndex
246
+ })), /*#__PURE__*/React.createElement(IconWrapper, null, /*#__PURE__*/React.createElement(Icon, {
247
+ icon: "time"
248
+ })), /*#__PURE__*/React.createElement(TimeList, {
249
+ className: isOpen && 'displayed',
250
+ ref: listRef
251
+ }, isOpen && options.map(function (option) {
252
+ return /*#__PURE__*/React.createElement("li", {
253
+ key: option.value,
254
+ ref: listRefs[option.value]
255
+ }, /*#__PURE__*/React.createElement("input", {
256
+ type: "radio",
257
+ onChange: handleChangeRadio,
258
+ onClick: handleClick,
259
+ value: option.value,
260
+ id: option.value,
261
+ name: "time",
262
+ checked: option.value === currentTimeSelected,
263
+ tabIndex: "0"
264
+ }), /*#__PURE__*/React.createElement("label", {
265
+ htmlFor: option.value
266
+ }, option.label));
267
+ })));
268
+ }
269
+ TimePicker.defaultProps = {
270
+ className: null,
271
+ onChange: function onChange() {},
272
+ tabIndex: '0',
273
+ seconds: false,
274
+ value: '',
275
+ step: 30
276
+ };
277
+ TimePicker.propTypes = {
278
+ className: PropTypes.string,
279
+ name: PropTypes.string.isRequired,
280
+ onChange: PropTypes.func,
281
+ seconds: PropTypes.bool,
282
+ step: function step(props, propName) {
283
+ return MINUTES_IN_HOUR % props[propName] > 0 && new Error('step should be divisible by 60');
284
+ },
285
+ tabIndex: PropTypes.string,
286
+ value: PropTypes.string
287
+ };
288
+ export default TimePicker;
@@ -0,0 +1,72 @@
1
+ /**
2
+ *
3
+ * Toggle
4
+ *
5
+ */
6
+
7
+ import React, { useCallback } from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import { Toggle as StyledToggle, ToggleWrapper } from '@punch-in/buffet-modern';
10
+ import Label from '../Label';
11
+ function Toggle(_ref) {
12
+ var disabled = _ref.disabled,
13
+ id = _ref.id,
14
+ className = _ref.className,
15
+ name = _ref.name,
16
+ onChange = _ref.onChange,
17
+ value = _ref.value,
18
+ leftLabel = _ref.leftLabel,
19
+ rightLabel = _ref.rightLabel;
20
+ var isIndeterminate = value === null;
21
+ var handleRef = useCallback(function (element) {
22
+ if (element) {
23
+ element.indeterminate = isIndeterminate; // eslint-disable-line no-param-reassign
24
+ }
25
+ }, [isIndeterminate]);
26
+ var handleChange = function handleChange(e) {
27
+ var targetValue = e.target.checked;
28
+ // Handle click when the state is inteterminate
29
+ if (isIndeterminate) {
30
+ // Select the right value depending on the mouse position
31
+ targetValue = e.nativeEvent.offsetX >= e.target.offsetWidth / 2;
32
+ }
33
+ onChange({
34
+ target: {
35
+ name: name,
36
+ value: targetValue
37
+ }
38
+ });
39
+ };
40
+ return /*#__PURE__*/React.createElement(ToggleWrapper, {
41
+ className: className
42
+ }, /*#__PURE__*/React.createElement(Label, {
43
+ htmlFor: id || name
44
+ }, /*#__PURE__*/React.createElement(StyledToggle, {
45
+ disabled: disabled,
46
+ checked: value || false,
47
+ id: id || name,
48
+ name: id || name,
49
+ onChange: handleChange,
50
+ ref: handleRef
51
+ }), /*#__PURE__*/React.createElement("span", null, leftLabel), /*#__PURE__*/React.createElement("span", null, rightLabel)));
52
+ }
53
+ Toggle.defaultProps = {
54
+ className: null,
55
+ disabled: false,
56
+ id: null,
57
+ leftLabel: 'OFF',
58
+ onChange: function onChange() {},
59
+ rightLabel: 'ON',
60
+ value: false
61
+ };
62
+ Toggle.propTypes = {
63
+ className: PropTypes.string,
64
+ disabled: PropTypes.bool,
65
+ id: PropTypes.string,
66
+ leftLabel: PropTypes.string,
67
+ name: PropTypes.string.isRequired,
68
+ onChange: PropTypes.func,
69
+ rightLabel: PropTypes.string,
70
+ value: PropTypes.bool
71
+ };
72
+ export default Toggle;
@@ -0,0 +1,19 @@
1
+ /**
2
+ *
3
+ * UnknownInput
4
+ *
5
+ */
6
+
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ var UnknownInput = function UnknownInput(_ref) {
10
+ var type = _ref.type;
11
+ return /*#__PURE__*/React.createElement("div", null, "This ", type, " is not available");
12
+ };
13
+ UnknownInput.defaultProps = {
14
+ type: null
15
+ };
16
+ UnknownInput.propTypes = {
17
+ type: PropTypes.string
18
+ };
19
+ export default UnknownInput;
@@ -0,0 +1,33 @@
1
+ export { default as AttributeIcon } from './components/AttributeIcon';
2
+ export { default as Button } from './components/Button';
3
+ export { default as Checkbox } from './components/Checkbox';
4
+ export { default as Count } from './components/Count';
5
+ export { default as DatePicker } from './components/DatePicker';
6
+ export { default as Enumeration } from './components/Enumeration';
7
+ export { default as Error } from './components/Error';
8
+ export { default as Flex } from './components/Flex';
9
+ export { default as HeaderActions } from './components/HeaderActions';
10
+ export { default as HeaderTitle } from './components/HeaderTitle';
11
+ export { default as Icon } from './components/Icon';
12
+ export { default as IconLinks } from './components/IconLinks';
13
+ export { default as InputNumber } from './components/InputNumber';
14
+ export { default as InputText } from './components/InputText';
15
+ export { default as Label } from './components/Label';
16
+ export { default as List } from './components/List';
17
+ export { default as ListHeader } from './components/ListHeader';
18
+ export { default as ListRow } from './components/ListRow';
19
+ export { default as NavTabs } from './components/NavTabs';
20
+ export { default as Option } from './components/Option';
21
+ export { default as Padded } from './components/Padded';
22
+ export { default as Picker } from './components/Picker';
23
+ export { default as PrefixIcon } from './components/PrefixIcon';
24
+ export { default as Select } from './components/Select';
25
+ export { default as Separator } from './components/Separator';
26
+ export { default as Table } from './components/Table';
27
+ export { default as TableHeader } from './components/TableHeader';
28
+ export { default as TableRow } from './components/TableRow';
29
+ export { default as Text } from './components/Text';
30
+ export { default as Textarea } from './components/Textarea';
31
+ export { default as TimePicker } from './components/TimePicker';
32
+ export { default as Toggle } from './components/Toggle';
33
+ export { default as UnknownInput } from './components/UnknownInput';
@@ -0,0 +1,48 @@
1
+ // This is the temporary list of colors
2
+ // TODO : To clean on theme setup
3
+ export default {
4
+ black: '#333740',
5
+ white: '#ffffff',
6
+ red: '#ff203c',
7
+ orange: '#ff5d00',
8
+ lightOrange: '#f64d0a',
9
+ yellow: '#ffd500',
10
+ green: '#6dbb1a',
11
+ blue: '#0097f7',
12
+ teal: '#5bc0de',
13
+ pink: '#ff5b77',
14
+ purple: '#613d7c',
15
+ gray: '#464a4c',
16
+ border: '#E3E9F3',
17
+ 'gray-dark': '#292b2c',
18
+ grayLight: '#636c72',
19
+ 'gray-lighter': '#eceeef',
20
+ 'gray-lightest': '#f7f7f9',
21
+ brightGrey: '#f0f3f8',
22
+ darkGrey: '#e3e9f3',
23
+ lightGrey: '#fafafa',
24
+ lightestGrey: '#fbfbfb',
25
+ mediumGrey: '#F2F3F4',
26
+ grey: '#9ea7b8',
27
+ greyDark: '#292b2c',
28
+ greyAlpha: 'rgba(227, 233, 243, 0.5)',
29
+ lightBlue: '#E6F0FB',
30
+ mediumBlue: '#007EFF',
31
+ darkBlue: '#AED4FB',
32
+ content: {
33
+ background: '#fafafb',
34
+ 'background-alpha': 'rgba(14, 22, 34, 0.02)'
35
+ },
36
+ leftMenu: {
37
+ 'link-hover': '#1c2431',
38
+ 'link-color': '#919bae',
39
+ 'title-color': '#5b626f'
40
+ },
41
+ strapi: {
42
+ 'gray-light': '#eff3f6',
43
+ gray: '#535f76',
44
+ 'blue-darker': '#18202e',
45
+ 'blue-dark': '#151c2e',
46
+ blue: '#0097f7'
47
+ }
48
+ };
package/build/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict';
3
+
4
+ if (process.env.NODE_ENV === "production") {
5
+ module.exports = require("./bundle.production.js");
6
+ } else {
7
+ module.exports = require("./bundle.development.js");
8
+ }