Skip to content

Commit

Permalink
Feat/docs (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
RockiRider authored Feb 22, 2024
1 parent f99ed89 commit c802ae5
Show file tree
Hide file tree
Showing 35 changed files with 5,065 additions and 2,529 deletions.
28 changes: 24 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: "20"
cache: npm
- run: npm ci
- run: npm run build
- name: Archive production artifacts
Expand All @@ -22,6 +23,13 @@ jobs:
retention-days: 30
path: packages/mui-sonner/dist

- name: Build Documentation Site
run: npm run docs:build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./apps/docs/out


publish:
runs-on: ubuntu-latest
Expand All @@ -33,7 +41,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: "20"
cache: npm
- run: npm ci
- name: Download production artifacts
uses: actions/download-artifact@v4
Expand All @@ -54,7 +63,7 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: v${{steps.publish.outputs.version}}
tag_prefix: vite-plugin-posthog_
tag_prefix: mui-sonner_

- name: Create a GitHub release
if: ${{ steps.publish.outputs.type }}
Expand All @@ -63,4 +72,15 @@ jobs:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
generateReleaseNotes: true
generateReleaseNotes: true

deploy:
runs-on: ubuntu-latest
needs: build_and_test
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# MUI-Sonner

This is a Monorepo for the mui-sonner project. You can find the package inside the `packages` folder.
This is a Monorepo for the mui-sonner project.
Read more about the project in the [README](./packages/mui-sonner/README.md) of the package.
File renamed without changes.
4 changes: 4 additions & 0 deletions apps/example-next/next.config.js → apps/docs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
output: "export",
transpilePackages: ["mui-sonner"],
images: {
unoptimized: true,
},
};
10 changes: 6 additions & 4 deletions apps/example-next/package.json → apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "example-next",
"name": "docs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"preview": "next start -p 3000",
"preview": "npx serve out -p 3000",
"lint": "next lint",
"post-update": "echo \"codesandbox preview only, need an update\" && pnpm update --latest"
},
Expand All @@ -17,10 +17,12 @@
"@mui/icons-material": "latest",
"@mui/material": "latest",
"@mui/material-nextjs": "latest",
"copy-to-clipboard": "^3.3.3",
"framer-motion": "^11.0.5",
"mui-sonner": "*",
"next": "latest",
"react": "latest",
"react-dom": "latest",
"mui-sonner": "*"
"react-dom": "latest"
},
"devDependencies": {
"@types/node": "latest",
Expand Down
34 changes: 21 additions & 13 deletions apps/example-next/pages/_app.tsx → apps/docs/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,41 @@ import { AppProps } from "next/app";
import { AppCacheProvider } from "@mui/material-nextjs/v14-pagesRouter";
import { ThemeProvider, createTheme } from "@mui/material/styles";
import CssBaseline from "@mui/material/CssBaseline";
import { Toaster } from "mui-sonner";
import getLPTheme from "@styles/dark";
import { CircularProgress, Icon, PaletteMode } from "@mui/material";
import { PaletteMode } from "@mui/material";
import { useState } from "react";
import CloseIcon from "@mui/icons-material/Close";
import CustomToaster from "@components/CustomToaster";

const defaultTheme = createTheme({});

export default function MyApp(props: AppProps) {
const { Component, pageProps } = props;
const [mode, setMode] = useState<PaletteMode>("dark");
const theme = createTheme(getLPTheme(mode));
const [showCustomTheme, setShowCustomTheme] = useState(true);
const customTheme = createTheme(getLPTheme(mode));

const toggleColorMode = () => {
setMode((prev) => (prev === "dark" ? "light" : "dark"));
};

const toggleCustomTheme = () => {
setShowCustomTheme((prev) => !prev);
};

return (
<AppCacheProvider {...props}>
<Head>
<meta name="viewport" content="initial-scale=1, width=device-width" />
</Head>
<ThemeProvider theme={theme}>
<ThemeProvider theme={showCustomTheme ? customTheme : defaultTheme}>
<CssBaseline />
<Toaster
closeIcon={
<Icon sx={{ width: 24, height: 24 }}>
<CloseIcon />
</Icon>
}
loadingIcon={<CircularProgress size={20} />}
<CustomToaster />
<Component
{...pageProps}
toggleTheme={toggleCustomTheme}
toggleColorMode={toggleColorMode}
showCustomTheme={showCustomTheme}
/>
<Component {...pageProps} />
</ThemeProvider>
</AppCacheProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function MyDocument(
<Html lang="en">
<Head>
{/* PWA primary color */}
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="shortcut icon" href="/icon.ico" />
<meta name="emotion-insertion-point" content="" />
<DocumentHeadTags {...props} />
</Head>
Expand Down
39 changes: 39 additions & 0 deletions apps/docs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Container from "@mui/material/Container";
import { Button, Stack } from "@mui/material";
import Intro from "@features/home/Intro";
import { toast } from "mui-sonner";
import ToggleCustomTheme from "@features/theme/ThemeToggle";
import Install from "@features/home/Install";
import Features from "@features/home/Features";
import Usage from "@features/home/Usage";
import Types from "@features/home/Types";
import Position from "@features/home/Position";
import OtherOptions from "@features/home/OtherOptions";
import Styling from "@features/home/Styling";

export default function Home({
toggleTheme,
showCustomTheme,
}: {
toggleTheme: () => void;
showCustomTheme: boolean;
}) {
return (
<Container maxWidth="md">
<Stack width={1} alignItems="center" gap={6}>
<Intro />
<Features />
<Install />
<Usage />
<Types />
<Position />
<Styling />
<OtherOptions />
<ToggleCustomTheme
showCustomTheme={showCustomTheme}
toggleCustomTheme={toggleTheme}
/>
</Stack>
</Container>
);
}
Binary file added apps/docs/public/icon.ico
Binary file not shown.
122 changes: 122 additions & 0 deletions apps/docs/src/components/Code.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { IconButton, Paper, Typography, useTheme } from "@mui/material";
import copy from "copy-to-clipboard";
import { useCallback, useState } from "react";
import { motion, AnimatePresence, MotionConfig } from "framer-motion";

const variants = {
visible: { opacity: 1, scale: 1 },
hidden: { opacity: 0, scale: 0.5 },
};

interface CodeProps {
code: string;
}

const Code = ({ code }: CodeProps) => {
const theme = useTheme();

const currentMode = theme.palette.mode;
const desiredBgColor =
currentMode === "dark"
? theme.palette.common.white
: theme.palette.common.black;

const desiredTextColor =
currentMode === "dark"
? theme.palette.common.black
: theme.palette.common.white;

const [copying, setCopying] = useState(0);

const onCopy = useCallback(() => {
copy(code);
setCopying((c) => c + 1);
setTimeout(() => {
setCopying((c) => c - 1);
}, 2000);
}, []);

return (
<Paper
sx={{
backgroundColor: desiredBgColor,
p: 2,
cursor: "pointer",
position: "relative",
}}
onClick={onCopy}
>
<Typography component="pre" sx={{ color: desiredTextColor }}>
{code}
</Typography>
<IconButton
sx={{
position: "absolute",
right: 8,
top: "50%",
color: desiredTextColor,
transform: "translateY(-50%)",
cursor: "pointer",
borderRadius: 5,
width: 26,
height: 26,
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
aria-label="Copy code"
>
<MotionConfig transition={{ duration: 0.15 }}>
<AnimatePresence initial={false} mode="wait">
{copying ? (
<motion.div
animate="visible"
exit="hidden"
initial="hidden"
key="check"
variants={variants}
>
<svg
viewBox="0 0 24 24"
width="14"
height="14"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
shapeRendering="geometricPrecision"
>
<path d="M20 6L9 17l-5-5"></path>
</svg>
</motion.div>
) : (
<motion.div
animate="visible"
exit="hidden"
initial="hidden"
key="copy"
variants={variants}
>
<svg
viewBox="0 0 24 24"
width="14"
height="14"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
shapeRendering="geometricPrecision"
>
<path d="M8 17.929H6c-1.105 0-2-.912-2-2.036V5.036C4 3.91 4.895 3 6 3h8c1.105 0 2 .911 2 2.036v1.866m-6 .17h8c1.105 0 2 .91 2 2.035v10.857C20 21.09 19.105 22 18 22h-8c-1.105 0-2-.911-2-2.036V9.107c0-1.124.895-2.036 2-2.036z"></path>
</svg>
</motion.div>
)}
</AnimatePresence>
</MotionConfig>
</IconButton>
</Paper>
);
};
export default Code;
20 changes: 20 additions & 0 deletions apps/docs/src/components/CustomToaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Icon, CircularProgress } from "@mui/material";
import { Toaster, ToasterProps } from "mui-sonner";
import CloseIcon from "@mui/icons-material/Close";

type CustomToasterProps = Omit<ToasterProps, "closeIcon" | "loadingIcon">;
const CustomToaster = (props: CustomToasterProps) => {
return (
<Toaster
{...props}
closeIcon={
<Icon sx={{ width: 24, height: 24 }}>
<CloseIcon />
</Icon>
}
loadingIcon={<CircularProgress size={20} />}
/>
);
};

export default CustomToaster;
30 changes: 30 additions & 0 deletions apps/docs/src/components/FuncDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Box, Stack } from "@mui/material";
import { useState } from "react";
import Code from "./Code";

export type FuncData = {
component: JSX.Element;
codeString: string;
};

interface FuncDisplayProps {
data: FuncData[];
}

const FuncDisplay = ({ data }: FuncDisplayProps) => {
const [selected, setSelected] = useState<number>(0);
return (
<Stack gap={2}>
<Stack direction="row" gap={2}>
{data.map((item, index) => (
<Box key={item.codeString} onClick={() => setSelected(index)}>
{item.component}
</Box>
))}
</Stack>
<Code code={data[selected]?.codeString as string} />
</Stack>
);
};

export default FuncDisplay;
Loading

0 comments on commit c802ae5

Please sign in to comment.