mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-12 11:12:07 +00:00
chore: refactoring toast
This commit is contained in:
parent
f81e4ac5b5
commit
b86746287f
15 changed files with 1602 additions and 98 deletions
|
@ -7,6 +7,7 @@ module.exports = {
|
||||||
"plugin:jsx-a11y/recommended",
|
"plugin:jsx-a11y/recommended",
|
||||||
"@electron-toolkit/eslint-config-ts/recommended",
|
"@electron-toolkit/eslint-config-ts/recommended",
|
||||||
"plugin:prettier/recommended",
|
"plugin:prettier/recommended",
|
||||||
|
"plugin:storybook/recommended"
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
"@typescript-eslint/explicit-function-return-type": "off",
|
"@typescript-eslint/explicit-function-return-type": "off",
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -14,3 +14,5 @@ aria2/
|
||||||
|
|
||||||
# Sentry Config File
|
# Sentry Config File
|
||||||
.env.sentry-build-plugin
|
.env.sentry-build-plugin
|
||||||
|
|
||||||
|
*storybook.log
|
||||||
|
|
85
.storybook/app.css.ts
Normal file
85
.storybook/app.css.ts
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
import { createContainer, globalStyle } from "@vanilla-extract/css";
|
||||||
|
import { vars } from "../src/renderer/src/theme.css";
|
||||||
|
|
||||||
|
export const appContainer = createContainer();
|
||||||
|
|
||||||
|
globalStyle("*", {
|
||||||
|
boxSizing: "border-box",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("::-webkit-scrollbar", {
|
||||||
|
width: "9px",
|
||||||
|
backgroundColor: vars.color.darkBackground,
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("::-webkit-scrollbar-track", {
|
||||||
|
backgroundColor: "rgba(255, 255, 255, 0.03)",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("::-webkit-scrollbar-thumb", {
|
||||||
|
backgroundColor: "rgba(255, 255, 255, 0.08)",
|
||||||
|
borderRadius: "24px",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("::-webkit-scrollbar-thumb:hover", {
|
||||||
|
backgroundColor: "rgba(255, 255, 255, 0.16)",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("html, body, #root, main", {
|
||||||
|
height: "100%",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("body", {
|
||||||
|
userSelect: "none",
|
||||||
|
fontFamily: "Noto Sans, sans-serif",
|
||||||
|
fontSize: vars.size.body,
|
||||||
|
color: vars.color.body,
|
||||||
|
margin: "0",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("button", {
|
||||||
|
padding: "0",
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
border: "none",
|
||||||
|
fontFamily: "inherit",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("h1, h2, h3, h4, h5, h6, p", {
|
||||||
|
margin: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("p", {
|
||||||
|
lineHeight: "20px",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("#root, main", {
|
||||||
|
display: "flex",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("#root", {
|
||||||
|
flexDirection: "column",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle(
|
||||||
|
"input::-webkit-outer-spin-button, input::-webkit-inner-spin-button",
|
||||||
|
{
|
||||||
|
WebkitAppearance: "none",
|
||||||
|
margin: "0",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
globalStyle("label", {
|
||||||
|
fontSize: vars.size.body,
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("input[type=number]", {
|
||||||
|
MozAppearance: "textfield",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle("img", {
|
||||||
|
WebkitUserDrag: "none",
|
||||||
|
} as Record<string, string>);
|
||||||
|
|
||||||
|
globalStyle("progress[value]", {
|
||||||
|
WebkitAppearance: "none",
|
||||||
|
});
|
31
.storybook/main.ts
Normal file
31
.storybook/main.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { resolve } from "path";
|
||||||
|
import type { StorybookConfig } from "@storybook/react-vite";
|
||||||
|
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
||||||
|
|
||||||
|
const config: StorybookConfig = {
|
||||||
|
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
|
||||||
|
addons: [
|
||||||
|
"@storybook/addon-onboarding",
|
||||||
|
"@storybook/addon-essentials",
|
||||||
|
"@chromatic-com/storybook",
|
||||||
|
"@storybook/addon-interactions",
|
||||||
|
],
|
||||||
|
framework: {
|
||||||
|
name: "@storybook/react-vite",
|
||||||
|
options: {},
|
||||||
|
},
|
||||||
|
viteFinal: (config) => {
|
||||||
|
return {
|
||||||
|
...config,
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@renderer": resolve("src/renderer/src"),
|
||||||
|
"@locales": resolve("src/locales"),
|
||||||
|
"@shared": resolve("src/shared"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [...config.plugins, vanillaExtractPlugin()],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default config;
|
22
.storybook/preview.ts
Normal file
22
.storybook/preview.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import type { Preview } from "@storybook/react";
|
||||||
|
|
||||||
|
import "@fontsource/noto-sans/400.css";
|
||||||
|
import "@fontsource/noto-sans/500.css";
|
||||||
|
import "@fontsource/noto-sans/700.css";
|
||||||
|
|
||||||
|
import "react-loading-skeleton/dist/skeleton.css";
|
||||||
|
|
||||||
|
import "./app.css";
|
||||||
|
|
||||||
|
const preview: Preview = {
|
||||||
|
parameters: {
|
||||||
|
controls: {
|
||||||
|
matchers: {
|
||||||
|
color: /(background|color)$/i,
|
||||||
|
date: /Date$/i,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default preview;
|
14
package.json
14
package.json
|
@ -29,7 +29,9 @@
|
||||||
"build:mac": "electron-vite build && electron-builder --mac",
|
"build:mac": "electron-vite build && electron-builder --mac",
|
||||||
"build:linux": "electron-vite build && electron-builder --linux",
|
"build:linux": "electron-vite build && electron-builder --linux",
|
||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
"knex:migrate:make": "knex --knexfile src/main/knexfile.ts migrate:make --esm"
|
"knex:migrate:make": "knex --knexfile src/main/knexfile.ts migrate:make --esm",
|
||||||
|
"storybook": "storybook dev -p 6006",
|
||||||
|
"build-storybook": "storybook build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-toolkit/preload": "^3.0.0",
|
"@electron-toolkit/preload": "^3.0.0",
|
||||||
|
@ -82,11 +84,19 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.705.0",
|
"@aws-sdk/client-s3": "^3.705.0",
|
||||||
|
"@chromatic-com/storybook": "^3.2.4",
|
||||||
"@commitlint/cli": "^19.6.0",
|
"@commitlint/cli": "^19.6.0",
|
||||||
"@commitlint/config-conventional": "^19.6.0",
|
"@commitlint/config-conventional": "^19.6.0",
|
||||||
"@electron-toolkit/eslint-config-prettier": "^2.0.0",
|
"@electron-toolkit/eslint-config-prettier": "^2.0.0",
|
||||||
"@electron-toolkit/eslint-config-ts": "^2.0.0",
|
"@electron-toolkit/eslint-config-ts": "^2.0.0",
|
||||||
"@electron-toolkit/tsconfig": "^1.0.1",
|
"@electron-toolkit/tsconfig": "^1.0.1",
|
||||||
|
"@storybook/addon-essentials": "^8.5.1",
|
||||||
|
"@storybook/addon-interactions": "^8.5.1",
|
||||||
|
"@storybook/addon-onboarding": "^8.5.1",
|
||||||
|
"@storybook/blocks": "^8.5.1",
|
||||||
|
"@storybook/react": "^8.5.1",
|
||||||
|
"@storybook/react-vite": "^8.5.1",
|
||||||
|
"@storybook/test": "^8.5.1",
|
||||||
"@swc/core": "^1.4.16",
|
"@swc/core": "^1.4.16",
|
||||||
"@types/auto-launch": "^5.0.5",
|
"@types/auto-launch": "^5.0.5",
|
||||||
"@types/color": "^3.0.6",
|
"@types/color": "^3.0.6",
|
||||||
|
@ -109,11 +119,13 @@
|
||||||
"eslint-plugin-jsx-a11y": "^6.10.2",
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
||||||
"eslint-plugin-react": "^7.37.2",
|
"eslint-plugin-react": "^7.37.2",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
|
"eslint-plugin-storybook": "^0.11.2",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"sass-embedded": "^1.80.6",
|
"sass-embedded": "^1.80.6",
|
||||||
|
"storybook": "^8.5.1",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^5.0.12",
|
"vite": "^5.0.12",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { registerEvent } from "../register-event";
|
||||||
import type { UserPreferences } from "@types";
|
import type { UserPreferences } from "@types";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
import { db, levelKeys } from "@main/level";
|
import { db, levelKeys } from "@main/level";
|
||||||
|
import { Crypto } from "@main/services";
|
||||||
|
|
||||||
const updateUserPreferences = async (
|
const updateUserPreferences = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
@ -21,6 +22,12 @@ const updateUserPreferences = async (
|
||||||
i18next.changeLanguage(preferences.language);
|
i18next.changeLanguage(preferences.language);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preferences.realDebridApiToken) {
|
||||||
|
preferences.realDebridApiToken = Crypto.encrypt(
|
||||||
|
preferences.realDebridApiToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await db.put<string, UserPreferences>(
|
await db.put<string, UserPreferences>(
|
||||||
levelKeys.userPreferences,
|
levelKeys.userPreferences,
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,17 +25,20 @@ export class DownloadManager {
|
||||||
) {
|
) {
|
||||||
PythonRPC.spawn(
|
PythonRPC.spawn(
|
||||||
download?.status === "active"
|
download?.status === "active"
|
||||||
? await this.getDownloadPayload(download).catch(() => undefined)
|
? await this.getDownloadPayload(download).catch((err) => {
|
||||||
|
logger.error("Error getting download payload", err);
|
||||||
|
return undefined;
|
||||||
|
})
|
||||||
: undefined,
|
: undefined,
|
||||||
downloadsToSeed?.map((download) => ({
|
downloadsToSeed?.map((download) => ({
|
||||||
game_id: `${download.shop}-${download.objectId}`,
|
game_id: levelKeys.game(download.shop, download.objectId),
|
||||||
url: download.uri,
|
url: download.uri,
|
||||||
save_path: download.downloadPath,
|
save_path: download.downloadPath,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (download) {
|
if (download) {
|
||||||
this.downloadingGameId = `${download.shop}-${download.objectId}`;
|
this.downloadingGameId = levelKeys.game(download.shop, download.objectId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { downloadSourcesWorker } from "./workers";
|
||||||
import { downloadSourcesTable } from "./dexie";
|
import { downloadSourcesTable } from "./dexie";
|
||||||
import { useSubscription } from "./hooks/use-subscription";
|
import { useSubscription } from "./hooks/use-subscription";
|
||||||
import { HydraCloudModal } from "./pages/shared-modals/hydra-cloud/hydra-cloud-modal";
|
import { HydraCloudModal } from "./pages/shared-modals/hydra-cloud/hydra-cloud-modal";
|
||||||
|
import { SPACING_UNIT } from "./theme.css";
|
||||||
|
|
||||||
export interface AppProps {
|
export interface AppProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
@ -212,22 +213,22 @@ export function App() {
|
||||||
const id = crypto.randomUUID();
|
const id = crypto.randomUUID();
|
||||||
const channel = new BroadcastChannel(`download_sources:sync:${id}`);
|
const channel = new BroadcastChannel(`download_sources:sync:${id}`);
|
||||||
|
|
||||||
channel.onmessage = (event: MessageEvent<number>) => {
|
channel.onmessage = async (event: MessageEvent<number>) => {
|
||||||
const newRepacksCount = event.data;
|
const newRepacksCount = event.data;
|
||||||
window.electron.publishNewRepacksNotification(newRepacksCount);
|
window.electron.publishNewRepacksNotification(newRepacksCount);
|
||||||
updateRepacks();
|
updateRepacks();
|
||||||
|
|
||||||
downloadSourcesTable.toArray().then((downloadSources) => {
|
const downloadSources = await downloadSourcesTable.toArray();
|
||||||
|
|
||||||
downloadSources
|
downloadSources
|
||||||
.filter((source) => !source.fingerprint)
|
.filter((source) => !source.fingerprint)
|
||||||
.forEach((downloadSource) => {
|
.forEach(async (downloadSource) => {
|
||||||
window.electron
|
const { fingerprint } = await window.electron.putDownloadSource(
|
||||||
.putDownloadSource(downloadSource.objectIds)
|
downloadSource.objectIds
|
||||||
.then(({ fingerprint }) => {
|
);
|
||||||
|
|
||||||
downloadSourcesTable.update(downloadSource.id, { fingerprint });
|
downloadSourcesTable.update(downloadSource.id, { fingerprint });
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
downloadSourcesWorker.postMessage(["SYNC_DOWNLOAD_SOURCES", id]);
|
downloadSourcesWorker.postMessage(["SYNC_DOWNLOAD_SOURCES", id]);
|
||||||
|
@ -250,12 +251,22 @@ export function App() {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
bottom: `${26 + SPACING_UNIT * 2}px`,
|
||||||
|
right: "16px",
|
||||||
|
maxWidth: "420px",
|
||||||
|
width: "420px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Toast
|
<Toast
|
||||||
visible={toast.visible}
|
visible={toast.visible}
|
||||||
message={toast.message}
|
message={toast.message}
|
||||||
type={toast.type}
|
type={toast.type}
|
||||||
onClose={handleToastClose}
|
onClose={handleToastClose}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<HydraCloudModal
|
<HydraCloudModal
|
||||||
visible={isHydraCloudModalVisible}
|
visible={isHydraCloudModalVisible}
|
||||||
|
|
|
@ -3,46 +3,54 @@ import { keyframes, style } from "@vanilla-extract/css";
|
||||||
import { SPACING_UNIT, vars } from "../../theme.css";
|
import { SPACING_UNIT, vars } from "../../theme.css";
|
||||||
import { recipe } from "@vanilla-extract/recipes";
|
import { recipe } from "@vanilla-extract/recipes";
|
||||||
|
|
||||||
const TOAST_HEIGHT = 80;
|
export const enter = keyframes({
|
||||||
|
"0%": {
|
||||||
export const slideIn = keyframes({
|
opacity: 0,
|
||||||
"0%": { transform: `translateY(${TOAST_HEIGHT + SPACING_UNIT * 2}px)` },
|
transform: "translateY(100%)",
|
||||||
"100%": { transform: "translateY(0)" },
|
},
|
||||||
|
"100%": {
|
||||||
|
opacity: 1,
|
||||||
|
transform: "translateY(0)",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const slideOut = keyframes({
|
export const exit = keyframes({
|
||||||
"0%": { transform: `translateY(0)` },
|
"0%": {
|
||||||
"100%": { transform: `translateY(${TOAST_HEIGHT + SPACING_UNIT * 2}px)` },
|
opacity: 1,
|
||||||
|
transform: "translateY(0)",
|
||||||
|
},
|
||||||
|
"100%": {
|
||||||
|
opacity: 0,
|
||||||
|
transform: "translateY(100%)",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const toast = recipe({
|
export const toast = recipe({
|
||||||
base: {
|
base: {
|
||||||
animationDuration: "0.2s",
|
animationDuration: "0.15s",
|
||||||
animationTimingFunction: "ease-in-out",
|
animationTimingFunction: "ease-in-out",
|
||||||
maxHeight: TOAST_HEIGHT,
|
maxWidth: "420px",
|
||||||
position: "fixed",
|
position: "absolute",
|
||||||
backgroundColor: vars.color.background,
|
backgroundColor: vars.color.background,
|
||||||
borderRadius: "4px",
|
borderRadius: "4px",
|
||||||
border: `solid 1px ${vars.color.border}`,
|
border: `solid 1px ${vars.color.border}`,
|
||||||
right: `${SPACING_UNIT * 2}px`,
|
right: "0",
|
||||||
/* Bottom panel height + 16px */
|
bottom: "0",
|
||||||
bottom: `${26 + SPACING_UNIT * 2}px`,
|
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
zIndex: vars.zIndex.toast,
|
zIndex: vars.zIndex.toast,
|
||||||
maxWidth: "500px",
|
|
||||||
},
|
},
|
||||||
variants: {
|
variants: {
|
||||||
closing: {
|
closing: {
|
||||||
true: {
|
true: {
|
||||||
animationName: slideOut,
|
animationName: exit,
|
||||||
transform: `translateY(${TOAST_HEIGHT + SPACING_UNIT * 2}px)`,
|
transform: "translateY(100%)",
|
||||||
},
|
},
|
||||||
false: {
|
false: {
|
||||||
animationName: slideIn,
|
animationName: enter,
|
||||||
transform: `translateY(0)`,
|
transform: "translateY(0)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -58,7 +66,7 @@ export const toastContent = style({
|
||||||
|
|
||||||
export const progress = style({
|
export const progress = style({
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "5px",
|
height: "3px",
|
||||||
"::-webkit-progress-bar": {
|
"::-webkit-progress-bar": {
|
||||||
backgroundColor: vars.color.darkBackground,
|
backgroundColor: vars.color.darkBackground,
|
||||||
},
|
},
|
||||||
|
@ -70,8 +78,10 @@ export const progress = style({
|
||||||
export const closeButton = style({
|
export const closeButton = style({
|
||||||
color: vars.color.body,
|
color: vars.color.body,
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
padding: "0",
|
transition: "all ease 0.15s",
|
||||||
margin: "0",
|
":hover": {
|
||||||
|
color: vars.color.muted,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const successIcon = style({
|
export const successIcon = style({
|
||||||
|
|
|
@ -13,12 +13,19 @@ export interface ToastProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
type: "success" | "error" | "warning";
|
type: "success" | "error" | "warning";
|
||||||
|
duration?: number;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const INITIAL_PROGRESS = 100;
|
const INITIAL_PROGRESS = 100;
|
||||||
|
|
||||||
export function Toast({ visible, message, type, onClose }: ToastProps) {
|
export function Toast({
|
||||||
|
visible,
|
||||||
|
message,
|
||||||
|
type,
|
||||||
|
duration = 5000,
|
||||||
|
onClose,
|
||||||
|
}: Readonly<ToastProps>) {
|
||||||
const [isClosing, setIsClosing] = useState(false);
|
const [isClosing, setIsClosing] = useState(false);
|
||||||
const [progress, setProgress] = useState(INITIAL_PROGRESS);
|
const [progress, setProgress] = useState(INITIAL_PROGRESS);
|
||||||
|
|
||||||
|
@ -31,7 +38,7 @@ export function Toast({ visible, message, type, onClose }: ToastProps) {
|
||||||
|
|
||||||
closingAnimation.current = requestAnimationFrame(
|
closingAnimation.current = requestAnimationFrame(
|
||||||
function animateClosing(time) {
|
function animateClosing(time) {
|
||||||
if (time - zero <= 200) {
|
if (time - zero <= 150) {
|
||||||
closingAnimation.current = requestAnimationFrame(animateClosing);
|
closingAnimation.current = requestAnimationFrame(animateClosing);
|
||||||
} else {
|
} else {
|
||||||
onClose();
|
onClose();
|
||||||
|
@ -43,17 +50,13 @@ export function Toast({ visible, message, type, onClose }: ToastProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
const zero = performance.now();
|
const zero = performance.now();
|
||||||
|
|
||||||
progressAnimation.current = requestAnimationFrame(
|
progressAnimation.current = requestAnimationFrame(
|
||||||
function animateProgress(time) {
|
function animateProgress(time) {
|
||||||
const elapsed = time - zero;
|
const elapsed = time - zero;
|
||||||
|
const progress = Math.min(elapsed / duration, 1);
|
||||||
const progress = Math.min(elapsed / 2500, 1);
|
|
||||||
const currentValue =
|
const currentValue =
|
||||||
INITIAL_PROGRESS + (0 - INITIAL_PROGRESS) * progress;
|
INITIAL_PROGRESS + (0 - INITIAL_PROGRESS) * progress;
|
||||||
|
|
||||||
setProgress(currentValue);
|
setProgress(currentValue);
|
||||||
|
|
||||||
if (progress < 1) {
|
if (progress < 1) {
|
||||||
progressAnimation.current = requestAnimationFrame(animateProgress);
|
progressAnimation.current = requestAnimationFrame(animateProgress);
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,25 +73,40 @@ export function Toast({ visible, message, type, onClose }: ToastProps) {
|
||||||
setIsClosing(false);
|
setIsClosing(false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {};
|
return () => {};
|
||||||
}, [startAnimateClosing, visible]);
|
}, [startAnimateClosing, duration, visible]);
|
||||||
|
|
||||||
if (!visible) return null;
|
if (!visible) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.toast({ closing: isClosing })}>
|
<div className={styles.toast({ closing: isClosing })}>
|
||||||
<div className={styles.toastContent}>
|
<div className={styles.toastContent}>
|
||||||
<div style={{ display: "flex", gap: `${SPACING_UNIT}px` }}>
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
gap: `${SPACING_UNIT}px`,
|
||||||
|
flexDirection: "column",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: `${SPACING_UNIT}px`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
{type === "success" && (
|
{type === "success" && (
|
||||||
<CheckCircleFillIcon className={styles.successIcon} />
|
<CheckCircleFillIcon className={styles.successIcon} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{type === "error" && <XCircleFillIcon className={styles.errorIcon} />}
|
{type === "error" && (
|
||||||
|
<XCircleFillIcon className={styles.errorIcon} />
|
||||||
|
)}
|
||||||
|
|
||||||
{type === "warning" && <AlertIcon className={styles.warningIcon} />}
|
{type === "warning" && <AlertIcon className={styles.warningIcon} />}
|
||||||
<span style={{ fontWeight: "bold" }}>{message}</span>
|
|
||||||
</div>
|
<span style={{ fontWeight: "bold", flex: 1 }}>{message}</span>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -100,6 +118,13 @@ export function Toast({ visible, message, type, onClose }: ToastProps) {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This is a really really long message that should wrap to the next
|
||||||
|
line
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<progress className={styles.progress} value={progress} max={100} />
|
<progress className={styles.progress} value={progress} max={100} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
74
src/stories/button.stories.tsx
Normal file
74
src/stories/button.stories.tsx
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
import type { Meta, StoryObj } from "@storybook/react";
|
||||||
|
import { Button } from "@renderer/components";
|
||||||
|
|
||||||
|
const meta = {
|
||||||
|
title: "Components/Button",
|
||||||
|
component: Button,
|
||||||
|
parameters: {
|
||||||
|
layout: "centered",
|
||||||
|
},
|
||||||
|
tags: ["autodocs"],
|
||||||
|
} satisfies Meta<typeof Button>;
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof Button>;
|
||||||
|
|
||||||
|
// Primary button (default)
|
||||||
|
export const Primary: Story = {
|
||||||
|
args: {
|
||||||
|
children: "Primary Button",
|
||||||
|
theme: "primary",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Outline variant
|
||||||
|
export const Outline: Story = {
|
||||||
|
args: {
|
||||||
|
children: "Outline Button",
|
||||||
|
theme: "outline",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Dark variant
|
||||||
|
export const Dark: Story = {
|
||||||
|
args: {
|
||||||
|
children: "Dark Button",
|
||||||
|
theme: "dark",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Danger variant
|
||||||
|
export const Danger: Story = {
|
||||||
|
args: {
|
||||||
|
children: "Danger Button",
|
||||||
|
theme: "danger",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Disabled state
|
||||||
|
export const Disabled: Story = {
|
||||||
|
args: {
|
||||||
|
children: "Disabled Button",
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Button with icon example
|
||||||
|
export const WithIcon: Story = {
|
||||||
|
args: {
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
<span>🚀</span>
|
||||||
|
<span>Button with Icon</span>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Different sizes example using className
|
||||||
|
export const CustomClassName: Story = {
|
||||||
|
args: {
|
||||||
|
children: "Custom Class Button",
|
||||||
|
className: "custom-class",
|
||||||
|
},
|
||||||
|
};
|
115
src/stories/toast.stories.tsx
Normal file
115
src/stories/toast.stories.tsx
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
import type { Meta, StoryObj } from "@storybook/react";
|
||||||
|
import { Toast } from "@renderer/components";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const meta = {
|
||||||
|
title: "Components/Toast",
|
||||||
|
component: Toast,
|
||||||
|
parameters: {
|
||||||
|
layout: "centered",
|
||||||
|
},
|
||||||
|
tags: ["autodocs"],
|
||||||
|
} satisfies Meta<typeof Toast>;
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof Toast>;
|
||||||
|
|
||||||
|
// Base stories for each variant
|
||||||
|
export const Success: Story = {
|
||||||
|
args: {
|
||||||
|
visible: true,
|
||||||
|
message: "Operation completed successfully",
|
||||||
|
type: "success",
|
||||||
|
onClose: () => {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Error: Story = {
|
||||||
|
args: {
|
||||||
|
visible: true,
|
||||||
|
message: "An error occurred",
|
||||||
|
type: "error",
|
||||||
|
onClose: () => {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Warning: Story = {
|
||||||
|
args: {
|
||||||
|
visible: true,
|
||||||
|
message: "Please review before proceeding",
|
||||||
|
type: "warning",
|
||||||
|
onClose: () => {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Interactive story with toggle functionality
|
||||||
|
const InteractiveToastTemplate = () => {
|
||||||
|
const [visible, setVisible] = useState(true);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: "20px" }}>
|
||||||
|
<button onClick={() => setVisible(true)} style={{ marginBottom: "20px" }}>
|
||||||
|
Show Toast
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
bottom: "16px",
|
||||||
|
right: "16px",
|
||||||
|
maxWidth: "420px",
|
||||||
|
width: "420px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Toast
|
||||||
|
visible={visible}
|
||||||
|
message="This is an interactive toast"
|
||||||
|
type="success"
|
||||||
|
onClose={() => setVisible(false)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Interactive: Story = {
|
||||||
|
render: () => <InteractiveToastTemplate />,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Long message example
|
||||||
|
export const LongMessage: Story = {
|
||||||
|
args: {
|
||||||
|
visible: true,
|
||||||
|
message:
|
||||||
|
"This is a very long message that demonstrates how the toast component handles text wrapping and content overflow in cases where the message is extensive",
|
||||||
|
type: "success",
|
||||||
|
onClose: () => {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Story with auto-close behavior
|
||||||
|
const AutoCloseToastTemplate = () => {
|
||||||
|
const [visible, setVisible] = useState(true);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: "20px" }}>
|
||||||
|
<button
|
||||||
|
onClick={() => setVisible(true)}
|
||||||
|
style={{ marginBottom: "20px" }}
|
||||||
|
disabled={visible}
|
||||||
|
>
|
||||||
|
Show Toast Again
|
||||||
|
</button>
|
||||||
|
<Toast
|
||||||
|
visible={visible}
|
||||||
|
message="This toast will auto-close in 2.5 seconds"
|
||||||
|
type="success"
|
||||||
|
onClose={() => setVisible(false)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AutoClose: Story = {
|
||||||
|
render: () => <AutoCloseToastTemplate />,
|
||||||
|
};
|
|
@ -6,7 +6,9 @@
|
||||||
"src/renderer/src/**/*.tsx",
|
"src/renderer/src/**/*.tsx",
|
||||||
"src/preload/*.d.ts",
|
"src/preload/*.d.ts",
|
||||||
"src/locales/index.ts",
|
"src/locales/index.ts",
|
||||||
"src/shared/**/*"
|
"src/shared/**/*",
|
||||||
|
"src/stories/**/*",
|
||||||
|
".storybook/**/*"
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
|
|
Loading…
Reference in a new issue