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

Sonner.Promise and other Fixes #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
105 changes: 75 additions & 30 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
<!doctype html>
<html>
<head>
<title>sonner-js example</title>
<link rel="stylesheet" href="../src/sonner.css" />
<script src="../src/sonner.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
Sonner.init({
closeButton: false,
richColors: false,
position: "bottom-center",
});

<head>
<title>sonner-js example</title>
<link rel="stylesheet" href="../src/sonner.css" />
<script src="../src/sonner.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
Sonner.init({
closeButton: false,
richColors: false,
position: "bottom-center",
});
});

function loading(fail) {
const promise = new Promise((resolve, reject) => {
setTimeout(() => {
if (fail) reject(new Error('OH NO!'));
resolve(Date.now())
}, 2_500);
});

Sonner.promise(promise, {
loading: 'Waiting for 2.5s...',
success: (data) => `The current time is now: ${data}`,
error: 'Oops! Failed :c',
});
</script>
</head>

<body>
<button onclick="Sonner.show('This is a sample toast')">Show Toast</button>
<button onclick="Sonner.success('This is a sample toast')">
Show Success Toast
</button>
<button onclick="Sonner.error('This is a sample toast')">
Show Error Toast
</button>
<button onclick="Sonner.warning('This is a sample toast')">
Show Warning Toast
</button>
<button onclick="Sonner.info('This is a sample toast')">
Show Info Toast
</button>
</body>
</html>
}

function loadingLots() {
for (let i = 0; i < 10; i++) {
const promise = new Promise((resolve, reject) => {
setTimeout(() => {
if (fail) reject(new Error('OH NO!'));
resolve(Date.now())
}, 1_000);
});
Sonner.promise(promise, {
loading: `#${i}: Waiting for 1s...`,
success: (data) => `The current time is now: ${data}`,
error: 'Oops! Failed :c',
duration: -1
});
}
}

</script>
</head>

<body>
<button onclick="Sonner.show('This is a sample toast')">Show Toast</button>
<button onclick="Sonner.success('This is a sample toast')">
Show Success Toast
</button>
<button onclick="Sonner.error('This is a sample toast')">
Show Error Toast
</button>
<button onclick="Sonner.warning('This is a sample toast')">
Show Warning Toast
</button>
<button onclick="Sonner.info('This is a sample toast')">
Show Info Toast
</button>

<button onclick="loading(false)">
Show Loading Toast
</button>
<button onclick="loading(true)">
Show Loading Failure Toast
</button>
<button onclick="loadingLots()">
Show Loading lots Toast
</button>
</body>

</html>
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dist"
],
"scripts": {
"prepare": "uglifyjs src/sonner.js -o dist/sonner.min.js && uglifycss src/sonner.css --output dist/sonner.min.css"
"build": "webpack"
},
"repository": {
"type": "git",
Expand All @@ -28,7 +28,13 @@
},
"homepage": "https://github.com/fernandojpps/sonner-js#readme",
"devDependencies": {
"uglify-js": "^3.6.0",
"uglifycss": "^0.0.29"
"css-loader": "^7.1.2",
"css-minimizer-webpack-plugin": "^7.0.0",
"mini-css-extract-plugin": "^2.9.0",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"style-loader": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions src/sonner.css
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ html[dir="rtl"],
}

[data-sonner-toast][data-expanded="false"][data-front="false"] {
--scale: var(--toasts-before) * 0.05 + 1;
--scale: var(--toasts-before) * 0.05;
--y: translateY(calc(var(--lift-amount) * var(--toasts-before)))
scale(calc(-1 * var(--scale)));
scale(calc(1 - var(--scale)));
height: var(--front-toast-height);
}

Expand Down
Loading