DocSpace-client/packages/shared/components/field-container/index.tsx

196 lines
8.5 KiB
TypeScript
Raw Normal View History

import React from "react";
import PropTypes from "prop-types";
import Label from "../label";
import HelpButton from "../help-button";
import Text from "../text";
import Container from "./styled-field-container";
const displayInlineBlock = { display: "inline-block" };
class FieldContainer extends React.Component {
2023-11-27 06:58:19 +00:00
constructor(props: any) {
super(props);
}
render() {
const {
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'isVertical' does not exist on type 'Read... Remove this comment to see the full error message
isVertical,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'className' does not exist on type 'Reado... Remove this comment to see the full error message
className,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'id' does not exist on type 'Readonly<{}>... Remove this comment to see the full error message
id,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'style' does not exist on type 'Readonly<... Remove this comment to see the full error message
style,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'isRequired' does not exist on type 'Read... Remove this comment to see the full error message
isRequired,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'hasError' does not exist on type 'Readon... Remove this comment to see the full error message
hasError,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'labelVisible' does not exist on type 'Re... Remove this comment to see the full error message
2020-07-16 12:44:15 +00:00
labelVisible,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'labelText' does not exist on type 'Reado... Remove this comment to see the full error message
labelText,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'children' does not exist on type 'Readon... Remove this comment to see the full error message
children,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'tooltipContent' does not exist on type '... Remove this comment to see the full error message
tooltipContent,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'place' does not exist on type 'Readonly<... Remove this comment to see the full error message
place,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'helpButtonHeaderContent' does not exist ... Remove this comment to see the full error message
helpButtonHeaderContent,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'maxLabelWidth' does not exist on type 'R... Remove this comment to see the full error message
maxLabelWidth,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'errorMessage' does not exist on type 'Re... Remove this comment to see the full error message
errorMessage,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'errorColor' does not exist on type 'Read... Remove this comment to see the full error message
errorColor,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'errorMessageWidth' does not exist on typ... Remove this comment to see the full error message
errorMessageWidth,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'inlineHelpButton' does not exist on type... Remove this comment to see the full error message
inlineHelpButton,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'offsetRight' does not exist on type 'Rea... Remove this comment to see the full error message
2022-04-27 09:25:05 +00:00
offsetRight,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'tooltipMaxWidth' does not exist on type ... Remove this comment to see the full error message
2022-04-27 09:25:05 +00:00
tooltipMaxWidth,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'tooltipClass' does not exist on type 'Re... Remove this comment to see the full error message
tooltipClass,
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'removeMargin' does not exist on type 'Re... Remove this comment to see the full error message
removeMargin,
} = this.props;
return (
<Container
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2769): No overload matches this call.
vertical={isVertical}
maxLabelWidth={maxLabelWidth}
className={className}
id={id}
style={style}
maxwidth={errorMessageWidth}
removeMargin={removeMargin}
>
{labelVisible &&
(!inlineHelpButton ? (
<div className="field-label-icon">
<Label
isRequired={isRequired}
//error={hasError}
text={labelText}
truncate={true}
className="field-label"
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2322): Type '{ isRequired: any; text: any; truncate: true... Remove this comment to see the full error message
2022-04-27 09:25:05 +00:00
tooltipMaxWidth={tooltipMaxWidth}
2020-07-16 12:44:15 +00:00
/>
{tooltipContent && (
<HelpButton
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2322): Type '{ className: any; tooltipContent: any; place... Remove this comment to see the full error message
className={tooltipClass}
tooltipContent={tooltipContent}
place={place}
helpButtonHeaderContent={helpButtonHeaderContent}
/>
)}
</div>
) : (
<div className="field-label-icon">
<Label
isRequired={isRequired}
//error={hasError}
text={labelText}
truncate={true}
className="field-label"
>
{tooltipContent && (
<HelpButton
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2322): Type '{ className: any; tooltipContent: any; place... Remove this comment to see the full error message
className={tooltipClass}
tooltipContent={tooltipContent}
place={place}
helpButtonHeaderContent={helpButtonHeaderContent}
style={displayInlineBlock}
offsetRight={0}
/>
)}
</Label>
</div>
))}
<div className="field-body">
{children}
{hasError ? (
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2322): Type '{ children: any; className: string; fontSize... Remove this comment to see the full error message
<Text className="error-label" fontSize="12px" color={errorColor}>
{errorMessage}
</Text>
) : null}
</div>
</Container>
);
}
}
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'displayName' does not exist on type 'typ... Remove this comment to see the full error message
FieldContainer.displayName = "FieldContainer";
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'propTypes' does not exist on type 'typeo... Remove this comment to see the full error message
FieldContainer.propTypes = {
/** Vertical or horizontal alignment */
isVertical: PropTypes.bool,
/** Remove default margin property */
removeMargin: PropTypes.bool,
/** Accepts class */
className: PropTypes.string,
/** Indicates that the field is required to fill */
isRequired: PropTypes.bool,
/** Indicates that the field is incorrect */
hasError: PropTypes.bool,
/** Sets visibility of the field label section */
2020-07-16 12:44:15 +00:00
labelVisible: PropTypes.bool,
/** Field label text or element */
labelText: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
/** Icon source */
icon: PropTypes.string,
/** Renders the help button inline instead of the separate div*/
inlineHelpButton: PropTypes.bool,
/** Children elements */
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
/** Tooltip content */
tooltipContent: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
/** Sets the global position of the tooltip */
place: PropTypes.string,
/** Tooltip header content (tooltip opened in aside) */
helpButtonHeaderContent: PropTypes.string,
/** Max label width in horizontal alignment */
maxLabelWidth: PropTypes.string,
/** Error message text */
errorMessage: PropTypes.string,
/** Error text color */
errorColor: PropTypes.string,
/** Error text width */
errorMessageWidth: PropTypes.string,
/** Accepts id */
id: PropTypes.string,
/** Accepts css style */
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
/** Specifies the offset */
2022-04-27 09:25:05 +00:00
offsetRight: PropTypes.number,
/** Sets the maximum width of the tooltip */
2022-04-27 09:25:05 +00:00
tooltipMaxWidth: PropTypes.string,
};
2023-11-27 06:58:19 +00:00
// @ts-expect-error TS(2339): Property 'defaultProps' does not exist on type 'ty... Remove this comment to see the full error message
FieldContainer.defaultProps = {
place: "bottom",
2020-07-16 12:44:15 +00:00
labelVisible: true,
maxLabelWidth: "110px",
errorMessageWidth: "293px",
2022-04-27 09:25:05 +00:00
offsetRight: 0,
removeMargin: false,
};
export default FieldContainer;