UNPKG

@fluentui/react-northstar

Version:
151 lines (149 loc) 5.54 kB
import _invoke from "lodash/invoke"; import { cardBehavior } from '@fluentui/accessibility'; import { getElementType, useAccessibility, useStyles, useFluentContext, useTelemetry, useUnhandledProps } from '@fluentui/react-bindings'; import { Ref } from '@fluentui/react-component-ref'; import * as CustomPropTypes from '@fluentui/react-proptypes'; import * as PropTypes from 'prop-types'; import * as React from 'react'; import { commonPropTypes, createShorthandFactory } from '../../utils'; import { CardBody } from './CardBody'; import { CardColumn } from './CardColumn'; import { CardFooter } from './CardFooter'; import { CardHeader } from './CardHeader'; import { CardPreview } from './CardPreview'; import { CardTopControls } from './CardTopControls'; import { CardExpandableBox } from './CardExpandableBox'; export 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). * */ export var Card = /*#__PURE__*/function () { var Card = /*#__PURE__*/React.forwardRef(function (props, ref) { var context = useFluentContext(); var _useTelemetry = 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 = getElementType(props); var unhandledProps = useUnhandledProps(Card.handledProps, props); var getA11yProps = 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 = 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; } _invoke(props, 'onClick', e, props); }; var element = /*#__PURE__*/React.createElement(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; }); Card.displayName = 'Card'; Card.propTypes = Object.assign({}, 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: cardBehavior, size: 'medium' }; Card.handledProps = Object.keys(Card.propTypes); Card.Header = CardHeader; Card.Body = CardBody; Card.Footer = CardFooter; Card.Preview = CardPreview; Card.TopControls = CardTopControls; Card.Column = CardColumn; Card.ExpandableBox = CardExpandableBox; Card.create = createShorthandFactory({ Component: Card }); return Card; }(); //# sourceMappingURL=Card.js.map