import React, { useMemo } from "react";
import PropTypes from "prop-types";
import hoistNonReactStatics from "hoist-non-react-statics";
import * as Grid from "antd/lib/grid";
import Typography from "antd/lib/typography";
import "./control-label.less";
export function ControlLabel({ layout, label, labelProps, disabled, children }) {
if (layout === "vertical" && label) {
return (
{children}
);
}
if (layout === "horizontal" && label) {
return (
{children}
);
}
return children;
}
ControlLabel.propTypes = {
layout: PropTypes.oneOf(["vertical", "horizontal"]),
label: PropTypes.node,
labelProps: PropTypes.object, // eslint-disable-line react/forbid-prop-types
disabled: PropTypes.bool,
children: PropTypes.node,
};
ControlLabel.defaultProps = {
layout: "vertical",
label: null,
disabled: false,
children: null,
};
export default function withControlLabel(WrappedControl) {
// eslint-disable-next-line react/prop-types
function ControlWrapper({ id, layout, label, labelProps, disabled, ...props }) {
const fallbackId = useMemo(
() =>
`visualization-editor-control-${Math.random()
.toString(36)
.substr(2, 10)}`,
[]
);
labelProps = {
...labelProps,
htmlFor: id || fallbackId,
};
return (
);
}
// Copy static methods from `WrappedComponent`
hoistNonReactStatics(ControlWrapper, WrappedControl);
return ControlWrapper;
}