@wix/design-system
Version:
@wix/design-system
16 lines • 808 B
JavaScript
import React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { useDefaultProps } from './useDefaultProps';
export function withDefaultProps(Wrapped, componentKey) {
const Component = Wrapped;
const WithDefaultProps = React.forwardRef((props, ref) => {
const resolvedProps = useDefaultProps(componentKey, props);
return React.createElement(Component, { ref: ref, ...resolvedProps });
});
WithDefaultProps.displayName =
Wrapped.displayName || Wrapped.name || componentKey;
// Copy static members (e.g. compound subcomponents like SidePanel.Header)
// and preserve them in the return type so `SidePanel.Header` stays typed.
return hoistNonReactStatics(WithDefaultProps, Wrapped);
}
//# sourceMappingURL=withDefaultProps.js.map