@fluentui/react-northstar
Version:
A themable React component library.
59 lines (57 loc) • 2.38 kB
JavaScript
import _keys from "lodash/keys";
import { useFluentContext } from '@fluentui/react-bindings';
import * as React from 'react';
import { renderComponent } from './renderComponent';
import { createShorthandFactory } from './factories';
export var createComponentInternal = function createComponentInternal(_ref) {
var _ref$displayName = _ref.displayName,
displayName = _ref$displayName === void 0 ? 'FluentUIComponent' : _ref$displayName,
_ref$className = _ref.className,
className = _ref$className === void 0 ? 'fluent-ui-component' : _ref$className,
_ref$shorthandPropNam = _ref.shorthandPropName,
shorthandPropName = _ref$shorthandPropNam === void 0 ? 'children' : _ref$shorthandPropNam,
_ref$defaultProps = _ref.defaultProps,
defaultProps = _ref$defaultProps === void 0 ? {} : _ref$defaultProps,
_ref$handledProps = _ref.handledProps,
handledProps = _ref$handledProps === void 0 ? [] : _ref$handledProps,
propTypes = _ref.propTypes,
actionHandlers = _ref.actionHandlers,
_render = _ref.render;
var mergedDefaultProps = Object.assign({
as: 'div'
}, defaultProps);
var FluentComponent = function FluentComponent(props) {
// Stores debug information for component.
// Note that this ref should go as the first one, to be discoverable by debug utils.
var ref = React.useRef(null);
var context = useFluentContext();
var isFirstRenderRef = React.useRef(true);
return renderComponent({
className: className,
displayName: displayName,
handledProps: _keys(propTypes).concat(handledProps),
props: props,
state: {},
actionHandlers: actionHandlers,
render: function render(config) {
return _render(config, props);
},
saveDebug: function saveDebug(fluentUIDebug) {
return ref.current = {
fluentUIDebug: fluentUIDebug
};
},
isFirstRenderRef: isFirstRenderRef
}, context);
};
FluentComponent.deprecated_className = className;
FluentComponent.create = createShorthandFactory({
Component: mergedDefaultProps.as,
mappedProp: shorthandPropName
});
FluentComponent.displayName = displayName;
FluentComponent.propTypes = propTypes; // TODO: generate prop types
FluentComponent.defaultProps = mergedDefaultProps;
return FluentComponent;
};
//# sourceMappingURL=createComponentInternal.js.map