├── .gitignore ├── .vscode └── launch.json ├── client └── googledocs │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt │ ├── src │ ├── App.css │ ├── App.js │ ├── components │ │ ├── atoms │ │ │ ├── create-document-button │ │ │ │ ├── create-document-btn.tsx │ │ │ │ └── index.ts │ │ │ ├── document-card │ │ │ │ ├── document-card.tsx │ │ │ │ └── index.ts │ │ │ ├── document-menu-button │ │ │ │ ├── document-menu-button.tsx │ │ │ │ └── index.ts │ │ │ ├── document-searchbar │ │ │ │ ├── document-searchbar.tsx │ │ │ │ └── index.ts │ │ │ ├── errors │ │ │ │ ├── errors.tsx │ │ │ │ └── index.ts │ │ │ ├── font-select │ │ │ │ ├── font-select.tsx │ │ │ │ └── index.ts │ │ │ ├── icon-button │ │ │ │ ├── icon-button.tsx │ │ │ │ └── index.ts │ │ │ ├── logo │ │ │ │ ├── index.ts │ │ │ │ └── logo.tsx │ │ │ ├── modal │ │ │ │ ├── index.ts │ │ │ │ └── modal.tsx │ │ │ ├── spinner │ │ │ │ ├── index.ts │ │ │ │ └── spinner.tsx │ │ │ ├── text-field │ │ │ │ ├── index.ts │ │ │ │ └── text-field.tsx │ │ │ ├── toast │ │ │ │ ├── index.ts │ │ │ │ └── toast.tsx │ │ │ └── user-dropdown │ │ │ │ ├── index.ts │ │ │ │ └── user-dropdown.tsx │ │ ├── molecules │ │ │ ├── auth-route │ │ │ │ ├── auth-route.tsx │ │ │ │ └── index.ts │ │ │ ├── document-menu-bar │ │ │ │ ├── document-menu-bar.tsx │ │ │ │ └── index.ts │ │ │ ├── documents-list │ │ │ │ ├── documents-list.tsx │ │ │ │ └── index.ts │ │ │ ├── editor-toolbar │ │ │ │ ├── editor-toolbar.tsx │ │ │ │ └── index.ts │ │ │ ├── share-document-modal │ │ │ │ ├── index.ts │ │ │ │ └── share-document-modal.tsx │ │ │ └── shared-users │ │ │ │ ├── index.ts │ │ │ │ └── shared-users.tsx │ │ └── organisms │ │ │ ├── document-create-header │ │ │ ├── document-create-header.tsx │ │ │ └── index.ts │ │ │ ├── document-editor │ │ │ ├── document-editor.tsx │ │ │ └── index.ts │ │ │ ├── document-header │ │ │ ├── document-header.tsx │ │ │ └── index.ts │ │ │ └── toast-manager │ │ │ ├── index.ts │ │ │ └── toast-manager.tsx │ ├── contexts │ │ ├── auth-context.tsx │ │ ├── document-context.tsx │ │ ├── editor-context.tsx │ │ └── toast-context.tsx │ ├── hooks │ │ ├── use-auth.tsx │ │ ├── use-document.tsx │ │ ├── use-documents.tsx │ │ ├── use-local-storage.tsx │ │ ├── use-random-background.tsx │ │ └── use-window-size.tsx │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── pages │ │ ├── document │ │ │ ├── create.tsx │ │ │ └── index.tsx │ │ ├── login │ │ │ └── index.tsx │ │ ├── register │ │ │ └── index.tsx │ │ └── user │ │ │ └── verify-email.tsx │ ├── services │ │ ├── api.ts │ │ ├── auth-service.ts │ │ ├── document-service.ts │ │ └── document-user-service.ts │ ├── types │ │ ├── enums │ │ │ ├── permission-enum.ts │ │ │ └── socket-events-enum.ts │ │ └── interfaces │ │ │ ├── action.ts │ │ │ ├── document-user.ts │ │ │ ├── document.ts │ │ │ ├── input.ts │ │ │ ├── toast.ts │ │ │ └── token.ts │ └── utils │ │ └── constants.ts │ ├── tailwind.config.js │ └── tsconfig.json └── server ├── .env.development ├── package-lock.json ├── package.json ├── src ├── config │ ├── db.config.ts │ ├── env.config.ts │ └── smtp.config.ts ├── controllers │ ├── auth │ │ └── auth.controller.ts │ ├── document │ │ ├── document.controller.ts │ │ └── share │ │ │ └── share.controller.ts │ └── user │ │ └── user.controller.ts ├── db │ └── models │ │ ├── document-user.model.ts │ │ ├── document.model.ts │ │ ├── index.ts │ │ ├── refresh-token.model.ts │ │ ├── role.model.ts │ │ ├── user-role.model.ts │ │ └── user.model.ts ├── index.ts ├── middleware │ ├── auth.ts │ ├── catch-async.ts │ └── error-handler.ts ├── responses │ └── index.ts ├── routes │ ├── auth.route.ts │ ├── document.route.ts │ ├── index.ts │ └── user.route.ts ├── server.ts ├── services │ ├── document.service.ts │ ├── mail.service.ts │ └── user.service.ts ├── types │ ├── enums │ │ ├── permission-enum.ts │ │ ├── role-enum.ts │ │ └── socket-events-enum.ts │ └── interfaces │ │ ├── environment.d.ts │ │ ├── express │ │ └── index.d.ts │ │ └── global.d.ts └── validators │ ├── auth.validator.ts │ ├── document.validator.ts │ ├── share.validator.ts │ └── user.validator.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | server/node_modules/* 2 | client/node_modules/* 3 | node_modules/* 4 | dist 5 | node_modules -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "msedge", 9 | "request": "launch", 10 | "name": "Launch Edge against localhost", 11 | "url": "http://localhost:8080", 12 | "webRoot": "${workspaceFolder}/server/" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /client/googledocs/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /client/googledocs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "googledocs", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@heroicons/react": "^1.0.5", 7 | "@testing-library/jest-dom": "^5.17.0", 8 | "@testing-library/react": "^13.4.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "@types/jest": "^29.5.3", 11 | "@types/node": "^20.4.10", 12 | "@types/react": "^18.2.20", 13 | "@types/react-dom": "^18.2.7", 14 | "axios": "^1.4.0", 15 | "draft-js": "^0.11.7", 16 | "inputmask": "^5.0.8", 17 | "jwt-decode": "^3.1.2", 18 | "react": "^18.2.0", 19 | "react-dom": "^18.2.0", 20 | "react-router-dom": "^6.15.0", 21 | "react-scripts": "5.0.1", 22 | "react-transition-group": "^4.4.5", 23 | "socket.io-client": "^4.7.2", 24 | "typescript": "^5.1.6", 25 | "uuid": "^9.0.0", 26 | "validator": "^13.11.0", 27 | "web-vitals": "^2.1.4" 28 | }, 29 | "scripts": { 30 | "start": "react-scripts start", 31 | "build": "react-scripts build", 32 | "test": "react-scripts test", 33 | "eject": "react-scripts eject" 34 | }, 35 | "eslintConfig": { 36 | "extends": [ 37 | "react-app", 38 | "react-app/jest" 39 | ] 40 | }, 41 | "browserslist": { 42 | "production": [ 43 | ">0.2%", 44 | "not dead", 45 | "not op_mini all" 46 | ], 47 | "development": [ 48 | "last 1 chrome version", 49 | "last 1 firefox version", 50 | "last 1 safari version" 51 | ] 52 | }, 53 | "devDependencies": { 54 | "tailwindcss": "^3.3.3" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /client/googledocs/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuluruvineeth/googledocs-clone/3069f795387d0afc17062e2ad9d7e97588029ee8/client/googledocs/public/favicon.ico -------------------------------------------------------------------------------- /client/googledocs/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /client/googledocs/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuluruvineeth/googledocs-clone/3069f795387d0afc17062e2ad9d7e97588029ee8/client/googledocs/public/logo192.png -------------------------------------------------------------------------------- /client/googledocs/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuluruvineeth/googledocs-clone/3069f795387d0afc17062e2ad9d7e97588029ee8/client/googledocs/public/logo512.png -------------------------------------------------------------------------------- /client/googledocs/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /client/googledocs/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /client/googledocs/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /client/googledocs/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | 3 | function App() { 4 | return ( 5 |

6 | Google Docs Frontend Application 7 |

8 | ); 9 | } 10 | 11 | export default App; 12 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/create-document-button/create-document-btn.tsx: -------------------------------------------------------------------------------- 1 | import { lazy, useContext, useState } from "react"; 2 | import { ToastContext } from "../../../contexts/toast-context"; 3 | import useAuth from "../../../hooks/use-auth"; 4 | import { useNavigate } from "react-router-dom"; 5 | import DocumentService from "../../../services/document-service"; 6 | import DocumentInterface from "../../../types/interfaces/document"; 7 | import { PlusIcon } from "@heroicons/react/outline"; 8 | import Spinner from "../spinner/spinner"; 9 | 10 | const CreateDocumentButton = () => { 11 | const { error } = useContext(ToastContext); 12 | const { accessToken } = useAuth(); 13 | const [loading, setLoading] = useState(false); 14 | const navigate = useNavigate(); 15 | 16 | const handleDocumentCreateBtnClick = async () => { 17 | if (accessToken === null) return; 18 | 19 | setLoading(true); 20 | 21 | try { 22 | const response = await DocumentService.create(accessToken); 23 | const { id } = response.data as DocumentInterface; 24 | 25 | navigate(`/document/${id}`); 26 | } catch (err) { 27 | error("Unable to create a new document. Please try again"); 28 | } finally { 29 | setLoading(false); 30 | } 31 | }; 32 | 33 | return ( 34 |
35 |
36 |

Start a new document

37 |
38 |
39 | 49 |

Blank

50 |
51 |
52 |
53 |
54 | ); 55 | }; 56 | 57 | export default CreateDocumentButton; 58 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/create-document-button/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./create-document-btn"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/document-card/document-card.tsx: -------------------------------------------------------------------------------- 1 | import { useNavigate } from "react-router-dom"; 2 | import useAuth from "../../../hooks/use-auth"; 3 | import DocumentInterface from "../../../types/interfaces/document"; 4 | import { MouseEvent } from "react"; 5 | import DocumentMenuButton from "../document-menu-button/document-menu-button"; 6 | 7 | interface DocumentCardProps { 8 | document: DocumentInterface; 9 | setDocuments: Function; 10 | } 11 | 12 | const DocumentCard = ({ document, setDocuments }: DocumentCardProps) => { 13 | const { userId } = useAuth(); 14 | const navigate = useNavigate(); 15 | 16 | const handleDocumentBtnClick = ( 17 | event: MouseEvent, 18 | documentId: number 19 | ) => { 20 | const classList = (event.target as HTMLDivElement).classList; 21 | if ( 22 | !classList.contains(`document-menu-btn-${documentId}`) && 23 | !classList.contains("document-menu") 24 | ) { 25 | navigate(`/document/${documentId}`); 26 | } 27 | }; 28 | 29 | const skeleton = ( 30 | <> 31 | {Array.from({ length: 18 }, (x, i) => i).map((i) => { 32 | return ( 33 |
38 | ); 39 | })} 40 | 41 | ); 42 | 43 | return ( 44 |
handleDocumentBtnClick(event, document.id)} 46 | key={document.id} 47 | className="text-left cursor-pointer" 48 | > 49 |
50 |
51 | {skeleton} 52 |
53 |
54 |
{document.title}
55 |
56 |
57 | 65 | 70 | 71 |

72 | {new Date(document.updatedAt).toLocaleDateString("en-US", { 73 | month: "short", 74 | day: "numeric", 75 | year: "numeric", 76 | })} 77 |

78 |
79 | {document.userId === userId && ( 80 | 84 | )} 85 |
86 |
87 |
88 |
89 | ); 90 | }; 91 | 92 | export default DocumentCard; 93 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/document-card/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./document-card"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/document-menu-button/document-menu-button.tsx: -------------------------------------------------------------------------------- 1 | import { FocusEvent, useContext, useRef, useState } from "react"; 2 | import useAuth from "../../../hooks/use-auth"; 3 | import { ToastContext } from "../../../contexts/toast-context"; 4 | import DocumentService from "../../../services/document-service"; 5 | import DocumentInterface from "../../../types/interfaces/document"; 6 | import { CSSTransition } from "react-transition-group"; 7 | 8 | interface DocumentMenuButtonProps { 9 | documentId: number; 10 | setDocuments: Function; 11 | } 12 | 13 | const DocumentMenuButton = ({ 14 | documentId, 15 | setDocuments, 16 | }: DocumentMenuButtonProps) => { 17 | const { accessToken } = useAuth(); 18 | 19 | const [loading, setLoading] = useState(false); 20 | const dropdownRef = useRef(null); 21 | const [showDropdown, setShowDropdown] = useState(false); 22 | const { error } = useContext(ToastContext); 23 | 24 | const handleDeleteBtnClick = async () => { 25 | if (accessToken === null) return; 26 | 27 | setLoading(true); 28 | 29 | try { 30 | await DocumentService.delete(accessToken, documentId); 31 | setDocuments((allDocuments: Array) => 32 | allDocuments.filter((document) => document.id !== documentId) 33 | ); 34 | } catch (err) { 35 | error("Unable to delete document. Please try again."); 36 | } finally { 37 | setLoading(false); 38 | } 39 | }; 40 | 41 | const handleMenuBtnBlur = (event: FocusEvent) => { 42 | const classList = (event.target as HTMLButtonElement).classList; 43 | 44 | if (!classList.contains("document-menu")) { 45 | setShowDropdown(false); 46 | } 47 | }; 48 | 49 | return ( 50 |
53 | 74 | 85 |
(!loading ? handleDeleteBtnClick() : () => {})} 87 | className="w-full text-black hover:bg-gray-100 text-sm px-6 py-1 text-left document-menu" 88 | > 89 | Delete 90 |
91 |
92 | } 93 | /> 94 | 95 | ); 96 | }; 97 | 98 | export default DocumentMenuButton; 99 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/document-menu-button/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./document-menu-button"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/document-searchbar/document-searchbar.tsx: -------------------------------------------------------------------------------- 1 | import { SearchIcon } from "@heroicons/react/outline"; 2 | import { useState } from "react"; 3 | 4 | const DocumentSearchBar = () => { 5 | const [isFocused, setIsFocused] = useState(false); 6 | 7 | return ( 8 |
13 |
14 | 15 |
16 | setIsFocused(true)} 18 | onBlur={() => setIsFocused(false)} 19 | type="text" 20 | className={`${ 21 | isFocused ? "bg-white" : "bg-gray-100" 22 | }w-full h-full pr-4 font-medium`} 23 | placeholder="Search" 24 | name="" 25 | id="" 26 | /> 27 |
28 | ); 29 | }; 30 | 31 | export default DocumentSearchBar; 32 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/document-searchbar/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./document-searchbar"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/errors/errors.tsx: -------------------------------------------------------------------------------- 1 | interface ErrorsProps { 2 | errors: Array; 3 | } 4 | 5 | const Errors = ({ errors }: ErrorsProps) => { 6 | return errors.length ? ( 7 |
8 | {errors.map((error) => { 9 | return ( 10 |

11 | {error} 12 |

13 | ); 14 | })} 15 |
16 | ) : ( 17 | <> 18 | ); 19 | }; 20 | 21 | export default Errors; 22 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/errors/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./errors"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/font-select/font-select.tsx: -------------------------------------------------------------------------------- 1 | import { useContext, useRef, useState } from "react"; 2 | import { EditorContext } from "../../../contexts/editor-context"; 3 | import { ChevronDownIcon } from "@heroicons/react/outline"; 4 | import { CSSTransition } from "react-transition-group"; 5 | import { FONTS } from "."; 6 | 7 | const FontSelect = () => { 8 | const [showTooltip, setShowTooltip] = useState(false); 9 | const [showDropdown, setShowDropdown] = useState(false); 10 | const { currentFont, setCurrentFont } = useContext(EditorContext); 11 | const dropdownRef = useRef(null); 12 | 13 | return ( 14 |
setShowDropdown(false)} 16 | className="relative flex justify-center items-center" 17 | > 18 | 27 | {showTooltip && !showDropdown && ( 28 |
29 |
30 |
31 | Fonts 32 |
33 |
34 | )} 35 | 46 | {FONTS.map((font) => { 47 | return ( 48 | 56 | ); 57 | })} 58 |
59 | } 60 | /> 61 | 62 | ); 63 | }; 64 | 65 | export default FontSelect; 66 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/font-select/index.ts: -------------------------------------------------------------------------------- 1 | export const FONTS = ["Inter", "Roboto", "Open Sans"]; 2 | 3 | export { default } from "./font-select"; 4 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/icon-button/icon-button.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | interface IconButtonProps { 4 | icon: JSX.Element; 5 | tooltip: string; 6 | onClick: Function; 7 | } 8 | 9 | const IconButton = ({ icon, tooltip, onClick }: IconButtonProps) => { 10 | const [showTooltip, setShowToolTip] = useState(false); 11 | 12 | return ( 13 |
setShowToolTip(true)} 15 | onMouseLeave={() => setShowToolTip(false)} 16 | className="relative flex justify-center items-center" 17 | > 18 | 24 | {showTooltip && ( 25 |
26 |
27 |
28 | {tooltip} 29 |
30 |
31 | )} 32 |
33 | ); 34 | }; 35 | 36 | export default IconButton; 37 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/icon-button/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./icon-button"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/logo/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./logo"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/logo/logo.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom"; 2 | 3 | const Logo = () => { 4 | return ( 5 | 9 | 17 | 22 | 23 | 24 | ); 25 | }; 26 | 27 | export default Logo; 28 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/modal/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./modal"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/modal/modal.tsx: -------------------------------------------------------------------------------- 1 | import { useRef, useState } from "react"; 2 | import { CSSTransition } from "react-transition-group"; 3 | 4 | interface ModalProps { 5 | button: JSX.Element; 6 | content: JSX.Element; 7 | size?: "sm" | "md" | "lg"; 8 | } 9 | 10 | const Modal = ({ button, content, size = "md" }: ModalProps) => { 11 | const [showModal, setShowModal] = useState(false); 12 | const contentRef = useRef(null); 13 | 14 | const getSizeClass = () => { 15 | switch (size) { 16 | case "sm": 17 | return "max-w-sm"; 18 | case "md": 19 | return "max-w-2xl"; 20 | case "lg": 21 | return "max-w-5xl"; 22 | } 23 | }; 24 | 25 | return ( 26 | <> 27 |
setShowModal(true)}>{button}
28 | 36 |
40 | {content} 41 |
42 |
setShowModal(false)} 44 | className="absolute top-0 left-0 right-0 bottom-0 bg-black opacity-50 z-0" 45 | >
46 | 47 | } 48 | /> 49 | 50 | ); 51 | }; 52 | 53 | export default Modal; 54 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/spinner/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./spinner"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/spinner/spinner.tsx: -------------------------------------------------------------------------------- 1 | interface SpinnerProps { 2 | size: "sm" | "md" | "lg"; 3 | className?: string; 4 | } 5 | 6 | const Spinner = ({ size, className }: SpinnerProps) => { 7 | const getSpinnerSize = () => { 8 | switch (size) { 9 | case "sm": 10 | return "w-4 h-4"; 11 | case "md": 12 | return "w-5 h-5"; 13 | case "lg": 14 | return "w-7 h-7"; 15 | } 16 | }; 17 | 18 | const getSpinnerDivSize = () => { 19 | switch (size) { 20 | case "sm": 21 | return "w-4 h-4 border-2 margin-2 border-white"; 22 | case "md": 23 | return "w-5 h-5 border-2 margin-2 border-white"; 24 | case "lg": 25 | return "w-7 h-7 border-2 margin-2 border-white"; 26 | } 27 | }; 28 | 29 | return ( 30 |
31 |
32 |
33 |
34 |
35 | ); 36 | }; 37 | 38 | export default Spinner; 39 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/text-field/index.ts: -------------------------------------------------------------------------------- 1 | export { default } from "./text-field"; 2 | -------------------------------------------------------------------------------- /client/googledocs/src/components/atoms/text-field/text-field.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useRef, useState } from "react"; 2 | import InputProps from "../../../types/interfaces/input"; 3 | import InputMask from "inputmask"; 4 | import { EyeIcon, EyeOffIcon } from "@heroicons/react/outline"; 5 | import { ExclamationCircleIcon } from "@heroicons/react/solid"; 6 | import Errors from "../errors/errors"; 7 | 8 | interface TextFieldProps extends InputProps { 9 | value?: string | number; 10 | onInput?: Function; 11 | type?: "text" | "password" | "textarea"; 12 | mask?: string; 13 | icon?: JSX.Element; 14 | color?: "primary" | "secondary"; 15 | } 16 | 17 | const TEXT_FIELD_CLASSES = { 18 | primary: "bg-white dark:bg-slate-800", 19 | secondary: "bg-slate-50 dark:bg-slate-700", 20 | }; 21 | 22 | const TextField = ({ 23 | value, 24 | onInput = () => alert("onInput not registered"), 25 | type = "text", 26 | label, 27 | placeholder, 28 | errors = [], 29 | mask, 30 | icon, 31 | color = "primary", 32 | }: TextFieldProps) => { 33 | const textFieldRef = useRef(null); 34 | const [showPassword, setShowPassword] = useState(false); 35 | const [isFocused, setIsFocused] = useState(false); 36 | 37 | useEffect(() => { 38 | if (textFieldRef && textFieldRef.current && mask) { 39 | const inputMask = new InputMask(mask); 40 | inputMask.mask(textFieldRef.current); 41 | } 42 | }, [mask]); 43 | 44 | return ( 45 |
46 | {label && } 47 |
58 |
{icon}
59 | {type !== "textarea" ? ( 60 |
61 | onInput((e.target as HTMLTextAreaElement).value)} 65 | onFocus={() => setIsFocused(true)} 66 | onBlur={() => setIsFocused(false)} 67 | value={value} 68 | className={`${TEXT_FIELD_CLASSES[color]} w-full p-2 rounded`} 69 | placeholder={placeholder && placeholder} 70 | /> 71 | {type === "password" && ( 72 | 83 | )} 84 |
85 | ) : ( 86 |