@gympass/yoga 7.66.0 → 7.67.0
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/cjs/Dialog/web/Dialog.js +12 -7
- package/cjs/Drawer/web/Drawer.js +5 -1
- package/cjs/Feedback/web/Feedback.js +16 -10
- package/esm/Accordion/web/Accordion.test.js +19 -0
- package/esm/ActionRequirement/index.native.js +2 -0
- package/esm/ActionRequirement/native/ActionRequirement.js +48 -0
- package/esm/ActionRequirement/native/ActionRequirement.test.js +45 -0
- package/esm/ActionRequirement/native/ActionRequirementStyles.js +25 -0
- package/esm/ActionRequirement/native/index.js +6 -0
- package/esm/ActionRequirement/web/ActionRequirement.test.js +36 -0
- package/esm/AutoComplete/web/AutoComplete.test.js +139 -0
- package/esm/Avatar/index.native.js +4 -0
- package/esm/Avatar/native/Avatar.js +96 -0
- package/esm/Avatar/native/Avatar.test.js +46 -0
- package/esm/Avatar/native/AvatarCircle.js +24 -0
- package/esm/Avatar/web/Avatar.test.js +63 -0
- package/esm/Banner/index.native.js +2 -0
- package/esm/Banner/native/Banner.js +128 -0
- package/esm/Banner/native/Banner.test.js +103 -0
- package/esm/Banner/native/index.js +2 -0
- package/esm/Banner/web/Banner.test.js +109 -0
- package/esm/BottomSheet/web/BottomSheet.test.js +48 -0
- package/esm/Box/index.native.js +2 -0
- package/esm/Box/native/Box.js +4 -0
- package/esm/Box/native/Box.test.js +16 -0
- package/esm/Box/native/index.js +2 -0
- package/esm/Box/web/Box.test.js +16 -0
- package/esm/Button/index.native.js +8 -0
- package/esm/Button/native/Button.js +110 -0
- package/esm/Button/native/Button.test.js +475 -0
- package/esm/Button/native/Icon.js +82 -0
- package/esm/Button/native/Link.js +35 -0
- package/esm/Button/native/Text.js +74 -0
- package/esm/Button/native/withTouchable.js +63 -0
- package/esm/Button/web/Button.test.js +772 -0
- package/esm/Card/index.native.js +2 -0
- package/esm/Card/native/Card/Actions.js +12 -0
- package/esm/Card/native/Card/Card.js +92 -0
- package/esm/Card/native/Card/Card.test.js +15 -0
- package/esm/Card/native/Card/Content.js +8 -0
- package/esm/Card/native/Card/Header.js +8 -0
- package/esm/Card/native/Card/index.js +8 -0
- package/esm/Card/native/EventCard/EventCard.js +169 -0
- package/esm/Card/native/EventCard/EventCard.test.js +65 -0
- package/esm/Card/native/EventCard/index.js +2 -0
- package/esm/Card/native/GymCard/CheckIn/Avatar.js +17 -0
- package/esm/Card/native/GymCard/CheckIn/CheckIn.js +66 -0
- package/esm/Card/native/GymCard/CheckIn/CheckIn.test.js +39 -0
- package/esm/Card/native/GymCard/CheckIn/Content.js +11 -0
- package/esm/Card/native/GymCard/CheckIn/Header.js +11 -0
- package/esm/Card/native/GymCard/CheckIn/index.js +2 -0
- package/esm/Card/native/GymCard/index.js +5 -0
- package/esm/Card/native/PlanCard/Actions.js +22 -0
- package/esm/Card/native/PlanCard/Content.js +75 -0
- package/esm/Card/native/PlanCard/List.js +73 -0
- package/esm/Card/native/PlanCard/PlanCard.js +51 -0
- package/esm/Card/native/PlanCard/PlanCard.test.js +84 -0
- package/esm/Card/native/PlanCard/Subtitle.js +15 -0
- package/esm/Card/native/PlanCard/Tag.js +34 -0
- package/esm/Card/native/PlanCard/index.js +15 -0
- package/esm/Card/native/index.js +5 -0
- package/esm/Card/web/Card/Card.test.js +14 -0
- package/esm/Card/web/EventCard/EventCard.test.js +27 -0
- package/esm/Card/web/PlanCard/PlanCard.test.js +94 -0
- package/esm/Checkbox/index.native.js +3 -0
- package/esm/Checkbox/native/Checkbox.js +179 -0
- package/esm/Checkbox/native/Checkbox.test.js +115 -0
- package/esm/Checkbox/native/Switch.js +115 -0
- package/esm/Checkbox/native/Switch.test.js +54 -0
- package/esm/Checkbox/native/index.js +3 -0
- package/esm/Checkbox/web/Checkbox.test.js +153 -0
- package/esm/Checkbox/web/Switch.test.js +56 -0
- package/esm/Chips/index.native.js +2 -0
- package/esm/Chips/native/Chips.js +104 -0
- package/esm/Chips/native/Chips.test.js +143 -0
- package/esm/Chips/native/Counter.js +20 -0
- package/esm/Chips/native/index.js +2 -0
- package/esm/Chips/web/Chips.test.js +128 -0
- package/esm/Datepicker/web/Datepicker.test.js +247 -0
- package/esm/Dialog/web/Dialog.js +13 -8
- package/esm/Dialog/web/Dialog.test.js +62 -0
- package/esm/Divider/index.native.js +2 -0
- package/esm/Divider/native/Divider.js +29 -0
- package/esm/Divider/native/Divider.test.js +29 -0
- package/esm/Divider/native/index.js +2 -0
- package/esm/Divider/web/Divider.test.js +29 -0
- package/esm/Drawer/web/Drawer.js +6 -2
- package/esm/Drawer/web/Drawer.test.js +33 -0
- package/esm/Dropdown/index.native.js +2 -0
- package/esm/Dropdown/native/Backdrop.js +93 -0
- package/esm/Dropdown/native/Backdrop.test.js +26 -0
- package/esm/Dropdown/native/Dropdown.js +142 -0
- package/esm/Dropdown/native/Dropdown.test.js +78 -0
- package/esm/Dropdown/native/Options.android.js +66 -0
- package/esm/Dropdown/native/Options.ios.js +71 -0
- package/esm/Dropdown/native/index.js +2 -0
- package/esm/Dropdown/web/Dropdown.test.js +93 -0
- package/esm/Feedback/web/Feedback.js +17 -11
- package/esm/Feedback/web/Feedback.test.js +94 -0
- package/esm/Grid/web/Col.test.js +48 -0
- package/esm/Grid/web/Container.test.js +14 -0
- package/esm/Grid/web/Hide.test.js +31 -0
- package/esm/Grid/web/Row.test.js +14 -0
- package/esm/Header/web/Header.test.js +38 -0
- package/esm/Heading/web/Heading.test.js +58 -0
- package/esm/Icon/index.native.js +2 -0
- package/esm/Icon/native/Icon.test.js +47 -0
- package/esm/Icon/native/index.js +2 -0
- package/esm/Icon/web/Icon.test.js +47 -0
- package/esm/Input/index.native.js +6 -0
- package/esm/Input/native/Email.js +15 -0
- package/esm/Input/native/Email.test.js +13 -0
- package/esm/Input/native/Helper.js +62 -0
- package/esm/Input/native/Input.js +234 -0
- package/esm/Input/native/Input.test.js +181 -0
- package/esm/Input/native/Number.js +12 -0
- package/esm/Input/native/Number.test.js +13 -0
- package/esm/Input/native/Password.js +112 -0
- package/esm/Input/native/Password.test.js +125 -0
- package/esm/Input/native/Tel.js +14 -0
- package/esm/Input/native/Tel.test.js +13 -0
- package/esm/Input/native/index.js +6 -0
- package/esm/Input/web/Email.test.js +13 -0
- package/esm/Input/web/Input.test.js +145 -0
- package/esm/Input/web/Number.test.js +13 -0
- package/esm/Input/web/Password.test.js +90 -0
- package/esm/Input/web/Phone.test.js +95 -0
- package/esm/Input/web/Tel.test.js +13 -0
- package/esm/List/index.native.js +3 -0
- package/esm/List/native/List.js +22 -0
- package/esm/List/native/List.test.js +106 -0
- package/esm/List/native/ListItem.js +51 -0
- package/esm/List/native/index.js +3 -0
- package/esm/List/web/List.test.js +62 -0
- package/esm/Menu/web/Menu.test.js +115 -0
- package/esm/Popover/web/Popover.test.js +19 -0
- package/esm/Progress/index.native.js +2 -0
- package/esm/Progress/native/Progress.js +103 -0
- package/esm/Progress/native/Progress.test.js +222 -0
- package/esm/Progress/native/index.js +2 -0
- package/esm/Progress/web/Progress.test.js +222 -0
- package/esm/RadioGroup/index.native.js +4 -0
- package/esm/RadioGroup/native/Button/RadioButton.js +64 -0
- package/esm/RadioGroup/native/Button/RadioButton.test.js +96 -0
- package/esm/RadioGroup/native/Radio/Radio.js +88 -0
- package/esm/RadioGroup/native/Radio/Radio.test.js +112 -0
- package/esm/RadioGroup/native/RadioGroup.js +66 -0
- package/esm/RadioGroup/native/RadioGroup.test.js +50 -0
- package/esm/RadioGroup/native/index.js +4 -0
- package/esm/RadioGroup/web/Button/RadioButton.test.js +121 -0
- package/esm/RadioGroup/web/Radio/Radio.test.js +108 -0
- package/esm/RadioGroup/web/RadioGroup.test.js +83 -0
- package/esm/Rating/index.native.js +2 -0
- package/esm/Rating/native/Rating.js +186 -0
- package/esm/Rating/native/Rating.test.js +121 -0
- package/esm/Rating/native/index.js +2 -0
- package/esm/Rating/web/Rating.test.js +184 -0
- package/esm/Result/index.native.js +8 -0
- package/esm/Result/native/Attendances.js +55 -0
- package/esm/Result/native/Details.js +97 -0
- package/esm/Result/native/Rate.js +35 -0
- package/esm/Result/native/Result.js +86 -0
- package/esm/Result/native/Result.test.js +107 -0
- package/esm/Result/native/ResultButton.js +13 -0
- package/esm/Result/native/Tags.js +41 -0
- package/esm/Result/native/TinyTextIcon.js +18 -0
- package/esm/Result/native/index.js +2 -0
- package/esm/Skeleton/index.native.js +2 -0
- package/esm/Skeleton/native/Skeleton.js +94 -0
- package/esm/Skeleton/native/Skeleton.test.js +78 -0
- package/esm/Skeleton/native/index.js +2 -0
- package/esm/Skeleton/web/Skeleton.test.js +77 -0
- package/esm/Slider/index.native.js +2 -0
- package/esm/Slider/native/Label.js +19 -0
- package/esm/Slider/native/Marker.js +68 -0
- package/esm/Slider/native/Slider.js +156 -0
- package/esm/Slider/native/Slider.test.js +122 -0
- package/esm/Slider/native/Step.js +14 -0
- package/esm/Slider/native/Tooltip.js +90 -0
- package/esm/Slider/web/Slider.test.js +86 -0
- package/esm/Snackbar/index.native.js +2 -0
- package/esm/Snackbar/native/Snackbar.js +199 -0
- package/esm/Snackbar/native/Snackbar.test.js +100 -0
- package/esm/Snackbar/native/SnackbarAnimationWrapper.js +124 -0
- package/esm/Snackbar/native/index.js +2 -0
- package/esm/Snackbar/web/Snackbar.test.js +118 -0
- package/esm/Stepper/index.native.js +3 -0
- package/esm/Stepper/native/Dots.js +45 -0
- package/esm/Stepper/native/Line.js +35 -0
- package/esm/Stepper/native/Step.js +19 -0
- package/esm/Stepper/native/Stepper.js +52 -0
- package/esm/Stepper/native/Stepper.test.js +70 -0
- package/esm/Stepper/native/index.js +3 -0
- package/esm/Stepper/web/Stepper.test.js +67 -0
- package/esm/Tag/index.native.js +4 -0
- package/esm/Tag/native/Informative.js +72 -0
- package/esm/Tag/native/Tag.js +75 -0
- package/esm/Tag/native/Tag.test.js +94 -0
- package/esm/Tag/native/index.js +2 -0
- package/esm/Tag/web/Tag.test.js +79 -0
- package/esm/Text/index.native.js +16 -0
- package/esm/Text/native/Text.js +69 -0
- package/esm/Text/native/Text.test.js +149 -0
- package/esm/Text/native/index.js +2 -0
- package/esm/Text/web/Text.test.js +149 -0
- package/esm/TextArea/index.native.js +2 -0
- package/esm/TextArea/native/TextArea.js +59 -0
- package/esm/TextArea/native/TextArea.test.js +11 -0
- package/esm/TextArea/native/index.js +2 -0
- package/esm/TextArea/web/TextArea.test.js +11 -0
- package/esm/Theme/Provider/index.native.js +2 -0
- package/esm/Theme/Provider/native/index.js +2 -0
- package/esm/Theme/Provider/web/FontLoader.test.js +11 -0
- package/esm/Theme/Provider/web/GlobalStyle.test.js +17 -0
- package/esm/Theme/helpers/themeReader/native/native.test.js +53 -0
- package/esm/Theme/helpers/themeReader/web/web.test.js +41 -0
- package/esm/Theme/index.native.js +5 -0
- package/esm/index.native.js +26 -0
- package/esm/shared/index.native.js +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var _excluded = ["label", "helper", "disabled", "checked", "error", "style", "onPressIn", "onPressOut", "inverted", "theme"];
|
|
2
|
+
|
|
3
|
+
var _templateObject;
|
|
4
|
+
|
|
5
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
|
|
6
|
+
|
|
7
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
8
|
+
|
|
9
|
+
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
|
|
10
|
+
|
|
11
|
+
import React, { useState } from 'react';
|
|
12
|
+
import { bool, func, string, shape } from 'prop-types';
|
|
13
|
+
import styled, { withTheme } from 'styled-components';
|
|
14
|
+
import { TouchableWithoutFeedback, View } from 'react-native';
|
|
15
|
+
import { hexToRgb } from '@gympass/yoga-common';
|
|
16
|
+
import { Check } from '@gympass/yoga-icons';
|
|
17
|
+
import Text from '../../Text';
|
|
18
|
+
var CheckboxWrapper = styled.View(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n flex-direction: row;\n align-items: center;\n"])));
|
|
19
|
+
var Label = styled(Text.Regular)(function (_ref) {
|
|
20
|
+
var checkbox = _ref.theme.yoga.components.checkbox;
|
|
21
|
+
return "\n padding-left: " + checkbox.label.padding.left + "px;\n\n font-size: " + checkbox.label.font.size + "px;\n\n color: " + checkbox.label.font.color + ";\n";
|
|
22
|
+
});
|
|
23
|
+
var HelperWrapper = styled.View(function (_ref2) {
|
|
24
|
+
var checkbox = _ref2.theme.yoga.components.checkbox;
|
|
25
|
+
return "\n margin-top: " + checkbox.helper.margin.top + "px;\n";
|
|
26
|
+
});
|
|
27
|
+
var Helper = styled(Text.Regular)(function (_ref3) {
|
|
28
|
+
var error = _ref3.error,
|
|
29
|
+
_ref3$theme$yoga = _ref3.theme.yoga,
|
|
30
|
+
feedback = _ref3$theme$yoga.colors.feedback,
|
|
31
|
+
checkbox = _ref3$theme$yoga.components.checkbox;
|
|
32
|
+
return "\n font-size: " + checkbox.helper.font.size + "px;\n\n color: " + (error ? feedback.attention[1] : checkbox.helper.font.color) + ";\n";
|
|
33
|
+
});
|
|
34
|
+
var CheckBackground = styled.View(function (_ref4) {
|
|
35
|
+
var checked = _ref4.checked,
|
|
36
|
+
disabled = _ref4.disabled,
|
|
37
|
+
inverted = _ref4.inverted,
|
|
38
|
+
error = _ref4.error,
|
|
39
|
+
_ref4$theme$yoga = _ref4.theme.yoga,
|
|
40
|
+
_ref4$theme$yoga$colo = _ref4$theme$yoga.colors,
|
|
41
|
+
primary = _ref4$theme$yoga$colo.primary,
|
|
42
|
+
feedback = _ref4$theme$yoga$colo.feedback,
|
|
43
|
+
elements = _ref4$theme$yoga$colo.elements,
|
|
44
|
+
white = _ref4$theme$yoga$colo.white,
|
|
45
|
+
checkbox = _ref4$theme$yoga.components.checkbox;
|
|
46
|
+
var borderColor = primary;
|
|
47
|
+
var bgColor = 'transparent';
|
|
48
|
+
|
|
49
|
+
if (error) {
|
|
50
|
+
var _feedback$attention = feedback.attention;
|
|
51
|
+
borderColor = _feedback$attention[1];
|
|
52
|
+
|
|
53
|
+
if (checked) {
|
|
54
|
+
var _feedback$attention2 = feedback.attention;
|
|
55
|
+
bgColor = _feedback$attention2[1];
|
|
56
|
+
}
|
|
57
|
+
} else if (disabled) {
|
|
58
|
+
borderColor = checkbox.disabled.border.color;
|
|
59
|
+
|
|
60
|
+
if (checked) {
|
|
61
|
+
bgColor = checkbox.disabled.backgroundColor;
|
|
62
|
+
borderColor = elements.lineAndBorders;
|
|
63
|
+
}
|
|
64
|
+
} else if (checked) {
|
|
65
|
+
borderColor = primary;
|
|
66
|
+
bgColor = primary;
|
|
67
|
+
|
|
68
|
+
if (inverted) {
|
|
69
|
+
bgColor = white;
|
|
70
|
+
borderColor = white;
|
|
71
|
+
}
|
|
72
|
+
} else if (inverted) {
|
|
73
|
+
borderColor = white;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return "\n position: absolute;\n\n width: " + checkbox.size + "px;\n height: " + checkbox.size + "px;\n\n border-radius: " + checkbox.border.radius + "px;\n border-width: " + checkbox.border.width + "px;\n border-style: solid;\n\n background-color: " + bgColor + ";\n\n border-color: " + borderColor + ";\n ";
|
|
77
|
+
});
|
|
78
|
+
var Shadow = styled.View(function (_ref5) {
|
|
79
|
+
var checked = _ref5.checked,
|
|
80
|
+
inverted = _ref5.inverted,
|
|
81
|
+
_ref5$theme$yoga = _ref5.theme.yoga,
|
|
82
|
+
_ref5$theme$yoga$colo = _ref5$theme$yoga.colors,
|
|
83
|
+
primary = _ref5$theme$yoga$colo.primary,
|
|
84
|
+
elements = _ref5$theme$yoga$colo.elements,
|
|
85
|
+
white = _ref5$theme$yoga$colo.white,
|
|
86
|
+
checkbox = _ref5$theme$yoga.components.checkbox;
|
|
87
|
+
var size = checkbox.size * 1.67;
|
|
88
|
+
var shadowColor = checked ? primary : elements.backgroundAndDisabled;
|
|
89
|
+
return "\n width: " + size + "px;\n height: " + size + "px;\n\n background-color: " + hexToRgb(inverted ? white : shadowColor, 0.75) + ";\n border-radius: " + checkbox.hover.border.radius + "px;\n ";
|
|
90
|
+
});
|
|
91
|
+
var CheckArea = styled.View(function (_ref6) {
|
|
92
|
+
var checkbox = _ref6.theme.yoga.components.checkbox;
|
|
93
|
+
return "\n justify-content: center;\n align-items: center;\n\n width: " + checkbox.size + "px;\n height: " + checkbox.size + "px;\n";
|
|
94
|
+
});
|
|
95
|
+
/** The checkbox component is used when the user needs to select one or more
|
|
96
|
+
* items on a task. This component can also allow the user to turn an option on
|
|
97
|
+
* or off. */
|
|
98
|
+
|
|
99
|
+
var Checkbox = function Checkbox(_ref7) {
|
|
100
|
+
var label = _ref7.label,
|
|
101
|
+
helper = _ref7.helper,
|
|
102
|
+
disabled = _ref7.disabled,
|
|
103
|
+
checked = _ref7.checked,
|
|
104
|
+
error = _ref7.error,
|
|
105
|
+
style = _ref7.style,
|
|
106
|
+
_onPressIn = _ref7.onPressIn,
|
|
107
|
+
_onPressOut = _ref7.onPressOut,
|
|
108
|
+
inverted = _ref7.inverted,
|
|
109
|
+
_ref7$theme$yoga = _ref7.theme.yoga,
|
|
110
|
+
checkbox = _ref7$theme$yoga.components.checkbox,
|
|
111
|
+
colors = _ref7$theme$yoga.colors,
|
|
112
|
+
rest = _objectWithoutPropertiesLoose(_ref7, _excluded);
|
|
113
|
+
|
|
114
|
+
var _useState = useState(false),
|
|
115
|
+
pressed = _useState[0],
|
|
116
|
+
setPressed = _useState[1];
|
|
117
|
+
|
|
118
|
+
return /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(TouchableWithoutFeedback, _extends({}, rest, {
|
|
119
|
+
disabled: disabled,
|
|
120
|
+
onPressIn: function onPressIn(e) {
|
|
121
|
+
setPressed(true);
|
|
122
|
+
|
|
123
|
+
_onPressIn(e);
|
|
124
|
+
},
|
|
125
|
+
onPressOut: function onPressOut(e) {
|
|
126
|
+
setPressed(false);
|
|
127
|
+
|
|
128
|
+
_onPressOut(e);
|
|
129
|
+
}
|
|
130
|
+
}), /*#__PURE__*/React.createElement(CheckboxWrapper, {
|
|
131
|
+
style: style
|
|
132
|
+
}, /*#__PURE__*/React.createElement(CheckArea, null, pressed && !disabled && /*#__PURE__*/React.createElement(Shadow, {
|
|
133
|
+
pressed: pressed,
|
|
134
|
+
checked: checked,
|
|
135
|
+
inverted: inverted
|
|
136
|
+
}), /*#__PURE__*/React.createElement(CheckBackground, {
|
|
137
|
+
disabled: disabled,
|
|
138
|
+
checked: checked,
|
|
139
|
+
error: error,
|
|
140
|
+
pressed: pressed,
|
|
141
|
+
inverted: inverted
|
|
142
|
+
}), checked && /*#__PURE__*/React.createElement(Check, {
|
|
143
|
+
fill: inverted ? colors.primary : checkbox.checked.icon.color,
|
|
144
|
+
style: {
|
|
145
|
+
position: 'absolute'
|
|
146
|
+
},
|
|
147
|
+
width: 24,
|
|
148
|
+
height: 24
|
|
149
|
+
})), label && /*#__PURE__*/React.createElement(Label, null, label))), (helper || error) && /*#__PURE__*/React.createElement(HelperWrapper, null, /*#__PURE__*/React.createElement(Helper, {
|
|
150
|
+
error: error
|
|
151
|
+
}, error || helper)));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
Checkbox.propTypes = {
|
|
155
|
+
label: string,
|
|
156
|
+
|
|
157
|
+
/** set a short helper text under checkbox */
|
|
158
|
+
helper: string,
|
|
159
|
+
checked: bool,
|
|
160
|
+
disabled: bool,
|
|
161
|
+
inverted: bool,
|
|
162
|
+
error: string,
|
|
163
|
+
style: shape({}),
|
|
164
|
+
onPressIn: func,
|
|
165
|
+
onPressOut: func
|
|
166
|
+
};
|
|
167
|
+
Checkbox.defaultProps = {
|
|
168
|
+
label: undefined,
|
|
169
|
+
helper: undefined,
|
|
170
|
+
checked: false,
|
|
171
|
+
disabled: false,
|
|
172
|
+
inverted: false,
|
|
173
|
+
error: undefined,
|
|
174
|
+
style: {},
|
|
175
|
+
onPressIn: function onPressIn() {},
|
|
176
|
+
onPressOut: function onPressOut() {}
|
|
177
|
+
};
|
|
178
|
+
Checkbox.displayName = 'Checkbox';
|
|
179
|
+
export default withTheme(Checkbox);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { render, fireEvent } from '@testing-library/react-native';
|
|
5
|
+
import Checkbox from '..';
|
|
6
|
+
import ThemeProvider from '../../Theme';
|
|
7
|
+
var data = {
|
|
8
|
+
label: 'Checkbox Component',
|
|
9
|
+
helper: 'Helper Text'
|
|
10
|
+
};
|
|
11
|
+
describe('<Checkbox />', function () {
|
|
12
|
+
describe('Snapshots', function () {
|
|
13
|
+
it('should match snapshot without label', function () {
|
|
14
|
+
var _render = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, null))),
|
|
15
|
+
toJSON = _render.toJSON;
|
|
16
|
+
|
|
17
|
+
expect(toJSON()).toMatchSnapshot();
|
|
18
|
+
});
|
|
19
|
+
it('should match snapshot without label', function () {
|
|
20
|
+
var _render2 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, null))),
|
|
21
|
+
toJSON = _render2.toJSON;
|
|
22
|
+
|
|
23
|
+
expect(toJSON()).toMatchSnapshot();
|
|
24
|
+
});
|
|
25
|
+
it('should match snapshot with default checkbox', function () {
|
|
26
|
+
var _render3 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, data))),
|
|
27
|
+
toJSON = _render3.toJSON;
|
|
28
|
+
|
|
29
|
+
expect(toJSON()).toMatchSnapshot();
|
|
30
|
+
});
|
|
31
|
+
it('should match snapshot with disabled checkbox', function () {
|
|
32
|
+
var _render4 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
33
|
+
disabled: true
|
|
34
|
+
})))),
|
|
35
|
+
toJSON = _render4.toJSON;
|
|
36
|
+
|
|
37
|
+
expect(toJSON()).toMatchSnapshot();
|
|
38
|
+
});
|
|
39
|
+
it('should match snapshot with checked checkbox', function () {
|
|
40
|
+
var _render5 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
41
|
+
checked: true
|
|
42
|
+
})))),
|
|
43
|
+
toJSON = _render5.toJSON;
|
|
44
|
+
|
|
45
|
+
expect(toJSON()).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
it('should match snapshot with disabled and checked checkbox', function () {
|
|
48
|
+
var _render6 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
49
|
+
disabled: true,
|
|
50
|
+
checked: true
|
|
51
|
+
})))),
|
|
52
|
+
toJSON = _render6.toJSON;
|
|
53
|
+
|
|
54
|
+
expect(toJSON()).toMatchSnapshot();
|
|
55
|
+
});
|
|
56
|
+
it('should match snapshot with error checkbox', function () {
|
|
57
|
+
var _render7 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
58
|
+
error: "Error text"
|
|
59
|
+
})))),
|
|
60
|
+
toJSON = _render7.toJSON;
|
|
61
|
+
|
|
62
|
+
expect(toJSON()).toMatchSnapshot();
|
|
63
|
+
});
|
|
64
|
+
it('should match snapshot with error and checked checkbox', function () {
|
|
65
|
+
var _render8 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
66
|
+
error: "Error text",
|
|
67
|
+
checked: true
|
|
68
|
+
})))),
|
|
69
|
+
toJSON = _render8.toJSON;
|
|
70
|
+
|
|
71
|
+
expect(toJSON()).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
it('should match snapshot with inverted', function () {
|
|
74
|
+
var _render9 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
75
|
+
inverted: true
|
|
76
|
+
})))),
|
|
77
|
+
toJSON = _render9.toJSON;
|
|
78
|
+
|
|
79
|
+
expect(toJSON()).toMatchSnapshot();
|
|
80
|
+
});
|
|
81
|
+
it('should match snapshot with inverted and checked', function () {
|
|
82
|
+
var _render10 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
83
|
+
inverted: true,
|
|
84
|
+
checked: true
|
|
85
|
+
})))),
|
|
86
|
+
toJSON = _render10.toJSON;
|
|
87
|
+
|
|
88
|
+
expect(toJSON()).toMatchSnapshot();
|
|
89
|
+
});
|
|
90
|
+
it('should match snapshot with inverted and checked and disabled', function () {
|
|
91
|
+
var _render11 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
92
|
+
inverted: true,
|
|
93
|
+
checked: true,
|
|
94
|
+
disabled: true
|
|
95
|
+
})))),
|
|
96
|
+
toJSON = _render11.toJSON;
|
|
97
|
+
|
|
98
|
+
expect(toJSON()).toMatchSnapshot();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('Events', function () {
|
|
102
|
+
it('should call onChange function when press on Checkbox', function () {
|
|
103
|
+
var onChangeMock = jest.fn();
|
|
104
|
+
|
|
105
|
+
var _render12 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
106
|
+
onPress: onChangeMock,
|
|
107
|
+
testID: "checkbox"
|
|
108
|
+
})))),
|
|
109
|
+
getByTestId = _render12.getByTestId;
|
|
110
|
+
|
|
111
|
+
fireEvent.press(getByTestId('checkbox'));
|
|
112
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var _templateObject, _templateObject2;
|
|
2
|
+
|
|
3
|
+
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
|
|
4
|
+
|
|
5
|
+
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import { bool } from 'prop-types';
|
|
7
|
+
import styled, { withTheme } from 'styled-components';
|
|
8
|
+
import { hexToRgb } from '@gympass/yoga-common';
|
|
9
|
+
import { Animated } from 'react-native';
|
|
10
|
+
import withTouchable from '../../Button/native/withTouchable';
|
|
11
|
+
import Box from '../../Box';
|
|
12
|
+
var SwitchTrack = styled.View(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n ", ";\n"])), function (_ref) {
|
|
13
|
+
var checkboxswitch = _ref.theme.yoga.components.checkboxswitch,
|
|
14
|
+
checked = _ref.checked,
|
|
15
|
+
disabled = _ref.disabled;
|
|
16
|
+
return "\n display: flex;\n justify-content: center;\n width: " + checkboxswitch.track.width + "px;\n height: " + checkboxswitch.track.height + "px;\n borderRadius: " + checkboxswitch.track.radii + "px;\n background-color: " + (checked ? checkboxswitch.track.checked.backgroundColor : checkboxswitch.track.backgroundColor) + ";\n\n " + (disabled ? "\n background-color: " + checkboxswitch.track.disabled.backgroundColor + ";" : '') + "\n ";
|
|
17
|
+
});
|
|
18
|
+
var ThumbShadow = styled.View(function (_ref2) {
|
|
19
|
+
var _ref2$theme$yoga = _ref2.theme.yoga,
|
|
20
|
+
colors = _ref2$theme$yoga.colors,
|
|
21
|
+
checkboxswitch = _ref2$theme$yoga.components.checkboxswitch,
|
|
22
|
+
checked = _ref2.checked;
|
|
23
|
+
var width = checkboxswitch.thumb.width * checkboxswitch.thumb.shadowScale;
|
|
24
|
+
var height = checkboxswitch.thumb.height * checkboxswitch.thumb.shadowScale;
|
|
25
|
+
return "\n width: " + width + "px;\n height: " + height + "px;\n position: absolute;\n background-color: " + (checked ? hexToRgb(colors.primary, 0.75) : hexToRgb(colors.elements.backgroundAndDisabled, 0.75)) + ";\n border-radius: " + checkboxswitch.thumb.radii + "px;\n ";
|
|
26
|
+
});
|
|
27
|
+
var SwitchThumb = styled(Box).attrs(function (_ref3) {
|
|
28
|
+
var checkboxswitch = _ref3.theme.yoga.components.checkboxswitch,
|
|
29
|
+
disabled = _ref3.disabled;
|
|
30
|
+
return {
|
|
31
|
+
width: checkboxswitch.thumb.width,
|
|
32
|
+
height: checkboxswitch.thumb.height,
|
|
33
|
+
borderRadius: checkboxswitch.thumb.radii,
|
|
34
|
+
bgColor: disabled ? checkboxswitch.thumb.disabled.backgroundColor : checkboxswitch.thumb.backgroundColor,
|
|
35
|
+
elevation: checkboxswitch.thumb.shadow
|
|
36
|
+
};
|
|
37
|
+
})(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose([""])));
|
|
38
|
+
|
|
39
|
+
var CheckboxSwitch = function CheckboxSwitch(_ref4) {
|
|
40
|
+
var checked = _ref4.checked,
|
|
41
|
+
pressed = _ref4.pressed,
|
|
42
|
+
disabled = _ref4.disabled,
|
|
43
|
+
checkboxswitch = _ref4.theme.yoga.components.checkboxswitch;
|
|
44
|
+
|
|
45
|
+
var _useState = useState(new Animated.Value(Number(checked))),
|
|
46
|
+
thumbPosition = _useState[0];
|
|
47
|
+
|
|
48
|
+
var thumbTo = checkboxswitch.track.width - checkboxswitch.thumb.width - checkboxswitch.thumb.left;
|
|
49
|
+
var thumbFrom = checkboxswitch.thumb.left;
|
|
50
|
+
var shadowDiameter = checkboxswitch.thumb.width * checkboxswitch.thumb.shadowScale;
|
|
51
|
+
var shadowAndThumbDiff = shadowDiameter - checkboxswitch.thumb.width;
|
|
52
|
+
var halfDiff = shadowAndThumbDiff / 2;
|
|
53
|
+
var thumbShadowFrom = (halfDiff - checkboxswitch.thumb.left) * -1;
|
|
54
|
+
var thumbShadowTo = thumbTo - halfDiff;
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
var toggle = function toggle(isChecked, position) {
|
|
57
|
+
var animValue = {
|
|
58
|
+
fromValue: isChecked ? 0 : 1,
|
|
59
|
+
toValue: isChecked ? 1 : 0,
|
|
60
|
+
duration: 100,
|
|
61
|
+
useNativeDriver: false
|
|
62
|
+
};
|
|
63
|
+
Animated.timing(position, animValue).start();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
toggle(!checked, thumbPosition);
|
|
67
|
+
}, [checked]);
|
|
68
|
+
return /*#__PURE__*/React.createElement(SwitchTrack, {
|
|
69
|
+
checked: checked,
|
|
70
|
+
disabled: disabled,
|
|
71
|
+
as: Animated.View,
|
|
72
|
+
style: !disabled && {
|
|
73
|
+
backgroundColor: thumbPosition.interpolate({
|
|
74
|
+
inputRange: [0, 1],
|
|
75
|
+
outputRange: [checkboxswitch.track.checked.backgroundColor, checkboxswitch.track.backgroundColor]
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}, pressed && !disabled && /*#__PURE__*/React.createElement(ThumbShadow, {
|
|
79
|
+
checked: checked,
|
|
80
|
+
as: Animated.View,
|
|
81
|
+
style: {
|
|
82
|
+
transform: [{
|
|
83
|
+
translateX: thumbPosition.interpolate({
|
|
84
|
+
inputRange: [0, 1],
|
|
85
|
+
outputRange: [thumbShadowTo, thumbShadowFrom]
|
|
86
|
+
})
|
|
87
|
+
}]
|
|
88
|
+
}
|
|
89
|
+
}), /*#__PURE__*/React.createElement(SwitchThumb, {
|
|
90
|
+
checked: checked,
|
|
91
|
+
disabled: disabled,
|
|
92
|
+
as: Animated.View,
|
|
93
|
+
style: {
|
|
94
|
+
transform: [{
|
|
95
|
+
translateX: thumbPosition.interpolate({
|
|
96
|
+
inputRange: [0, 1],
|
|
97
|
+
outputRange: [thumbTo, thumbFrom]
|
|
98
|
+
})
|
|
99
|
+
}]
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
CheckboxSwitch.propTypes = {
|
|
105
|
+
checked: bool,
|
|
106
|
+
disabled: bool,
|
|
107
|
+
pressed: bool
|
|
108
|
+
};
|
|
109
|
+
CheckboxSwitch.defaultProps = {
|
|
110
|
+
checked: false,
|
|
111
|
+
disabled: false,
|
|
112
|
+
pressed: false
|
|
113
|
+
};
|
|
114
|
+
CheckboxSwitch.displayName = 'Checkbox.Switch';
|
|
115
|
+
export default withTouchable(withTheme(CheckboxSwitch));
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react-native';
|
|
3
|
+
import Checkbox from '..';
|
|
4
|
+
import ThemeProvider from '../../Theme';
|
|
5
|
+
jest.useFakeTimers();
|
|
6
|
+
describe('<Checkbox />', function () {
|
|
7
|
+
describe('<Checkbox.Switch />', function () {
|
|
8
|
+
describe('Snapshots', function () {
|
|
9
|
+
it('should match snapshot with default switch', function () {
|
|
10
|
+
var _render = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, null))),
|
|
11
|
+
toJSON = _render.toJSON;
|
|
12
|
+
|
|
13
|
+
expect(toJSON()).toMatchSnapshot();
|
|
14
|
+
});
|
|
15
|
+
it('should match snapshot with disabled switch', function () {
|
|
16
|
+
var _render2 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
17
|
+
disabled: true
|
|
18
|
+
}))),
|
|
19
|
+
toJSON = _render2.toJSON;
|
|
20
|
+
|
|
21
|
+
expect(toJSON()).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
it('should match snapshot with checked switch', function () {
|
|
24
|
+
var _render3 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
25
|
+
checked: true
|
|
26
|
+
}))),
|
|
27
|
+
toJSON = _render3.toJSON;
|
|
28
|
+
|
|
29
|
+
expect(toJSON()).toMatchSnapshot();
|
|
30
|
+
});
|
|
31
|
+
it('should match snapshot with disabled and checked switch', function () {
|
|
32
|
+
var _render4 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
33
|
+
disabled: true,
|
|
34
|
+
checked: true
|
|
35
|
+
}))),
|
|
36
|
+
toJSON = _render4.toJSON;
|
|
37
|
+
|
|
38
|
+
expect(toJSON()).toMatchSnapshot();
|
|
39
|
+
});
|
|
40
|
+
it('should call onChange function when click on Checkbox.Switch', function () {
|
|
41
|
+
var onChangeMock = jest.fn();
|
|
42
|
+
|
|
43
|
+
var _render5 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
44
|
+
onChange: onChangeMock,
|
|
45
|
+
accessibilityRole: "button"
|
|
46
|
+
}))),
|
|
47
|
+
getByRole = _render5.getByRole;
|
|
48
|
+
|
|
49
|
+
fireEvent.press(getByRole('button'));
|
|
50
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
6
|
+
import Checkbox from '..';
|
|
7
|
+
import ThemeProvider from '../../Theme';
|
|
8
|
+
var data = {
|
|
9
|
+
label: 'Checkbox Component',
|
|
10
|
+
helper: 'Helper Text'
|
|
11
|
+
};
|
|
12
|
+
var originalError = console.error;
|
|
13
|
+
beforeEach(function () {
|
|
14
|
+
console.error = jest.fn();
|
|
15
|
+
});
|
|
16
|
+
afterEach(function () {
|
|
17
|
+
console.error = originalError;
|
|
18
|
+
});
|
|
19
|
+
describe('<Checkbox />', function () {
|
|
20
|
+
describe('Snapshots', function () {
|
|
21
|
+
it('should match snapshot without props', function () {
|
|
22
|
+
var _render = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, null))),
|
|
23
|
+
container = _render.container;
|
|
24
|
+
|
|
25
|
+
expect(container).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
it('should match snapshot with default checkbox', function () {
|
|
28
|
+
var _render2 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, data))),
|
|
29
|
+
container = _render2.container;
|
|
30
|
+
|
|
31
|
+
expect(container).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
it('should match snapshot with disabled checkbox', function () {
|
|
34
|
+
var _render3 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
35
|
+
disabled: true
|
|
36
|
+
})))),
|
|
37
|
+
container = _render3.container;
|
|
38
|
+
|
|
39
|
+
expect(container).toMatchSnapshot();
|
|
40
|
+
});
|
|
41
|
+
it('should match snapshot with checked checkbox', function () {
|
|
42
|
+
var _render4 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
43
|
+
checked: true
|
|
44
|
+
})))),
|
|
45
|
+
container = _render4.container;
|
|
46
|
+
|
|
47
|
+
expect(container).toMatchSnapshot();
|
|
48
|
+
});
|
|
49
|
+
it('should match snapshot with disabled and checked checkbox', function () {
|
|
50
|
+
var _render5 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
51
|
+
disabled: true,
|
|
52
|
+
checked: true
|
|
53
|
+
})))),
|
|
54
|
+
container = _render5.container;
|
|
55
|
+
|
|
56
|
+
expect(container).toMatchSnapshot();
|
|
57
|
+
});
|
|
58
|
+
it('should match snapshot with error checkbox', function () {
|
|
59
|
+
var _render6 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
60
|
+
error: "Error msg"
|
|
61
|
+
})))),
|
|
62
|
+
container = _render6.container;
|
|
63
|
+
|
|
64
|
+
expect(container).toMatchSnapshot();
|
|
65
|
+
});
|
|
66
|
+
it('should match snapshot with error and checked checkbox', function () {
|
|
67
|
+
var _render7 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
68
|
+
error: "Error msg",
|
|
69
|
+
checked: true
|
|
70
|
+
})))),
|
|
71
|
+
container = _render7.container;
|
|
72
|
+
|
|
73
|
+
expect(container).toMatchSnapshot();
|
|
74
|
+
});
|
|
75
|
+
it('should match snapshot with inverted', function () {
|
|
76
|
+
var _render8 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
77
|
+
inverted: true
|
|
78
|
+
})))),
|
|
79
|
+
container = _render8.container;
|
|
80
|
+
|
|
81
|
+
expect(container).toMatchSnapshot();
|
|
82
|
+
});
|
|
83
|
+
it('should match snapshot with inverted and checked', function () {
|
|
84
|
+
var _render9 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
85
|
+
inverted: true,
|
|
86
|
+
checked: true
|
|
87
|
+
})))),
|
|
88
|
+
container = _render9.container;
|
|
89
|
+
|
|
90
|
+
expect(container).toMatchSnapshot();
|
|
91
|
+
});
|
|
92
|
+
it('should match snapshot with inverted and checked and disabled', function () {
|
|
93
|
+
var _render10 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
94
|
+
inverted: true,
|
|
95
|
+
checked: true,
|
|
96
|
+
disabled: true
|
|
97
|
+
})))),
|
|
98
|
+
container = _render10.container;
|
|
99
|
+
|
|
100
|
+
expect(container).toMatchSnapshot();
|
|
101
|
+
});
|
|
102
|
+
it('should match snapshot with indeterminate', function () {
|
|
103
|
+
var _render11 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
104
|
+
indeterminate: true
|
|
105
|
+
}))),
|
|
106
|
+
container = _render11.container;
|
|
107
|
+
|
|
108
|
+
expect(container).toMatchSnapshot();
|
|
109
|
+
});
|
|
110
|
+
it('should match snapshot with indeterminate and disabled checkbox', function () {
|
|
111
|
+
var _render12 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
112
|
+
indeterminate: true,
|
|
113
|
+
disabled: true
|
|
114
|
+
}))),
|
|
115
|
+
container = _render12.container;
|
|
116
|
+
|
|
117
|
+
expect(container).toMatchSnapshot();
|
|
118
|
+
});
|
|
119
|
+
it('should match snapshot with error and indeterminate checkbox', function () {
|
|
120
|
+
var _render13 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
121
|
+
error: "Error msg",
|
|
122
|
+
indeterminate: true
|
|
123
|
+
})))),
|
|
124
|
+
container = _render13.container;
|
|
125
|
+
|
|
126
|
+
expect(container).toMatchSnapshot();
|
|
127
|
+
});
|
|
128
|
+
it('should match snapshot with inverted and indeterminate', function () {
|
|
129
|
+
var _render14 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
130
|
+
inverted: true,
|
|
131
|
+
indeterminate: true
|
|
132
|
+
})))),
|
|
133
|
+
container = _render14.container;
|
|
134
|
+
|
|
135
|
+
expect(container).toMatchSnapshot();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('Events', function () {
|
|
139
|
+
it('should call onChange function when press on Checkbox', function () {
|
|
140
|
+
var onChangeMock = jest.fn();
|
|
141
|
+
|
|
142
|
+
var _render15 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox, _extends({}, data, {
|
|
143
|
+
onChange: onChangeMock
|
|
144
|
+
})))),
|
|
145
|
+
getByRole = _render15.getByRole;
|
|
146
|
+
|
|
147
|
+
fireEvent.click(getByRole('checkbox', {
|
|
148
|
+
hidden: true
|
|
149
|
+
}));
|
|
150
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import Checkbox from '..';
|
|
4
|
+
import ThemeProvider from '../../Theme';
|
|
5
|
+
describe('<Checkbox />', function () {
|
|
6
|
+
describe('<Checkbox.Switch />', function () {
|
|
7
|
+
describe('Snapshots', function () {
|
|
8
|
+
it('should match snapshot with default switch', function () {
|
|
9
|
+
var _render = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, null))),
|
|
10
|
+
container = _render.container;
|
|
11
|
+
|
|
12
|
+
expect(container).toMatchSnapshot();
|
|
13
|
+
});
|
|
14
|
+
it('should match snapshot with disabled switch', function () {
|
|
15
|
+
var _render2 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
16
|
+
disabled: true
|
|
17
|
+
}))),
|
|
18
|
+
container = _render2.container;
|
|
19
|
+
|
|
20
|
+
expect(container).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
it('should match snapshot with checked switch', function () {
|
|
23
|
+
var _render3 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
24
|
+
checked: true
|
|
25
|
+
}))),
|
|
26
|
+
container = _render3.container;
|
|
27
|
+
|
|
28
|
+
expect(container).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
it('should match snapshot with disabled and checked switch', function () {
|
|
31
|
+
var _render4 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
32
|
+
disabled: true,
|
|
33
|
+
checked: true
|
|
34
|
+
}))),
|
|
35
|
+
container = _render4.container;
|
|
36
|
+
|
|
37
|
+
expect(container).toMatchSnapshot();
|
|
38
|
+
});
|
|
39
|
+
it('should call onChange function when click on Checkbox.Switch', function () {
|
|
40
|
+
var onChangeMock = jest.fn();
|
|
41
|
+
|
|
42
|
+
var _render5 = render( /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(Checkbox.Switch, {
|
|
43
|
+
disabled: true,
|
|
44
|
+
checked: true,
|
|
45
|
+
onChange: onChangeMock
|
|
46
|
+
}))),
|
|
47
|
+
getByRole = _render5.getByRole;
|
|
48
|
+
|
|
49
|
+
fireEvent.click(getByRole('switch', {
|
|
50
|
+
hidden: true
|
|
51
|
+
}));
|
|
52
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|