@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.
- package/LICENSE +22 -0
- package/__testUtils__/globals.js +0 -0
- package/es/ErrorBoundary.js +29 -0
- package/es/__tests__/abbreviateNumber.spec.js +70 -0
- package/es/__tests__/compileClassNames.spec.js +48 -0
- package/es/__tests__/contextFactory.spec.js +12 -0
- package/es/__tests__/createTemplateLiteral.spec.js +4 -0
- package/es/abbreviateNumber.js +44 -0
- package/es/accessKeyCodes.js +18 -0
- package/es/applyOpenToCustomize.js +31 -0
- package/es/combineCustomStyle.js +39 -0
- package/es/compileClassNames.js +151 -0
- package/es/constantProps/index.js +1 -0
- package/es/constantProps/uiProps.js +34 -0
- package/es/contextFactory.js +15 -0
- package/es/createTemplateLiteral.js +77 -0
- package/es/dataTypes.js +25 -0
- package/es/debounce.js +12 -0
- package/es/disCustomStyleProps.js +45 -0
- package/es/getCompliedClassName.js +12 -0
- package/es/getCompliedCustomId.js +16 -0
- package/es/index.js +10 -0
- package/es/isTouchDevice.js +9 -0
- package/es/loadResource.js +56 -0
- package/es/mergeStyle.js +31 -0
- package/es/objectUtils.js +4 -0
- package/es/omit.js +12 -0
- package/es/props/automationProps.js +7 -0
- package/es/props/customReducerPropTypes.js +5 -0
- package/es/props/customStyleProps.js +9 -0
- package/es/props/generalAriaProps.js +6 -0
- package/es/props/tagAttributeProps.js +24 -0
- package/es/props/tagGeneralAttributeProps.js +24 -0
- package/es/props/uiProps.js +65 -0
- package/es/reducerHandler.js +18 -0
- package/es/replaceAtFirst.js +3 -0
- package/es/replaceAtLast.js +3 -0
- package/es/uniqueNumber.js +14 -0
- package/package.json +22 -0
- package/src/ErrorBoundary.js +24 -0
- package/src/__tests__/abbreviateNumber.spec.js +70 -0
- package/src/__tests__/compileClassNames.spec.js +35 -0
- package/src/__tests__/contextFactory.spec.js +13 -0
- package/src/__tests__/createTemplateLiteral.spec.js +4 -0
- package/src/abbreviateNumber.js +35 -0
- package/src/accessKeyCodes.js +19 -0
- package/src/applyOpenToCustomize.js +32 -0
- package/src/combineCustomStyle.js +52 -0
- package/src/compileClassNames.js +156 -0
- package/src/constantProps/index.js +1 -0
- package/src/constantProps/uiProps.js +41 -0
- package/src/contextFactory.js +14 -0
- package/src/createTemplateLiteral.js +73 -0
- package/src/dataTypes.js +30 -0
- package/src/debounce.js +13 -0
- package/src/disCustomStyleProps.js +69 -0
- package/src/getCompliedClassName.js +9 -0
- package/src/getCompliedCustomId.js +15 -0
- package/src/index.js +10 -0
- package/src/isTouchDevice.js +10 -0
- package/src/loadResource.js +45 -0
- package/src/mergeStyle.js +31 -0
- package/src/objectUtils.js +4 -0
- package/src/omit.js +10 -0
- package/src/props/automationProps.js +8 -0
- package/src/props/customReducerPropTypes.js +7 -0
- package/src/props/customStyleProps.js +10 -0
- package/src/props/generalAriaProps.js +7 -0
- package/src/props/tagAttributeProps.js +40 -0
- package/src/props/tagGeneralAttributeProps.js +48 -0
- package/src/props/uiProps.js +72 -0
- package/src/reducerHandler.js +23 -0
- package/src/replaceAtFirst.js +3 -0
- package/src/replaceAtLast.js +3 -0
- package/src/uniqueNumber.js +16 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
|
|
3
|
+
const attributesList = [
|
|
4
|
+
"accesskey",
|
|
5
|
+
"contentEditable",
|
|
6
|
+
"dir",
|
|
7
|
+
"draggable",
|
|
8
|
+
"hidden",
|
|
9
|
+
"lang",
|
|
10
|
+
"tabIndex",
|
|
11
|
+
"title",
|
|
12
|
+
"spellcheck",
|
|
13
|
+
"translate"
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const dataAttribute = "^data|on";
|
|
17
|
+
|
|
18
|
+
export const tagGeneralAttributesPropType = function(props, propName, componentName ) {
|
|
19
|
+
|
|
20
|
+
if( Object.prototype.toString.call(props) !== "[object Object]"){
|
|
21
|
+
|
|
22
|
+
console.error(`Warning: Failed prop type: Invalid prop \`${propName}\` of type \`${ props ? (typeof props) : undefined}\` supplied to \`${componentName}\`, expected \`object\`.`);
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let curPattern = new RegExp(`^(${attributesList.join("|")})$`);
|
|
27
|
+
let curPattern2 = new RegExp(dataAttribute);
|
|
28
|
+
|
|
29
|
+
Object.keys(props[propName]).forEach((keyName)=>{
|
|
30
|
+
|
|
31
|
+
if( !(curPattern.test( keyName ) || curPattern2.test(keyName)) ){
|
|
32
|
+
|
|
33
|
+
console.warn(`Warning: these attributes name ${keyName} are not allowed in tagGeneralAttributes`);
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
tagGeneralAttributes: tagGeneralAttributesPropType
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* tagGeneralAttributes - is to spread the global attributes in component.
|
|
47
|
+
*/
|
|
48
|
+
export const tagGeneralAttributes = "tagGeneralAttributes";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable no-labels */
|
|
2
|
+
/* eslint-disable no-restricted-syntax */
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import { variants , colors, sizes, shapes } from "../constantProps";
|
|
6
|
+
|
|
7
|
+
export const getVariantProps = (variants,exvariant)=>{
|
|
8
|
+
let variant=[];
|
|
9
|
+
if(exvariant){
|
|
10
|
+
variant=[...exvariant]
|
|
11
|
+
}
|
|
12
|
+
variant=[...variant,...variants]
|
|
13
|
+
return(
|
|
14
|
+
{variant:PropTypes.oneOf(variant)}
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const variantProps = {
|
|
19
|
+
|
|
20
|
+
variant : PropTypes.oneOf(variants)
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export const getColorProps = (colors,excolors)=>{
|
|
25
|
+
let color=[];
|
|
26
|
+
if(excolors){
|
|
27
|
+
color=[...excolors]
|
|
28
|
+
}
|
|
29
|
+
color=[...color,...colors]
|
|
30
|
+
return(
|
|
31
|
+
{color:PropTypes.oneOf(color)}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export const colorProps = {
|
|
38
|
+
color : PropTypes.oneOf(colors)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export const getSizeProps = (sizes,exSizes)=>{
|
|
43
|
+
let size=[];
|
|
44
|
+
if(exSizes){
|
|
45
|
+
size=[...exSizes]
|
|
46
|
+
}
|
|
47
|
+
size=[...size,...sizes]
|
|
48
|
+
return(
|
|
49
|
+
{size:PropTypes.oneOf(size)}
|
|
50
|
+
)
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const sizeProps = {
|
|
54
|
+
|
|
55
|
+
size : PropTypes.oneOf(sizes)
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const getShapeProps = (shapes,exshapes)=>{
|
|
59
|
+
let shape=[];
|
|
60
|
+
if(exshapes){
|
|
61
|
+
shape=[...exshapes]
|
|
62
|
+
}
|
|
63
|
+
shape=[...shape,...shapes]
|
|
64
|
+
return(
|
|
65
|
+
{shape:PropTypes.oneOf(shape)}
|
|
66
|
+
)
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const shapeProps = {
|
|
70
|
+
|
|
71
|
+
shape : PropTypes.oneOf(shapes)
|
|
72
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useReducer } from "react";
|
|
2
|
+
export default function useCommonReducer(
|
|
3
|
+
defaultReducer,
|
|
4
|
+
customReducer,
|
|
5
|
+
initialArg,
|
|
6
|
+
init
|
|
7
|
+
) {
|
|
8
|
+
const proxyReducer = (state, action) => {
|
|
9
|
+
let lastState = defaultReducer(state, action);
|
|
10
|
+
|
|
11
|
+
if (customReducer) {
|
|
12
|
+
return customReducer(lastState, action);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return lastState;
|
|
16
|
+
};
|
|
17
|
+
const [state, dispatch] = useReducer(proxyReducer, initialArg, init);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
state,
|
|
21
|
+
dispatch
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default function uniqueNumber(prefix=''){
|
|
2
|
+
//let randomId = (Date.now() + Math.random()).toString(36);
|
|
3
|
+
var date = Date.now();
|
|
4
|
+
|
|
5
|
+
// If created at same millisecond as previous
|
|
6
|
+
if (date <= uniqueNumber.previous) {
|
|
7
|
+
date = ++uniqueNumber.previous;
|
|
8
|
+
} else {
|
|
9
|
+
uniqueNumber.previous = date;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return prefix ? `${prefix}-${date}` : date;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
uniqueNumber.previous = 0;
|
|
16
|
+
|