@mui/joy
Version:
Joy UI is an open-source React component library that implements MUI's own design principles. It's comprehensive and can be used in production out of the box.
137 lines (136 loc) • 4.51 kB
JavaScript
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["className", "component", "children", "slots", "slotProps"];
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses } from '@mui/base';
import { useThemeProps } from '../styles';
import styled from '../styles/styled';
import { getCardCoverUtilityClass } from './cardCoverClasses';
import useSlot from '../utils/useSlot';
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = () => {
const slots = {
root: ['root']
};
return composeClasses(slots, getCardCoverUtilityClass, {});
};
const CardCoverRoot = styled('div', {
name: 'JoyCardCover',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
})({
position: 'absolute',
zIndex: 0,
top: 0,
left: 0,
right: 0,
bottom: 0,
borderRadius: 'var(--CardCover-radius)',
// use data-attribute instead of :first-child to support zero config SSR (emotion)
// use nested selector for integrating with nextjs image `fill` layout (spans are inserted on top of the img)
'& [data-first-child]': {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
objectFit: 'cover',
boxSizing: 'border-box',
borderRadius: 'var(--CardCover-radius)',
margin: 0,
padding: 0,
'& > img': {
// support art-direction that uses <picture><img /></picture>
width: '100%',
height: '100%',
objectFit: 'cover'
}
}
});
/**
*
* Demos:
*
* - [Card](https://mui.com/joy-ui/react-card/)
*
* API:
*
* - [CardCover API](https://mui.com/joy-ui/api/card-cover/)
*/
const CardCover = /*#__PURE__*/React.forwardRef(function CardCover(inProps, ref) {
const props = useThemeProps({
props: inProps,
name: 'JoyCardCover'
});
const {
className,
component = 'div',
children,
slots = {},
slotProps = {}
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const ownerState = _extends({}, props, {
component
});
const classes = useUtilityClasses();
const externalForwardedProps = _extends({}, other, {
component,
slots,
slotProps
});
const [SlotRoot, rootProps] = useSlot('root', {
ref,
className: clsx(classes.root, className),
elementType: CardCoverRoot,
externalForwardedProps,
ownerState
});
return /*#__PURE__*/_jsx(SlotRoot, _extends({}, rootProps, {
children: React.Children.map(children, (child, index) => index === 0 && /*#__PURE__*/React.isValidElement(child) ? /*#__PURE__*/React.cloneElement(child, {
'data-first-child': ''
}) : child)
}));
});
process.env.NODE_ENV !== "production" ? CardCover.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* Used to render icon or text elements inside the CardCover if `src` is not set.
* This can be an element, or just a string.
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside.
* @default {}
*/
slotProps: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside.
* @default {}
*/
slots: PropTypes.shape({
root: PropTypes.elementType
}),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
export default CardCover;