@zohodesk/components 1.2.50 → 1.2.52

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.
@@ -0,0 +1,56 @@
1
+ import { compileClassNames } from '@zohodesk/utils';
2
+ import { letterspacingMapping, lineheightMapping } from "../utils";
3
+ export default function cssJSLogic(_ref) {
4
+ let {
5
+ props,
6
+ style
7
+ } = _ref;
8
+ let {
9
+ $flag_reset,
10
+ $flag_dotted,
11
+ $ui_size,
12
+ $ui_lineClamp,
13
+ $ui_lineHeight,
14
+ $ui_display,
15
+ $ui_weight,
16
+ $ui_typeFace,
17
+ $ui_textAlign,
18
+ $ui_letterSpacing,
19
+ $ui_transform,
20
+ $ui_decoration,
21
+ $ui_className,
22
+ $ui_wordBreak,
23
+ $ui_wordWrap,
24
+ $ui_whiteSpace
25
+ } = props;
26
+
27
+ if ($ui_letterSpacing) {
28
+ $ui_letterSpacing = letterspacingMapping[$ui_letterSpacing];
29
+ }
30
+
31
+ if ($ui_lineHeight) {
32
+ $ui_lineHeight = lineheightMapping[$ui_lineHeight];
33
+ }
34
+
35
+ let typographyClass = compileClassNames({
36
+ [style.reset]: $flag_reset,
37
+ [style.dotted]: $flag_dotted,
38
+ [style[`size${$ui_size}`]]: !!$ui_size,
39
+ [style[`lineclamp_${$ui_lineClamp}`]]: !!$ui_lineClamp,
40
+ [style[`lineheight_${$ui_lineHeight}`]]: !!$ui_lineHeight,
41
+ [style[`display_${$ui_display}`]]: !!$ui_display,
42
+ [style[`font_${$ui_weight}`]]: !!$ui_weight,
43
+ [style[`fontStyles_${$ui_typeFace}`]]: !!$ui_typeFace,
44
+ [style[`textalign_${$ui_textAlign}`]]: !!$ui_textAlign,
45
+ [style[`letterspacing_${$ui_letterSpacing}`]]: !!$ui_letterSpacing,
46
+ [style[`transform_${$ui_transform}`]]: !!$ui_transform,
47
+ [style[`decoration_${$ui_decoration}`]]: !!$ui_decoration,
48
+ [$ui_className]: !!$ui_className,
49
+ [style[`wordBreak_${$ui_wordBreak}`]]: !!$ui_wordBreak,
50
+ [style[`wordWrap_${$ui_wordWrap}`]]: !!$ui_wordWrap,
51
+ [style[`whiteSpace_${$ui_whiteSpace}`]]: !!$ui_whiteSpace
52
+ });
53
+ return {
54
+ typographyClass
55
+ };
56
+ }
@@ -0,0 +1,8 @@
1
+ export const defaultProps = {
2
+ $ui_className: '',
3
+ $ui_tagName: 'div',
4
+ $flag_reset: false,
5
+ $flag_dotted: false,
6
+ $tagAttributes_text: {},
7
+ $a11yAttributes_text: {}
8
+ };
@@ -0,0 +1,27 @@
1
+ import PropTypes from 'prop-types';
2
+ export const propTypes = {
3
+ children: PropTypes.node,
4
+ $ui_className: PropTypes.string,
5
+ $ui_tagName: PropTypes.string,
6
+ $flag_reset: PropTypes.bool,
7
+ $flag_dotted: PropTypes.bool,
8
+ $ui_display: PropTypes.oneOf(['block', 'inlineBlock', 'inline', 'initial']),
9
+ $ui_weight: PropTypes.oneOf(['regular', 'light', 'semibold', 'bold']),
10
+ $ui_textAlign: PropTypes.oneOf(['left', 'right', 'center', 'justify']),
11
+ $ui_transform: PropTypes.oneOf(['default', 'upper', 'lower', 'capital']),
12
+ $ui_lineClamp: PropTypes.oneOf(['1', '2', '3', '4', '5']),
13
+ $ui_typeFace: PropTypes.oneOf(['normal', 'italic']),
14
+ $ui_decoration: PropTypes.oneOf(['default', 'underline', 'strike', 'overline']),
15
+ $ui_size: PropTypes.oneOf(['7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '24', '25', '26', '28', '29', '30', '32', '34', '35', '36', '40', '50', 'inherit']),
16
+ $ui_lineHeight: PropTypes.oneOf(['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '2', 'normal', 'initial', 'inherit']),
17
+ $ui_letterSpacing: PropTypes.oneOf(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1', '1.1', '1.2', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8', '1.9', '2', 'inherit']),
18
+ $ui_wordBreak: PropTypes.oneOf(['breakAll', 'keepAll', 'breakWord']),
19
+ $ui_wordWrap: PropTypes.oneOf(['normal', 'break']),
20
+ $ui_whiteSpace: PropTypes.oneOf(['normal', 'noWrap', 'pre', 'preLine', 'preWrap']),
21
+ $i18n_dataTitle: PropTypes.string,
22
+ testId: PropTypes.string,
23
+ customId: PropTypes.string,
24
+ customStyle: PropTypes.object,
25
+ $a11yAttributes_text: PropTypes.object,
26
+ $tagAttributes_text: PropTypes.object
27
+ };
@@ -0,0 +1,50 @@
1
+ /* eslint-disable */
2
+ export const letterspacingMapping = {
3
+ 'inherit': 'inherit',
4
+ '0.1': '0_1',
5
+ '0.2': '0_2',
6
+ '0.3': '0_3',
7
+ '0.4': '0_4',
8
+ '0.5': '0_5',
9
+ '0.6': '0_6',
10
+ '0.7': '0_7',
11
+ '0.8': '0_8',
12
+ '0.9': '0_9',
13
+ '1': '1',
14
+ '1.1': '1_1',
15
+ '1.2': '1_2',
16
+ '1.3': '1_3',
17
+ '1.4': '1_4',
18
+ '1.5': '1_5',
19
+ '1.6': '1_6',
20
+ '1.7': '1_7',
21
+ '1.8': '1_8',
22
+ '1.9': '1_9',
23
+ '2': '2'
24
+ };
25
+ export const lineheightMapping = {
26
+ 'inherit': 'inherit',
27
+ 'initial': 'initial',
28
+ 'normal': 'normal',
29
+ '0': '0',
30
+ '0.1': '0_1',
31
+ '0.2': '0_2',
32
+ '0.3': '0_3',
33
+ '0.4': '0_4',
34
+ '0.5': '0_5',
35
+ '0.6': '0_6',
36
+ '0.7': '0_7',
37
+ '0.8': '0_8',
38
+ '0.9': '0_9',
39
+ '1': '1',
40
+ '1.1': '1_1',
41
+ '1.2': '1_2',
42
+ '1.3': '1_3',
43
+ '1.4': '1_4',
44
+ '1.5': '1_5',
45
+ '1.6': '1_6',
46
+ '1.7': '1_7',
47
+ '1.8': '1_8',
48
+ '1.9': '1_9',
49
+ '2': '2'
50
+ };
package/es/index.js CHANGED
@@ -39,4 +39,4 @@ import * as _utils from "./utils";
39
39
  export { _utils as utils };
40
40
  export * from "./VelocityAnimation";
41
41
  export * from "./semantic";
42
- export { default as Typography } from "./v1/Typography/Typography";
42
+ export { default as Typography } from "./Typography/Typography";
@@ -3,7 +3,7 @@ import { defaultProps } from "./props/defaultProps";
3
3
  import { propTypes } from "./props/propTypes";
4
4
  import cssJSLogic from "./css/cssJSLogic";
5
5
  import { mergeStyle } from '@zohodesk/utils';
6
- import defaultStyle from "./css/Typography.module.css";
6
+ import defaultStyle from "./css/v1_Typography.module.css";
7
7
 
8
8
  const Typography = props => {
9
9
  const {
@@ -158,6 +158,8 @@ var Popup = function Popup(Component) {
158
158
  _this.preventKeyboardScroll = _this.preventKeyboardScroll.bind(_assertThisInitialized(_this));
159
159
  _this.addScrollBlockListeners = _this.addScrollBlockListeners.bind(_assertThisInitialized(_this));
160
160
  _this.removeScrollBlockListeners = _this.removeScrollBlockListeners.bind(_assertThisInitialized(_this));
161
+ _this.handleAddingScrollBlock = _this.handleAddingScrollBlock.bind(_assertThisInitialized(_this));
162
+ _this.handleRemovingScrollBlock = _this.handleRemovingScrollBlock.bind(_assertThisInitialized(_this));
161
163
  _this.handleIntersectionObserver = _this.handleIntersectionObserver.bind(_assertThisInitialized(_this));
162
164
  _this.popupObserver = new _ResizeObserver["default"](_this.handlePopupResize); //dropBoxSize
163
165
 
@@ -216,10 +218,7 @@ var Popup = function Popup(Component) {
216
218
  oldStateOpen = _ref2$isPopupReady === void 0 ? false : _ref2$isPopupReady;
217
219
 
218
220
  var dropElement = this.dropElement;
219
- var _this$props = this.props,
220
- propResizeHandling = _this$props.needResizeHandling,
221
- isAbsolutePositioningNeeded = _this$props.isAbsolutePositioningNeeded,
222
- isOutsideScrollBlocked = _this$props.isOutsideScrollBlocked;
221
+ var propResizeHandling = this.props.needResizeHandling;
223
222
 
224
223
  if (oldStateOpen !== isPopupReady) {
225
224
  if (isPopupReady && dropElement && (propResizeHandling !== undefined ? propResizeHandling : needResizeHandling)) {
@@ -229,14 +228,10 @@ var Popup = function Popup(Component) {
229
228
  this.popupObserver.disconnect();
230
229
  }
231
230
 
232
- if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
233
- if (isPopupReady) {
234
- (0, _intersectionObserver.addIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
235
- this.addScrollBlockListeners();
236
- } else {
237
- (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
238
- this.removeScrollBlockListeners();
239
- }
231
+ if (isPopupReady) {
232
+ this.handleAddingScrollBlock();
233
+ } else {
234
+ this.handleRemovingScrollBlock();
240
235
  }
241
236
  }
242
237
  }
@@ -258,8 +253,7 @@ var Popup = function Popup(Component) {
258
253
 
259
254
  return res;
260
255
  }, popups);
261
- (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
262
- this.removeScrollBlockListeners();
256
+ this.handleRemovingScrollBlock();
263
257
  var noPopups = true;
264
258
 
265
259
  for (var i in popups) {
@@ -283,6 +277,30 @@ var Popup = function Popup(Component) {
283
277
  document.removeEventListener('focus', this.handleDocumentFocus, true);
284
278
  }
285
279
  }
280
+ }, {
281
+ key: "handleAddingScrollBlock",
282
+ value: function handleAddingScrollBlock() {
283
+ var _this$props = this.props,
284
+ isAbsolutePositioningNeeded = _this$props.isAbsolutePositioningNeeded,
285
+ isOutsideScrollBlocked = _this$props.isOutsideScrollBlocked;
286
+
287
+ if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
288
+ (0, _intersectionObserver.addIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
289
+ this.addScrollBlockListeners();
290
+ }
291
+ }
292
+ }, {
293
+ key: "handleRemovingScrollBlock",
294
+ value: function handleRemovingScrollBlock() {
295
+ var _this$props2 = this.props,
296
+ isAbsolutePositioningNeeded = _this$props2.isAbsolutePositioningNeeded,
297
+ isOutsideScrollBlocked = _this$props2.isOutsideScrollBlocked;
298
+
299
+ if (isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
300
+ (0, _intersectionObserver.removeIntersectionObserver)(this.placeHolderElement, this.handleIntersectionObserver);
301
+ this.removeScrollBlockListeners();
302
+ }
303
+ }
286
304
  }, {
287
305
  key: "addScrollBlockListeners",
288
306
  value: function addScrollBlockListeners() {
@@ -22,41 +22,51 @@ var observerCallbacks = null;
22
22
  var intersectionObserver = null;
23
23
 
24
24
  function handleObserverCallbacks(entries) {
25
- entries.map(function (entry, i) {
25
+ entries.forEach(function (entry) {
26
26
  var oldCallbacks = observerCallbacks.get(entry.target);
27
- oldCallbacks.length && oldCallbacks.forEach(function (callback) {
28
- callback && callback(entry);
29
- });
27
+
28
+ if (Array.isArray(oldCallbacks) && oldCallbacks.length) {
29
+ oldCallbacks.forEach(function (callback) {
30
+ callback && callback(entry);
31
+ });
32
+ }
30
33
  });
31
34
  }
32
35
 
33
36
  function addIntersectionObserver(element, callback, options) {
34
- if (intersectionObserver === null && observerCallbacks === null) {
35
- intersectionObserver = new IntersectionObserver(function (entries) {
36
- handleObserverCallbacks(entries);
37
- }, options);
38
- observerCallbacks = new Map();
39
- }
37
+ if (!!element && typeof callback == 'function') {
38
+ if (intersectionObserver === null && observerCallbacks === null) {
39
+ intersectionObserver = new IntersectionObserver(function (entries) {
40
+ handleObserverCallbacks(entries);
41
+ }, options);
42
+ observerCallbacks = new Map();
43
+ }
40
44
 
41
- intersectionObserver.observe(element);
42
- var oldCallbacks = observerCallbacks.get(element) || [];
43
- observerCallbacks.set(element, [].concat(_toConsumableArray(oldCallbacks), [callback]));
45
+ intersectionObserver.observe(element);
46
+ var oldCallbacks = observerCallbacks.get(element) || [];
47
+ observerCallbacks.set(element, [].concat(_toConsumableArray(oldCallbacks), [callback]));
48
+ }
44
49
  }
45
50
 
46
51
  function removeIntersectionObserver(element, callback) {
47
- var oldCallbacks = observerCallbacks ? observerCallbacks.get(element) : [];
48
- oldCallbacks = oldCallbacks.filter(function (handler) {
49
- return handler !== callback;
50
- });
52
+ if (!!element && typeof callback == 'function') {
53
+ var oldCallbacks = observerCallbacks ? observerCallbacks.get(element) : null;
51
54
 
52
- if (intersectionObserver && oldCallbacks.length === 0) {
53
- observerCallbacks["delete"](element);
54
- intersectionObserver.unobserve(element);
55
- }
55
+ if (Array.isArray(oldCallbacks)) {
56
+ var callbacks = oldCallbacks.filter(function (handler) {
57
+ return handler !== callback;
58
+ });
59
+
60
+ if (intersectionObserver && callbacks.length === 0) {
61
+ observerCallbacks["delete"](element);
62
+ intersectionObserver.unobserve(element);
63
+ }
64
+ }
56
65
 
57
- if (intersectionObserver && observerCallbacks && observerCallbacks.size === 0) {
58
- intersectionObserver.disconnect();
59
- intersectionObserver = null;
60
- observerCallbacks = null;
66
+ if (intersectionObserver && observerCallbacks && observerCallbacks.size === 0) {
67
+ intersectionObserver.disconnect();
68
+ intersectionObserver = null;
69
+ observerCallbacks = null;
70
+ }
61
71
  }
62
72
  }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _defaultProps = require("./props/defaultProps");
11
+
12
+ var _propTypes = require("./props/propTypes");
13
+
14
+ var _cssJSLogic2 = _interopRequireDefault(require("./css/cssJSLogic"));
15
+
16
+ var _utils = require("@zohodesk/utils");
17
+
18
+ var _TypographyModule = _interopRequireDefault(require("./css/Typography.module.css"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
+
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
+
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
+
26
+ 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; }
27
+
28
+ var Typography = function Typography(props) {
29
+ var children = props.children,
30
+ $ui_tagName = props.$ui_tagName,
31
+ $i18n_dataTitle = props.$i18n_dataTitle,
32
+ testId = props.testId,
33
+ customId = props.customId,
34
+ $tagAttributes_text = props.$tagAttributes_text,
35
+ $a11yAttributes_text = props.$a11yAttributes_text,
36
+ customStyle = props.customStyle;
37
+ var style = (0, _utils.mergeStyle)(_TypographyModule["default"], customStyle);
38
+
39
+ var _cssJSLogic = (0, _cssJSLogic2["default"])({
40
+ props: props,
41
+ style: style
42
+ }),
43
+ typographyClass = _cssJSLogic.typographyClass;
44
+
45
+ return /*#__PURE__*/_react["default"].createElement($ui_tagName, _objectSpread(_objectSpread({
46
+ className: typographyClass,
47
+ 'data-title': $i18n_dataTitle,
48
+ 'data-id': customId,
49
+ 'data-test-id': testId
50
+ }, $tagAttributes_text), $a11yAttributes_text), children);
51
+ };
52
+
53
+ Typography.propTypes = _propTypes.propTypes;
54
+ Typography.defaultProps = _defaultProps.defaultProps;
55
+ var _default = Typography;
56
+ exports["default"] = _default;