@progress/kendo-themes-html 4.41.3-dev.2
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.md +17 -0
- package/lib/jsx-runtime.js +112 -0
- package/package.json +46 -0
- package/src/button.jsx +114 -0
- package/src/component.js +43 -0
- package/src/icon.jsx +37 -0
- package/src/index.js +20 -0
- package/utils/object.js +28 -0
- package/utils/styles.js +101 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Kendo UI Themes HTML Helpers
|
|
2
|
+
|
|
3
|
+
This package is part of the following suites:
|
|
4
|
+
|
|
5
|
+
* [Kendo UI for Angular](http://www.telerik.com/kendo-angular-ui/)
|
|
6
|
+
* [KendoReact](http://www.telerik.com/kendo-react-ui/)
|
|
7
|
+
* [Kendo UI for jQuery](http://www.telerik.com/kendo-ui)
|
|
8
|
+
* [UI for ASP.NET MVC](http://www.telerik.com/aspnet-mvc)
|
|
9
|
+
* [UI for ASP.NET Core](http://www.telerik.com/aspnet-core-ui)
|
|
10
|
+
|
|
11
|
+
## License
|
|
12
|
+
|
|
13
|
+
All available Kendo UI commercial licenses may be obtained at http://www.telerik.com/purchase/kendo-ui.
|
|
14
|
+
|
|
15
|
+
If you do not own a commercial license, the usage of this software shall be governed by the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
|
|
16
|
+
|
|
17
|
+
*Copyright © 2020 Progress Software Corporation and/or one of its subsidiaries or affiliates. All rights reserved.*
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { isFunction, isArray, isObject } from '../utils/object';
|
|
2
|
+
import { classNames } from '../utils/styles';
|
|
3
|
+
|
|
4
|
+
const JSX_FRAGMENT = '#fragment';
|
|
5
|
+
const JSX_TEXT = '#text';
|
|
6
|
+
|
|
7
|
+
const attrMap = {
|
|
8
|
+
'class': 'className',
|
|
9
|
+
themecolor: 'themeColor',
|
|
10
|
+
fillmode: 'fillMode'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function attrToProps( element ) {
|
|
14
|
+
let attributes = element.attributes;
|
|
15
|
+
let props = {};
|
|
16
|
+
|
|
17
|
+
Array.from(attributes).forEach((attrObj) => {
|
|
18
|
+
let attrName = attrObj.name;
|
|
19
|
+
|
|
20
|
+
if (attrMap[attrName]) {
|
|
21
|
+
attrName = attrMap[attrName];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
props[ attrName ] = attrObj.value;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return props;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function jsx( type, config ) {
|
|
31
|
+
|
|
32
|
+
if ( isFunction( type ) ) {
|
|
33
|
+
return type( { ...type.defaultProps, ...config } );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let { children = [], ...props } = config;
|
|
37
|
+
|
|
38
|
+
if (!isArray( children) ) {
|
|
39
|
+
children = [ children ];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
children.forEach( ( child, index ) => {
|
|
43
|
+
if ( !isObject( child ) ) {
|
|
44
|
+
children[index] = {
|
|
45
|
+
type: JSX_TEXT,
|
|
46
|
+
props: {
|
|
47
|
+
text: child
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
type,
|
|
55
|
+
props: {
|
|
56
|
+
...props,
|
|
57
|
+
children
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function jsxs( type, config ) {
|
|
63
|
+
return jsx( type, config );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function renderDOM( jsxNode, container = null ) {
|
|
67
|
+
|
|
68
|
+
const nodeType = jsxNode.type;
|
|
69
|
+
const { children = [], ...props } = jsxNode.props;
|
|
70
|
+
let element;
|
|
71
|
+
let textNode;
|
|
72
|
+
|
|
73
|
+
if ( nodeType === JSX_TEXT ) {
|
|
74
|
+
textNode = document.createTextNode( props.text || '' );
|
|
75
|
+
|
|
76
|
+
if ( container !== null ) {
|
|
77
|
+
container.appendChild( textNode );
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return textNode;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if ( nodeType === JSX_FRAGMENT ) {
|
|
84
|
+
element = document.createDocumentFragment();
|
|
85
|
+
} else {
|
|
86
|
+
element = document.createElement(nodeType);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
props.className = classNames( props.className );
|
|
90
|
+
|
|
91
|
+
for (let [ attr, val ] of Object.entries(props)) {
|
|
92
|
+
element[attr] = val;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
children.forEach( child => {
|
|
96
|
+
renderDOM( child, element );
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if ( container !== null ) {
|
|
100
|
+
container.appendChild( element );
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return element;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
jsx,
|
|
108
|
+
jsxs,
|
|
109
|
+
JSX_FRAGMENT as Fragment,
|
|
110
|
+
renderDOM,
|
|
111
|
+
attrToProps
|
|
112
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@progress/kendo-themes-html",
|
|
3
|
+
"description": "A collection of HTML helpers used for developing Kendo UI themes",
|
|
4
|
+
"version": "4.41.3-dev.2",
|
|
5
|
+
"author": "Progress",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"Kendo UI",
|
|
9
|
+
"Theme",
|
|
10
|
+
"HTML",
|
|
11
|
+
"Helpers"
|
|
12
|
+
],
|
|
13
|
+
"main": "index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/",
|
|
16
|
+
"src/",
|
|
17
|
+
"lib/",
|
|
18
|
+
"utils/"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://github.com/telerik/kendo-themes/tree/master/packages/html",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/telerik/kendo-themes.git",
|
|
24
|
+
"directory": "packages/html"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/telerik/kendo-themes/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "rollup -c",
|
|
34
|
+
"dev": "rollup -cw"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@babel/core": "^7.15.5",
|
|
38
|
+
"@babel/preset-env": "^7.15.6",
|
|
39
|
+
"@babel/preset-react": "^7.14.5",
|
|
40
|
+
"@rollup/plugin-babel": "^5.3.0",
|
|
41
|
+
"@rollup/plugin-commonjs": "^20.0.0",
|
|
42
|
+
"@rollup/plugin-node-resolve": "^13.0.5",
|
|
43
|
+
"rollup": "^2.57.0"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "dac8c87fd7d383c2f551aad1075492fe8422b173"
|
|
46
|
+
}
|
package/src/button.jsx
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as styles from '../utils/styles';
|
|
2
|
+
import { Component } from './component';
|
|
3
|
+
import { IconStatic } from './icon.jsx';
|
|
4
|
+
|
|
5
|
+
class Button extends Component {
|
|
6
|
+
|
|
7
|
+
init() {
|
|
8
|
+
this._props.text = this.element.innerHTML;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
render() {
|
|
12
|
+
return <ButtonStatic {...this.props} />;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function ButtonStatic(props) {
|
|
17
|
+
const {
|
|
18
|
+
text,
|
|
19
|
+
className: ownClassName,
|
|
20
|
+
type,
|
|
21
|
+
|
|
22
|
+
size,
|
|
23
|
+
rounded,
|
|
24
|
+
shape,
|
|
25
|
+
|
|
26
|
+
fillMode,
|
|
27
|
+
themeColor,
|
|
28
|
+
|
|
29
|
+
icon,
|
|
30
|
+
|
|
31
|
+
aria,
|
|
32
|
+
legacy
|
|
33
|
+
} = props;
|
|
34
|
+
|
|
35
|
+
let buttonClasses = [
|
|
36
|
+
ownClassName,
|
|
37
|
+
'k-button',
|
|
38
|
+
styles.sizeClass( size, 'k-button' ),
|
|
39
|
+
styles.roundedClass( rounded ),
|
|
40
|
+
styles.shapeClass( shape, 'k-button' ),
|
|
41
|
+
styles.fillModeClass( fillMode, 'k-button' ),
|
|
42
|
+
styles.themeColorClass( fillMode, themeColor, 'k-button' )
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
let legacyClasses = [
|
|
46
|
+
ownClassName,
|
|
47
|
+
'k-button',
|
|
48
|
+
{
|
|
49
|
+
'k-primary': themeColor === 'primary',
|
|
50
|
+
'k-flat': fillMode === 'flat',
|
|
51
|
+
'k-outline': fillMode === 'outline'
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
let ariaAttr = aria
|
|
56
|
+
? {}
|
|
57
|
+
: {};
|
|
58
|
+
|
|
59
|
+
if (legacy) {
|
|
60
|
+
return (
|
|
61
|
+
<button type={type} className={legacyClasses} {...ariaAttr}>
|
|
62
|
+
<IconStatic name={icon} />
|
|
63
|
+
{ text }
|
|
64
|
+
</button>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<button type={type} className={buttonClasses} {...ariaAttr}>
|
|
70
|
+
<IconStatic className="k-button-icon" name={icon} />
|
|
71
|
+
<span className="k-button-text">{ text }</span>
|
|
72
|
+
</button>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
ButtonStatic.defaultProps = {
|
|
77
|
+
text: '',
|
|
78
|
+
icon: '',
|
|
79
|
+
|
|
80
|
+
className: '',
|
|
81
|
+
type: 'button',
|
|
82
|
+
|
|
83
|
+
size: 'medium',
|
|
84
|
+
rounded: 'medium',
|
|
85
|
+
shape: 'rectangle',
|
|
86
|
+
|
|
87
|
+
fillMode: 'solid',
|
|
88
|
+
themeColor: 'base',
|
|
89
|
+
|
|
90
|
+
aria: false,
|
|
91
|
+
legacy: false
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
ButtonStatic.propTypes = {
|
|
95
|
+
text: typeof '',
|
|
96
|
+
icon: typeof '',
|
|
97
|
+
|
|
98
|
+
className: typeof '',
|
|
99
|
+
type: typeof [ 'button', 'submit', 'reset' ],
|
|
100
|
+
|
|
101
|
+
size: typeof [ 'none', 'small', 'medium', 'large' ],
|
|
102
|
+
rounded: typeof [ 'none', '0', 'small', 'medium', 'large', 'pill', 'circle' ],
|
|
103
|
+
shape: typeof [ 'none', 'rectangle', 'square' ],
|
|
104
|
+
|
|
105
|
+
fillMode: typeof [ 'none', 'solid', 'flat', 'outline' ],
|
|
106
|
+
themeColor: typeof [ 'none', 'surface', 'base', 'primary' ],
|
|
107
|
+
|
|
108
|
+
aria: typeof false,
|
|
109
|
+
legacy: typeof false,
|
|
110
|
+
|
|
111
|
+
htmlAttributes: typeof []
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { Button, ButtonStatic };
|
package/src/component.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isFunction } from '../utils/object';
|
|
2
|
+
import { renderDOM, attrToProps } from '../lib/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
const globalDefaultProps = {
|
|
5
|
+
legacy: true,
|
|
6
|
+
|
|
7
|
+
aria: false,
|
|
8
|
+
disabled: false,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
class Component {
|
|
12
|
+
|
|
13
|
+
get element() {
|
|
14
|
+
return this._element;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get props() {
|
|
18
|
+
return this._props;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor( element ) {
|
|
22
|
+
|
|
23
|
+
this._element = element;
|
|
24
|
+
this._props = { ...globalDefaultProps, ...attrToProps( element ) };
|
|
25
|
+
|
|
26
|
+
delete this._props.is;
|
|
27
|
+
|
|
28
|
+
if (isFunction( this.init )) {
|
|
29
|
+
this.init();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (isFunction( this.render )) {
|
|
33
|
+
let htmlObj = this.render();
|
|
34
|
+
let htmlFragment = renderDOM(htmlObj);
|
|
35
|
+
let html = htmlFragment.outerHTML;
|
|
36
|
+
|
|
37
|
+
this.element.outerHTML = html;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { Component };
|
package/src/icon.jsx
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Component } from './component';
|
|
2
|
+
|
|
3
|
+
class Icon extends Component {
|
|
4
|
+
render() {
|
|
5
|
+
return <IconStatic {...this.props} />;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function IconStatic(props) {
|
|
10
|
+
const {
|
|
11
|
+
name,
|
|
12
|
+
className: ownClassName
|
|
13
|
+
} = props;
|
|
14
|
+
|
|
15
|
+
let iconClassName = [
|
|
16
|
+
ownClassName,
|
|
17
|
+
'k-icon',
|
|
18
|
+
`k-i-${name}`
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<>
|
|
23
|
+
{ name && <span className={iconClassName}></span> }
|
|
24
|
+
</>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
IconStatic.defaultProps = {
|
|
29
|
+
name: '',
|
|
30
|
+
className: ''
|
|
31
|
+
};
|
|
32
|
+
IconStatic.propTypes = {
|
|
33
|
+
name: typeof '',
|
|
34
|
+
className: typeof ''
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { Icon, IconStatic };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable no-new */
|
|
2
|
+
/* global kendo */
|
|
3
|
+
import { isFunction } from '../utils/object';
|
|
4
|
+
import { Button } from './button.jsx';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
Button
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
window.addEventListener('DOMContentLoaded', () => {
|
|
12
|
+
document.querySelectorAll('[is]').forEach( element => {
|
|
13
|
+
const componentName = element.getAttribute('is');
|
|
14
|
+
const component = kendo.Html[componentName];
|
|
15
|
+
|
|
16
|
+
if (isFunction( component )) {
|
|
17
|
+
new component( element );
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
package/utils/object.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function isString( obj ) {
|
|
2
|
+
return typeof obj === 'string';
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function isFunction( obj ) {
|
|
6
|
+
return typeof obj === 'function';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isElement( obj ) {
|
|
10
|
+
return obj instanceof HTMLElement;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isArray( obj ) {
|
|
14
|
+
return Array.isArray( obj );
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isObject( obj ) {
|
|
18
|
+
return typeof obj === 'object';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
isString,
|
|
24
|
+
isFunction,
|
|
25
|
+
isElement,
|
|
26
|
+
isArray,
|
|
27
|
+
isObject
|
|
28
|
+
};
|
package/utils/styles.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isString, isObject } from './object';
|
|
2
|
+
|
|
3
|
+
const SPACE = ' ';
|
|
4
|
+
|
|
5
|
+
const sizeMap = {
|
|
6
|
+
'small': 'sm',
|
|
7
|
+
'medium': 'md',
|
|
8
|
+
'large': 'lg'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const roundedMap = {
|
|
12
|
+
'small': 'sm',
|
|
13
|
+
'medium': 'md',
|
|
14
|
+
'large': 'lg'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function lookup( map, key ) {
|
|
18
|
+
let result = map[key];
|
|
19
|
+
|
|
20
|
+
if (result) {
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return key;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sizeClass( size, prefix ) {
|
|
28
|
+
if ( size === 'none' ) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return `${prefix}-${lookup(sizeMap, size)}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function roundedClass( rounded ) {
|
|
36
|
+
if ( rounded === 'none' ) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return `k-rounded-${lookup(roundedMap, rounded)}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function shapeClass( shape, prefix ) {
|
|
44
|
+
if ( shape === 'none' ) {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return `${prefix}-${shape}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function fillModeClass( fill, prefix ) {
|
|
52
|
+
if ( fill === 'none' ) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return `${prefix}-${fill}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function themeColorClass( fill, color, prefix ) {
|
|
60
|
+
if ( fill === 'none' || color === 'none' ) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return `${prefix}-${fill}-${color}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function classNames( ...args ) {
|
|
68
|
+
|
|
69
|
+
/* eslint-disable arrow-body-style, no-nested-ternary */
|
|
70
|
+
let result = new Set();
|
|
71
|
+
let temp = args.flat().filter( arg => arg !== true && Boolean( arg ) );
|
|
72
|
+
|
|
73
|
+
temp.forEach( className => {
|
|
74
|
+
if ( isString( className ) ) {
|
|
75
|
+
className.split( SPACE ).forEach( part => result.add( part ) );
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if ( isObject( className ) ) {
|
|
80
|
+
for (let [ key, val ] of Object.entries( className )) {
|
|
81
|
+
if (val === true) {
|
|
82
|
+
key.split( SPACE ).forEach( part => result.add( part ) );
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return [ ...result ].join( SPACE );
|
|
89
|
+
/* eslint-enable */
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
sizeClass,
|
|
95
|
+
roundedClass,
|
|
96
|
+
shapeClass,
|
|
97
|
+
fillModeClass,
|
|
98
|
+
themeColorClass,
|
|
99
|
+
|
|
100
|
+
classNames
|
|
101
|
+
};
|