diff --git a/examples/gql-blog/.gitignore b/examples/gql-blog/.gitignore new file mode 100644 index 0000000000..4d29575de8 --- /dev/null +++ b/examples/gql-blog/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/examples/gql-blog/README.md b/examples/gql-blog/README.md new file mode 100644 index 0000000000..9c40dcdc3d --- /dev/null +++ b/examples/gql-blog/README.md @@ -0,0 +1,68 @@ +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `yarn start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `yarn test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `yarn build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `yarn eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting + +### Analyzing the Bundle Size + +This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size + +### Making a Progressive Web App + +This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app + +### Advanced Configuration + +This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration + +### Deployment + +This section has moved here: https://facebook.github.io/create-react-app/docs/deployment + +### `yarn build` fails to minify + +This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify diff --git a/examples/gql-blog/package.json b/examples/gql-blog/package.json new file mode 100644 index 0000000000..51d661b9d0 --- /dev/null +++ b/examples/gql-blog/package.json @@ -0,0 +1,46 @@ +{ + "name": "blog-query", + "version": "0.1.0", + "private": true, + "dependencies": { + "@fortawesome/fontawesome-svg-core": "^1.2.32", + "@fortawesome/free-solid-svg-icons": "^5.15.1", + "@fortawesome/react-fontawesome": "^0.1.11", + "@testing-library/jest-dom": "^4.2.4", + "@testing-library/react": "^9.3.2", + "@testing-library/user-event": "^7.1.2", + "graphql": "^15.3.0", + "graphql-request": "^3.1.0", + "react": "^16.13.1", + "react-dom": "^16.13.1", + "react-markdown": "^4.3.1", + "react-query": "^2.23.1", + "react-query-devtools": "^2.5.1", + "react-router": "^5.2.0", + "react-router-dom": "^5.2.0", + "react-scripts": "3.4.3", + "react-syntax-highlighter": "^15.1.0", + "sriracha-ui": "^1.8.3" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/gql-blog/public/android-chrome-192x192.png b/examples/gql-blog/public/android-chrome-192x192.png new file mode 100644 index 0000000000..3328c0ab76 Binary files /dev/null and b/examples/gql-blog/public/android-chrome-192x192.png differ diff --git a/examples/gql-blog/public/android-chrome-512x512.png b/examples/gql-blog/public/android-chrome-512x512.png new file mode 100644 index 0000000000..1568c37191 Binary files /dev/null and b/examples/gql-blog/public/android-chrome-512x512.png differ diff --git a/examples/gql-blog/public/apple-touch-icon.png b/examples/gql-blog/public/apple-touch-icon.png new file mode 100644 index 0000000000..85c2c43a89 Binary files /dev/null and b/examples/gql-blog/public/apple-touch-icon.png differ diff --git a/examples/gql-blog/public/favicon-16x16.png b/examples/gql-blog/public/favicon-16x16.png new file mode 100644 index 0000000000..eebe577944 Binary files /dev/null and b/examples/gql-blog/public/favicon-16x16.png differ diff --git a/examples/gql-blog/public/favicon-32x32.png b/examples/gql-blog/public/favicon-32x32.png new file mode 100644 index 0000000000..4e9c5d9200 Binary files /dev/null and b/examples/gql-blog/public/favicon-32x32.png differ diff --git a/examples/gql-blog/public/favicon.ico b/examples/gql-blog/public/favicon.ico new file mode 100644 index 0000000000..7c8b975148 Binary files /dev/null and b/examples/gql-blog/public/favicon.ico differ diff --git a/examples/gql-blog/public/index.html b/examples/gql-blog/public/index.html new file mode 100644 index 0000000000..08681aa892 --- /dev/null +++ b/examples/gql-blog/public/index.html @@ -0,0 +1,38 @@ + + + + + React Query GQL Blog + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/examples/gql-blog/public/robots.txt b/examples/gql-blog/public/robots.txt new file mode 100644 index 0000000000..e9e57dc4d4 --- /dev/null +++ b/examples/gql-blog/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/examples/gql-blog/public/site.webmanifest b/examples/gql-blog/public/site.webmanifest new file mode 100644 index 0000000000..ed84b5d1f5 --- /dev/null +++ b/examples/gql-blog/public/site.webmanifest @@ -0,0 +1,16 @@ +{ + "name": "", + "short_name": "", + "icons": [{ + "src": "/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, { + "src": "/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + }], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} \ No newline at end of file diff --git a/examples/gql-blog/src/App.js b/examples/gql-blog/src/App.js new file mode 100644 index 0000000000..92d4d5aeaf --- /dev/null +++ b/examples/gql-blog/src/App.js @@ -0,0 +1,32 @@ +import React from "react"; + +import { Switch, Route } from "react-router"; +import Layout from "./components/Layout"; +import Home from "./pages/Home"; +import Blog from "./pages/Blog"; + +import { AppContainer, useDarkMode } from "sriracha-ui"; + +import { library } from "@fortawesome/fontawesome-svg-core"; +import { faMoon, faSun, faSpinner } from "@fortawesome/free-solid-svg-icons"; +import About from "./pages/About"; + +library.add(faMoon, faSun, faSpinner); + +function App() { + const { themeString, toggleTheme } = useDarkMode(); + + return ( + + + + + + + + + + ); +} + +export default App; diff --git a/examples/gql-blog/src/components/Layout/NavLinks/NavLink.js b/examples/gql-blog/src/components/Layout/NavLinks/NavLink.js new file mode 100644 index 0000000000..509d87aee0 --- /dev/null +++ b/examples/gql-blog/src/components/Layout/NavLinks/NavLink.js @@ -0,0 +1,15 @@ +import React from "react"; +import { Flex, Text } from "sriracha-ui"; +import { Link } from "react-router-dom"; + +export default function NavLink({ link }) { + return ( + + + + {link} + + + + ); +} diff --git a/examples/gql-blog/src/components/Layout/NavLinks/index.js b/examples/gql-blog/src/components/Layout/NavLinks/index.js new file mode 100644 index 0000000000..3e3c045e03 --- /dev/null +++ b/examples/gql-blog/src/components/Layout/NavLinks/index.js @@ -0,0 +1,17 @@ +import React from "react"; +import { Box } from "sriracha-ui"; +import NavLink from "./NavLink"; + +export default function NavLinks() { + const links = ["Home", "About"]; + return ( + <> + {links.map((link) => ( + + + + + ))} + + ); +} diff --git a/examples/gql-blog/src/components/Layout/index.js b/examples/gql-blog/src/components/Layout/index.js new file mode 100644 index 0000000000..b1e92908a0 --- /dev/null +++ b/examples/gql-blog/src/components/Layout/index.js @@ -0,0 +1,76 @@ +import React from "react"; +import { + Wrapper, + NavBar, + Box, + Flex, + Cabinet, + useCabinet, + useTheme, +} from "sriracha-ui"; +import NavLinks from "./NavLinks"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +const navHeight = "5rem"; + +export default function Layout({ children }) { + const { isCabinet, toggleCabinet } = useCabinet(); + const { toggleTheme, themeString, lightTheme } = useTheme(); + const { colors } = lightTheme; + return ( + +
+ + + + + + + + + + + + + + + + + + {themeString === "dark" ? ( + + ) : ( + + )} + + + +
+ + + + + + + + + {children} + +
+ ); +} diff --git a/examples/gql-blog/src/index.js b/examples/gql-blog/src/index.js new file mode 100644 index 0000000000..c3033408ce --- /dev/null +++ b/examples/gql-blog/src/index.js @@ -0,0 +1,14 @@ +import React from "react"; +import ReactDOM from "react-dom"; +import App from "./App"; +import { BrowserRouter as Router } from "react-router-dom"; +import "./styles.css"; + +ReactDOM.render( + + + + + , + document.getElementById("root") +); diff --git a/examples/gql-blog/src/pages/About.js b/examples/gql-blog/src/pages/About.js new file mode 100644 index 0000000000..ce989ca4fa --- /dev/null +++ b/examples/gql-blog/src/pages/About.js @@ -0,0 +1,16 @@ +import React from "react"; +import { Card, Text } from "sriracha-ui"; + +export default function About() { + return ( + + + About page + + + This is a simple blog created using React Query to manage all of our + server state from Best Markdown Editor. + + + ); +} diff --git a/examples/gql-blog/src/pages/Blog.js b/examples/gql-blog/src/pages/Blog.js new file mode 100644 index 0000000000..77267a1ef3 --- /dev/null +++ b/examples/gql-blog/src/pages/Blog.js @@ -0,0 +1,62 @@ +import React from "react"; +import { useQuery } from "react-query"; +import { Card, Box } from "sriracha-ui"; +import { client } from "../utils"; +import { gql } from "graphql-request"; +import { useParams } from "react-router"; +import ReactMarkdown from "react-markdown"; +import { PrismAsync as SyntaxHighlighter } from "react-syntax-highlighter"; +import dark from "../syntaxTheme"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +const CodeBlock = ({ language, value }) => { + return ( + + {value} + + ); +}; + +const query = gql` + query GetPubFileBySlug($slug: String!) { + getPubFileBySlug(slug: $slug) { + body + } + } +`; + +export default function Blog() { + const { slug } = useParams(); + + const { data, isLoading, status } = useQuery("posts", async () => { + const res = await client.request(query, { slug }); + return res; + }); + + const file = data?.getPubFileBySlug; + console.log("file:", file); + + if (status === "error") + return ( + + The blog your looking for doesn't exist or was deleted by the user. + + ); + + return ( + + + {isLoading ? ( + + ) : ( + + )} + + + ); +} diff --git a/examples/gql-blog/src/pages/Home.js b/examples/gql-blog/src/pages/Home.js new file mode 100644 index 0000000000..ffbaef8856 --- /dev/null +++ b/examples/gql-blog/src/pages/Home.js @@ -0,0 +1,86 @@ +import React from "react"; +import { Card, Text, Box, Flex, Img } from "sriracha-ui"; +import { Link } from "react-router-dom"; +import { gql } from "graphql-request"; +import { client } from "../utils"; +import { useQuery } from "react-query"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +const query = gql` + query GetPubFiles { + getPubFiles { + id + slug + title + description + thumbnail + body + } + } +`; + +export default function Home() { + const { data, isLoading } = useQuery("posts", async () => { + const res = await client.request(query); + return res; + }); + const files = data?.getPubFiles; + return ( + + + Welcome To My Blog! + + + Powered by{" "} + + Sriracha UI + + ,{" "} + + Best Markdown Editor{" "} + + and{" "} + + React Query + + ! + + + + {isLoading ? ( + + ) : ( + <> + {files?.map((file) => ( + + + {file.title} + + preview + {file.description} + + ))} + + )} + + + ); +} diff --git a/examples/gql-blog/src/styles.css b/examples/gql-blog/src/styles.css new file mode 100644 index 0000000000..fd42c4f06b --- /dev/null +++ b/examples/gql-blog/src/styles.css @@ -0,0 +1,15 @@ +@import url("https://fonts.googleapis.com/css?family=Bellota|Ubuntu+Mono|Open+Sans|Ubuntu|Raleway&display=swap"); + +.nav-cabinet-menu { + display: none; +} + +@media only screen and (max-width: 650px) { + .nav-cabinet-menu { + display: block; + } + + .nav-link-list { + display: none; + } +} diff --git a/examples/gql-blog/src/syntaxTheme.js b/examples/gql-blog/src/syntaxTheme.js new file mode 100644 index 0000000000..6172283c41 --- /dev/null +++ b/examples/gql-blog/src/syntaxTheme.js @@ -0,0 +1,156 @@ +const dark = { + 'code[class*="language-"]': { + color: "#c5c8c6", + textShadow: "0 1px rgba(0, 0, 0, 0.3)", + fontFamily: '"Space Mono", monospace', + direction: "ltr", + textAlign: "left", + whiteSpace: "pre", + wordSpacing: "normal", + wordBreak: "normal", + lineHeight: "1.5", + MozTabSize: "4", + OTabSize: "4", + tabSize: "4", + WebkitHyphens: "none", + MozHyphens: "none", + msHyphens: "none", + hyphens: "none", + }, + 'pre[class*="language-"]': { + color: "#c5c8c6", + textShadow: "0 1px rgba(0, 0, 0, 0.3)", + fontFamily: + "Inconsolata, Monaco, Consolas, 'Courier New', Courier, monospace", + direction: "ltr", + textAlign: "left", + whiteSpace: "pre", + wordSpacing: "normal", + wordBreak: "normal", + lineHeight: "1.5", + MozTabSize: "4", + OTabSize: "4", + tabSize: "4", + WebkitHyphens: "none", + MozHyphens: "none", + msHyphens: "none", + hyphens: "none", + padding: "1em", + margin: ".5em 0", + overflow: "auto", + borderRadius: "0.3em", + background: "#333", + }, + ':not(pre) > code[class*="language-"]': { + background: "#333", + padding: ".1em", + borderRadius: ".3em", + }, + comment: { + color: "#90A4AE", + }, + prolog: { + color: "#90A4AE", + }, + doctype: { + color: "#90A4AE", + }, + cdata: { + color: "#90A4AE", + }, + punctuation: { + color: "#FFD54F", + }, + ".namespace": { + Opacity: ".7", + }, + property: { + color: "#40c4ff", + }, + keyword: { + color: "#40c4ff", + }, + tag: { + color: "#40c4ff", + }, + "class-name": { + color: "#FF9800", + textDecoration: "underline", + }, + boolean: { + color: "#9FA8DA", + }, + constant: { + color: "#9FA8DA", + }, + symbol: { + color: "#F06292", + }, + deleted: { + color: "#F06292", + }, + number: { + color: "#F06292", + }, + selector: { + color: "#81C784", + }, + "attr-name": { + color: "#81C784", + }, + string: { + color: "#81C784", + }, + char: { + color: "#81C784", + }, + builtin: { + color: "#81C784", + }, + inserted: { + color: "#81C784", + }, + variable: { + color: "#E0F2F1", + }, + operator: { + color: "#E0F2F1", + }, + entity: { + color: "#FFECB3", + cursor: "help", + }, + url: { + color: "#03A9F4", + }, + ".language-css .token.string": { + color: "#26A69A", + }, + ".style .token.string": { + color: "#26A69A", + }, + atrule: { + color: "#FFE082", + }, + "attr-value": { + color: "#FFE082", + }, + function: { + color: "#FFD54F", + }, + regex: { + color: "#FFA000", + }, + important: { + color: "#F44336", + fontWeight: "bold", + }, + bold: { + fontWeight: "bold", + }, + italic: { + fontStyle: "italic", + }, +}; + +export default dark; diff --git a/examples/gql-blog/src/utils/index.js b/examples/gql-blog/src/utils/index.js new file mode 100644 index 0000000000..8c7808ab55 --- /dev/null +++ b/examples/gql-blog/src/utils/index.js @@ -0,0 +1,10 @@ +import { GraphQLClient } from "graphql-request"; + +const endpoint = "https://best-markdown-editor-be.herokuapp.com/cms"; + +export const client = new GraphQLClient(endpoint, { + headers: { + "Content-Type": "application/json", + token: "588c454c-7176-457e-9d42-ad6d0e7ffdc4", + }, +});