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

65 lines
1.5 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { HStack, IconButton, Stack, Text } from 'soapbox/components/ui';
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>
);
2023-01-10 15:03:15 -08:00
interface IWidgetBody {
children: React.ReactNode
}
/** Body of a widget. */
2023-01-10 15:03:15 -08:00
const WidgetBody: React.FC<IWidgetBody> = ({ 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,
action?: JSX.Element,
2023-01-10 15:03:15 -08:00
children?: React.ReactNode,
}
/** Sidebar widget. */
2022-04-18 20:49:17 -07:00
const Widget: React.FC<IWidget> = ({
title,
children,
onActionClick,
actionIcon = require('@tabler/icons/arrow-right.svg'),
2022-04-18 20:49:17 -07:00
actionTitle,
action,
2022-04-18 20:49:17 -07:00
}): JSX.Element => {
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} />
{action || (onActionClick && (
2022-04-18 20:49:17 -07:00
<IconButton
2022-12-04 17:40:09 -08:00
className='w-6 h-6 ml-2 text-black dark:text-white rtl:rotate-180'
2022-04-18 20:49:17 -07:00
src={actionIcon}
onClick={onActionClick}
title={actionTitle}
/>
))}
2022-04-18 20:49:17 -07:00
</HStack>
<WidgetBody>{children}</WidgetBody>
</Stack>
);
};
export default Widget;