import classNames from 'clsx';
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { Link } from 'react-router-dom';
import { HStack, Text } from 'soapbox/components/ui';
import SvgIcon from 'soapbox/components/ui/icon/svg-icon';
const sizes = {
md: 'p-4 sm:rounded-xl',
lg: 'p-4 sm:p-6 sm:rounded-xl',
xl: 'p-4 sm:p-10 sm:rounded-3xl',
};
const messages = defineMessages({
back: { id: 'card.back.label', defaultMessage: 'Back' },
});
interface ICard {
/** The type of card. */
variant?: 'default' | 'rounded'
/** Card size preset. */
size?: keyof typeof sizes
/** Extra classnames for the
element. */
className?: string
/** Elements inside the card. */
children: React.ReactNode
}
/** An opaque backdrop to hold a collection of related elements. */
const Card = React.forwardRef
(({ children, variant = 'default', size = 'md', className, ...filteredProps }, ref): JSX.Element => (
{children}
));
interface ICardHeader {
backHref?: string,
onBackClick?: (event: React.MouseEvent) => void
}
/**
* Card header container with back button.
* Typically holds a CardTitle.
*/
const CardHeader: React.FC = ({ children, backHref, onBackClick }): JSX.Element => {
const intl = useIntl();
const renderBackButton = () => {
if (!backHref && !onBackClick) {
return null;
}
const Comp: React.ElementType = backHref ? Link : 'button';
const backAttributes = backHref ? { to: backHref } : { onClick: onBackClick };
return (
{intl.formatMessage(messages.back)}
);
};
return (
{renderBackButton()}
{children}
);
};
interface ICardTitle {
title: React.ReactNode
}
/** A card's title. */
const CardTitle: React.FC = ({ title }): JSX.Element => (
{title}
);
/** A card's body. */
const CardBody: React.FC = ({ children }): JSX.Element => (
{children}
);
export { Card, CardHeader, CardTitle, CardBody };