@zohodesk/utils 1.0.1-alpha.2057

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 (75) hide show
  1. package/LICENSE +22 -0
  2. package/__testUtils__/globals.js +0 -0
  3. package/es/ErrorBoundary.js +29 -0
  4. package/es/__tests__/abbreviateNumber.spec.js +70 -0
  5. package/es/__tests__/compileClassNames.spec.js +48 -0
  6. package/es/__tests__/contextFactory.spec.js +12 -0
  7. package/es/__tests__/createTemplateLiteral.spec.js +4 -0
  8. package/es/abbreviateNumber.js +44 -0
  9. package/es/accessKeyCodes.js +18 -0
  10. package/es/applyOpenToCustomize.js +31 -0
  11. package/es/combineCustomStyle.js +39 -0
  12. package/es/compileClassNames.js +151 -0
  13. package/es/constantProps/index.js +1 -0
  14. package/es/constantProps/uiProps.js +34 -0
  15. package/es/contextFactory.js +15 -0
  16. package/es/createTemplateLiteral.js +77 -0
  17. package/es/dataTypes.js +25 -0
  18. package/es/debounce.js +12 -0
  19. package/es/disCustomStyleProps.js +45 -0
  20. package/es/getCompliedClassName.js +12 -0
  21. package/es/getCompliedCustomId.js +16 -0
  22. package/es/index.js +10 -0
  23. package/es/isTouchDevice.js +9 -0
  24. package/es/loadResource.js +56 -0
  25. package/es/mergeStyle.js +31 -0
  26. package/es/objectUtils.js +4 -0
  27. package/es/omit.js +12 -0
  28. package/es/props/automationProps.js +7 -0
  29. package/es/props/customReducerPropTypes.js +5 -0
  30. package/es/props/customStyleProps.js +9 -0
  31. package/es/props/generalAriaProps.js +6 -0
  32. package/es/props/tagAttributeProps.js +24 -0
  33. package/es/props/tagGeneralAttributeProps.js +24 -0
  34. package/es/props/uiProps.js +65 -0
  35. package/es/reducerHandler.js +18 -0
  36. package/es/replaceAtFirst.js +3 -0
  37. package/es/replaceAtLast.js +3 -0
  38. package/es/uniqueNumber.js +14 -0
  39. package/package.json +22 -0
  40. package/src/ErrorBoundary.js +24 -0
  41. package/src/__tests__/abbreviateNumber.spec.js +70 -0
  42. package/src/__tests__/compileClassNames.spec.js +35 -0
  43. package/src/__tests__/contextFactory.spec.js +13 -0
  44. package/src/__tests__/createTemplateLiteral.spec.js +4 -0
  45. package/src/abbreviateNumber.js +35 -0
  46. package/src/accessKeyCodes.js +19 -0
  47. package/src/applyOpenToCustomize.js +32 -0
  48. package/src/combineCustomStyle.js +52 -0
  49. package/src/compileClassNames.js +156 -0
  50. package/src/constantProps/index.js +1 -0
  51. package/src/constantProps/uiProps.js +41 -0
  52. package/src/contextFactory.js +14 -0
  53. package/src/createTemplateLiteral.js +73 -0
  54. package/src/dataTypes.js +30 -0
  55. package/src/debounce.js +13 -0
  56. package/src/disCustomStyleProps.js +69 -0
  57. package/src/getCompliedClassName.js +9 -0
  58. package/src/getCompliedCustomId.js +15 -0
  59. package/src/index.js +10 -0
  60. package/src/isTouchDevice.js +10 -0
  61. package/src/loadResource.js +45 -0
  62. package/src/mergeStyle.js +31 -0
  63. package/src/objectUtils.js +4 -0
  64. package/src/omit.js +10 -0
  65. package/src/props/automationProps.js +8 -0
  66. package/src/props/customReducerPropTypes.js +7 -0
  67. package/src/props/customStyleProps.js +10 -0
  68. package/src/props/generalAriaProps.js +7 -0
  69. package/src/props/tagAttributeProps.js +40 -0
  70. package/src/props/tagGeneralAttributeProps.js +48 -0
  71. package/src/props/uiProps.js +72 -0
  72. package/src/reducerHandler.js +23 -0
  73. package/src/replaceAtFirst.js +3 -0
  74. package/src/replaceAtLast.js +3 -0
  75. package/src/uniqueNumber.js +16 -0
@@ -0,0 +1,52 @@
1
+ const REPLACER_SYMBOL = "$";
2
+
3
+ /**
4
+ *
5
+ * if two is same ==> do the think if replace do, if append do.
6
+ * replace vs append ==> append
7
+ * append vs replace ==> replace
8
+ * @param {*} style1
9
+ * @param {*} style2
10
+ * @returns
11
+ */
12
+ export default function combineCustomStyle(style1, style2) {
13
+
14
+ let resultStyle = { ...style1};
15
+
16
+ Object.keys(style2).forEach(styleName => {
17
+
18
+ let oldStyleName = style1[`$${styleName}`] ? `$${styleName}` : styleName;
19
+
20
+ if (oldStyleName.startsWith(REPLACER_SYMBOL) && styleName.startsWith(REPLACER_SYMBOL)) {
21
+
22
+ resultStyle[styleName] = style2[styleName];
23
+
24
+ }
25
+ else if ( !oldStyleName.startsWith(REPLACER_SYMBOL) && !styleName.startsWith(REPLACER_SYMBOL) ) {
26
+
27
+ resultStyle[styleName] = `${resultStyle[styleName]} ${style2[styleName]}`;
28
+
29
+ }
30
+ else{
31
+ delete resultStyle[oldStyleName];
32
+ resultStyle[styleName] = style2[styleName];
33
+ }
34
+
35
+ /*else if (oldStyleName.startsWith(REPLACER_SYMBOL) && !styleName.startsWith(REPLACER_SYMBOL) ) {
36
+
37
+ delete resultStyle[oldStyleName];
38
+ resultStyle[styleName] = style2[styleName];
39
+
40
+ }
41
+ else if (!oldStyleName.startsWith(REPLACER_SYMBOL) && styleName.startsWith(REPLACER_SYMBOL) ) {
42
+
43
+ delete resultStyle[oldStyleName];
44
+ resultStyle[styleName] = style2[styleName];
45
+
46
+ }*/
47
+
48
+ });
49
+
50
+ return resultStyle;
51
+
52
+ }
@@ -0,0 +1,156 @@
1
+ import dataTypes, { isDataTypeOf } from "./dataTypes";
2
+ import { hasOwnProperty, isToStringReferenceEqual } from "./objectUtils";
3
+
4
+ /**
5
+ *
6
+ * @param {object} classinfoList
7
+ * @returns {string}
8
+ */
9
+ const collectClassNames = (processedClassNameList,...classinfoList) => {
10
+
11
+ for (let index = 0; index < classinfoList.length; index++) {
12
+
13
+ let classInfo = classinfoList[index];
14
+
15
+ if (!classInfo) {
16
+ continue;
17
+ }
18
+
19
+ if (isDataTypeOf(classInfo, dataTypes.string) || isDataTypeOf(classInfo, dataTypes.number)) {
20
+ processedClassNameList.push(classInfo);
21
+ }
22
+ else if (isDataTypeOf(classInfo, dataTypes.array)) {
23
+ processedClassNameList.push(collectClassNames.apply(null, classInfo));
24
+ }
25
+ else if (isDataTypeOf(classInfo, dataTypes.object)) {
26
+
27
+ for (let property in classInfo) {
28
+ if (hasOwnProperty.call(classInfo, property) && classInfo[property]) {
29
+ processedClassNameList.push(property==="undefined"?'':property);
30
+ }
31
+ }
32
+
33
+ }
34
+ }
35
+
36
+ }
37
+
38
+ export default function compileClassNames(...classinfoList){
39
+ let resultClassNameList = [];
40
+ collectClassNames(resultClassNameList,...classinfoList);
41
+ return resultClassNameList.join(' ');
42
+ };
43
+
44
+
45
+ /* discussion
46
+ passing object is enough i think. remaining option needed!!!
47
+ */
48
+
49
+
50
+ //18-Nov-2021 code review changes updated.
51
+
52
+ /*
53
+ >>>>>>>>>>Code Review Suggestion Starts >>>>>>
54
+ let hasOwn = {}.hasOwnProperty;
55
+
56
+ Accounting readability, please change this to Object.hasOwnProperty
57
+
58
+ ---
59
+ const compileClassNames = (...props)=>{
60
+ Please check the alternate term - collate -> collateClassNames -> Collect and Combine the classnames.
61
+ ---
62
+
63
+ for (let i = 0; i < props.length; i++) {
64
+
65
+ Please try to to stick with functional programming. Again for the readability perspective.
66
+ Also, please stick with naming conventions for variables (i -> index).
67
+
68
+ ---
69
+ if (argType === 'string' || argType === 'number') {
70
+ classes.push(this && this[arg] || arg);
71
+ } else if (Array.isArray(arg)) {
72
+ classes.push(compileClassNames.apply(this, arg));
73
+ } else if (argType === 'object') {
74
+ if (arg.toString === Object.prototype.toString) {
75
+ for (let key in arg) {
76
+ if (hasOwn.call(arg, key) && arg[key]) {
77
+ classes.push(this && this[key] || key);
78
+ }
79
+ }
80
+ } else {
81
+ classes.push(arg.toString());
82
+ }
83
+ }
84
+ }
85
+ In this code block, pushing up the array,object checks before string || number will be easy to follow up as it clarifies about the reursive call, its context.
86
+ Please check the possibility of avoiding the usage of 'this' statement due to its complexity in understanding the concept.
87
+
88
+ ---
89
+ Please write a functional method for the below line for easier understanding
90
+
91
+ if (arg.toString === Object.prototype.toString) {
92
+
93
+ ---
94
+
95
+ Adding dedicated method to get the datatype of variables will help to stick on the SRP.
96
+ ---
97
+ Check the possibility of providing platform to extend the algorithm works for other data structures like Map, WeakMap,etc..
98
+
99
+ >>>>>>> Code Review Suggestion Ends >>>>>>>>>>>>>>>>
100
+ */
101
+
102
+ /*
103
+
104
+ >>>>>> Alternative Implementation Starts >>>>>>>>>>>>>>>>
105
+
106
+ let boundHasOwnMethod = Object.hasOwnProperty;
107
+
108
+ const collateClassNames = (...classinfoList) =>{
109
+ let processedClassNameList = [];
110
+ classinfoList.forEach( ( classInfo,index )=>{
111
+ if(!classInfo)
112
+ {
113
+ // continue the next iteration
114
+ return;
115
+ }
116
+ let dataTypeofClassInfo = getDataType(classInfo);
117
+ if (dataTypeofClassInfo === 'string' || dataTypeofClassInfo === 'number')
118
+ {
119
+ processedClassNameList.push(classInfo);
120
+ }
121
+ else if(dataTypeofClassInfo === 'array')
122
+ {
123
+ processedClassNameList.push(collateClassNames(...classInfo));
124
+ }
125
+ else if(dataTypeofClassInfo === 'object')
126
+ {
127
+ for (let property in classInfo) {
128
+ if (boundHasOwnMethod.call(classInfo,property ) && classInfo[property]) {
129
+ processedClassNameList.push(property);
130
+ }
131
+ }
132
+ }
133
+
134
+
135
+ });
136
+ const joinClassNames = processedClassNameList.join(' ');
137
+ return joinClassNames;
138
+
139
+ }
140
+
141
+ const getDataType = (data)=>{
142
+ let dataTypeofClassInfo = typeof data;
143
+ let isArrayDataType = Array.isArray(data) === true;
144
+ if(isArrayDataType)
145
+ {
146
+ return 'array';
147
+ }
148
+ else
149
+ {
150
+ return dataTypeofClassInfo;
151
+ }
152
+
153
+ };
154
+
155
+ >>>>>>>>>>>>>>>> Alternative Implementation Ends>>>>>>>>>>>>>>
156
+ */
@@ -0,0 +1 @@
1
+ export * from "./uiProps";
@@ -0,0 +1,41 @@
1
+ export const variantList = {
2
+ outlined: 'variant_outlined',
3
+ contained: 'variant_contained',
4
+ flushed: 'variant_flushed',
5
+ plain: 'variant_plain'
6
+ };
7
+
8
+ export const variants = Object.values(variantList);
9
+
10
+ export const sizeList = {
11
+ xsmall: 'size_xsmall',
12
+ small: 'size_small',
13
+ medium: 'size_medium',
14
+ large: 'size_large',
15
+ xlarge: 'size_xlarge'
16
+ };
17
+
18
+ export const sizeKeys = Object.keys(sizeList);
19
+ export const sizes = Object.values(sizeList);
20
+
21
+ export const colorList = {
22
+ danger: 'color_danger',
23
+ success: 'color_success',
24
+ info: 'color_info',
25
+ primary: 'color_primary',
26
+ secondary: 'color_secondary',
27
+ warning: 'color_warning'
28
+ };
29
+
30
+ export const colorKeys = Object.keys(colorList);
31
+ export const colors = Object.values(colorList);
32
+
33
+ export const shapeList = {
34
+ circle: 'shape_circle',
35
+ oval: 'shape_oval',
36
+ square: 'shape_square',
37
+ roundedRect: 'shape_roundedRect',
38
+ rounded: 'shape_rounded'
39
+ };
40
+
41
+ export const shapes = Object.values(shapeList);
@@ -0,0 +1,14 @@
1
+ import { createContext } from 'react';
2
+
3
+ const context = {}
4
+ /**
5
+ *
6
+ * @param {string} name
7
+ * @returns {object}
8
+ */
9
+ export default function contextFactory(name) {
10
+ if (!context[name]) {
11
+ context[name] = createContext();
12
+ }
13
+ return context[name]
14
+ }
@@ -0,0 +1,73 @@
1
+ export default function createTemplateLiteral(templateStrings, ...expressionKeys) {
2
+
3
+ return ( ...expressionValues) => {
4
+
5
+ let resultString = [templateStrings[0]];
6
+ expressionKeys.forEach(function (expressionKey, i) {
7
+ let expressionValue = expressionValues[i];
8
+ let nextTemplateString = templateStrings[i + 1];
9
+ if (expressionValue === null || expressionValue === undefined || expressionValue === "") {
10
+ nextTemplateString = nextTemplateString.replace(/^_/, '');
11
+ }
12
+ resultString.push(expressionValue, nextTemplateString);
13
+ });
14
+
15
+ let resultStr = resultString.join('');
16
+ resultStr = resultStr.replace(/_$/, '');
17
+ return resultStr;
18
+ };
19
+ }
20
+
21
+
22
+
23
+ /* refer the doc https://developers.google.com/web/updates/2015/01/ES6-Template-Strings
24
+
25
+ UnderSatnd the terms - String interpolation, Embedded expressions
26
+
27
+ Go through the topic https://developers.google.com/web/updates/2015/01/ES6-Template-Strings#tagged_templates
28
+
29
+ Things to note fn`Hello ${you}! You're looking ${adjective} today!` desugars to fn(["Hello ", "! You're looking ", " today!"], you, adjective);
30
+
31
+ Please go through the example code
32
+
33
+ Our implementation constructCustomMessage is the handler for the tagged template function.
34
+ It receives the static words and its substitutions as seen above as the arguments.
35
+
36
+ It returns a function that receives the values for the substitutions. Upon passing the values for the inner function
37
+ it executes the algorithm as mentioned in the doc to construct the final message.
38
+ "The (n + 1)th argument corresponds to the substitution that takes place between the nth and (n + 1)th entries in the string array"
39
+
40
+
41
+ function constructCustomMessage(staticWordsList, ...embeddedExpressionKeyList)
42
+ {
43
+ return (...valuesForEmbeddedExpressionList)=>{
44
+
45
+ let finalMessage = staticWordsList[0];
46
+ embeddedExpressionKeyList.forEach(function(expressionKey, index) {
47
+ let expressionValue = valuesForEmbeddedExpressionList[index];
48
+ let nextStaticWord = staticWordsList[index+1];
49
+ if(expressionValue===null || expressionValue === undefined || expressionValue === ""){
50
+ // Replace the underscore '_' present at the beginning of string with empty value.
51
+ nextStaticWord = nextStaticWord.replace(/^_/, '');
52
+ }
53
+ finalMessage += expressionValue + nextStaticWord;
54
+
55
+ });
56
+ // Replace the underscore '_' present at the end of string with empty value.
57
+ finalMessage = finalMessage.replace(/_$/,'');
58
+ return finalMessage ;
59
+ };
60
+
61
+ }
62
+ */
63
+
64
+ /*
65
+ Sample Invocation Format
66
+
67
+ var username;
68
+ var tag;
69
+ var handlerFunctiontoFormMessage = constructCustomMessage`<b>${username} says</b>: "${tag}"`;
70
+ var outputString = handlerFunctiontoFormMessage('Mani Venkat', '& is a fun tag');
71
+ console.log(outputString);
72
+
73
+ */
@@ -0,0 +1,30 @@
1
+ const dataTypes = {
2
+ "number" : "number",
3
+ "array" : "array",
4
+ "string" : "string",
5
+ "object" : "object",
6
+ "bigint" : "bigint",
7
+ "symbol" : "symbol",
8
+ "undefined" : "undefined",
9
+ "function" : "function",
10
+ "boolean" : "boolean"
11
+ };
12
+
13
+ export const getDataType = (data)=>{
14
+ let typeofData = typeof data;
15
+ let isArrayDataType = Array.isArray(data);
16
+ if(isArrayDataType)
17
+ {
18
+ return dataTypes.array;
19
+ }
20
+ else
21
+ {
22
+ return dataTypes[typeofData];
23
+ }
24
+ };
25
+
26
+ export const isDataTypeOf=(data,type)=>{
27
+ return getDataType(data) === type;
28
+ }
29
+
30
+ export default dataTypes;
@@ -0,0 +1,13 @@
1
+ export default function debounce(fn, delay) {
2
+ let handle = null
3
+
4
+ return function () {
5
+ if (handle) {
6
+ handle = clearTimeout(handle)
7
+ }
8
+
9
+ handle = setTimeout(() => {
10
+ fn(...arguments)
11
+ }, delay)
12
+ }
13
+ }
@@ -0,0 +1,69 @@
1
+ // import PropTypes from "prop-types";
2
+ // import mergeStyle from "./mergeStyle";
3
+ // import { Button } from "../../base/src/Button/index";
4
+ // export default (props)=>{
5
+
6
+ // let { customStyle, openCustomStyle} = props;
7
+
8
+ // return {
9
+ // customStyle,
10
+ // openDefaultToCustomize
11
+ // };
12
+
13
+ // }
14
+
15
+
16
+ // if two is same ==> do the think replace with last , append at end
17
+
18
+ // replace vs append ==> append
19
+ // append vs replace ==> replace
20
+
21
+
22
+ // DotButton.js
23
+ // DotButton.module.css
24
+ // function DotButton({ customStyle }){
25
+
26
+ // dotButdefault => customStyle : {
27
+ // base : DotButton.style.pols
28
+ // }
29
+
30
+ // props => customStyle {
31
+ // base :
32
+ // }
33
+
34
+ // return <Button customStyle={}></Button>
35
+ // }
36
+
37
+ // Button => set of compoents
38
+ // DotButton => set of comepons
39
+
40
+ // function creatButtonWithIcon({Button,Icon}){
41
+
42
+ // return (props)=>{
43
+
44
+ // customStyle={}
45
+ // return <Button customStyle={ssss}>
46
+
47
+ // <Icon></Icon>
48
+ // </Button>
49
+
50
+ // }
51
+
52
+ // }
53
+
54
+
55
+ // Button1.js
56
+ // Icon1.js
57
+ // creatButtonWithIcon({
58
+
59
+ // Button : Button1,
60
+ // Icon : Icon1
61
+
62
+ // });
63
+
64
+ // Button1custome(props){
65
+
66
+ // props.customStyle
67
+ // combineCustomStyle()
68
+ // return Button
69
+ // }
@@ -0,0 +1,9 @@
1
+ import compileClassNames from "./compileClassNames";
2
+
3
+ export default (customClassName, ...props) => {
4
+
5
+ let isPlainClassName = typeof customClassName === "string" ? true : false;
6
+ return compileClassNames(...props, {
7
+ [customClassName]: !!isPlainClassName
8
+ });
9
+ }
@@ -0,0 +1,15 @@
1
+ export default (
2
+ { customId, customIdPrefix = "", customIdSuffix = "" },
3
+ defaultCustomId,
4
+ otherCustomOption=[]
5
+ ) => {
6
+ let returnId = customId;
7
+
8
+ if (typeof defaultCustomId === "function") {
9
+ let options = [ '',customIdPrefix, customIdSuffix, ...otherCustomOption];
10
+ returnId = defaultCustomId.apply(null,options);
11
+ //returnId = defaultCustomId`${customIdPrefix} ${customIdSuffix}`;
12
+ }
13
+
14
+ return returnId ? returnId.toLowerCase() : null;
15
+ };
package/src/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { default as debounce } from './debounce';
2
+ export { default as uniqueNumber } from './uniqueNumber'
3
+ export { default as omit } from './omit';
4
+ export { default as mergeStyle } from './mergeStyle'
5
+ export { default as applyOpenToCustomize } from './applyOpenToCustomize';
6
+ export { default as combineCustomStyle } from './combineCustomStyle'
7
+ export { default as compileClassNames } from './compileClassNames';
8
+ export { default as ErrorBoundary } from './ErrorBoundary'
9
+ export { default as loadResource } from './loadResource'
10
+ export { default as accessKeyCodes, accessKeyNames } from "./accessKeyCodes";
@@ -0,0 +1,10 @@
1
+ export default function isTouchDevice() {
2
+ if (('ontouchstart' in window) ||
3
+ (navigator.maxTouchPoints > 0) ||
4
+ (navigator.msMaxTouchPoints > 0)) {
5
+ /* browser with either Touch Events of Pointer Events
6
+ running on touch-capable device */
7
+ return true;
8
+ }
9
+ return false;
10
+ }
@@ -0,0 +1,45 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ /* use promise and remove callback */
3
+ export default function loadResource(url, type, id, callback, needDefer = true) {
4
+ return new Promise((resolve) => {
5
+ let css;
6
+ let script;
7
+ if (id && document.getElementById(id)) {
8
+ resolve();
9
+ return;
10
+ }
11
+ if (type === 'css') {
12
+ css = document.createElement('link');
13
+ css.type = 'text/css';
14
+ css.rel = 'stylesheet';
15
+ css.href = url;
16
+ css.id = id || '';
17
+ css.onload = function () {
18
+ resolve();
19
+ };
20
+ css.onerror = function () {
21
+ resolve();
22
+ };
23
+ document.getElementsByTagName('head')[0].appendChild(css);
24
+ } else if (type === 'js') {
25
+ script = document.createElement('script');
26
+ script.type = 'text/javascript';
27
+ script.src = url;
28
+ script.defer = needDefer;
29
+
30
+ script.onload = function () {
31
+ resolve();
32
+ if (id) {
33
+ script.id = id;
34
+ }
35
+ if (typeof callback === 'function') {
36
+ callback();
37
+ }
38
+ };
39
+ script.onerror = function () {
40
+ resolve();
41
+ };
42
+ document.getElementsByTagName('head')[0].appendChild(script);
43
+ }
44
+ });
45
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * REPLACER_SYMBOL used to indentify
3
+ */
4
+ const REPLACER_SYMBOL = "$";
5
+ /**
6
+ * $ startWith is used for replace the existing style.
7
+ * all other will be append
8
+ * @param {*} defaultStyle
9
+ * @param {*} customStyle
10
+ * @returns
11
+ */
12
+ export default function mergeStyle(defaultStyle, customStyle) {
13
+ return Object.keys(customStyle).reduce((res, next) => {
14
+ if (next.startsWith(REPLACER_SYMBOL)) {
15
+ let styleValue = customStyle[next];
16
+ let styleName = next.replace(REPLACER_SYMBOL, "");
17
+
18
+ if (!defaultStyle[styleName]) {
19
+ return res;
20
+ }
21
+
22
+ res[styleName] = styleValue;
23
+ } else if (defaultStyle[next]) {
24
+ res[next] = defaultStyle[next] + " " + customStyle[next];
25
+ }
26
+
27
+ return res;
28
+ }, { ...defaultStyle
29
+ });
30
+
31
+ }
@@ -0,0 +1,4 @@
1
+ export const hasOwnProperty = Object.hasOwnProperty;
2
+ export const isToStringReferenceEqual =(data)=>{
3
+ return data.toString === Object.prototype.toString
4
+ }
package/src/omit.js ADDED
@@ -0,0 +1,10 @@
1
+ export default (keys) => {
2
+ return function omit(obj) {
3
+ return Object.keys(obj).reduce((res, next) => {
4
+ if (!keys.includes(next)) {
5
+ res[next] = obj[next];
6
+ }
7
+ return res;
8
+ }, {})
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ export const automationPropsName = 'customId';
4
+ export default {
5
+ customId: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
6
+ customIdPrefix: PropTypes.string,
7
+ customIdSuffix: PropTypes.string
8
+ };
@@ -0,0 +1,7 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ export default {
4
+ customReducer: PropTypes.func
5
+ };
6
+
7
+ export const customReducer = 'customReducer';
@@ -0,0 +1,10 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ export default {
4
+ customStyle: PropTypes.object
5
+ };
6
+
7
+ /**
8
+ * Prop Name
9
+ */
10
+ export const customStyle = "customStyle";
@@ -0,0 +1,7 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ export default {
4
+ 'aria-label': PropTypes.string,
5
+ 'aria-labelledby': PropTypes.string,
6
+ tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
7
+ };
@@ -0,0 +1,40 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ const attributesList = [
4
+ "tabIndex"
5
+ ];
6
+
7
+ const dataAttribute = "^data|on";
8
+
9
+ export const tagAttributesPropType = function(props, propName, componentName ) {
10
+
11
+ if( Object.prototype.toString.call(props) !== "[object Object]"){
12
+
13
+ console.error(`Warning: Failed prop type: Invalid prop \`${propName}\` of type \`${ props ? (typeof props) : undefined}\` supplied to \`${componentName}\`, expected \`object\`.`);
14
+
15
+ }
16
+
17
+ let curPattern = new RegExp(`^(${attributesList.join("|")})$`);
18
+ let curPattern2 = new RegExp(dataAttribute);
19
+
20
+ Object.keys(props[propName]).forEach((keyName)=>{
21
+
22
+ if( !(curPattern.test( keyName ) || curPattern2.test(keyName)) ){
23
+
24
+ console.warn(`Warning: these attributes name ${keyName} are not allowed in ${propName}`);
25
+
26
+ }
27
+
28
+ });
29
+
30
+ }
31
+
32
+ export default {
33
+ tagAttributes: tagAttributesPropType
34
+ }
35
+
36
+
37
+ /**
38
+ * tagAttributes - is used to spread these attributes for events customize and override few attributes.
39
+ */
40
+ export const tagAttributes = "tagAttributes";