-
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 all 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
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,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> | ||
); | ||
}; |
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,99 @@ | ||
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> = ({ | ||
title, | ||
message, | ||
onPress, | ||
type, | ||
topOffset = 24, | ||
}) => { | ||
const width = type === "success" ? 300 : 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} | ||
style={{ | ||
flexShrink: 0, | ||
}} | ||
/> | ||
</> | ||
)} | ||
<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, | ||
maxWidth: type === "error" ? maxWidth - 130 : maxWidth - 50, | ||
}} | ||
> | ||
{message} | ||
</BrandText> | ||
) : null} | ||
</View> | ||
</Box> | ||
</TouchableOpacity> | ||
); | ||
}; |
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.
there is a regression in this component, on main it has an icon
on this pr the
!
icon does not appear