@fluentui/react-northstar
Version:
A themable React component library.
157 lines (154 loc) • 6.88 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.cardClassName = exports.Card = void 0;
var _invoke2 = _interopRequireDefault(require("lodash/invoke"));
var _accessibility = require("@fluentui/accessibility");
var _reactBindings = require("@fluentui/react-bindings");
var _reactComponentRef = require("@fluentui/react-component-ref");
var CustomPropTypes = _interopRequireWildcard(require("@fluentui/react-proptypes"));
var PropTypes = _interopRequireWildcard(require("prop-types"));
var React = _interopRequireWildcard(require("react"));
var _utils = require("../../utils");
var _CardBody = require("./CardBody");
var _CardColumn = require("./CardColumn");
var _CardFooter = require("./CardFooter");
var _CardHeader = require("./CardHeader");
var _CardPreview = require("./CardPreview");
var _CardTopControls = require("./CardTopControls");
var _CardExpandableBox = require("./CardExpandableBox");
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 cardClassName = 'ui-card';
/**
* A Card is used to display data in sematically grouped way.
* * @accessibility
* By default adds `group` role ([more information available in aria documentation](https://www.w3.org/TR/wai-aria-1.1/#group)), thus it's necessary to provide `aria-roledescription` for correct widget description. [More information available in aria documentation.](https://www.w3.org/TR/wai-aria-1.1/#aria-roledescription-property)
* When card is actionable (i.e. has `onClick` property), use [cardFocusableBehavior](/components/card/accessibility#card-focusable). [More information available in aria documentation.](https://www.w3.org/TR/wai-aria-practices/#gridNav_focus)
* When card contains actionable elements, use [cardChildrenFocusableBehavior](/components/card/accessibility#card-children-focusable).
*
*/
exports.cardClassName = cardClassName;
var Card = /*#__PURE__*/React.forwardRef(function (props, ref) {
var context = (0, _reactBindings.useFluentContext)();
var _useTelemetry = (0, _reactBindings.useTelemetry)(Card.displayName, context.telemetry),
setStart = _useTelemetry.setStart,
setEnd = _useTelemetry.setEnd;
setStart();
var cardRef = React.useRef();
var className = props.className,
design = props.design,
styles = props.styles,
variables = props.variables,
children = props.children,
compact = props.compact,
horizontal = props.horizontal,
centered = props.centered,
size = props.size,
fluid = props.fluid,
onClick = props.onClick,
disabled = props.disabled,
expandable = props.expandable,
elevated = props.elevated,
inverted = props.inverted,
ghost = props.ghost,
selected = props.selected;
var ElementType = (0, _reactBindings.getElementType)(props);
var unhandledProps = (0, _reactBindings.useUnhandledProps)(Card.handledProps, props);
var getA11yProps = (0, _reactBindings.useAccessibility)(props.accessibility, {
debugName: Card.displayName,
actionHandlers: {
performClick: function performClick(e) {
// prevent Spacebar from scrolling
e.preventDefault();
handleClick(e);
},
focusCard: function focusCard(e) {
cardRef.current.focus();
}
},
mapPropsToBehavior: function mapPropsToBehavior() {
return {
disabled: disabled
};
},
rtl: context.rtl
});
var _useStyles = (0, _reactBindings.useStyles)(Card.displayName, {
className: cardClassName,
mapPropsToStyles: function mapPropsToStyles() {
return {
centered: centered,
horizontal: horizontal,
compact: compact,
size: size,
fluid: fluid,
actionable: !!onClick,
disabled: disabled,
expandable: expandable,
elevated: elevated,
inverted: inverted,
ghost: ghost,
selected: selected
};
},
mapPropsToInlineStyles: function mapPropsToInlineStyles() {
return {
className: className,
design: design,
styles: styles,
variables: variables
};
},
rtl: context.rtl
}),
classes = _useStyles.classes;
var handleClick = function handleClick(e) {
if (disabled) {
e.preventDefault();
return;
}
(0, _invoke2.default)(props, 'onClick', e, props);
};
var element = /*#__PURE__*/React.createElement(_reactComponentRef.Ref, {
innerRef: cardRef
}, getA11yProps.unstable_wrapWithFocusZone( /*#__PURE__*/React.createElement(ElementType, getA11yProps('root', Object.assign({
className: classes.root,
onClick: handleClick,
ref: ref
}, unhandledProps)), children)));
setEnd();
return element;
});
exports.Card = Card;
Card.displayName = 'Card';
Card.propTypes = Object.assign({}, _utils.commonPropTypes.createCommon(), {
onClick: PropTypes.func,
compact: PropTypes.bool,
horizontal: PropTypes.bool,
centered: PropTypes.bool,
size: CustomPropTypes.size,
fluid: PropTypes.bool,
expandable: PropTypes.bool,
disabled: PropTypes.bool,
elevated: PropTypes.bool,
ghost: PropTypes.bool,
inverted: PropTypes.bool,
selected: PropTypes.bool
});
Card.defaultProps = {
accessibility: _accessibility.cardBehavior,
size: 'medium'
};
Card.handledProps = Object.keys(Card.propTypes);
Card.Header = _CardHeader.CardHeader;
Card.Body = _CardBody.CardBody;
Card.Footer = _CardFooter.CardFooter;
Card.Preview = _CardPreview.CardPreview;
Card.TopControls = _CardTopControls.CardTopControls;
Card.Column = _CardColumn.CardColumn;
Card.ExpandableBox = _CardExpandableBox.CardExpandableBox;
Card.create = (0, _utils.createShorthandFactory)({
Component: Card
});
//# sourceMappingURL=Card.js.map
;