Skip to content

Commit

Permalink
Merge pull request #1 from pheralb/next
Browse files Browse the repository at this point in the history
🚀 v0.2.0
  • Loading branch information
pheralb authored Aug 1, 2024
2 parents f6279a0 + cc8d3e2 commit 5810685
Show file tree
Hide file tree
Showing 42 changed files with 2,367 additions and 369 deletions.
6 changes: 5 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["@pheralb/toast-website"]
"ignore": [
"@pheralb/toast-website",
"@pheralb-toast/nextjs-example",
"@pheralb-toast/astro-example"
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Astro
.astro

# Dependencies
node_modules
.pnp
Expand Down
8 changes: 8 additions & 0 deletions examples/astro/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'astro/config';

import react from "@astrojs/react";

// https://astro.build/config
export default defineConfig({
integrations: [react()]
});
24 changes: 24 additions & 0 deletions examples/astro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@pheralb-toast/astro-example",
"type": "module",
"private": true,
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@pheralb/toast": "workspace:^",
"@astrojs/check": "0.9.1",
"@astrojs/react": "3.6.1",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"astro": "4.12.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "5.5.4"
}
}
17 changes: 17 additions & 0 deletions examples/astro/src/components/showToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { toast } from '@pheralb/toast';

const ShowToast = () => {
const handleClick = () => {
toast.default({
text: 'Hello, world!',
});
};

return (
<button type="button" onClick={handleClick}>
Show Toast
</button>
);
};

export default ShowToast;
1 change: 1 addition & 0 deletions examples/astro/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="astro/client" />
25 changes: 25 additions & 0 deletions examples/astro/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
interface Props {
title: string;
}
import { Toaster } from '@pheralb/toast';
const { title } = Astro.props;
---

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Astro description" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot />
<Toaster client:load theme="light" />
</body>
</html>
11 changes: 11 additions & 0 deletions examples/astro/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Layout from '../layouts/Layout.astro';
import ShowToast from '../components/showToast';
---

<Layout title="Welcome to Astro.">
<main>
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
<ShowToast client:load />
</main>
</Layout>
7 changes: 7 additions & 0 deletions examples/astro/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
}
}
3 changes: 2 additions & 1 deletion examples/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default function RootLayout({
enableSystem
disableTransitionOnChange
>
<ToastClientProvider>{children}</ToastClientProvider>
<ToastClientProvider />
{children}
</ThemeProvider>
</body>
</html>
Expand Down
15 changes: 7 additions & 8 deletions examples/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
'use client';

import { useToast } from '@pheralb/toast';
import { toast } from '@pheralb/toast';
import { PartyPopperIcon } from 'lucide-react';
import { useTheme } from 'next-themes';
import { useState } from 'react';

export default function Home() {
const { setTheme } = useTheme();
const [duration, setDuration] = useState<number>(8000);
const t = useToast();
const buttonStyles =
'p-2 m-2 bg-neutral-100 border border-neutral-300 dark:border-neutral-700 dark:bg-neutral-800 text-sm dark:text-white rounded-md';

const renderToast = () => {
t.default({
toast.default({
text: 'Rendered toast!',
description: 'This is a success toast!',
delayDuration: duration,
});
};

const renderToastWithIcon = () => {
t.default({
toast.default({
text: 'Rendered toast without icon',
description: 'This is a default toast!',
delayDuration: duration,
});
t.success({
toast.success({
text: 'Rendered toast with library icon',
description: 'This is a success toast',
delayDuration: duration,
});
t.error({
toast.error({
text: 'Rendered toast without library icon',
description: 'This is a error toast',
delayDuration: duration,
});
t.warning({
toast.warning({
text: 'Rendered toast with library icon',
description: 'This is a warning toast',
delayDuration: duration,
});
t.default({
toast.default({
text: 'Rendered toast with custom icon',
description: 'This is a default toast',
delayDuration: duration,
Expand Down
10 changes: 3 additions & 7 deletions examples/nextjs/src/providers/toastProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
'use client';

import {
ToastProvider,
ToastTheme,
type ToastProviderProperties,
} from '@pheralb/toast';
import { Toaster, ToastTheme, type ToasterProperties } from '@pheralb/toast';
import { useTheme } from 'next-themes';

const ToastClientProvider = (props: ToastProviderProperties) => {
const ToastClientProvider = (props: ToasterProperties) => {
const { theme } = useTheme();
return (
<ToastProvider
<Toaster
toastFont="font-sans"
maxToasts={10}
theme={theme as ToastTheme}
Expand Down
22 changes: 14 additions & 8 deletions library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ yarn install @pheralb/toast

```tsx
// 📃 root.tsx
import { ToastProvider } from '@pheralb/toast';

import { Toaster } from '@pheralb/toast';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<ToastProvider>
<App />
</ToastProvider>
<App />
<Toaster />
</React.StrictMode>,
);
```
Expand All @@ -91,8 +91,10 @@ ReactDOM.createRoot(document.getElementById('root')!).render(

```jsx
// 📃 index.tsx

import { toast } from '@pheralb/toast';

export default function Index() {
const toast = useToast();
return (
<>
<button
Expand All @@ -116,7 +118,7 @@ export default function Index() {
## 🔭 Roadmap

- [ ] 🚗 Add `.loading` variant.
- [ ] 📚 Add support for Astro + React.
- [x] 📚 Add support for Astro + React.
- [ ] 🎨 Add rich colors support.

## 🤝 Contributing
Expand Down Expand Up @@ -152,8 +154,12 @@ pnpm build
pnpm test
```

- Open [`http://localhost:5173`](http://localhost:5173) to view the **Remix** documentation website.
- Open [`http://localhost:3000`](http://localhost:3000) to view the **Next.js** playground. Only for test the functionality of the library.
🧑‍🚀 Open [`http://localhost:5173`](http://localhost:5173) to view the **Remix** documentation website.

🔎 Only for test the functionality of the library:

- Open [`http://localhost:3000`](http://localhost:3000) to view the **Next.js** playground.
- Open [`http://localhost:4321`](http://localhost:3001) to view the **Astro** playground.

and create a pull request with your features or fixes 🚀✨.

Expand Down
2 changes: 1 addition & 1 deletion library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pheralb/toast",
"version": "0.1.3",
"version": "0.2.0",
"author": "@pheralb_",
"keywords": [
"react",
Expand Down
20 changes: 20 additions & 0 deletions library/src/components/toast-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ToastPropsWithVariant } from '../types/toast.types';
import { openToast } from './toaster';

export const toast = {
default: (data: ToastPropsWithVariant) => {
openToast({ ...data });
},
success: (data: ToastPropsWithVariant) => {
openToast({ ...data, variant: 'success' });
},
error: (data: ToastPropsWithVariant) => {
openToast({ ...data, variant: 'error' });
},
warning: (data: ToastPropsWithVariant) => {
openToast({ ...data, variant: 'warning' });
},
info: (data: ToastPropsWithVariant) => {
openToast({ ...data, variant: 'info' });
},
};
6 changes: 4 additions & 2 deletions library/src/components/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
} from '../types/toast.types';
import '../styles/toast-component.css';

import { Error, Info, Success, Warning } from '../icons';
import { Error, Info, Loading, Success, Warning } from '../icons';
import { useTimeout } from '../hooks/useTimeout';
import { classNames, prefersReducedMotion } from '../utils';

Expand All @@ -15,13 +15,15 @@ const icons: Record<Variant, FC<React.SVGProps<SVGSVGElement>>> = {
error: Error,
warning: Warning,
info: Info,
loading: Loading,
};

const iconsColors: Record<Variant, string> = {
success: '#22c55e',
error: '#ef4444',
warning: '#eab308',
info: '#3b82f6',
loading: '#6b7280',
};

interface ToastComponentProps extends ToastPropsWithVariant {
Expand Down Expand Up @@ -86,7 +88,7 @@ const Toast = (props: ToastComponentProps) => {
return (
<div
title={props.text}
aria-label="notification"
aria-label="Notification"
className={classNames(
't_global',
prefersReducedMotion() ? '' : animationClass,
Expand Down
Loading

0 comments on commit 5810685

Please sign in to comment.