tg-core-components 5.2.1-history-time-label.0 → 5.3.0-master.1

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 (93) hide show
  1. package/es/components/AcceptUpdatedTaC/index.js +8 -3
  2. package/es/components/Checkbox/index.js +93 -0
  3. package/es/components/Deposit/CardInput/index.js +1 -3
  4. package/es/components/Input/index.js +222 -22
  5. package/es/components/InputWrapper/index.js +69 -0
  6. package/es/components/Notification.js +4 -4
  7. package/es/components/Select/index.js +202 -64
  8. package/es/components/Select/test.js +111 -0
  9. package/es/index.js +2 -1
  10. package/es/lib/utils/translate.js +1 -8
  11. package/es/widgets/AccountDetail/index.js +53 -77
  12. package/es/widgets/ActivateWidget/index.js +59 -293
  13. package/es/widgets/BonusWidget/BonusCode.js +24 -17
  14. package/es/widgets/BonusWidget/index.js +83 -45
  15. package/es/widgets/Cashier/Deposit/PaymentForm/NewTab.js +28 -0
  16. package/es/widgets/Cashier/Deposit/PaymentForm/index.js +6 -2
  17. package/es/widgets/CashierAccordion/Deposit/BonusCodeInput/index.js +9 -6
  18. package/es/widgets/CashierAccordion/Deposit/DepositWidget/index.js +19 -29
  19. package/es/widgets/CashierAccordion/Payment/PaymentAccountForms/index.js +163 -347
  20. package/es/widgets/CashierAccordion/Payment/PaymentAccountParser.js +0 -6
  21. package/es/widgets/CashierAccordion/Withdraw/WithdrawWidget/index.js +8 -22
  22. package/es/widgets/ChangePassword/index.js +53 -40
  23. package/es/widgets/HistoryWidget/index.js +69 -51
  24. package/es/widgets/HistoryWidget/message.js +17 -20
  25. package/es/widgets/RequestResetPassword/index.js +15 -14
  26. package/es/widgets/ResetPassword/index.js +22 -18
  27. package/es/widgets/ResponsibleGamingAccordion/LimitStatus/index.js +5 -2
  28. package/es/widgets/ResponsibleGamingAccordion/PeriodItemContent/index.js +1 -2
  29. package/es/widgets/ResponsibleGamingSingleSignUp/AmountItem/index.js +1 -2
  30. package/es/widgets/ResponsibleGamingWidget/Timespan.js +14 -24
  31. package/es/widgets/ResponsibleGamingWidget/helpers.js +2 -2
  32. package/es/widgets/ResponsibleGamingWidget/validate.js +1 -1
  33. package/es/widgets/Settings/index.js +2 -2
  34. package/es/widgets/SignIn/SignInForm.js +4 -6
  35. package/es/widgets/SignIn/index.js +21 -21
  36. package/es/widgets/SignUp/ContactInfoStep.js +5 -6
  37. package/es/widgets/SportsbookSettings/index.js +10 -24
  38. package/es/widgets/Subscriptions/index.js +3 -5
  39. package/lib/components/AcceptUpdatedTaC/index.js +11 -3
  40. package/lib/components/Checkbox/index.js +106 -0
  41. package/lib/components/Deposit/CardInput/index.js +1 -3
  42. package/lib/components/Input/index.js +223 -26
  43. package/lib/components/InputWrapper/index.js +85 -0
  44. package/lib/components/Notification.js +3 -3
  45. package/lib/components/Select/index.js +209 -63
  46. package/lib/components/Select/test.js +121 -0
  47. package/lib/index.js +9 -4
  48. package/lib/lib/utils/translate.js +1 -8
  49. package/lib/widgets/AccountDetail/index.js +53 -86
  50. package/lib/widgets/ActivateWidget/index.js +58 -305
  51. package/lib/widgets/BonusWidget/BonusCode.js +24 -20
  52. package/lib/widgets/BonusWidget/index.js +85 -44
  53. package/lib/widgets/Cashier/Deposit/PaymentForm/NewTab.js +44 -0
  54. package/lib/widgets/Cashier/Deposit/PaymentForm/index.js +9 -2
  55. package/lib/widgets/CashierAccordion/Deposit/BonusCodeInput/index.js +13 -7
  56. package/lib/widgets/CashierAccordion/Deposit/DepositWidget/index.js +22 -32
  57. package/lib/widgets/CashierAccordion/Payment/PaymentAccountForms/index.js +195 -378
  58. package/lib/widgets/CashierAccordion/Payment/PaymentAccountParser.js +0 -6
  59. package/lib/widgets/CashierAccordion/Withdraw/WithdrawWidget/index.js +10 -24
  60. package/lib/widgets/ChangePassword/index.js +53 -43
  61. package/lib/widgets/HistoryWidget/index.js +69 -51
  62. package/lib/widgets/HistoryWidget/message.js +17 -20
  63. package/lib/widgets/RequestResetPassword/index.js +15 -17
  64. package/lib/widgets/ResetPassword/index.js +25 -21
  65. package/lib/widgets/ResponsibleGamingAccordion/LimitStatus/index.js +5 -2
  66. package/lib/widgets/ResponsibleGamingAccordion/PeriodItemContent/index.js +1 -2
  67. package/lib/widgets/ResponsibleGamingSingleSignUp/AmountItem/index.js +1 -2
  68. package/lib/widgets/ResponsibleGamingWidget/Timespan.js +14 -24
  69. package/lib/widgets/ResponsibleGamingWidget/helpers.js +2 -2
  70. package/lib/widgets/ResponsibleGamingWidget/validate.js +1 -1
  71. package/lib/widgets/Settings/index.js +6 -6
  72. package/lib/widgets/SignIn/SignInForm.js +7 -6
  73. package/lib/widgets/SignIn/index.js +25 -25
  74. package/lib/widgets/SignUp/ContactInfoStep.js +8 -6
  75. package/lib/widgets/SportsbookSettings/index.js +10 -24
  76. package/lib/widgets/Subscriptions/index.js +3 -11
  77. package/package.json +8 -3
  78. package/es/components/Input/BirthdateInput.js +0 -171
  79. package/es/components/Input/Checkbox.js +0 -51
  80. package/es/components/Input/Input.js +0 -73
  81. package/es/components/Input/PasswordInput.js +0 -84
  82. package/es/components/Input/PhoneNumberInput.js +0 -110
  83. package/es/components/Input/input.test.js +0 -80
  84. package/es/components/Input/old-input.test.js +0 -100
  85. package/es/components/common.js +0 -339
  86. package/lib/components/Input/BirthdateInput.js +0 -192
  87. package/lib/components/Input/Checkbox.js +0 -65
  88. package/lib/components/Input/Input.js +0 -87
  89. package/lib/components/Input/PasswordInput.js +0 -101
  90. package/lib/components/Input/PhoneNumberInput.js +0 -127
  91. package/lib/components/Input/input.test.js +0 -89
  92. package/lib/components/Input/old-input.test.js +0 -107
  93. package/lib/components/common.js +0 -359
@@ -1,110 +0,0 @@
1
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
2
-
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
-
5
- import React from 'react';
6
- import { Input, Select, useId, useValue, useFocus, createClassName, statusIcons, flatObj } from '../common';
7
- import Translate from '../Translate';
8
- import cn from 'classnames';
9
-
10
- var PhoneNumberInput = function PhoneNumberInput(props) {
11
- var val = props.value || '';
12
-
13
- var callingCodeValue = ((props.callingCodes || []).find(function (c) {
14
- return val.startsWith(c.value);
15
- }) || (props.callingCodes || [])[0] || {}).value || '';
16
- var phoneNumberValue = callingCodeValue ? val.replace(new RegExp('^' + callingCodeValue), '').replace(/^0*/, '') : val;
17
-
18
- var callingCodeSelect = {
19
- id: useId(),
20
- value: useValue(callingCodeValue),
21
- focus: useFocus()
22
- };
23
- var phoneNumberInput = {
24
- id: useId(),
25
- value: useValue(phoneNumberValue),
26
- focus: useFocus()
27
- };
28
-
29
- var createValue = function createValue() {
30
- var _Object$values;
31
-
32
- var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
33
- var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
34
- return Object.values((_Object$values = {}, _defineProperty(_Object$values, callingCodeSelect.id, callingCodeSelect.value.value), _defineProperty(_Object$values, phoneNumberInput.id, phoneNumberInput.value.value), _defineProperty(_Object$values, id, value), _Object$values)).join('');
35
- };
36
-
37
- var _onChange = function _onChange(e) {
38
- return props.onChange && props.onChange(e, createValue(e.target.id, e.target.value));
39
- };
40
-
41
- var _onBlur = function _onBlur(e) {
42
- return props.onBlur && props.onBlur(e, createValue(e.target.id, e.target.value));
43
- };
44
-
45
- var inputs = [callingCodeSelect, phoneNumberInput];
46
- var className = createClassName('tg-phonenumber-input', {
47
- hasValue: inputs.some(function (i) {
48
- return i.value.hasValue;
49
- }),
50
- hasFocus: inputs.some(function (i) {
51
- return i.focus.hasFocus;
52
- }),
53
- status: props.status
54
- });
55
-
56
- return React.createElement(
57
- 'div',
58
- { className: cn(props.className, className) },
59
- callingCodeSelect.value.hasValue && React.createElement(
60
- Select,
61
- _extends({}, flatObj(callingCodeSelect), {
62
- name: props.name + '_calling-code',
63
- label: React.createElement(Translate, { id: 'label.calling-code', defaultMessage: 'Calling code' }),
64
- onChange: function onChange(e) {
65
- callingCodeSelect.value.onChange(e.target.value);
66
- _onChange(e);
67
- },
68
- onBlur: function onBlur(e) {
69
- callingCodeSelect.focus.onBlur();
70
- _onBlur(e);
71
- },
72
- status: props.status }),
73
- (props.callingCodes || []).map(function (c, i) {
74
- return React.createElement(
75
- Select.Option,
76
- { key: c.value + i, value: c.value },
77
- c.label
78
- );
79
- })
80
- ),
81
- React.createElement(Input, _extends({}, flatObj(phoneNumberInput), {
82
- type: 'tel',
83
- name: props.name + '_number',
84
- label: React.createElement(Translate, {
85
- id: 'label.mobile_number',
86
- defaultMessage: 'MobilePhoneNumber'
87
- }),
88
- onChange: function onChange(e) {
89
- phoneNumberInput.value.onChange(e.target.value);
90
- _onChange(e);
91
- },
92
- onBlur: function onBlur(e) {
93
- phoneNumberInput.focus.onBlur();
94
- _onBlur(e);
95
- },
96
- status: props.status,
97
- trailingLane: [statusIcons[props.status]].filter(function (i) {
98
- return i;
99
- })
100
- })),
101
- React.createElement(Input, { type: 'hidden', name: props.name, value: createValue() }),
102
- React.createElement(
103
- 'div',
104
- { className: 'tg-phonenumber-input__status-text' },
105
- props.statusText
106
- )
107
- );
108
- };
109
-
110
- export default PhoneNumberInput;
@@ -1,80 +0,0 @@
1
- var _this = this;
2
-
3
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
4
-
5
- import React from 'react';
6
- import { render, screen, fireEvent, waitFor } from '@testing-library/react';
7
- import '@testing-library/jest-dom/extend-expect';
8
- import Input from './index.js';
9
-
10
- test('text has value and associated label', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
11
- var input;
12
- return regeneratorRuntime.wrap(function _callee$(_context) {
13
- while (1) {
14
- switch (_context.prev = _context.next) {
15
- case 0:
16
- render(React.createElement(Input, { type: 'text', label: 'input label', value: '1337' }));
17
- input = screen.getByLabelText('input label');
18
-
19
- fireEvent.click(input);
20
- expect(input).toHaveValue('1337');
21
-
22
- case 4:
23
- case 'end':
24
- return _context.stop();
25
- }
26
- }
27
- }, _callee, _this);
28
- })));
29
-
30
- test('text input has placeholder', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
31
- var input;
32
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
33
- while (1) {
34
- switch (_context2.prev = _context2.next) {
35
- case 0:
36
- render(React.createElement(Input, {
37
- type: 'text',
38
- label: 'input label',
39
- placeholder: 'Placeholder text',
40
- value: '1337'
41
- }));
42
- input = screen.getByPlaceholderText('Placeholder text');
43
-
44
- expect(input).toHaveValue('1337');
45
-
46
- case 3:
47
- case 'end':
48
- return _context2.stop();
49
- }
50
- }
51
- }, _callee2, _this);
52
- })));
53
-
54
- test('text input has correct class names', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
55
- var input;
56
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
57
- while (1) {
58
- switch (_context3.prev = _context3.next) {
59
- case 0:
60
- render(React.createElement(Input, {
61
- type: 'text',
62
- label: 'input label',
63
- placeholder: 'Placeholder text',
64
- value: '1337'
65
- }));
66
- input = screen.getByLabelText('input label');
67
-
68
- expect(input.parentElement.parentElement).toHaveClass('DefaultInput');
69
- fireEvent.click(input);
70
- waitFor(function () {
71
- return expect(input.parentElement).toHaveClass('Input--has-focus');
72
- });
73
-
74
- case 5:
75
- case 'end':
76
- return _context3.stop();
77
- }
78
- }
79
- }, _callee3, _this);
80
- })));
@@ -1,100 +0,0 @@
1
- var _this = this;
2
-
3
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
4
-
5
- import React from 'react';
6
- import { render, screen, fireEvent, waitFor } from '@testing-library/react';
7
- import '@testing-library/jest-dom/extend-expect';
8
- import { Input } from 'tg-core-components';
9
-
10
- test('input has title', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
11
- var _render, container, label;
12
-
13
- return regeneratorRuntime.wrap(function _callee$(_context) {
14
- while (1) {
15
- switch (_context.prev = _context.next) {
16
- case 0:
17
- _render = render(React.createElement(Input, { type: 'text', title: 'input label', value: '1337' })), container = _render.container;
18
- label = container.querySelector('.input_title');
19
-
20
- expect(label).toBeInTheDocument();
21
-
22
- case 3:
23
- case 'end':
24
- return _context.stop();
25
- }
26
- }
27
- }, _callee, _this);
28
- })));
29
-
30
- test('input has correct value', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
31
- var input;
32
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
33
- while (1) {
34
- switch (_context2.prev = _context2.next) {
35
- case 0:
36
- render(React.createElement(Input, { type: 'text', title: 'input label', value: '1337' }));
37
- input = screen.getByDisplayValue('1337');
38
-
39
- expect(input).toHaveValue('1337');
40
-
41
- case 3:
42
- case 'end':
43
- return _context2.stop();
44
- }
45
- }
46
- }, _callee2, _this);
47
- })));
48
-
49
- test('input shows error message', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
50
- var _render2, container, errorMessage;
51
-
52
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
53
- while (1) {
54
- switch (_context3.prev = _context3.next) {
55
- case 0:
56
- _render2 = render(React.createElement(Input, {
57
- type: 'text',
58
- title: 'input label',
59
- value: '1337',
60
- error: 'Very bad error.'
61
- })), container = _render2.container;
62
- errorMessage = container.querySelector('.error-message');
63
-
64
- expect(errorMessage).toBeInTheDocument();
65
-
66
- case 3:
67
- case 'end':
68
- return _context3.stop();
69
- }
70
- }
71
- }, _callee3, _this);
72
- })));
73
-
74
- test('input shows toggle icon', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
75
- var _render3, container, input, toggle;
76
-
77
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
78
- while (1) {
79
- switch (_context4.prev = _context4.next) {
80
- case 0:
81
- _render3 = render(React.createElement(Input, { type: 'text', title: 'input label', value: '1337', showToggleIcon: true })), container = _render3.container;
82
- input = container.querySelector('input[type=text]');
83
- toggle = container.querySelector('.toggle-password.fa.fa-eye');
84
-
85
- expect(input).toBeInTheDocument();
86
- expect(toggle).toBeInTheDocument();
87
-
88
- fireEvent.click(toggle);
89
- waitFor(function () {
90
- var input = container.querySelector('input[type=asdd]');
91
- expect(input).toBeInTheDocument();
92
- });
93
-
94
- case 7:
95
- case 'end':
96
- return _context4.stop();
97
- }
98
- }
99
- }, _callee4, _this);
100
- })));
@@ -1,339 +0,0 @@
1
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2
-
3
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
4
-
5
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6
-
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
- function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
10
-
11
- import React, { useMemo, useState, useEffect, useLayoutEffect, useRef } from 'react';
12
- import Icon from './Icon';
13
- import ButtonLoader from './ButtonLoader';
14
- import cn from 'classnames';
15
-
16
- export var statusIcons = {
17
- success: React.createElement(Icon, { icon: 'check-circle', className: 'SuccessIcon' }),
18
- failure: React.createElement(Icon, { icon: 'exclamation-circle', className: 'FailureIcon' }),
19
- loading: React.createElement(ButtonLoader, null)
20
- };
21
-
22
- var Input = function Input(_ref) {
23
- var label = _ref.label,
24
- hasValue = _ref.hasValue,
25
- hasFocus = _ref.hasFocus,
26
- hasTouched = _ref.hasTouched,
27
- hasAutofill = _ref.hasAutofill,
28
- status = _ref.status,
29
- leadingLane = _ref.leadingLane,
30
- trailingLane = _ref.trailingLane,
31
- rest = _objectWithoutProperties(_ref, ['label', 'hasValue', 'hasFocus', 'hasTouched', 'hasAutofill', 'status', 'leadingLane', 'trailingLane']);
32
-
33
- var className = createClassName('Input', {
34
- hasLabel: Boolean(label),
35
- hasValue: hasValue,
36
- hasFocus: hasFocus,
37
- hasTouched: hasTouched,
38
- hasAutofill: hasAutofill,
39
- disabled: rest.disabled,
40
- status: status,
41
- type: rest.type
42
- });
43
- var leadingLaneRef = useRef();
44
- var leadingLaneWidth = useRefWidth(leadingLaneRef);
45
- var trailingLaneRef = useRef();
46
- var trailingLaneWidth = useRefWidth(trailingLaneRef);
47
- return React.createElement(
48
- 'div',
49
- {
50
- className: className,
51
- style: {
52
- '--leading-lane-width': leadingLaneWidth + 'px',
53
- '--trailing-lane-width': trailingLaneWidth + 'px'
54
- } },
55
- React.createElement('input', _extends({}, rest, {
56
- type: rest.type || 'text',
57
- className: 'Input__input',
58
- name: rest.name || rest.id,
59
- ref: rest.setRef
60
- })),
61
- React.createElement(
62
- 'label',
63
- { className: 'Input__label', htmlFor: rest.id },
64
- label
65
- ),
66
- React.createElement(
67
- 'div',
68
- { className: 'Input__leading-lane', ref: leadingLaneRef },
69
- leadingLane
70
- ),
71
- React.createElement(
72
- 'div',
73
- { className: 'Input__trailing-lane', ref: trailingLaneRef },
74
- trailingLane
75
- ),
76
- React.createElement('div', {
77
- className: cn('Input__status-line', {
78
- 'Input__status-line--active': status === 'failure' || status === 'success' || hasFocus
79
- })
80
- })
81
- );
82
- };
83
-
84
- export { Input };
85
- var Select = function Select(_ref2) {
86
- var label = _ref2.label,
87
- hasValue = _ref2.hasValue,
88
- hasFocus = _ref2.hasFocus,
89
- hasTouched = _ref2.hasTouched,
90
- hasAutofill = _ref2.hasAutofill,
91
- status = _ref2.status,
92
- children = _ref2.children,
93
- leadingLane = _ref2.leadingLane,
94
- trailingLane = _ref2.trailingLane,
95
- rest = _objectWithoutProperties(_ref2, ['label', 'hasValue', 'hasFocus', 'hasTouched', 'hasAutofill', 'status', 'children', 'leadingLane', 'trailingLane']);
96
-
97
- var className = createClassName('Select', {
98
- hasLabel: Boolean(label),
99
- hasValue: hasValue,
100
- hasFocus: hasFocus,
101
- hasTouched: hasTouched,
102
- hasAutofill: hasAutofill,
103
- disabled: rest.disabled,
104
- status: status,
105
- type: rest.type
106
- });
107
- var leadingLaneRef = useRef();
108
- var leadingLaneWidth = useRefWidth(leadingLaneRef);
109
- var trailingLaneRef = useRef();
110
- var trailingLaneWidth = useRefWidth(leadingLaneRef);
111
- return React.createElement(
112
- 'div',
113
- {
114
- className: className,
115
- style: {
116
- '--leading-lane-width': leadingLaneWidth + 'px',
117
- '--trailing-lane-width': trailingLaneWidth + 'px'
118
- } },
119
- React.createElement(
120
- 'select',
121
- _extends({}, rest, {
122
- className: 'Select__select',
123
- name: rest.name || rest.id,
124
- ref: rest.setRef }),
125
- children
126
- ),
127
- React.createElement(
128
- 'label',
129
- { className: 'Select__label', htmlFor: rest.id },
130
- label
131
- ),
132
- React.createElement(
133
- 'div',
134
- { className: 'Input__leading-lane', ref: leadingLaneRef },
135
- leadingLane
136
- ),
137
- React.createElement(
138
- 'div',
139
- { className: 'Input__trailing-lane', ref: trailingLaneRef },
140
- trailingLane,
141
- React.createElement(Icon, { icon: 'caret-down' })
142
- ),
143
- React.createElement('div', {
144
- className: cn('Select__status-line', {
145
- 'Select__status-line--active': status === 'failure' || status === 'success' || hasFocus
146
- })
147
- })
148
- );
149
- };
150
- export { Select };
151
- var Option = function Option(_ref3) {
152
- var children = _ref3.children,
153
- rest = _objectWithoutProperties(_ref3, ['children']);
154
-
155
- return React.createElement(
156
- 'option',
157
- rest,
158
- children
159
- );
160
- };
161
- Select.Option = Option;
162
- var OptGroup = function OptGroup(_ref4) {
163
- var children = _ref4.children,
164
- rest = _objectWithoutProperties(_ref4, ['children']);
165
-
166
- return React.createElement(
167
- 'optgroup',
168
- rest,
169
- children
170
- );
171
- };
172
- Select.OptGroup = OptGroup;
173
-
174
- var Checkbox = function Checkbox(_ref5) {
175
- var label = _ref5.label,
176
- hasValue = _ref5.hasValue,
177
- hasFocus = _ref5.hasFocus,
178
- hasTouched = _ref5.hasTouched,
179
- hasAutofill = _ref5.hasAutofill,
180
- status = _ref5.status,
181
- rest = _objectWithoutProperties(_ref5, ['label', 'hasValue', 'hasFocus', 'hasTouched', 'hasAutofill', 'status']);
182
-
183
- var className = createClassName('Checkbox', {
184
- hasLabel: Boolean(label),
185
- hasValue: hasValue,
186
- hasFocus: hasFocus,
187
- hasTouched: hasTouched,
188
- hasAutofill: hasAutofill,
189
- disabled: rest.disabled,
190
- status: status,
191
- type: rest.type
192
- });
193
- return React.createElement(
194
- 'div',
195
- { className: className },
196
- React.createElement(
197
- 'div',
198
- { className: 'Checkbox__input-wrapper' },
199
- React.createElement('input', _extends({}, rest, {
200
- className: 'Checkbox__input',
201
- name: rest.name || rest.id,
202
- checked: hasValue,
203
- ref: rest.setRef
204
- })),
205
- React.createElement('div', { className: 'Checkbox__background' })
206
- ),
207
- React.createElement(
208
- 'label',
209
- { className: 'Checkbox__label', htmlFor: rest.id },
210
- label
211
- )
212
- );
213
- };
214
-
215
- /**
216
- * Returns a unique id. Id will stay the same between renders.
217
- */
218
- export { Checkbox };
219
- export var useId = function useId() {
220
- return useMemo(function () {
221
- return Date.now().toString(36) + Math.random().toString(36).substr(2);
222
- }, []);
223
- };
224
-
225
- /**
226
- * Useful hook for inputs that want to control value
227
- */
228
- export var useValue = function useValue() {
229
- var initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
230
-
231
- var _useState = useState(initialValue),
232
- _useState2 = _slicedToArray(_useState, 2),
233
- value = _useState2[0],
234
- setValue = _useState2[1];
235
-
236
- useEffect(function () {
237
- setValue(initialValue);
238
- }, [initialValue, setValue]);
239
- var onChange = function onChange(value) {
240
- return setValue(value);
241
- };
242
- return { value: value, hasValue: Boolean(value), onChange: onChange };
243
- };
244
-
245
- /**
246
- * Convenient hook that will keep track of input focus state
247
- */
248
- export var useFocus = function useFocus() {
249
- var _useState3 = useState(false),
250
- _useState4 = _slicedToArray(_useState3, 2),
251
- hasFocus = _useState4[0],
252
- setHasFocus = _useState4[1];
253
-
254
- var onFocus = function onFocus() {
255
- return setHasFocus(true);
256
- };
257
- var onBlur = function onBlur() {
258
- return setHasFocus(false);
259
- };
260
- return { hasFocus: hasFocus, onFocus: onFocus, onBlur: onBlur };
261
- };
262
-
263
- /**
264
- * Keeps track of touched state
265
- */
266
- export var useTouched = function useTouched() {
267
- var _useState5 = useState(false),
268
- _useState6 = _slicedToArray(_useState5, 2),
269
- hasTouched = _useState6[0],
270
- setHasTouched = _useState6[1];
271
-
272
- var onFocus = function onFocus() {
273
- return setHasTouched(true);
274
- };
275
- return { hasTouched: hasTouched, onFocus: onFocus };
276
- };
277
-
278
- /**
279
- * Convenient hook to control input type
280
- */
281
- export var useType = function useType(initialType) {
282
- var _useState7 = useState(initialType),
283
- _useState8 = _slicedToArray(_useState7, 2),
284
- type = _useState8[0],
285
- setType = _useState8[1];
286
-
287
- return { type: type, setType: setType };
288
- };
289
-
290
- /**
291
- * Useful hook to detect when input has been autofilled by browser
292
- * Requires animation to work
293
- */
294
- export var useAutofill = function useAutofill() {
295
- var _useState9 = useState(false),
296
- _useState10 = _slicedToArray(_useState9, 2),
297
- hasAutofill = _useState10[0],
298
- setHasAutofill = _useState10[1];
299
-
300
- var onAnimationStart = function onAnimationStart(e) {
301
- if (e.animationName === 'onAutoFill') {
302
- setHasAutofill(true);
303
- }
304
- };
305
- return { hasAutofill: hasAutofill, onAnimationStart: onAnimationStart };
306
- };
307
-
308
- /**
309
- * Helper function to create BEM modifiers
310
- */
311
- export var createClassName = function createClassName(baseName, props) {
312
- var _cn;
313
-
314
- return cn(baseName, (_cn = {}, _defineProperty(_cn, baseName + '--has-value', props.hasValue), _defineProperty(_cn, baseName + '--has-focus', props.hasFocus), _defineProperty(_cn, baseName + '--has-touched', props.hasTouched), _defineProperty(_cn, baseName + '--has-label', props.hasLabel), _defineProperty(_cn, baseName + '--has-autofill', props.hasAutofill), _defineProperty(_cn, baseName + '--disabled', props.disabled), _defineProperty(_cn, baseName + '--status-' + props.status, props.status), _defineProperty(_cn, baseName + '--type-' + props.type, props.type), _cn));
315
- };
316
-
317
- /**
318
- * Hook keeping track of ref element width
319
- */
320
- var useRefWidth = function useRefWidth(ref) {
321
- var _useState11 = useState(0),
322
- _useState12 = _slicedToArray(_useState11, 2),
323
- width = _useState12[0],
324
- setWidth = _useState12[1];
325
-
326
- useLayoutEffect(function () {
327
- setWidth(ref.current.clientWidth);
328
- });
329
- return width;
330
- };
331
-
332
- /**
333
- * Flat object one layer
334
- */
335
- export var flatObj = function flatObj(obj) {
336
- return Object.keys(obj).reduce(function (acc, key) {
337
- return _extends({}, acc, _typeof(obj[key]) === 'object' ? obj[key] : _defineProperty({}, key, obj[key]));
338
- }, {});
339
- };