UNPKG

@zag-js/solid

Version:

The solid.js wrapper for zag

40 lines (39 loc) 1.25 kB
// src/merge-props.ts import { mergeProps as zagMergeProps } from "@zag-js/core"; function mergeProps(...sources) { const target = {}; for (let i = 0; i < sources.length; i++) { let source = sources[i]; if (typeof source === "function") source = source(); if (source) { const descriptors = Object.getOwnPropertyDescriptors(source); for (const key in descriptors) { if (key in target) continue; Object.defineProperty(target, key, { enumerable: true, get() { let e = {}; if (key === "style" || key === "class" || key === "className" || key.startsWith("on")) { for (let i2 = 0; i2 < sources.length; i2++) { let s = sources[i2]; if (typeof s === "function") s = s(); e = zagMergeProps(e, { [key]: (s || {})[key] }); } return e[key]; } for (let i2 = sources.length - 1; i2 >= 0; i2--) { let v, s = sources[i2]; if (typeof s === "function") s = s(); v = (s || {})[key]; if (v !== void 0) return v; } } }); } } } return target; } export { mergeProps };