UNPKG

@fluentui/react-northstar

Version:
143 lines (140 loc) 6.15 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.alertDismissActionSlotClassNames = exports.alertDismissActionClassName = exports.AlertDismissAction = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _invoke2 = _interopRequireDefault(require("lodash/invoke")); var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty")); var _accessibility = require("@fluentui/accessibility"); var PropTypes = _interopRequireWildcard(require("prop-types")); var React = _interopRequireWildcard(require("react")); var _utils = require("../../utils"); var _reactBindings = require("@fluentui/react-bindings"); var _Box = require("../Box/Box"); 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 alertDismissActionClassName = 'ui-alert__dismissaction'; exports.alertDismissActionClassName = alertDismissActionClassName; var alertDismissActionSlotClassNames = { content: alertDismissActionClassName + "__content" }; /** * A AlertDismissAction allows users to customize the dismissAction slot inside the Alert component. * * @accessibility * Implements [ARIA Button](https://www.w3.org/TR/wai-aria-practices-1.1/#button) design pattern. */ exports.alertDismissActionSlotClassNames = alertDismissActionSlotClassNames; var AlertDismissAction = /*#__PURE__*/React.forwardRef(function (props, ref) { var context = (0, _reactBindings.useFluentContext)(); var _useTelemetry = (0, _reactBindings.useTelemetry)(AlertDismissAction.displayName, context.telemetry), setStart = _useTelemetry.setStart, setEnd = _useTelemetry.setEnd; setStart(); var accessibility = props.accessibility, as = props.as, children = props.children, className = props.className, content = props.content, disabled = props.disabled, design = props.design, styles = props.styles, variables = props.variables, danger = props.danger, warning = props.warning, info = props.info, success = props.success; var hasChildren = (0, _utils.childrenExist)(children); var hasContent = !!content && !(0, _isEmpty2.default)(content); var getA11Props = (0, _reactBindings.useAccessibility)(accessibility, { debugName: AlertDismissAction.displayName, mapPropsToBehavior: function mapPropsToBehavior() { return { as: String(as), disabled: disabled }; }, actionHandlers: { performClick: function performClick(event) { event.preventDefault(); handleClick(event); } }, rtl: context.rtl }); var _useStyles = (0, _reactBindings.useStyles)(AlertDismissAction.displayName, { className: alertDismissActionClassName, mapPropsToStyles: function mapPropsToStyles() { return { disabled: disabled, danger: danger, warning: warning, info: info, success: success, hasContent: hasContent || hasChildren }; }, mapPropsToInlineStyles: function mapPropsToInlineStyles() { return { className: className, design: design, styles: styles, variables: variables }; }, rtl: context.rtl }), classes = _useStyles.classes, resolvedStyles = _useStyles.styles; var unhandledProps = (0, _reactBindings.useUnhandledProps)(AlertDismissAction.handledProps, props); var ElementType = (0, _reactBindings.getElementType)(props); var handleClick = function handleClick(e) { if (disabled) { e.preventDefault(); return; } (0, _invoke2.default)(props, 'onClick', e, props); }; var result = /*#__PURE__*/React.createElement(ElementType, (0, _extends2.default)({}, _utils.rtlTextContainer.getAttributes({ forElements: [children] }), getA11Props('root', Object.assign({ onClick: handleClick, disabled: disabled, className: classes.root }, unhandledProps, { ref: ref }))), hasChildren ? children : _Box.Box.create(content, { defaultProps: function defaultProps() { return getA11Props('content', { as: 'span', className: alertDismissActionSlotClassNames.content, styles: resolvedStyles.content }); } })); setEnd(); return result; }); exports.AlertDismissAction = AlertDismissAction; AlertDismissAction.defaultProps = { as: 'button', accessibility: _accessibility.buttonBehavior, content: {} }; AlertDismissAction.displayName = 'AlertDismissAction'; AlertDismissAction.propTypes = Object.assign({}, _utils.commonPropTypes.createCommon({ content: 'shorthand' }), { disabled: PropTypes.bool, danger: PropTypes.bool, warning: PropTypes.bool, info: PropTypes.bool, onClick: PropTypes.func, success: PropTypes.bool }); AlertDismissAction.handledProps = Object.keys(AlertDismissAction.propTypes); AlertDismissAction.create = (0, _utils.createShorthandFactory)({ Component: AlertDismissAction, mappedProp: 'content' }); //# sourceMappingURL=AlertDismissAction.js.map