@fluentui/react-northstar
Version:
A themable React component library.
102 lines (99 loc) • 4.63 kB
JavaScript
exports.__esModule = true;
exports.imageClassName = exports.Image = void 0;
var _accessibility = require("@fluentui/accessibility");
var _reactBindings = require("@fluentui/react-bindings");
var PropTypes = _interopRequireWildcard(require("prop-types"));
var React = _interopRequireWildcard(require("react"));
var _utils = require("../../utils");
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 imageClassName = 'ui-image';
/**
* An Image is a graphic representation of something.
*
* @accessibility
* If image should be visible to screen readers, textual representation needs to be provided in 'alt' property.
*
* Other considerations:
* - when alt property is empty, then Narrator in scan mode navigates to image and narrates it as empty paragraph.
* - when image has role='presentation' then screen readers navigate to the element in scan/virtual mode. To avoid this, the attribute "aria-hidden='true'" is applied by the default image behavior.
* - when alt property is used in combination with aria-label, arialabbeledby or title, additional screen readers verification is needed as each screen reader handles this combination differently.
*/
exports.imageClassName = imageClassName;
var Image = /*#__PURE__*/React.forwardRef(function (props, ref) {
var context = (0, _reactBindings.useFluentContext)();
var _useTelemetry = (0, _reactBindings.useTelemetry)(Image.displayName, context.telemetry),
setStart = _useTelemetry.setStart,
setEnd = _useTelemetry.setEnd;
setStart();
var accessibility = props.accessibility,
alt = props.alt,
ariaLabel = props['aria-label'],
avatar = props.avatar,
circular = props.circular,
className = props.className,
design = props.design,
fluid = props.fluid,
styles = props.styles,
variables = props.variables;
var getA11Props = (0, _reactBindings.useAccessibility)(accessibility, {
debugName: Image.displayName,
mapPropsToBehavior: function mapPropsToBehavior() {
return {
alt: alt,
'aria-label': ariaLabel
};
},
rtl: context.rtl
});
var _useStyles = (0, _reactBindings.useStyles)(Image.displayName, {
className: imageClassName,
mapPropsToStyles: function mapPropsToStyles() {
return {
avatar: avatar,
circular: circular,
fluid: fluid
};
},
mapPropsToInlineStyles: function mapPropsToInlineStyles() {
return {
className: className,
design: design,
styles: styles,
variables: variables
};
},
rtl: context.rtl
}),
classes = _useStyles.classes;
var ElementType = (0, _reactBindings.getElementType)(props);
var unhandledProps = (0, _reactBindings.useUnhandledProps)(Image.handledProps, props);
var result = /*#__PURE__*/React.createElement(ElementType, getA11Props('root', Object.assign({
className: classes.root,
ref: ref
}, unhandledProps)));
setEnd();
return result;
});
exports.Image = Image;
Image.displayName = 'Image';
Image.defaultProps = {
as: 'img',
accessibility: _accessibility.imageBehavior
};
Image.propTypes = Object.assign({}, _utils.commonPropTypes.createCommon({
children: false,
content: false
}), {
avatar: PropTypes.bool,
circular: PropTypes.bool,
fluid: PropTypes.bool
});
Image.handledProps = Object.keys(Image.propTypes);
Image.create = (0, _utils.createShorthandFactory)({
Component: Image,
mappedProp: 'src',
allowsJSX: false
});
//# sourceMappingURL=Image.js.map
;