mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-02 22:01:52 +00:00
Created new Result component to display operation result messages consistently
This commit is contained in:
30
src/utils/Result.tsx
Normal file
30
src/utils/Result.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { FC } from 'react';
|
||||
import { Row } from 'reactstrap';
|
||||
import classNames from 'classnames';
|
||||
import { SimpleCard } from './SimpleCard';
|
||||
|
||||
interface ResultProps {
|
||||
type: 'success' | 'error' | 'warning';
|
||||
className?: string;
|
||||
textCentered?: boolean;
|
||||
small?: boolean;
|
||||
}
|
||||
|
||||
export const Result: FC<ResultProps> = ({ children, type, className, textCentered = false, small = false }) => (
|
||||
<Row className={className}>
|
||||
<div className={classNames({ 'col-md-10 offset-md-1': !small, 'col-12': small })}>
|
||||
<SimpleCard
|
||||
className={classNames({
|
||||
'bg-main': type === 'success',
|
||||
'bg-danger': type === 'error',
|
||||
'bg-warning': type === 'warning',
|
||||
'text-white': type !== 'warning',
|
||||
'text-center': textCentered,
|
||||
})}
|
||||
bodyClassName={classNames({ 'p-2': small })}
|
||||
>
|
||||
{children}
|
||||
</SimpleCard>
|
||||
</div>
|
||||
</Row>
|
||||
);
|
||||
@@ -4,11 +4,12 @@ import { ReactNode } from 'react';
|
||||
|
||||
interface SimpleCardProps extends Omit<CardProps, 'title'> {
|
||||
title?: ReactNode;
|
||||
bodyClassName?: string;
|
||||
}
|
||||
|
||||
export const SimpleCard = ({ title, children, ...rest }: SimpleCardProps) => (
|
||||
export const SimpleCard = ({ title, children, bodyClassName, ...rest }: SimpleCardProps) => (
|
||||
<Card {...rest}>
|
||||
{title && <CardHeader>{title}</CardHeader>}
|
||||
<CardBody>{children}</CardBody>
|
||||
<CardBody className={bodyClassName}>{children}</CardBody>
|
||||
</Card>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user