UNPKG

@fluentui/react-northstar

Version:
113 lines (110 loc) 4.76 kB
"use strict"; exports.__esModule = true; exports.textClassName = exports.Text = void 0; var customPropTypes = _interopRequireWildcard(require("@fluentui/react-proptypes")); var PropTypes = _interopRequireWildcard(require("prop-types")); var React = _interopRequireWildcard(require("react")); var _utils = require("../../utils"); var _reactBindings = require("@fluentui/react-bindings"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var textClassName = 'ui-text'; /** * A Text consistently styles and formats occurrences of text. */ exports.textClassName = textClassName; var Text = /*#__PURE__*/React.forwardRef(function (props, ref) { var context = (0, _reactBindings.useFluentContext)(); var _useTelemetry = (0, _reactBindings.useTelemetry)(Text.displayName, context.telemetry), setStart = _useTelemetry.setStart, setEnd = _useTelemetry.setEnd; setStart(); var accessibility = props.accessibility, align = props.align, atMention = props.atMention, children = props.children, className = props.className, color = props.color, content = props.content, design = props.design, disabled = props.disabled, error = props.error, important = props.important, size = props.size, styles = props.styles, success = props.success, timestamp = props.timestamp, truncated = props.truncated, temporary = props.temporary, variables = props.variables, weight = props.weight; var getA11Props = (0, _reactBindings.useAccessibility)(accessibility, { debugName: Text.displayName, rtl: context.rtl }); var _useStyles = (0, _reactBindings.useStyles)(Text.displayName, { className: textClassName, mapPropsToStyles: function mapPropsToStyles() { return { atMention: atMention, color: color, important: important, timestamp: timestamp, truncated: truncated, disabled: disabled, error: error, success: success, temporary: temporary, align: align, weight: weight, size: size }; }, mapPropsToInlineStyles: function mapPropsToInlineStyles() { return { className: className, design: design, styles: styles, variables: variables }; }, rtl: context.rtl }), classes = _useStyles.classes; var unhandledProps = (0, _reactBindings.useUnhandledProps)(Text.handledProps, props); var ElementType = (0, _reactBindings.getElementType)(props); var element = /*#__PURE__*/React.createElement(ElementType, getA11Props('root', Object.assign({ className: classes.root, ref: ref }, _utils.rtlTextContainer.getAttributes({ forElements: [children, content] }), unhandledProps)), (0, _utils.childrenExist)(children) ? children : content); setEnd(); return element; }); exports.Text = Text; Text.displayName = 'Text'; Text.defaultProps = { as: 'span' }; Text.propTypes = Object.assign({}, _utils.commonPropTypes.createCommon({ color: true }), { atMention: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['me'])]), disabled: PropTypes.bool, error: PropTypes.bool, important: PropTypes.bool, size: customPropTypes.size, weight: PropTypes.oneOf(['light', 'semilight', 'regular', 'semibold', 'bold']), success: PropTypes.bool, temporary: PropTypes.bool, align: customPropTypes.align, timestamp: PropTypes.bool, truncated: PropTypes.bool }); Text.handledProps = Object.keys(Text.propTypes); Text.create = (0, _utils.createShorthandFactory)({ Component: Text, mappedProp: 'content' }); //# sourceMappingURL=Text.js.map