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

Move Backdrop to TW theme #253

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 0 additions & 10 deletions src/layers/Backdrop/Backdrop.module.css

This file was deleted.

35 changes: 23 additions & 12 deletions src/layers/Backdrop/Backdrop.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { FC, MouseEvent } from 'react';
import classNames from 'classnames';
import { motion } from 'framer-motion';
import css from './Backdrop.module.css';
import { cn, useComponentTheme } from '@/utils';

import { BackdropTheme } from './BackdropTheme';

export interface BackdropProps {
/**
Expand All @@ -19,6 +20,11 @@ export interface BackdropProps {
*/
className?: string;

/**
* Theme for the Backdrop.
*/
theme?: BackdropTheme;

/**
* Callback for when the backdrop is clicked.
*/
Expand All @@ -29,14 +35,19 @@ export const Backdrop: FC<BackdropProps> = ({
zIndex = 998,
portalIndex = 0,
className,
theme: customTheme,
onClick
}) => (
<motion.div
className={classNames(css.backdrop, className)}
initial={{ opacity: 0 }}
animate={{ opacity: 0.8 - (portalIndex as number) / 10 }}
exit={{ opacity: 0 }}
style={{ zIndex }}
onClick={onClick}
/>
);
}) => {
const theme = useComponentTheme<BackdropTheme>('backdrop', customTheme);

return (
<motion.div
className={cn(theme.base, className)}
initial={{ opacity: 0 }}
animate={{ opacity: theme.opacity - (portalIndex as number) / 10 }}
exit={{ opacity: 0 }}
style={{ zIndex }}
onClick={onClick}
/>
);
};
14 changes: 14 additions & 0 deletions src/layers/Backdrop/BackdropTheme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface BackdropTheme {
base: string;
opacity: number;
}

export const backdropTheme: BackdropTheme = {
base: 'fixed top-0 left-0 w-full h-full opacity-0 select-none bg-black',
opacity: 0.8
};

export const legacyBackdropTheme: BackdropTheme = {
base: 'fixed top-0 left-0 w-full h-full opacity-0 select-none bg-[var(--color-layer-transparent)]',
opacity: 0.8
};
1 change: 1 addition & 0 deletions src/layers/Backdrop/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Backdrop';
export * from './BackdropTheme';
12 changes: 9 additions & 3 deletions src/utils/Theme/themes/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ import {
TooltipTheme,
CalloutTheme,
calloutTheme,
legacyCalloutTheme
legacyCalloutTheme,
BackdropTheme,
backdropTheme,
legacyBackdropTheme
} from '@/layers';

import {
Expand Down Expand Up @@ -194,6 +197,7 @@ export interface ReablocksTheme {
breadcrumbs: BreadcrumbsTheme;
stepper: StepperTheme;
callout: CalloutTheme;
backdrop: BackdropTheme;
};
}

Expand Down Expand Up @@ -242,7 +246,8 @@ export const theme: ReablocksTheme = {
jsonTree: jsonTreeTheme,
breadcrumbs: breadcrumbsTheme,
stepper: stepperTheme,
callout: calloutTheme
callout: calloutTheme,
backdrop: backdropTheme
}
};

Expand Down Expand Up @@ -291,6 +296,7 @@ export const legacyThemeVars: ReablocksTheme = {
jsonTree: legacyJsonTreeTheme,
breadcrumbs: legacyBreadcrumbTheme,
stepper: legacyStepperTheme,
callout: legacyCalloutTheme
callout: legacyCalloutTheme,
backdrop: legacyBackdropTheme
}
};
Loading