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

chore(toast): renamed types to normal convention #169

Merged
merged 2 commits into from
Nov 25, 2020
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
19 changes: 11 additions & 8 deletions src/toast/ToastProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { objectKeys } from "@chakra-ui/utils";

import { isFunction } from "../utils";
import { ToastController } from "./ToastController";
import { IToast, useToastState, ToastStateReturn } from "./ToastState";
import { Toast, useToastState, ToastStateReturn } from "./ToastState";

const DEFAULT_TIMEOUT = 5000;
const PLACEMENTS = {
Expand All @@ -20,12 +20,15 @@ const PLACEMENTS = {
// let's infer the union types from the placement values instead of hardcoding them
export type Placements = keyof typeof PLACEMENTS;

interface IToastContext extends ToastStateReturn {
interface ToastContextState extends ToastStateReturn {
toastTypes: ToastTypes;
}

const ToastContext = React.createContext<IToastContext | undefined>(undefined);
const ToastContext = React.createContext<ToastContextState | undefined>(
undefined,
);
export const ToastContextProvider = ToastContext.Provider;

export function useToast() {
const context = React.useContext(ToastContext);

Expand All @@ -41,15 +44,15 @@ export function useToast() {
export type ToastTypes = Record<
string,
React.FC<
Pick<IToast, "content" | "id" | "isVisible"> & {
Pick<Toast, "content" | "id" | "isVisible"> & {
hideToast: ToastStateReturn["hideToast"];
}
>
>;

export type TToastWrapper = (props: any) => React.ReactElement<any>;
export type ToastWrapper = (props: any) => React.ReactElement<any>;

type IToastProvider = {
type ToastProviderProps = {
/**
* Specify types of toast in an object
*/
Expand Down Expand Up @@ -79,10 +82,10 @@ type IToastProvider = {
/**
* Wrapper function to enhance the behaviour of ToastController
*/
toastWrapper?: TToastWrapper;
toastWrapper?: ToastWrapper;
};

export const ToastProvider: React.FC<IToastProvider> = ({
export const ToastProvider: React.FC<ToastProviderProps> = ({
children,
toastTypes,
placement: providerPlacement = "bottom-center",
Expand Down
8 changes: 4 additions & 4 deletions src/toast/ToastState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Placements } from "./ToastProvider";

type StringOrElement = string | React.ReactNode;

export interface IToast {
export interface Toast {
/**
* Unique id for the toast
*/
Expand Down Expand Up @@ -37,8 +37,8 @@ export interface IToast {
isVisible?: boolean;
}

export type ToastList = Record<string, IToast>;
export type SortedToastList = Record<Placements, IToast[]>;
export type ToastList = Record<string, Toast>;
export type SortedToastList = Record<Placements, Toast[]>;

interface ToastStateProps {
defaultPlacement?: Placements;
Expand Down Expand Up @@ -76,7 +76,7 @@ export const useToastState = ({
timeout,
autoDismiss,
placement = defaultPlacement,
}: Partial<Omit<IToast, "isVisible">>) => {
}: Partial<Omit<Toast, "isVisible">>) => {
COUNTER.current = COUNTER.current + 1;
const id = idProps || `toast-${COUNTER.current}`;

Expand Down
4 changes: 2 additions & 2 deletions src/toast/stories/ToastCSSAnimated.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from "react";
import { CSSTransition } from "react-transition-group";

import { Variants, Placements } from "./Utils.component";
import { ToastProvider, TToastWrapper } from "renderless-components";
import { ToastProvider, ToastWrapper } from "renderless-components";

const CSSTransitionAnimationWrapper: TToastWrapper = ({
const CSSTransitionAnimationWrapper: ToastWrapper = ({
isVisible,
children,
}) => {
Expand Down
4 changes: 2 additions & 2 deletions src/toast/stories/ToastReactSpring.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from "react";
import { animated, useTransition } from "react-spring";

import { Variants, Placements } from "./Utils.component";
import { ToastProvider, TToastWrapper } from "renderless-components";
import { ToastProvider, ToastWrapper } from "renderless-components";

const SpringAnimationWrapper: TToastWrapper = ({
const SpringAnimationWrapper: ToastWrapper = ({
placement,
isVisible,
children,
Expand Down
6 changes: 3 additions & 3 deletions src/toast/stories/Utils.component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

import { useToast, Placements as IPlacements } from "renderless-components";
import { useToast } from "renderless-components";

const randomType = (): string => {
return ["error", "warning", "success"].splice(Math.random() * 3, 1)[0];
Expand Down Expand Up @@ -63,7 +63,7 @@ export const Placements: React.FC = () => {
"bottom-left",
"bottom-right",
"bottom-center",
];
] as const;

return (
<div>
Expand All @@ -75,7 +75,7 @@ export const Placements: React.FC = () => {
showToast({
type: randomType(),
content: `This is ${placement}`,
placement: placement as IPlacements,
placement,
});
}}
>
Expand Down