UNPKG

@pnp/spfx-controls-react

Version:

Reusable React controls for SharePoint Framework solutions

51 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WebPartTitle = void 0; var tslib_1 = require("tslib"); var React = tslib_1.__importStar(require("react")); var strings = tslib_1.__importStar(require("ControlStrings")); var sp_core_library_1 = require("@microsoft/sp-core-library"); var WebPartTitle_module_scss_1 = tslib_1.__importDefault(require("./WebPartTitle.module.scss")); var telemetry = tslib_1.__importStar(require("../../common/telemetry")); /** * Web Part Title component */ var WebPartTitle = /** @class */ (function (_super) { tslib_1.__extends(WebPartTitle, _super); /** * Constructor */ function WebPartTitle(props) { var _this = _super.call(this, props) || this; telemetry.track('ReactWebPartTitle', { title: !!props.title, updateProperty: !!props.updateProperty, className: !!props.className }); _this._onChange = _this._onChange.bind(_this); return _this; } /** * Process the text area change */ WebPartTitle.prototype._onChange = function (event) { this.props.updateProperty(event.target.value); }; /** * Default React component render method */ WebPartTitle.prototype.render = function () { var color = (!!this.props.themeVariant && this.props.themeVariant.semanticColors.bodyText) || null; if (this.props.title || this.props.moreLink || this.props.displayMode === sp_core_library_1.DisplayMode.Edit) { return (React.createElement("div", { className: "".concat(WebPartTitle_module_scss_1.default.webPartHeader, " ").concat(this.props.className ? this.props.className : "") }, React.createElement("div", { className: WebPartTitle_module_scss_1.default.webPartTitle, style: { color: color } }, this.props.displayMode === sp_core_library_1.DisplayMode.Edit && (React.createElement("textarea", { placeholder: this.props.placeholder ? this.props.placeholder : strings.WebPartTitlePlaceholder, "aria-label": strings.WebPartTitleLabel, onChange: this._onChange, defaultValue: this.props.title })), this.props.displayMode !== sp_core_library_1.DisplayMode.Edit && this.props.title && React.createElement("span", { role: "heading", "aria-level": 2 }, this.props.title)), this.props.moreLink && (React.createElement("span", { className: WebPartTitle_module_scss_1.default.moreLink }, typeof this.props.moreLink === "function" ? this.props.moreLink() : this.props.moreLink)))); } return null; }; return WebPartTitle; }(React.Component)); exports.WebPartTitle = WebPartTitle; //# sourceMappingURL=WebPartTitle.js.map