pleroma/app/soapbox/components/ui/widget/widget.tsx

60 lines
1.5 KiB
TypeScript
Raw Normal View History

import React from 'react';
2022-04-19 09:36:55 -07:00
import { Text, IconButton } from 'soapbox/components/ui';
import HStack from 'soapbox/components/ui/hstack/hstack';
import Stack from 'soapbox/components/ui/stack/stack';
interface IWidgetTitle {
/** Title text for the widget. */
title: React.ReactNode,
}
/** Title of a widget. */
const WidgetTitle = ({ title }: IWidgetTitle): JSX.Element => (
<Text size='xl' weight='bold' tag='h1'>{title}</Text>
);
/** Body of a widget. */
const WidgetBody: React.FC = ({ children }): JSX.Element => (
<Stack space={3}>{children}</Stack>
);
interface IWidget {
/** Widget title text. */
title: React.ReactNode,
/** Callback when the widget action is clicked. */
2022-04-18 20:49:17 -07:00
onActionClick?: () => void,
/** URL to the svg icon for the widget action. */
2022-04-18 20:49:17 -07:00
actionIcon?: string,
/** Text for the action. */
2022-04-18 20:49:17 -07:00
actionTitle?: string,
}
/** Sidebar widget. */
2022-04-18 20:49:17 -07:00
const Widget: React.FC<IWidget> = ({
title,
children,
onActionClick,
actionIcon = require('@tabler/icons/icons/arrow-right.svg'),
actionTitle,
}): JSX.Element => {
return (
<Stack space={2}>
2022-04-18 20:49:17 -07:00
<HStack alignItems='center'>
<WidgetTitle title={title} />
{onActionClick && (
<IconButton
2022-04-19 10:28:37 -07:00
className='w-6 h-6 ml-2 text-black dark:text-white'
2022-04-18 20:49:17 -07:00
src={actionIcon}
onClick={onActionClick}
title={actionTitle}
/>
)}
</HStack>
<WidgetBody>{children}</WidgetBody>
</Stack>
);
};
export default Widget;