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

feat: rework toasts api and add mini mode support in toasts #987

Merged
merged 25 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3508852
feat:created toast component for mini mode and added icons and colors…
sachin-into Feb 21, 2024
b52efdd
refactor: moved toast message clear logic from toast component to toa…
sachin-into Feb 22, 2024
2cb5fc3
refactor: replaced MiniToast on mini comment input
sachin-into Feb 22, 2024
168d4a3
refactor: removed ToastProvider and moved added miniToast on feedback…
sachin-into Feb 23, 2024
45f1dae
chore: removed console.log
sachin-into Feb 23, 2024
1fe5339
feat: added clear toast on press
sachin-into Feb 23, 2024
6b96729
Merge branch 'main' into feat/mini-Toast
sakul-budhathoki Feb 23, 2024
b7947c6
refactor: Feedback Provider to use single api for mini and normal toast,
sachin-into Feb 28, 2024
a5fe0a0
Merge branch 'feat/mini-Toast' of https://github.com/TERITORI/teritor…
sachin-into Feb 28, 2024
ff0c80f
fix: tsc errors
sachin-into Feb 28, 2024
080813d
fix: unused exports error
sachin-into Feb 28, 2024
46fc3ab
feat:created toast component for mini mode and added icons and colors…
sachin-into Feb 21, 2024
06d66ba
refactor: moved toast message clear logic from toast component to toa…
sachin-into Feb 22, 2024
3402c3b
refactor: replaced MiniToast on mini comment input
sachin-into Feb 22, 2024
94397d1
refactor: removed ToastProvider and moved added miniToast on feedback…
sachin-into Feb 23, 2024
d956383
chore: removed console.log
sachin-into Feb 23, 2024
713687e
feat: added clear toast on press
sachin-into Feb 23, 2024
149d2a4
refactor: Feedback Provider to use single api for mini and normal toast,
sachin-into Feb 28, 2024
2b4ac8d
fix: tsc errors
sachin-into Feb 28, 2024
a43cf04
fix: unused exports error
sachin-into Feb 28, 2024
52da131
fix: regression
sakul-budhathoki Feb 28, 2024
effd876
fix: regression no right padding
sachin-into Feb 29, 2024
7503178
Merge branch 'feat/mini-Toast' of https://github.com/TERITORI/teritor…
sachin-into Feb 29, 2024
3a9f7c8
fix:padding diffrenece in success and error
sachin-into Feb 29, 2024
26e1b4c
fix: different with for success and error as in main
sachin-into Feb 29, 2024
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
11 changes: 11 additions & 0 deletions assets/icons/toast/check-circular-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/icons/toast/check-green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/toast/cross-red.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/toast/cross-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/icons/toast/info-circle-blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/icons/toast/info-circle-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/icons/toast/loader-blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/icons/toast/loader-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/icons/toast/warning-orange.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/icons/toast/warning-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 26 additions & 12 deletions packages/components/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import { View } from "react-native";
import Animated, {
Easing,
Expand All @@ -7,23 +7,30 @@ import Animated, {
withRepeat,
withTiming,
} from "react-native-reanimated";
import { SvgProps } from "react-native-svg";

import { SVG } from "./SVG";

import refreshSVG from "@/assets/icons/refresh-white.svg";

const SVG_SIZE = 20;

export const Spinner = () => {
type SpinnerProps = {
svg?: React.FC<SvgProps>;
size?: number;
};
export const Spinner = ({ size, svg }: SpinnerProps) => {
const rotate = useSharedValue(0);

rotate.value = withRepeat(
withTiming(360, {
duration: 1000,
easing: Easing.linear,
}),
-1,
);
useEffect(() => {
rotate.value = withRepeat(
withTiming(360, {
duration: 1000,
easing: Easing.linear,
}),
-1,
);
}, [rotate]);

const animatedStyle = useAnimatedStyle(() => {
return {
transform: [{ rotate: `${rotate.value}deg` }],
Expand All @@ -32,9 +39,16 @@ export const Spinner = () => {
return (
<View>
<Animated.View
style={[animatedStyle, { height: SVG_SIZE, width: SVG_SIZE }]}
style={[
animatedStyle,
{ height: size || SVG_SIZE, width: size || SVG_SIZE },
]}
>
<SVG source={refreshSVG} width={SVG_SIZE} height={SVG_SIZE} />
<SVG
source={svg || refreshSVG}
width={size || SVG_SIZE}
height={size || SVG_SIZE}
/>
</Animated.View>
</View>
);
Expand Down
138 changes: 138 additions & 0 deletions packages/components/toasts/MiniToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import React from "react";
import { View, useWindowDimensions } from "react-native";

import { Spinner } from "../Spinner";
import { CustomPressable } from "../buttons/CustomPressable";

import checkWhiteSVG from "@/assets/icons/toast/check-circular-white.svg";
import checkSVG from "@/assets/icons/toast/check-green.svg";
import crossRedSVG from "@/assets/icons/toast/cross-red.svg";
import crossWhiteSVG from "@/assets/icons/toast/cross-white.svg";
import infoBlueSVG from "@/assets/icons/toast/info-circle-blue.svg";
import infoWhiteSVG from "@/assets/icons/toast/info-circle-white.svg";
import loaderBlueSVG from "@/assets/icons/toast/loader-blue.svg";
import loaderWhiteSVG from "@/assets/icons/toast/loader-white.svg";
import warningOrangeSVG from "@/assets/icons/toast/warning-orange.svg";
import warningWhiteSVG from "@/assets/icons/toast/warning-white.svg";
import { BrandText } from "@/components/BrandText";
import { SVG } from "@/components/SVG";
import {
blueDefault,
neutral00,
toastGreen,
toastOrange,
toastRed,
} from "@/utils/style/colors";
import { fontSemibold14 } from "@/utils/style/fonts";
import { layout } from "@/utils/style/layout";

type ToastStatusType = "info" | "success" | "error" | "warning" | "loading";
type ToastVariantType = "solid" | "outline";

export interface MiniToastProps {
type?: ToastStatusType;
message: string;
variant?: ToastVariantType;
topOffset?: number;
showAlways?: boolean;
onPress?: () => void;
}

const getColors = (type: ToastStatusType) => {
switch (type) {
case "error":
return toastRed;
case "success":
return toastGreen;
case "warning":
return toastOrange;
case "loading":
return blueDefault;
default:
return blueDefault;
}
};

const getIcons = (type: ToastStatusType, variant: ToastVariantType) => {
switch (type) {
case "error":
return variant === "outline" ? crossRedSVG : crossWhiteSVG;
case "success":
return variant === "outline" ? checkSVG : checkWhiteSVG;
case "warning":
return variant === "outline" ? warningOrangeSVG : warningWhiteSVG;
case "loading":
return variant === "outline" ? loaderBlueSVG : loaderWhiteSVG;
default:
return variant === "outline" ? infoBlueSVG : infoWhiteSVG;
}
};
export const MiniToast = ({
type = "info",
message,
variant = "solid",
topOffset = 70,
onPress,
}: MiniToastProps) => {
const { width: windowWidth } = useWindowDimensions();

if (!message) {
return null;
}

const onToastPress = () => {
if (onPress) {
onPress();
}
};

return (
<CustomPressable
onPress={onToastPress}
style={{
position: "absolute",
top: topOffset || 70,
maxWidth: windowWidth - 40,
zIndex: 50000,
alignSelf: "center",
}}
>
<View
style={{
backgroundColor: variant === "outline" ? neutral00 : getColors(type),
borderColor: getColors(type),
borderWidth: 1,
borderStyle: "solid",
borderRadius: variant === "outline" ? 32 : 10,
paddingHorizontal: layout.spacing_x2,
paddingVertical: layout.spacing_x1_5,
flexDirection: "row",
gap: layout.spacing_x1,
}}
>
{type === "loading" ? (
<Spinner svg={getIcons(type, variant)} size={16} />
) : (
<SVG
source={getIcons(type, variant)}
height={16}
width={16}
style={{ flexShrink: 0 }}
/>
)}
<BrandText
style={[
fontSemibold14,
{
lineHeight: 16,
paddingRight: layout.spacing_x2,
maxWidth: "100%",
},
]}
>
{message}
</BrandText>
</View>
</CustomPressable>
);
};
87 changes: 87 additions & 0 deletions packages/components/toasts/NormalToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from "react";
import { TouchableOpacity, useWindowDimensions, View } from "react-native";

import warningSVG from "../../../assets/icons/warning.svg";
import {
errorColor,
neutral11,
neutral77,
successColor,
} from "../../utils/style/colors";
import { BrandText } from "../BrandText";
import { SVG } from "../SVG";
import { Box } from "../boxes/Box";
import { SpacerRow } from "../spacer";

const marginHorizontal = 24;

export interface NormalToastProps {
title: string;
message?: string;
onPress?: () => void;
type?: "error" | "success";
topOffset?: number;
}

export const NormalToast: React.FC<NormalToastProps> = ({
Copy link
Collaborator

@n0izn0iz n0izn0iz Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a regression in this component, on main it has an icon

Screenshot 2024-02-28 at 12 20 47

on this pr the ! icon does not appear

Screenshot 2024-02-28 at 12 23 13

title,
message,
onPress,
type,
topOffset = 24,
}) => {
const width = 432;
const { width: windowWidth } = useWindowDimensions();

const maxWidth = width < windowWidth ? width : windowWidth - marginHorizontal;

return (
<TouchableOpacity
onPress={onPress}
style={{
maxWidth,
width,
height: "auto",
position: "absolute",
top: topOffset,
left: windowWidth / 2 - maxWidth / 2,
zIndex: 999,
}}
>
<Box
notched
style={{
width: "100%",
height: "100%",
flexDirection: "row",
alignItems: "center",
backgroundColor: neutral11,
borderColor: type === "error" ? errorColor : successColor,
borderWidth: 1,
}}
>
{type === "error" && (
<>
<SpacerRow size={3} />
<SVG width={24} height={24} source={warningSVG} />
</>
)}
<SpacerRow size={3} />
<View
style={{ width: width - marginHorizontal * 2, marginVertical: 12 }}
>
<BrandText style={{ fontSize: 13, lineHeight: 20 }}>
{title}
</BrandText>
{message ? (
<BrandText
style={{ fontSize: 13, lineHeight: 15, color: neutral77 }}
>
{message}
</BrandText>
) : null}
</View>
</Box>
</TouchableOpacity>
);
};
Loading
Loading