-
Notifications
You must be signed in to change notification settings - Fork 17
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
Changes from 6 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 b52efdd
refactor: moved toast message clear logic from toast component to toa…
sachin-into 2cb5fc3
refactor: replaced MiniToast on mini comment input
sachin-into 168d4a3
refactor: removed ToastProvider and moved added miniToast on feedback…
sachin-into 45f1dae
chore: removed console.log
sachin-into 1fe5339
feat: added clear toast on press
sachin-into 6b96729
Merge branch 'main' into feat/mini-Toast
sakul-budhathoki b7947c6
refactor: Feedback Provider to use single api for mini and normal toast,
sachin-into a5fe0a0
Merge branch 'feat/mini-Toast' of https://github.com/TERITORI/teritor…
sachin-into ff0c80f
fix: tsc errors
sachin-into 080813d
fix: unused exports error
sachin-into 46fc3ab
feat:created toast component for mini mode and added icons and colors…
sachin-into 06d66ba
refactor: moved toast message clear logic from toast component to toa…
sachin-into 3402c3b
refactor: replaced MiniToast on mini comment input
sachin-into 94397d1
refactor: removed ToastProvider and moved added miniToast on feedback…
sachin-into d956383
chore: removed console.log
sachin-into 713687e
feat: added clear toast on press
sachin-into 149d2a4
refactor: Feedback Provider to use single api for mini and normal toast,
sachin-into 2b4ac8d
fix: tsc errors
sachin-into a43cf04
fix: unused exports error
sachin-into 52da131
fix: regression
sakul-budhathoki effd876
fix: regression no right padding
sachin-into 7503178
Merge branch 'feat/mini-Toast' of https://github.com/TERITORI/teritor…
sachin-into 3a9f7c8
fix:padding diffrenece in success and error
sachin-into 26e1b4c
fix: different with for success and error as in main
sachin-into File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
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 type MiniToastProps = { | ||
status?: ToastStatusType; | ||
message: string | null; | ||
variant?: ToastVariantType; | ||
duration?: number; | ||
topOffset?: number; | ||
showAlways?: boolean; | ||
onPress?: () => void; | ||
}; | ||
|
||
const getColors = (status: ToastStatusType) => { | ||
switch (status) { | ||
case "error": | ||
return toastRed; | ||
case "success": | ||
return toastGreen; | ||
case "warning": | ||
return toastOrange; | ||
case "loading": | ||
return blueDefault; | ||
default: | ||
return blueDefault; | ||
} | ||
}; | ||
|
||
const getIcons = (status: ToastStatusType, variant: ToastVariantType) => { | ||
switch (status) { | ||
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 = ({ | ||
status = "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(status), | ||
borderColor: getColors(status), | ||
borderWidth: 1, | ||
borderStyle: "solid", | ||
borderRadius: variant === "outline" ? 32 : 10, | ||
paddingHorizontal: layout.spacing_x2, | ||
paddingVertical: layout.spacing_x1_5, | ||
flexDirection: "row", | ||
gap: layout.spacing_x1, | ||
}} | ||
> | ||
{status === "loading" ? ( | ||
<Spinner svg={getIcons(status, variant)} size={16} /> | ||
) : ( | ||
<SVG | ||
source={getIcons(status, variant)} | ||
height={16} | ||
width={16} | ||
style={{ flexShrink: 0 }} | ||
/> | ||
)} | ||
<BrandText | ||
style={[ | ||
fontSemibold14, | ||
{ | ||
lineHeight: 16, | ||
paddingRight: layout.spacing_x2, | ||
maxWidth: "100%", | ||
}, | ||
]} | ||
> | ||
{message} | ||
</BrandText> | ||
</View> | ||
</CustomPressable> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't add new api, use previous api or extend it and change the toast render only
we need all existing toasts to work in mini mode also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mini toast has 4 different status and 2 different variant style so I created new api without touching previous working apis. Previous toast works as it used to and new api is for mini mode. Won't that be simple and easier to distinguish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think, a toast should be a toast, the mode can affect how it renders but we should have a single api
you can extend the current api