Skip to content

Commit

Permalink
refactor: Remove toast action, update toast types (#86)
Browse files Browse the repository at this point in the history
* refactor: Remove toast action, update toast types

* chore: Remove unused import
  • Loading branch information
hachiojidev authored Apr 27, 2021
1 parent 4338ec5 commit 11edb58
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
15 changes: 2 additions & 13 deletions packages/pancake-uikit/src/widgets/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React, { useCallback, useEffect, useRef } from "react";
import { CSSTransition } from "react-transition-group";
import styled from "styled-components";
import { Alert, alertVariants } from "../../components/Alert";
import { Text } from "../../components/Text";
import ToastAction from "./ToastAction";
import { ToastProps, types } from "./types";

const alertTypeMap = {
Expand All @@ -29,7 +27,7 @@ const Toast: React.FC<ToastProps> = ({ toast, onRemove, style, ttl, ...props })
const timer = useRef<number>();
const ref = useRef(null);
const removeHandler = useRef(onRemove);
const { id, title, description, type, action } = toast;
const { id, title, description, type } = toast;

const handleRemove = useCallback(() => removeHandler.current(id), [id, removeHandler]);

Expand Down Expand Up @@ -65,16 +63,7 @@ const Toast: React.FC<ToastProps> = ({ toast, onRemove, style, ttl, ...props })
<CSSTransition nodeRef={ref} timeout={250} style={style} {...props}>
<StyledToast ref={ref} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
<Alert title={title} variant={alertTypeMap[type]} onClick={handleRemove}>
{action ? (
<>
<Text as="p" mb="8px">
{description}
</Text>
<ToastAction action={action} />
</>
) : (
description
)}
{description}
</Alert>
</StyledToast>
</CSSTransition>
Expand Down
27 changes: 0 additions & 27 deletions packages/pancake-uikit/src/widgets/Toast/ToastAction.tsx

This file was deleted.

10 changes: 3 additions & 7 deletions packages/pancake-uikit/src/widgets/Toast/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ReactNode } from "react";

export const types = {
SUCCESS: "success",
DANGER: "danger",
Expand All @@ -7,17 +9,11 @@ export const types = {

export type Types = typeof types[keyof typeof types];

export interface ToastAction {
text: string;
url: string;
}

export interface Toast {
id: string;
type: Types;
title: string;
description?: string;
action?: ToastAction;
description?: ReactNode;
}

export interface ToastContainerProps {
Expand Down

0 comments on commit 11edb58

Please sign in to comment.