reuse vairant logic

This commit is contained in:
Dexter 2022-03-31 17:26:48 +01:00
parent 9c3957caa3
commit c4e6450290
3 changed files with 26 additions and 8 deletions

View File

@ -1,9 +1,11 @@
import type { ReactNode } from 'react';
import classNames from 'classnames';
import type { Variant } from '../../utils/intent';
import { getVariantBackground } from '../../utils/intent';
interface LozengeProps {
children: ReactNode;
variant?: 'success' | 'warning' | 'danger' | 'highlight';
variant?: Variant;
className?: string;
details?: string;
}
@ -13,13 +15,10 @@ const getWrapperClasses = (className: LozengeProps['className']) => {
};
const getLozengeClasses = (variant: LozengeProps['variant']) => {
return classNames(['rounded-md', 'font-mono', 'leading-none', 'p-4'], {
'bg-intent-success text-black': variant === 'success',
'bg-intent-danger text-white': variant === 'danger',
'bg-intent-warning text-black': variant === 'warning',
'bg-intent-highlight text-black': variant === 'highlight',
'bg-intent-help text-white': !variant,
});
return classNames(
['rounded-md', 'font-mono', 'leading-none', 'p-4'],
getVariantBackground(variant)
);
};
export const Lozenge = ({

View File

@ -21,6 +21,8 @@ export { ThemeSwitcher } from './components/theme-switcher';
export { Dialog } from './components/dialog/dialog';
export { VegaLogo } from './components/vega-logo';
export { Tooltip } from './components/tooltip';
export { Indicator } from './components/indicator';
export { Card } from './components/card';
// Utils
export * from './utils/intent';

View File

@ -9,6 +9,13 @@ export enum Intent {
Help = 'help',
}
export enum Variant {
Success = 'success',
Warning = 'warning',
Danger = 'danger',
Highlight = 'highlight',
}
export const getIntentShadow = (intent?: Intent) => {
return classNames('shadow-callout', {
'shadow-intent-danger': intent === Intent.Danger,
@ -19,3 +26,13 @@ export const getIntentShadow = (intent?: Intent) => {
'shadow-intent-help': intent === Intent.Help,
});
};
export const getVariantBackground = (variant?: Variant) => {
return classNames('shadow-callout', {
'bg-intent-success text-black': variant === Variant.Success,
'bg-intent-danger text-white': variant === Variant.Danger,
'bg-intent-warning text-black': variant === Variant.Warning,
'bg-intent-highlight text-black': variant === Variant.Highlight,
'bg-intent-help text-white': !variant,
});
};