@pdftron/webviewer-react-toolkit
Version:
A React component library for integrating with PDFTron WebViewer API.
16 lines (15 loc) • 1.16 kB
JavaScript
import { __assign, __rest } from "tslib";
import classnames from 'classnames';
import React, { cloneElement } from 'react';
import { useID } from '../../hooks/useID';
export var Label = function (_a) {
var label = _a.label, optionalText = _a.optionalText, children = _a.children, className = _a.className, htmlFor = _a.htmlFor, props = __rest(_a, ["label", "optionalText", "children", "className", "htmlFor"]);
var childrenId = children === null || children === void 0 ? void 0 : children.props.id;
var id = useID(childrenId);
var labelClass = classnames('ui__base ui__label', { 'ui__label--disabled': children === null || children === void 0 ? void 0 : children.props.disabled, 'ui__label--attached': children }, className);
return (React.createElement(React.Fragment, null,
React.createElement("label", __assign({}, props, { className: labelClass, htmlFor: htmlFor !== null && htmlFor !== void 0 ? htmlFor : id }),
label,
optionalText ? React.createElement("span", { className: "ui__label__optional" }, optionalText) : undefined),
children ? cloneElement(children, { id: id }) : undefined));
};