-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguinda.react.js
More file actions
52 lines (39 loc) · 1.3 KB
/
guinda.react.js
File metadata and controls
52 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-FileCopyrightText: 2021-2025 Luciano Iam <oss@lucianoiam.com>
// SPDX-License-Identifier: MIT
(() => {
const createElement =
(typeof React !== 'undefined' && typeof React.createElement === 'function') ? React.createElement :
(typeof h === 'function') ? h :
null;
if (! createElement) {
throw new Error('No valid createElement function found');
}
const R = {};
for (const [name, clazz] of Object.entries(window.Guinda)) {
const attributes = clazz._attributes || [];
const defaultProps = {};
let valueParser = null;
for (const attr of attributes) {
if (attr.parser) {
if (attr.key === 'value') {
valueParser = attr.parser;
} else if (attr.key === 'scale') {
// TODO
} else {
defaultProps[attr.key] = attr.default;
}
}
}
const Component = function (props) {
return createElement('g-' + name.toLowerCase(), {
...props,
value: valueParser?.(props.value) ?? props.value
});
};
const className = `${name}Component`;
Component.defaultProps = defaultProps;
Component.displayName = className;
R[className] = Component;
}
window.Guinda.React = R;
})();