Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Callout component #225

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
'rules': {
'react/display-name': 'off',
'no-unused-vars': [0],
'indent': ['error', 2],
'indent': ['error', 2, {'SwitchCase': 1}],
amcdnl marked this conversation as resolved.
Show resolved Hide resolved
'react/prop-types': [0],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
Expand Down
60 changes: 60 additions & 0 deletions src/layers/Callout/Callout.story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import { Stack } from '@/layout';
import { Text } from '@/typography';

import {
Callout,
SuccessCallout,
WarningCallout,
ErrorCallout,
InfoCallout
} from '@/layers';

import CalendarIcon from '@/assets/icons/calendar.svg?react';

export default {
title: 'Components/Layers/Callout',
component: Callout
};

export const Simple = () => (
<div className="w-[80%]">
<Callout text="You will need admin privileges to install and access this application." />
</div>
);

export const Variants = () => (
<Stack direction="column" className="w-full">
<Callout text="You will need admin privileges to install and access this application." />
<SuccessCallout text="You will need admin privileges to install and access this application." />
<WarningCallout text="You will need admin privileges to install and access this application." />
<ErrorCallout text="You will need admin privileges to install and access this application." />
<InfoCallout text="You will need admin privileges to install and access this application." />
</Stack>
);

export const CustomIcon = () => (
<div className="w-[80%]">
<InfoCallout
icon={<CalendarIcon />}
text="You will need admin privileges to install and access this application."
/>
</div>
);

export const CustomText = () => (
<div className="w-[80%]">
<InfoCallout
variant="info"
text={
<Text>
You will need{' '}
<Text fontStyle="bold" color="warning">
admin
</Text>{' '}
privileges to install and access this application.
</Text>
}
/>
</div>
);
46 changes: 46 additions & 0 deletions src/layers/Callout/Callout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { FC, ReactNode } from 'react';
import { Stack } from '@/layout';
import { cn, useComponentTheme } from '@/utils';
import { CalloutTheme } from './CalloutTheme';

export interface CalloutProps {
/**
* The text of the callout.
*/
text: string | ReactNode;

/**
* The icon of the callout.
*/
icon?: ReactNode;

/**
* The variant of the callout.
*/
variant?: 'default' | 'success' | 'error' | 'warning' | 'info';

/**
* The theme of the callout.
*/
theme?: CalloutTheme;
}

export const Callout: FC<CalloutProps> = ({
text,
icon,
variant = 'default',
theme: customTheme
}) => {
const theme = useComponentTheme('callout', customTheme);

return (
<Stack className={cn(theme.base.common, theme.base.variant[variant])}>
{icon && (
<div className={cn(theme.icon.common, theme.icon.variant[variant])}>
{icon}
</div>
)}
<div className={theme.text}>{text}</div>
</Stack>
);
};
51 changes: 51 additions & 0 deletions src/layers/Callout/CalloutTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export interface CalloutTheme {
base: {
common: string;
variant: {
default: string;
success: string;
error: string;
warning: string;
info: string;
[key: string]: string;
};
};
icon: {
common: string;
variant: {
default: string;
success: string;
error: string;
warning: string;
info: string;
[key: string]: string;
};
};
text: string;
}

export const calloutTheme: CalloutTheme = {
base: {
common: 'px-4 py-3 border-b',
variant: {
default: 'bg-panel-background border-panel-accent',
success: 'bg-success-background border-success',
error: 'bg-error-background border-error',
warning: 'bg-warning-background border-warning',
info: 'bg-info-background border-info'
}
},
icon: {
common: '',
variant: {
default: '',
success: 'text-success',
error: 'text-error',
warning: 'text-warning',
info: 'text-info'
}
},
text: 'text-base'
};

export const legacyCalloutTheme: CalloutTheme = calloutTheme;
13 changes: 13 additions & 0 deletions src/layers/Callout/ErrorCallout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { FC } from 'react';
import { Callout, CalloutProps } from './Callout';

import ErrorCircleIcon from '@/assets/icons/error_circle.svg?react';

export const ErrorCallout: FC<CalloutProps> = ({ icon, text, theme }) => (
<Callout
icon={icon ?? <ErrorCircleIcon />}
text={text}
variant="error"
theme={theme}
/>
);
13 changes: 13 additions & 0 deletions src/layers/Callout/InfoCallout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { FC } from 'react';
import { Callout, CalloutProps } from './Callout';

import InfoIcon from '@/assets/icons/info.svg?react';

export const InfoCallout: FC<CalloutProps> = ({ icon, text, theme }) => (
<Callout
icon={icon ?? <InfoIcon />}
text={text}
variant="info"
theme={theme}
/>
);
13 changes: 13 additions & 0 deletions src/layers/Callout/SuccessCallout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { FC } from 'react';
import { Callout, CalloutProps } from './Callout';

import CheckCircleIcon from '@/assets/icons/check_circle.svg?react';

export const SuccessCallout: FC<CalloutProps> = ({ icon, text, theme }) => (
<Callout
icon={icon ?? <CheckCircleIcon />}
text={text}
variant="success"
theme={theme}
SerhiiTsybulskyi marked this conversation as resolved.
Show resolved Hide resolved
/>
);
13 changes: 13 additions & 0 deletions src/layers/Callout/WarningCallout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { FC } from 'react';
import { Callout, CalloutProps } from './Callout';

import WarningIcon from '@/assets/icons/warning.svg?react';

export const WarningCallout: FC<CalloutProps> = ({ icon, text, theme }) => (
<Callout
icon={icon ?? <WarningIcon />}
text={text}
variant="warning"
theme={theme}
/>
);
6 changes: 6 additions & 0 deletions src/layers/Callout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './Callout';
export * from './CalloutTheme';
export * from './SuccessCallout';
export * from './ErrorCallout';
export * from './WarningCallout';
export * from './InfoCallout';
1 change: 1 addition & 0 deletions src/layers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './Menu';
export * from './ContextMenu';
export * from './Notification';
export * from './Backdrop';
export * from './Callout';
12 changes: 9 additions & 3 deletions src/utils/Theme/themes/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ import {
MenuTheme,
NotificationTheme,
PopoverTheme,
TooltipTheme
TooltipTheme,
CalloutTheme,
calloutTheme,
legacyCalloutTheme
} from '@/layers';

import {
Expand Down Expand Up @@ -190,6 +193,7 @@ export interface ReablocksTheme {
tabs: TabsTheme;
breadcrumbs: BreadcrumbsTheme;
stepper: StepperTheme;
callout: CalloutTheme;
};
}

Expand Down Expand Up @@ -237,7 +241,8 @@ export const theme: ReablocksTheme = {
tabs: tabsTheme,
jsonTree: jsonTreeTheme,
breadcrumbs: breadcrumbsTheme,
stepper: stepperTheme
stepper: stepperTheme,
callout: calloutTheme
}
};

Expand Down Expand Up @@ -285,6 +290,7 @@ export const legacyThemeVars: ReablocksTheme = {
tabs: legacyTabsTheme,
jsonTree: legacyJsonTreeTheme,
breadcrumbs: legacyBreadcrumbTheme,
stepper: legacyStepperTheme
stepper: legacyStepperTheme,
callout: legacyCalloutTheme
}
};
Loading