Skip to content

Commit

Permalink
Adding the ToastManager inside the main container to properly place t…
Browse files Browse the repository at this point in the history
…he toasts and modified animation
  • Loading branch information
Marc-Antoine Hinse committed Nov 29, 2024
1 parent ba495ac commit 2188dd9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/react-components/src/ConfigurationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ConfigurationScreen: FC<{ theme: string }> = ({ theme }) => {
const [configurationStep, setConfigurationStep] = useState(ConfigurationStep.Initial);
const [apiKey, setApiKey] = useState('');

toastManager.setTheme(theme);
toastManager.setup('container', theme);

const handleBackButton = (): void => {
switch (configurationStep) {
Expand Down
15 changes: 7 additions & 8 deletions packages/react-components/src/components/Toast.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
margin-bottom: 10px;
min-height: 2rem;
padding: 1rem 2rem;
animation: slide-in 0.2s;
animation: toast-animation-in 0.2s;
transition: all 0.3s ease;
border-radius: 0.25rem;
display: flex;
flex-direction: row;
gap: 1rem;
align-items: center;
user-select: none;
}

.toast-success {
Expand All @@ -23,32 +24,30 @@
}

.toast-timed-out {
animation: slide-out 0.2s;
animation: toast-animation-out 0.2s;
}

.toast-text {
color: var(--text-color);
overflow-wrap: anywhere;
}

@keyframes slide-in {
@keyframes toast-animation-in {
from {
transform: translateX(30rem);
transform: translateY(-2rem);
opacity: 0;
}
to {
transform: translateX(0px);
transform: translateY(0px);
opacity: 1;
}
}

@keyframes slide-out {
@keyframes toast-animation-out {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(100%);
opacity: 0;
}
}
4 changes: 2 additions & 2 deletions packages/react-components/src/components/ToastManager.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#toast-container-main {
position: fixed;
top: 8rem;
position: absolute;
top: 2rem;
right: 6rem;
z-index: 9999999;
display: flex;
Expand Down
27 changes: 14 additions & 13 deletions packages/react-components/src/components/ToastManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ export class ToastManager {

private toasts: ToastProps[] = [];

constructor() {
const body = document.getElementsByTagName('body')[0] as HTMLBodyElement;
const toastContainer = document.createElement('div') as HTMLDivElement;
toastContainer.id = TOAST_CONTAINER_ID;
body.insertAdjacentElement('beforeend', toastContainer);
this.containerRef = toastContainer;
}

public setTheme(theme: string): void {
if (theme === 'dark') {
this.containerRef.className = theme;
} else {
this.containerRef.className = '';
public setup(containerId: string, theme: string): void {
if (!this.containerRef) {
const container = document.getElementById(containerId) as HTMLDivElement;
if (container) {
const toastContainer = document.createElement('div') as HTMLDivElement;
toastContainer.id = TOAST_CONTAINER_ID;
container.insertAdjacentElement('beforeend', toastContainer);
this.containerRef = toastContainer;
if (theme === 'dark') {
this.containerRef.className = theme;
} else {
this.containerRef.className = '';
}
}
}
}

Expand Down

0 comments on commit 2188dd9

Please sign in to comment.