2022-03-25 12:08:12 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-11-25 10:28:43 -08:00
|
|
|
import { HStack, IconButton, Stack, Text } from 'soapbox/components/ui';
|
2022-03-25 12:08:12 -07:00
|
|
|
|
|
|
|
interface IWidgetTitle {
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Title text for the widget. */
|
2023-02-15 13:26:27 -08:00
|
|
|
title: React.ReactNode
|
2022-03-25 12:08:12 -07:00
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Title of a widget. */
|
2022-03-25 12:08:12 -07:00
|
|
|
const WidgetTitle = ({ title }: IWidgetTitle): JSX.Element => (
|
|
|
|
<Text size='xl' weight='bold' tag='h1'>{title}</Text>
|
|
|
|
);
|
|
|
|
|
2023-01-10 15:03:15 -08:00
|
|
|
interface IWidgetBody {
|
|
|
|
children: React.ReactNode
|
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Body of a widget. */
|
2023-01-10 15:03:15 -08:00
|
|
|
const WidgetBody: React.FC<IWidgetBody> = ({ children }): JSX.Element => (
|
2022-03-25 12:08:12 -07:00
|
|
|
<Stack space={3}>{children}</Stack>
|
|
|
|
);
|
|
|
|
|
|
|
|
interface IWidget {
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Widget title text. */
|
2023-02-15 13:26:27 -08:00
|
|
|
title: React.ReactNode
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Callback when the widget action is clicked. */
|
2023-02-15 13:26:27 -08:00
|
|
|
onActionClick?: () => void
|
2022-04-30 21:39:58 -07:00
|
|
|
/** URL to the svg icon for the widget action. */
|
2023-02-15 13:26:27 -08:00
|
|
|
actionIcon?: string
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Text for the action. */
|
2023-02-15 13:26:27 -08:00
|
|
|
actionTitle?: string
|
|
|
|
action?: JSX.Element
|
|
|
|
children?: React.ReactNode
|
2022-03-25 12:08:12 -07:00
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Sidebar widget. */
|
2022-04-18 20:49:17 -07:00
|
|
|
const Widget: React.FC<IWidget> = ({
|
|
|
|
title,
|
|
|
|
children,
|
|
|
|
onActionClick,
|
2022-07-09 09:20:02 -07:00
|
|
|
actionIcon = require('@tabler/icons/arrow-right.svg'),
|
2022-04-18 20:49:17 -07:00
|
|
|
actionTitle,
|
2022-05-28 09:02:04 -07:00
|
|
|
action,
|
2022-04-18 20:49:17 -07:00
|
|
|
}): JSX.Element => {
|
2022-03-25 12:08:12 -07:00
|
|
|
return (
|
2022-09-26 12:23:51 -07:00
|
|
|
<Stack space={4}>
|
2022-09-26 12:22:00 -07:00
|
|
|
<HStack alignItems='center' justifyContent='between'>
|
2022-04-18 20:49:17 -07:00
|
|
|
<WidgetTitle title={title} />
|
2022-05-28 09:02:04 -07:00
|
|
|
{action || (onActionClick && (
|
2022-04-18 20:49:17 -07:00
|
|
|
<IconButton
|
2023-02-01 14:13:42 -08:00
|
|
|
className='ml-2 h-6 w-6 text-black rtl:rotate-180 dark:text-white'
|
2022-04-18 20:49:17 -07:00
|
|
|
src={actionIcon}
|
|
|
|
onClick={onActionClick}
|
|
|
|
title={actionTitle}
|
|
|
|
/>
|
2022-05-28 09:02:04 -07:00
|
|
|
))}
|
2022-04-18 20:49:17 -07:00
|
|
|
</HStack>
|
2022-03-25 12:08:12 -07:00
|
|
|
<WidgetBody>{children}</WidgetBody>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Widget;
|