@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
103 lines (102 loc) • 3.04 kB
JavaScript
"use client";
import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js";
import React, { useContext } from 'react';
import clsx from 'clsx';
import Flex from "../flex/Flex.js";
import { SectionParams } from "../section/Section.js";
import { combineLabelledBy } from "../../shared/component-helper.js";
import CardContext from "./CardContext.js";
import Space from "../Space.js";
import useId from "../../shared/helpers/useId.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
function Card(props) {
const nestedContext = useContext(CardContext);
const {
className,
stack,
direction,
gap,
innerSpace,
alignSelf = 'stretch',
align,
divider = 'space',
rowGap,
responsive = !(nestedContext !== null && nestedContext !== void 0 && nestedContext.isNested),
filled,
outset,
outlineWidth = 'var(--card-outline-width)',
dropShadow,
title,
children,
...rest
} = props;
const titleId = useId();
const falseWhenSmall = {
small: false,
medium: true,
large: true
};
const trueWhenSmall = {
small: true,
medium: false,
large: false
};
const basisSpace = {
top: 'small',
right: 'small',
bottom: 'small',
left: 'small'
};
const smallSpace = responsive ? {
...basisSpace,
right: 0,
left: 0
} : basisSpace;
const params = SectionParams({
className: clsx('dnb-card', className, responsive && 'dnb-card--responsive', filled && 'dnb-card--filled', !innerSpace && innerSpace != null && 'dnb-card--no-inner-space'),
breakout: responsive ? trueWhenSmall : false,
outset: nestedContext !== null && nestedContext !== void 0 && nestedContext.isNested ? false : outset === true ? falseWhenSmall : outset,
roundedCorner: responsive ? falseWhenSmall : true,
outline: 'var(--card-outline-color)',
outlineWidth,
dropShadow,
backgroundColor: 'var(--card-background-color)',
innerSpace: innerSpace !== null && innerSpace !== void 0 ? innerSpace : {
small: smallSpace,
medium: basisSpace,
large: basisSpace
},
...rest,
'aria-labelledby': combineLabelledBy(rest, title && titleId)
});
return _jsx(Flex.Item, {
alignSelf: alignSelf,
element: "section",
...params,
children: _jsx(CardContext, {
value: {
...nestedContext,
isNested: true
},
children: _jsxs(Flex.Container, {
direction: direction !== null && direction !== void 0 ? direction : 'vertical',
divider: divider,
alignSelf: alignSelf,
align: stack ? 'stretch' : align,
wrap: !stack,
gap: gap !== null && gap !== void 0 ? gap : stack ? 'medium' : false,
rowGap: rowGap,
children: [title && _jsx(Space, {
id: titleId,
className: "dnb-card__title",
children: title
}), children]
})
})
});
}
withComponentMarkers(Card, {
_supportsSpacingProps: true
});
export default Card;
//# sourceMappingURL=Card.js.map