@shopgate/pwa-ui-shared 7.30.0-alpha.7 → 7.30.0-alpha.9

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 (266) hide show
  1. package/AccordionContainer/index.js +39 -5
  2. package/AccordionContainer/spec.js +25 -2
  3. package/ActionButton/index.js +63 -7
  4. package/ActionButton/spec.js +63 -2
  5. package/ActionButton/style.js +22 -1
  6. package/AddToCartButton/index.js +184 -27
  7. package/AddToCartButton/mock.js +18 -4
  8. package/AddToCartButton/spec.js +65 -2
  9. package/AddToCartButton/style.js +127 -11
  10. package/Availability/index.js +34 -2
  11. package/Availability/spec.js +41 -1
  12. package/Availability/style.js +19 -1
  13. package/Button/index.js +76 -5
  14. package/Button/spec.js +33 -1
  15. package/Button/style.js +130 -21
  16. package/ButtonLink/connector.js +11 -2
  17. package/ButtonLink/index.js +44 -6
  18. package/ButtonLink/spec.js +23 -1
  19. package/Card/index.js +19 -2
  20. package/Card/style.js +11 -1
  21. package/CardList/components/Item/index.js +26 -2
  22. package/CardList/components/Item/style.js +7 -1
  23. package/CardList/index.js +34 -3
  24. package/CartTotalLine/components/Amount/index.js +28 -2
  25. package/CartTotalLine/components/Amount/style.js +8 -1
  26. package/CartTotalLine/components/Hint/index.js +23 -2
  27. package/CartTotalLine/components/Hint/style.js +12 -1
  28. package/CartTotalLine/components/Label/index.js +36 -2
  29. package/CartTotalLine/components/Label/style.js +17 -1
  30. package/CartTotalLine/components/Spacer/index.js +16 -2
  31. package/CartTotalLine/index.js +39 -2
  32. package/CartTotalLine/style.js +31 -1
  33. package/Checkbox/index.js +31 -2
  34. package/Checkbox/style.js +18 -1
  35. package/Chip/index.js +61 -2
  36. package/Chip/spec.js +24 -1
  37. package/Chip/style.js +71 -3
  38. package/ContextMenu/ContextMenu.hooks.js +6 -2
  39. package/ContextMenu/ContextMenuProvider.context.js +9 -3
  40. package/ContextMenu/ContextMenuProvider.js +21 -2
  41. package/ContextMenu/components/Item/index.js +67 -5
  42. package/ContextMenu/components/Item/style.js +32 -3
  43. package/ContextMenu/components/Position/index.js +61 -10
  44. package/ContextMenu/components/Position/style.js +11 -1
  45. package/ContextMenu/index.js +124 -3
  46. package/ContextMenu/spec.js +101 -2
  47. package/ContextMenu/style.js +45 -1
  48. package/Dialog/components/BasicDialog/index.js +5 -1
  49. package/Dialog/components/HtmlContentDialog/index.js +22 -2
  50. package/Dialog/components/HtmlContentDialog/spec.js +59 -1
  51. package/Dialog/components/PipelineErrorDialog/index.js +114 -25
  52. package/Dialog/components/PipelineErrorDialog/spec.js +92 -12
  53. package/Dialog/components/TextMessageDialog/index.js +28 -2
  54. package/Dialog/components/TextMessageDialog/spec.js +59 -1
  55. package/Dialog/components/VariantSelectModal/connector.js +11 -2
  56. package/Dialog/components/VariantSelectModal/index.js +65 -6
  57. package/Dialog/components/VariantSelectModal/spec.js +51 -2
  58. package/Dialog/constants.js +6 -1
  59. package/Dialog/index.js +114 -7
  60. package/Dialog/spec.js +81 -3
  61. package/DiscountBadge/index.js +30 -2
  62. package/DiscountBadge/spec.js +19 -1
  63. package/DiscountBadge/style.js +34 -2
  64. package/FavoritesButton/connector.js +18 -3
  65. package/FavoritesButton/index.js +118 -15
  66. package/FavoritesButton/mock.js +50 -4
  67. package/FavoritesButton/spec.js +120 -2
  68. package/FavoritesButton/style.js +26 -1
  69. package/Form/Builder/builders/buildCountryList.js +40 -6
  70. package/Form/Builder/builders/buildFormDefaults.js +35 -6
  71. package/Form/Builder/builders/buildFormElements.js +68 -10
  72. package/Form/Builder/builders/buildProvinceList.js +19 -2
  73. package/Form/Builder/builders/buildValidationErrorList.js +7 -2
  74. package/Form/Builder/classes/ActionListener/constants.js +22 -2
  75. package/Form/Builder/classes/ActionListener/index.js +441 -93
  76. package/Form/Builder/classes/ActionListener/spec.js +321 -19
  77. package/Form/Builder/components/CheckboxElement.js +35 -3
  78. package/Form/Builder/components/CountryElement.js +40 -3
  79. package/Form/Builder/components/ProvinceElement.js +40 -3
  80. package/Form/Builder/components/RadioElement.js +41 -3
  81. package/Form/Builder/components/SelectElement.js +39 -3
  82. package/Form/Builder/components/TextElement.js +49 -4
  83. package/Form/Builder/elementTypes.js +11 -1
  84. package/Form/Builder/index.js +298 -52
  85. package/Form/Builder/iso-3166-2.js +4943 -1
  86. package/Form/Builder/spec.js +308 -16
  87. package/Form/Checkbox/index.js +66 -4
  88. package/Form/Checkbox/style.js +25 -2
  89. package/Form/InfoField/index.js +50 -2
  90. package/Form/InfoField/spec.js +9 -1
  91. package/Form/InfoField/style.js +11 -1
  92. package/Form/Password/index.js +51 -6
  93. package/Form/Password/spec.js +34 -1
  94. package/Form/Password/style.js +11 -1
  95. package/Form/RadioGroup/components/Item/index.js +59 -3
  96. package/Form/RadioGroup/components/Item/style.js +32 -2
  97. package/Form/RadioGroup/index.js +101 -9
  98. package/Form/RadioGroup/spec.js +83 -3
  99. package/Form/RadioGroup/style.js +18 -2
  100. package/Form/Select/index.js +158 -10
  101. package/Form/Select/spec.js +36 -5
  102. package/Form/Select/style.js +27 -1
  103. package/Form/SelectContextChoices/index.js +77 -3
  104. package/Form/SelectContextChoices/spec.js +33 -4
  105. package/Form/SelectContextChoices/style.js +23 -1
  106. package/Form/TextField/index.js +92 -8
  107. package/Form/TextField/spec.js +110 -1
  108. package/Form/TextField/style.js +66 -8
  109. package/Form/index.js +54 -13
  110. package/FormElement/components/ErrorText/index.js +31 -2
  111. package/FormElement/components/ErrorText/style.js +13 -1
  112. package/FormElement/components/Label/index.js +35 -2
  113. package/FormElement/components/Label/style.js +76 -8
  114. package/FormElement/components/Placeholder/index.js +26 -2
  115. package/FormElement/components/Placeholder/style.js +48 -6
  116. package/FormElement/components/Underline/index.js +18 -2
  117. package/FormElement/components/Underline/style.js +51 -4
  118. package/FormElement/index.js +91 -6
  119. package/FormElement/spec.js +67 -2
  120. package/FormElement/style.js +13 -2
  121. package/Glow/index.js +90 -7
  122. package/Glow/spec.js +9 -1
  123. package/Glow/style.js +18 -1
  124. package/IndicatorCircle/index.js +33 -3
  125. package/IndicatorCircle/spec.js +28 -1
  126. package/IndicatorCircle/style.js +57 -3
  127. package/LoadingIndicator/index.js +29 -2
  128. package/LoadingIndicator/style.js +20 -1
  129. package/Manufacturer/index.js +20 -2
  130. package/Manufacturer/style.js +5 -1
  131. package/MessageBar/index.js +36 -2
  132. package/MessageBar/spec.js +79 -1
  133. package/MessageBar/style.js +38 -1
  134. package/NoResults/components/Icon/index.js +130 -2
  135. package/NoResults/components/Icon/style.js +17 -1
  136. package/NoResults/index.js +46 -2
  137. package/NoResults/style.js +31 -1
  138. package/Placeholder/index.js +25 -3
  139. package/Placeholder/style.js +11 -1
  140. package/PlaceholderLabel/index.js +27 -2
  141. package/PlaceholderLabel/spec.js +19 -1
  142. package/PlaceholderLabel/style.js +12 -1
  143. package/PlaceholderParagraph/index.js +36 -2
  144. package/PlaceholderParagraph/spec.js +19 -1
  145. package/Price/index.js +88 -7
  146. package/Price/style.js +22 -1
  147. package/PriceInfo/index.js +20 -2
  148. package/PriceInfo/style.js +5 -1
  149. package/PriceStriked/index.js +83 -12
  150. package/PriceStriked/style.js +33 -3
  151. package/ProductProperties/index.js +32 -2
  152. package/ProgressBar/index.js +101 -13
  153. package/ProgressBar/spec.js +13 -1
  154. package/ProgressBar/style.js +83 -2
  155. package/RadioButton/index.js +18 -2
  156. package/RadioButton/spec.js +21 -1
  157. package/RadioButton/style.js +21 -1
  158. package/RatingNumber/index.js +29 -2
  159. package/RatingStars/constants.js +2 -1
  160. package/RatingStars/index.js +130 -12
  161. package/RatingStars/spec.js +90 -3
  162. package/RatingStars/style.js +51 -2
  163. package/Ripple/components/RippleAnimation/index.js +88 -6
  164. package/Ripple/index.js +218 -40
  165. package/Ripple/style.js +18 -1
  166. package/RippleButton/index.js +52 -5
  167. package/RippleButton/spec.js +45 -1
  168. package/ScannerOverlay/components/CameraOverlay/index.js +13 -2
  169. package/ScannerOverlay/components/CameraOverlay/style.js +40 -1
  170. package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +34 -2
  171. package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/style.js +28 -1
  172. package/ScannerOverlay/components/ScannerBar/components/ScannerInstructions/index.js +11 -2
  173. package/ScannerOverlay/components/ScannerBar/index.js +31 -2
  174. package/ScannerOverlay/components/ScannerBar/style.js +20 -1
  175. package/ScannerOverlay/index.js +47 -7
  176. package/Sheet/components/Header/components/SearchBar/index.js +46 -2
  177. package/Sheet/components/Header/components/SearchBar/spec.js +21 -3
  178. package/Sheet/components/Header/components/SearchBar/style.js +47 -1
  179. package/Sheet/components/Header/index.js +75 -7
  180. package/Sheet/components/Header/spec.js +14 -1
  181. package/Sheet/components/Header/style.js +50 -1
  182. package/Sheet/index.js +170 -17
  183. package/Sheet/spec.js +85 -5
  184. package/Sheet/style.js +143 -2
  185. package/TaxDisclaimer/index.js +34 -4
  186. package/TaxDisclaimer/spec.js +31 -3
  187. package/TaxDisclaimer/style.js +9 -1
  188. package/TextField/components/ErrorText/index.js +33 -2
  189. package/TextField/components/ErrorText/style.js +25 -3
  190. package/TextField/components/FormElement/index.js +19 -2
  191. package/TextField/components/FormElement/style.js +32 -4
  192. package/TextField/components/Hint/index.js +21 -2
  193. package/TextField/components/Hint/style.js +40 -5
  194. package/TextField/components/Label/index.js +32 -3
  195. package/TextField/components/Label/style.js +68 -8
  196. package/TextField/components/Underline/index.js +19 -2
  197. package/TextField/components/Underline/style.js +51 -4
  198. package/TextField/index.js +189 -27
  199. package/TextField/spec.js +128 -3
  200. package/TextField/style.js +34 -4
  201. package/ToggleIcon/index.js +58 -8
  202. package/ToggleIcon/spec.js +35 -1
  203. package/icons/AccountBoxIcon.js +11 -2
  204. package/icons/AddMoreIcon.js +11 -2
  205. package/icons/ArrowDropIcon.js +11 -2
  206. package/icons/ArrowIcon.js +21 -2
  207. package/icons/BarcodeScannerIcon.js +11 -2
  208. package/icons/BoxIcon.js +11 -2
  209. package/icons/BrowseIcon.js +11 -2
  210. package/icons/BurgerIcon.js +11 -2
  211. package/icons/CalendarIcon.js +15 -3
  212. package/icons/CartCouponIcon.js +72 -2
  213. package/icons/CartIcon.js +11 -2
  214. package/icons/CartPlusIcon.js +11 -2
  215. package/icons/CheckIcon.js +11 -2
  216. package/icons/CheckedIcon.js +11 -2
  217. package/icons/ChevronIcon.js +11 -2
  218. package/icons/CreditCardIcon.js +11 -2
  219. package/icons/CrossIcon.js +11 -2
  220. package/icons/DescriptionIcon.js +11 -2
  221. package/icons/FilterIcon.js +11 -2
  222. package/icons/FlashDisabledIcon.js +11 -2
  223. package/icons/FlashEnabledIcon.js +11 -2
  224. package/icons/GridIcon.js +11 -2
  225. package/icons/HeartIcon.js +11 -2
  226. package/icons/HeartOutlineIcon.js +11 -2
  227. package/icons/HeartPlusIcon.js +12 -2
  228. package/icons/HeartPlusOutlineIcon.js +12 -2
  229. package/icons/HomeIcon.js +11 -2
  230. package/icons/InfoIcon.js +11 -2
  231. package/icons/InfoOutlineIcon.js +11 -2
  232. package/icons/ListIcon.js +11 -2
  233. package/icons/LocalShippingIcon.js +11 -2
  234. package/icons/LocationIcon.js +13 -3
  235. package/icons/LocatorIcon.js +11 -2
  236. package/icons/LockIcon.js +11 -2
  237. package/icons/LogoutIcon.js +11 -2
  238. package/icons/MagnifierIcon.js +11 -2
  239. package/icons/MapMarkerIcon.js +24 -3
  240. package/icons/MoreIcon.js +11 -2
  241. package/icons/MoreVertIcon.js +11 -2
  242. package/icons/NotificationIcon.js +14 -3
  243. package/icons/PersonIcon.js +12 -2
  244. package/icons/PhoneIcon.js +13 -3
  245. package/icons/PlaceholderIcon.js +11 -2
  246. package/icons/RadioCheckedIcon.js +11 -2
  247. package/icons/RadioUncheckedIcon.js +11 -2
  248. package/icons/SecurityIcon.js +11 -2
  249. package/icons/ShippingMethodIcon.js +18 -3
  250. package/icons/ShoppingCartIcon.js +11 -2
  251. package/icons/SortIcon.js +11 -2
  252. package/icons/StarHalfIcon.js +18 -2
  253. package/icons/StarIcon.js +18 -2
  254. package/icons/StarOutlineIcon.js +11 -2
  255. package/icons/StopIcon.js +11 -2
  256. package/icons/TickIcon.js +11 -2
  257. package/icons/TimeIcon.js +14 -3
  258. package/icons/TrashIcon.js +11 -2
  259. package/icons/TrashOutlineIcon.js +12 -2
  260. package/icons/UncheckedIcon.js +11 -2
  261. package/icons/ViewListIcon.js +11 -2
  262. package/icons/VisibilityIcon.js +11 -2
  263. package/icons/VisibilityOffIcon.js +11 -2
  264. package/icons/WarningIcon.js +11 -2
  265. package/index.js +13 -1
  266. package/package.json +5 -5
@@ -1,6 +1,62 @@
1
- import _camelCase from"lodash/camelCase";function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _extends(){_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;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}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;}import React,{PureComponent}from'react';import PropTypes from'prop-types';import classNames from'classnames';import{I18n,CheckedIcon,UncheckedIcon}from'@shopgate/engage/components';import style from"./style";/**
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _camelCase from "lodash/camelCase";
3
+ import React, { PureComponent } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import classNames from 'classnames';
6
+ import { I18n, CheckedIcon, UncheckedIcon } from '@shopgate/engage/components';
7
+ import style from "./style";
8
+
9
+ /**
2
10
  * RadioItem component.
3
- */var RadioItem=/*#__PURE__*/function(_PureComponent){function RadioItem(){_classCallCheck(this,RadioItem);return _callSuper(this,RadioItem,arguments);}_inherits(RadioItem,_PureComponent);return _createClass(RadioItem,[{key:"render",value:function render(){var _this$props=this.props,ItemLabel=_this$props.label,name=_this$props.name,onChange=_this$props.onChange,checked=_this$props.checked,className=_this$props.className,attributes=_this$props.attributes,id=_this$props.id;var _ref=attributes||{},disabled=_ref.disabled;return React.createElement("label",{className:classNames(style.container,className,_defineProperty({},style.disabled,!!disabled),_camelCase(name),'radioItem'),htmlFor:id||name},checked&&React.createElement(CheckedIcon,{className:classNames(style.active,style.icon,'checkedIcon')}),!checked&&React.createElement(UncheckedIcon,{className:classNames(style.icon,'uncheckedIcon')}),React.createElement("input",_extends({className:classNames('sr-only','input'),checked:checked,id:id||name,type:"radio",name:name,onChange:onChange,"aria-labelledby":"".concat(id||name,"-label")},attributes)),React.createElement(I18n.Text,{string:ItemLabel,"aria-hidden":true,id:"".concat(id||name,"-label"),className:classNames(style.label,'label')}));}}]);}(PureComponent);_defineProperty(RadioItem,"defaultProps",{attributes:null,id:null,checked:false,className:'',onChange:function onChange(){}/**
11
+ */
12
+ class RadioItem extends PureComponent {
13
+ /**
4
14
  * Renders the component.
5
15
  * @returns {JSX.Element}
6
- */});export default RadioItem;
16
+ */
17
+ render() {
18
+ const {
19
+ label: ItemLabel,
20
+ name,
21
+ onChange,
22
+ checked,
23
+ className,
24
+ attributes,
25
+ id
26
+ } = this.props;
27
+ const {
28
+ disabled
29
+ } = attributes || {};
30
+ return /*#__PURE__*/React.createElement("label", {
31
+ className: classNames(style.container, className, {
32
+ [style.disabled]: !!disabled
33
+ }, _camelCase(name), 'radioItem'),
34
+ htmlFor: id || name
35
+ }, checked && /*#__PURE__*/React.createElement(CheckedIcon, {
36
+ className: classNames(style.active, style.icon, 'checkedIcon')
37
+ }), !checked && /*#__PURE__*/React.createElement(UncheckedIcon, {
38
+ className: classNames(style.icon, 'uncheckedIcon')
39
+ }), /*#__PURE__*/React.createElement("input", _extends({
40
+ className: classNames('sr-only', 'input'),
41
+ checked: checked,
42
+ id: id || name,
43
+ type: "radio",
44
+ name: name,
45
+ onChange: onChange,
46
+ "aria-labelledby": `${id || name}-label`
47
+ }, attributes)), /*#__PURE__*/React.createElement(I18n.Text, {
48
+ string: ItemLabel,
49
+ "aria-hidden": true,
50
+ id: `${id || name}-label`,
51
+ className: classNames(style.label, 'label')
52
+ }));
53
+ }
54
+ }
55
+ RadioItem.defaultProps = {
56
+ attributes: null,
57
+ id: null,
58
+ checked: false,
59
+ className: '',
60
+ onChange: () => {}
61
+ };
62
+ export default RadioItem;
@@ -1,2 +1,32 @@
1
- import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var container=css({display:'flex',marginLeft:-1// Removes margin of svg.
2
- }).toString();var icon=css({width:24,height:24,flexShrink:0}).toString();var disabled=css({opacity:0.25,pointerEvents:'none'}).toString();var label=css({flex:1,fontSize:'1rem',lineHeight:1.5,marginLeft:themeConfig.variables.gap.small,marginBottom:themeConfig.variables.gap.small}).toString();var active=css({color:"var(--color-primary, ".concat(themeConfig.colors.primary,")")}).toString();export default{icon:icon,disabled:disabled,container:container,label:label,active:active};
1
+ import { css } from 'glamor';
2
+ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
3
+ const container = css({
4
+ display: 'flex',
5
+ marginLeft: -1 // Removes margin of svg.
6
+ }).toString();
7
+ const icon = css({
8
+ width: 24,
9
+ height: 24,
10
+ flexShrink: 0
11
+ }).toString();
12
+ const disabled = css({
13
+ opacity: 0.25,
14
+ pointerEvents: 'none'
15
+ }).toString();
16
+ const label = css({
17
+ flex: 1,
18
+ fontSize: '1rem',
19
+ lineHeight: 1.5,
20
+ marginLeft: themeConfig.variables.gap.small,
21
+ marginBottom: themeConfig.variables.gap.small
22
+ }).toString();
23
+ const active = css({
24
+ color: `var(--color-primary, ${themeConfig.colors.primary})`
25
+ }).toString();
26
+ export default {
27
+ icon,
28
+ disabled,
29
+ container,
30
+ label,
31
+ active
32
+ };
@@ -1,13 +1,105 @@
1
- function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}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;}import React,{Component,Children,cloneElement}from'react';import PropTypes from'prop-types';import classNames from'classnames';import FormElement from'@shopgate/pwa-ui-shared/FormElement';import style from"./style";/**
1
+ import React, { Component, Children, cloneElement } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+ import FormElement from '@shopgate/pwa-ui-shared/FormElement';
5
+ import style from "./style";
6
+
7
+ /**
2
8
  * RadioGroup component.
3
- */var RadioGroup=/*#__PURE__*/function(_Component){function RadioGroup(props){var _this2;_classCallCheck(this,RadioGroup);_this2=_callSuper(this,RadioGroup,[props]);/**
4
- * @param {string} event click from radio element
5
- */_defineProperty(_this2,"handleChange",function(_ref){var name=_ref.target.name;if(_this2.props.disabled){return;}if(!_this2.props.isControlled){_this2.setState({value:name});}_this2.props.onChange(name);});_this2.state={value:props.value};return _this2;}/**
9
+ */
10
+ class RadioGroup extends Component {
11
+ /**
12
+ * Initializes the component.
13
+ * @param {Object} props The components props.
14
+ */
15
+ constructor(props) {
16
+ super(props);
17
+ /**
18
+ * @param {string} event click from radio element
19
+ */
20
+ this.handleChange = ({
21
+ target: {
22
+ name
23
+ }
24
+ }) => {
25
+ if (this.props.disabled) {
26
+ return;
27
+ }
28
+ if (!this.props.isControlled) {
29
+ this.setState({
30
+ value: name
31
+ });
32
+ }
33
+ this.props.onChange(name);
34
+ };
35
+ this.state = {
36
+ value: props.value
37
+ };
38
+ }
39
+
40
+ /**
6
41
  * @param {Object} nextProps props
7
- */_inherits(RadioGroup,_Component);return _createClass(RadioGroup,[{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){if(this.props.isControlled&&this.state.value!==nextProps.value){this.setState({value:nextProps.value});}}},{key:"render",value:/**
42
+ */
43
+ UNSAFE_componentWillReceiveProps(nextProps) {
44
+ if (this.props.isControlled && this.state.value !== nextProps.value) {
45
+ this.setState({
46
+ value: nextProps.value
47
+ });
48
+ }
49
+ }
50
+ /**
8
51
  * Renders the component.
9
52
  * @returns {JSX}
10
- */function render(){var _this3=this;var _this$props=this.props,children=_this$props.children,className=_this$props.className,label=_this$props.label,errorText=_this$props.errorText,direction=_this$props.direction,name=_this$props.name,translateErrorText=_this$props.translateErrorText,disabled=_this$props.disabled,showErrorText=_this$props.showErrorText;return React.createElement(FormElement,{className:classNames(className,'radioGroup','ui-shared__form__radio-group',{disabled:disabled}),label:label,labelStatic:true,errorText:errorText,translateErrorText:translateErrorText,showErrorText:showErrorText,htmlFor:"none",hasUnderline:false,hasValue:true},React.createElement("div",{className:classNames(style.container(direction),'radioGroup')},Children.map(children,function(child){if(!child){return null;}return cloneElement(child,{key:"".concat(name,"_").concat(child.props.name),checked:_this3.state.value===child.props.name,onChange:_this3.handleChange});})));}}]);}(Component);_defineProperty(RadioGroup,"defaultProps",{onChange:function onChange(){},children:null,className:'',direction:'column',disabled:false,errorText:'',isControlled:false,label:'',translateErrorText:true,value:null,showErrorText:true/**
11
- * Initializes the component.
12
- * @param {Object} props The components props.
13
- */});export default RadioGroup;
53
+ */
54
+ render() {
55
+ const {
56
+ children,
57
+ className,
58
+ label,
59
+ errorText,
60
+ direction,
61
+ name,
62
+ translateErrorText,
63
+ disabled,
64
+ showErrorText
65
+ } = this.props;
66
+ return /*#__PURE__*/React.createElement(FormElement, {
67
+ className: classNames(className, 'radioGroup', 'ui-shared__form__radio-group', {
68
+ disabled
69
+ }),
70
+ label: label,
71
+ labelStatic: true,
72
+ errorText: errorText,
73
+ translateErrorText: translateErrorText,
74
+ showErrorText: showErrorText,
75
+ htmlFor: "none",
76
+ hasUnderline: false,
77
+ hasValue: true
78
+ }, /*#__PURE__*/React.createElement("div", {
79
+ className: classNames(style.container(direction), 'radioGroup')
80
+ }, Children.map(children, child => {
81
+ if (!child) {
82
+ return null;
83
+ }
84
+ return /*#__PURE__*/cloneElement(child, {
85
+ key: `${name}_${child.props.name}`,
86
+ checked: this.state.value === child.props.name,
87
+ onChange: this.handleChange
88
+ });
89
+ })));
90
+ }
91
+ }
92
+ RadioGroup.defaultProps = {
93
+ onChange: () => {},
94
+ children: null,
95
+ className: '',
96
+ direction: 'column',
97
+ disabled: false,
98
+ errorText: '',
99
+ isControlled: false,
100
+ label: '',
101
+ translateErrorText: true,
102
+ value: null,
103
+ showErrorText: true
104
+ };
105
+ export default RadioGroup;
@@ -1,3 +1,83 @@
1
- function _extends(){_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;};return _extends.apply(this,arguments);}function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}import React from'react';import{mount}from'enzyme';import RadioItem from"./components/Item";import RadioGroup from'.';var defProps={name:'radio'};jest.mock('@shopgate/engage/components');describe('<RadioGroup />',function(){it('should render empty group',function(){var wrapper=mount(React.createElement(RadioGroup,defProps));expect(wrapper).toMatchSnapshot();});it('should render column group with items',function(){var wrapper=mount(React.createElement(RadioGroup,defProps,React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(1);expect(_typeof(wrapper.find(RadioItem).prop('onChange'))).toEqual('function');});it('should render rows group with items',function(){var wrapper=mount(React.createElement(RadioGroup,_extends({},defProps,{direction:"rows"}),React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();});it('should use default value',function(){var wrapper=mount(React.createElement(RadioGroup,_extends({},defProps,{value:"foo"}),React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(1);expect(wrapper.find(RadioItem).prop('checked')).toEqual(true);});it('should have on value at a time',function(){var wrapper=mount(React.createElement(RadioGroup,defProps,React.createElement(RadioItem,{name:"foo",label:"foo"}),React.createElement(RadioItem,{name:"bar",label:"bar"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(2);var radio1=wrapper.find(RadioItem).at(0).find('input');var radio2=wrapper.find(RadioItem).at(1).find('input');// First element value
2
- radio1.simulate('change');wrapper.update();expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(true);expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(false);// Second element value
3
- radio2.simulate('change');wrapper.update();expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(false);expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(true);});it('should call onChange callback',function(){var onChange=jest.fn();var wrapper=mount(React.createElement(RadioGroup,_extends({},defProps,{onChange:onChange}),React.createElement(RadioItem,{name:"foo",label:"foo"})));expect(wrapper).toMatchSnapshot();expect(wrapper.find(RadioItem).length).toEqual(1);var radio=wrapper.find(RadioItem).at(0).find('input');radio.simulate('change');expect(onChange).toHaveBeenCalledWith('foo');});});
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import { mount } from 'enzyme';
4
+ import RadioItem from "./components/Item";
5
+ import RadioGroup from '.';
6
+ const defProps = {
7
+ name: 'radio'
8
+ };
9
+ jest.mock('@shopgate/engage/components');
10
+ describe('<RadioGroup />', () => {
11
+ it('should render empty group', () => {
12
+ const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, defProps));
13
+ expect(wrapper).toMatchSnapshot();
14
+ });
15
+ it('should render column group with items', () => {
16
+ const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, defProps, /*#__PURE__*/React.createElement(RadioItem, {
17
+ name: "foo",
18
+ label: "foo"
19
+ })));
20
+ expect(wrapper).toMatchSnapshot();
21
+ expect(wrapper.find(RadioItem).length).toEqual(1);
22
+ expect(typeof wrapper.find(RadioItem).prop('onChange')).toEqual('function');
23
+ });
24
+ it('should render rows group with items', () => {
25
+ const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, _extends({}, defProps, {
26
+ direction: "rows"
27
+ }), /*#__PURE__*/React.createElement(RadioItem, {
28
+ name: "foo",
29
+ label: "foo"
30
+ })));
31
+ expect(wrapper).toMatchSnapshot();
32
+ });
33
+ it('should use default value', () => {
34
+ const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, _extends({}, defProps, {
35
+ value: "foo"
36
+ }), /*#__PURE__*/React.createElement(RadioItem, {
37
+ name: "foo",
38
+ label: "foo"
39
+ })));
40
+ expect(wrapper).toMatchSnapshot();
41
+ expect(wrapper.find(RadioItem).length).toEqual(1);
42
+ expect(wrapper.find(RadioItem).prop('checked')).toEqual(true);
43
+ });
44
+ it('should have on value at a time', () => {
45
+ const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, defProps, /*#__PURE__*/React.createElement(RadioItem, {
46
+ name: "foo",
47
+ label: "foo"
48
+ }), /*#__PURE__*/React.createElement(RadioItem, {
49
+ name: "bar",
50
+ label: "bar"
51
+ })));
52
+ expect(wrapper).toMatchSnapshot();
53
+ expect(wrapper.find(RadioItem).length).toEqual(2);
54
+ const radio1 = wrapper.find(RadioItem).at(0).find('input');
55
+ const radio2 = wrapper.find(RadioItem).at(1).find('input');
56
+
57
+ // First element value
58
+ radio1.simulate('change');
59
+ wrapper.update();
60
+ expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(true);
61
+ expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(false);
62
+
63
+ // Second element value
64
+ radio2.simulate('change');
65
+ wrapper.update();
66
+ expect(wrapper.find(RadioItem).at(0).prop('checked')).toEqual(false);
67
+ expect(wrapper.find(RadioItem).at(1).prop('checked')).toEqual(true);
68
+ });
69
+ it('should call onChange callback', () => {
70
+ const onChange = jest.fn();
71
+ const wrapper = mount(/*#__PURE__*/React.createElement(RadioGroup, _extends({}, defProps, {
72
+ onChange: onChange
73
+ }), /*#__PURE__*/React.createElement(RadioItem, {
74
+ name: "foo",
75
+ label: "foo"
76
+ })));
77
+ expect(wrapper).toMatchSnapshot();
78
+ expect(wrapper.find(RadioItem).length).toEqual(1);
79
+ const radio = wrapper.find(RadioItem).at(0).find('input');
80
+ radio.simulate('change');
81
+ expect(onChange).toHaveBeenCalledWith('foo');
82
+ });
83
+ });
@@ -1,4 +1,20 @@
1
- import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';/**
1
+ import { css } from 'glamor';
2
+ import { themeConfig } from '@shopgate/pwa-common/helpers/config';
3
+
4
+ /**
2
5
  * @param {string} direction flex direction
3
6
  * @returns {*}
4
- */var container=function container(direction){return css({display:'flex',flexDirection:direction}).toString();};var label=css({fontSize:'0.8rem',paddingBottom:themeConfig.variables.gap.small,color:themeConfig.colors.shade12}).toString();export default{container:container,label:label};
7
+ */
8
+ const container = direction => css({
9
+ display: 'flex',
10
+ flexDirection: direction
11
+ }).toString();
12
+ const label = css({
13
+ fontSize: '0.8rem',
14
+ paddingBottom: themeConfig.variables.gap.small,
15
+ color: themeConfig.colors.shade12
16
+ }).toString();
17
+ export default {
18
+ container,
19
+ label
20
+ };
@@ -1,18 +1,166 @@
1
- function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _extends(){_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;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}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;}import React,{Component}from'react';import PropTypes from'prop-types';import classNames from'classnames';import Chevron from"../../icons/ChevronIcon";import FormElement from"../../FormElement";import styles from"./style";/**
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { Component } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import classNames from 'classnames';
5
+ import Chevron from "../../icons/ChevronIcon";
6
+ import FormElement from "../../FormElement";
7
+ import styles from "./style";
8
+
9
+ /**
2
10
  * A component that provides a styled select for user input in material design.
3
- */var Select=/*#__PURE__*/function(_Component){/**
11
+ */
12
+ class Select extends Component {
13
+ /**
4
14
  * Creates a new text field component.
5
15
  * @param {Object} props The component properties.
6
- */function Select(props){var _this2;_classCallCheck(this,Select);_this2=_callSuper(this,Select,[props]);/**
7
- * @param {string} value The entered text.
8
- */_defineProperty(_this2,"handleChange",function(_ref){var target=_ref.target;var multiple=_this2.props.multiple;var value=target.value;if(multiple){value=Array.from(target.selectedOptions,function(option){return option.value;});}if(!_this2.props.isControlled){_this2.setState({value:value});}_this2.props.onChange(value);});/**
9
- * @param {boolean} isFocused focused
10
- */_defineProperty(_this2,"handleFocusChange",function(isFocused){_this2.setState({isFocused:isFocused});});_this2.state={value:props.value,isFocused:false};return _this2;}/**
16
+ */
17
+ constructor(props) {
18
+ super(props);
19
+ /**
20
+ * @param {string} value The entered text.
21
+ */
22
+ this.handleChange = ({
23
+ target
24
+ }) => {
25
+ const {
26
+ multiple
27
+ } = this.props;
28
+ let {
29
+ value
30
+ } = target;
31
+ if (multiple) {
32
+ value = Array.from(target.selectedOptions, option => option.value);
33
+ }
34
+ if (!this.props.isControlled) {
35
+ this.setState({
36
+ value
37
+ });
38
+ }
39
+ this.props.onChange(value);
40
+ };
41
+ /**
42
+ * @param {boolean} isFocused focused
43
+ */
44
+ this.handleFocusChange = isFocused => {
45
+ this.setState({
46
+ isFocused
47
+ });
48
+ };
49
+ this.state = {
50
+ value: props.value,
51
+ isFocused: false
52
+ };
53
+ }
54
+
55
+ /**
11
56
  * Corrects the selected value to the first option when the initial value is not located within
12
57
  * the options.
13
- */_inherits(Select,_Component);return _createClass(Select,[{key:"componentDidMount",value:function componentDidMount(){var _this$props=this.props,multiple=_this$props.multiple,options=_this$props.options;var value=this.state.value;if(!multiple&&(options===null||options===void 0?void 0:options[value])===undefined){var _Object$entries,_Object$entries$;var fallback=(_Object$entries=Object.entries(options))===null||_Object$entries===void 0?void 0:(_Object$entries$=_Object$entries[0])===null||_Object$entries$===void 0?void 0:_Object$entries$[0];if(fallback!==undefined){this.handleChange({target:{value:fallback}});}}}/**
58
+ */
59
+ componentDidMount() {
60
+ const {
61
+ multiple,
62
+ options
63
+ } = this.props;
64
+ const {
65
+ value
66
+ } = this.state;
67
+ if (!multiple && options?.[value] === undefined) {
68
+ const fallback = Object.entries(options)?.[0]?.[0];
69
+ if (fallback !== undefined) {
70
+ this.handleChange({
71
+ target: {
72
+ value: fallback
73
+ }
74
+ });
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
14
80
  * Update state with new props.
15
81
  * @param {Object} nextProps The new props.
16
- */},{key:"UNSAFE_componentWillReceiveProps",value:function UNSAFE_componentWillReceiveProps(nextProps){this.setState({value:nextProps.value});}},{key:"render",value:/**
82
+ */
83
+ UNSAFE_componentWillReceiveProps(nextProps) {
84
+ this.setState({
85
+ value: nextProps.value
86
+ });
87
+ }
88
+ /**
17
89
  * @return {JSX.Element}
18
- */function render(){var _this3=this;var _this$props2=this.props,name=_this$props2.name,options=_this$props2.options,translateErrorText=_this$props2.translateErrorText,disabled=_this$props2.disabled,multiple=_this$props2.multiple,size=_this$props2.size,showErrorText=_this$props2.showErrorText,className=_this$props2.className,placeholder=_this$props2.placeholder,label=_this$props2.label,errorText=_this$props2.errorText,required=_this$props2.required,ariaInvalid=_this$props2['aria-invalid'],ariaDescribedBy=_this$props2['aria-describedby'];var _this$state=this.state,value=_this$state.value,isFocused=_this$state.isFocused;return React.createElement(FormElement,{className:"".concat(className," ui-shared__form__select"),placeholder:placeholder,htmlFor:name,label:label,errorText:errorText,translateErrorText:translateErrorText,isFocused:isFocused,hasValue:!!value||!!options[''],hasPlaceholder:!disabled||value!=='',disabled:disabled,showErrorText:showErrorText},React.createElement("select",_extends({id:name,name:name,onChange:this.handleChange,onFocus:function onFocus(){return _this3.handleFocusChange(true);},onBlur:function onBlur(){return _this3.handleFocusChange(false);},value:value,className:classNames(styles.select,'select'),disabled:disabled,required:required,"aria-invalid":ariaInvalid,"aria-describedby":ariaDescribedBy},multiple&&{multiple:multiple,size:size}),Object.keys(options).map(function(key){return React.createElement("option",{className:"option",value:key,key:"".concat(name,"_").concat(key)},options[key]);})),React.createElement(Chevron,{className:styles.chevron}));}}]);}(Component);_defineProperty(Select,"defaultProps",{'aria-invalid':false,'aria-describedby':null,className:'',errorText:'',isControlled:false,placeholder:'',label:'',onChange:function onChange(){},options:{},translateErrorText:true,showErrorText:true,size:null,value:'',disabled:false,required:false,multiple:false});export default Select;
90
+ */
91
+ render() {
92
+ const {
93
+ name,
94
+ options,
95
+ translateErrorText,
96
+ disabled,
97
+ multiple,
98
+ size,
99
+ showErrorText,
100
+ className,
101
+ placeholder,
102
+ label,
103
+ errorText,
104
+ required,
105
+ 'aria-invalid': ariaInvalid,
106
+ 'aria-describedby': ariaDescribedBy
107
+ } = this.props;
108
+ const {
109
+ value,
110
+ isFocused
111
+ } = this.state;
112
+ return /*#__PURE__*/React.createElement(FormElement, {
113
+ className: `${className} ui-shared__form__select`,
114
+ placeholder: placeholder,
115
+ htmlFor: name,
116
+ label: label,
117
+ errorText: errorText,
118
+ translateErrorText: translateErrorText,
119
+ isFocused: isFocused,
120
+ hasValue: !!value || !!options[''],
121
+ hasPlaceholder: !disabled || value !== '',
122
+ disabled: disabled,
123
+ showErrorText: showErrorText
124
+ }, /*#__PURE__*/React.createElement("select", _extends({
125
+ id: name,
126
+ name: name,
127
+ onChange: this.handleChange,
128
+ onFocus: () => this.handleFocusChange(true),
129
+ onBlur: () => this.handleFocusChange(false),
130
+ value: value,
131
+ className: classNames(styles.select, 'select'),
132
+ disabled: disabled,
133
+ required: required,
134
+ "aria-invalid": ariaInvalid,
135
+ "aria-describedby": ariaDescribedBy
136
+ }, multiple && {
137
+ multiple,
138
+ size
139
+ }), Object.keys(options).map(key => /*#__PURE__*/React.createElement("option", {
140
+ className: "option",
141
+ value: key,
142
+ key: `${name}_${key}`
143
+ }, options[key]))), /*#__PURE__*/React.createElement(Chevron, {
144
+ className: styles.chevron
145
+ }));
146
+ }
147
+ }
148
+ Select.defaultProps = {
149
+ 'aria-invalid': false,
150
+ 'aria-describedby': null,
151
+ className: '',
152
+ errorText: '',
153
+ isControlled: false,
154
+ placeholder: '',
155
+ label: '',
156
+ onChange: () => {},
157
+ options: {},
158
+ translateErrorText: true,
159
+ showErrorText: true,
160
+ size: null,
161
+ value: '',
162
+ disabled: false,
163
+ required: false,
164
+ multiple: false
165
+ };
166
+ export default Select;
@@ -1,5 +1,36 @@
1
- function _extends(){_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;};return _extends.apply(this,arguments);}import React from'react';import{mount}from'enzyme';import Select from"./index";var inputProps={name:'test-name'};describe('<Select />',function(){// Simple tests for snapshots
2
- var tests={'should render select with no options':{},// eslint-disable-next-line extra-rules/no-single-line-objects
3
- 'should render select with 2 options':{options:{DE:'Germany',US:'United states'}},// eslint-disable-next-line extra-rules/no-single-line-objects
4
- 'should render select with 1 selected option':{options:{DE:'Germany',US:'United states'},value:'DE'}};Object.keys(tests).forEach(function(test){it(test,function(){var testFixtures=tests[test];// eslint-disable-next-line extra-rules/no-single-line-objects
5
- var wrapper=mount(React.createElement(Select,_extends({},inputProps,{},testFixtures)));expect(wrapper).toMatchSnapshot();});});});
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import { mount } from 'enzyme';
4
+ import Select from "./index";
5
+ const inputProps = {
6
+ name: 'test-name'
7
+ };
8
+ describe('<Select />', () => {
9
+ // Simple tests for snapshots
10
+ const tests = {
11
+ 'should render select with no options': {},
12
+ // eslint-disable-next-line extra-rules/no-single-line-objects
13
+ 'should render select with 2 options': {
14
+ options: {
15
+ DE: 'Germany',
16
+ US: 'United states'
17
+ }
18
+ },
19
+ // eslint-disable-next-line extra-rules/no-single-line-objects
20
+ 'should render select with 1 selected option': {
21
+ options: {
22
+ DE: 'Germany',
23
+ US: 'United states'
24
+ },
25
+ value: 'DE'
26
+ }
27
+ };
28
+ Object.keys(tests).forEach(test => {
29
+ it(test, () => {
30
+ const testFixtures = tests[test];
31
+ // eslint-disable-next-line extra-rules/no-single-line-objects
32
+ const wrapper = mount(/*#__PURE__*/React.createElement(Select, _extends({}, inputProps, testFixtures)));
33
+ expect(wrapper).toMatchSnapshot();
34
+ });
35
+ });
36
+ });
@@ -1 +1,27 @@
1
- import{css}from'glamor';var select=css({appearance:'none',position:'relative',overflow:'hidden',whiteSpace:'nowrap',textOverflow:'ellipsis',padding:'0 20px 0 0',width:'100%',margin:'24px 0 0 0',outline:0,fontSize:16,lineHeight:'19px',zIndex:10}).toString();var chevron=css({position:'absolute',top:'50%',right:0,transform:'translateY(-50%) rotateZ(-90deg)',fontSize:'1.3em !important',marginTop:-3}).toString();export default{select:select,chevron:chevron};
1
+ import { css } from 'glamor';
2
+ const select = css({
3
+ appearance: 'none',
4
+ position: 'relative',
5
+ overflow: 'hidden',
6
+ whiteSpace: 'nowrap',
7
+ textOverflow: 'ellipsis',
8
+ padding: '0 20px 0 0',
9
+ width: '100%',
10
+ margin: '24px 0 0 0',
11
+ outline: 0,
12
+ fontSize: 16,
13
+ lineHeight: '19px',
14
+ zIndex: 10
15
+ }).toString();
16
+ const chevron = css({
17
+ position: 'absolute',
18
+ top: '50%',
19
+ right: 0,
20
+ transform: 'translateY(-50%) rotateZ(-90deg)',
21
+ fontSize: '1.3em !important',
22
+ marginTop: -3
23
+ }).toString();
24
+ export default {
25
+ select,
26
+ chevron
27
+ };