-
Notifications
You must be signed in to change notification settings - Fork 0
/
cjs.js
49 lines (40 loc) · 1.34 KB
/
cjs.js
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
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = _interopDefault(require('react'));
var clsx = _interopDefault(require('clsx'));
function isFunction(object) {
return Boolean(object && object.constructor && object.call && object.apply)
}
function resolveStyles(props, styles, replacements) {
const resolved = styles.flatMap((s, i) => [
s.replace(/\s+/g, " ").trim(),
replacements[i] && isFunction(replacements[i])
? replacements[i](props)
: replacements[i],
]);
return clsx(resolved, props.className)
}
function filterProps(props, noForward) {
return Object.entries(props).reduce(
(filteredProps, [propName, propValue]) =>
noForward.includes(propName)
? filteredProps
: { ...filteredProps, [propName]: propValue },
{}
)
}
const windsock = (Component, options = {}) => (styles, ...replacements) =>
React.forwardRef((props, ref) =>
React.createElement(Component, {
...(options.noForward ? filterProps(props, options.noForward) : props),
className: resolveStyles(props, styles, replacements),
ref,
})
);
var index = new Proxy(windsock, {
get: (obj, prop) => {
return obj(prop)
},
});
exports.default = index;