Skip to content

Commit

Permalink
Toast positions for sm devices
Browse files Browse the repository at this point in the history
  • Loading branch information
brodysmith1 committed Mar 4, 2024
1 parent 4686ac2 commit 095e862
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/lib/components/Toast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
if (mounted && toast) {
toast?.onEnter?.(callbackProps)
if (toast.target) {
const element = qs(toast.target)
const query = (window.innerWidth <= 900 && toast.mobileTarget) || toast.target
const element = qs(query)
if (element) {
const style = getComputedStyle(element)
Expand Down Expand Up @@ -218,14 +219,6 @@
display: grid
grid-template-columns: auto 1fr
&.top
top: 0
bottom: auto
&.right
right: 0
left: auto
.toast-img
width: 35px
display: flex
Expand Down Expand Up @@ -266,6 +259,15 @@
.toast-wrapper
font-size: 0.875rem
.toast
&.top
top: 0
bottom: auto
&.right
right: 0
left: auto
.toast-button
font-size: 1rem
Expand Down
18 changes: 17 additions & 1 deletion src/lib/data/toasts/tips.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get } from "svelte/store"
import { gameSettings } from "$lib/stores/state"
import { gameSettings, userState } from "$lib/stores/state"

import type { Toast } from "./types"

Expand All @@ -13,6 +13,7 @@ export const tips: Toast[] = [
img: "guide.png",
title: "Tip: Make a move",
target: "#food-menu-wrapper",
mobilePosition: "bottom right",
message:
"Click the buttons here to pick up a food item, then click a square on your farm to swap them.",
button: "Next"
Expand All @@ -24,6 +25,8 @@ export const tips: Toast[] = [
img: "guide.png",
title: "Tip: Undo your moves",
target: "header .button-undo",
mobileTarget: "#mobile-menu .button-undo",
mobilePosition: "bottom right",
message: `Did you know you can use this button to undo your last move? You have up to ${$gameSettings.undoLimit} undos per game, so use them wisely!`,
button: "Next"
},
Expand All @@ -33,9 +36,22 @@ export const tips: Toast[] = [
next: "tip-4",
img: "guide.png",
target: ".food-items-grid",
mobilePosition: "bottom right",
title: "Tip: Optimise your land use",
message:
"The best foods to add are the ones that will give you the most calories per hectare. Swap them out with the lowest calorie per hectare foods you have on your farm.",
onEnter: () => {
userState.update(($u) => {
$u.isMobileTablesOpen = true
return $u
})
},
onDismiss: () => {
userState.update(($u) => {
$u.isMobileTablesOpen = false
return $u
})
},
button: "Next"
},
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/data/toasts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type Toast = {
button?: string
target?: string
next?: string | number
mobileTarget?: string
mobilePosition?: "top left" | "top right" | "bottom left" | "bottom right"
task?: (props: CallBackProps) => boolean
trigger?: (props: CallBackProps) => boolean
Expand Down

0 comments on commit 095e862

Please sign in to comment.