├── public
├── robots.txt
├── favicon.ico
├── logo192.png
├── logo512.png
├── manifest.json
└── index.html
├── src
├── components
│ └── Draggable
│ │ ├── style.css
│ │ └── index.js
├── setupTests.js
├── App.test.js
├── index.css
├── reportWebVitals.js
├── index.js
├── App.js
├── App.css
└── logo.svg
├── README.md
├── .gitignore
└── package.json
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rachitiitr/react-components/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rachitiitr/react-components/HEAD/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rachitiitr/react-components/HEAD/public/logo512.png
--------------------------------------------------------------------------------
/src/components/Draggable/style.css:
--------------------------------------------------------------------------------
1 | .draggable__area {
2 | -webkit-touch-callout: none;
3 | -webkit-user-select: none;
4 | -khtml-user-select: none;
5 | -moz-user-select: none;
6 | -ms-user-select: none;
7 | user-select: none;
8 | }
9 |
--------------------------------------------------------------------------------
/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from '@testing-library/react';
2 | import App from './App';
3 |
4 | test('renders learn react link', () => {
5 | render();
6 | const linkElement = screen.getByText(/learn react/i);
7 | expect(linkElement).toBeInTheDocument();
8 | });
9 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want to start measuring performance in your app, pass a function
15 | // to log results (for example: reportWebVitals(console.log))
16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17 | reportWebVitals();
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # About
2 | This is the list of React components built for re-usability and as a hobby by [@rachitiitr](https://linkedin.com/in/rachitiitr), a FullStack Developer and [YouTuber](https://youtube.com/rachitjain) (150K+ subscribers).
3 |
4 | # Demo
5 | Demo of the custom components built is available [here](https://rachitiitr.github.io/react-components/).
6 | # List of React components
7 |
8 | ## Draggable
9 | > Makes any component draggable
10 | **Example**
11 | ```javscript
12 |
13 |
14 |
You can drag me now
15 |
16 |
17 | ```
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import logo from './logo.svg';
2 | import './App.css';
3 | import Draggable from './components/Draggable';
4 |
5 | function App() {
6 | return (
7 |
25 | );
26 | }
27 |
28 | export default App;
29 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_STORE
2 | node_modules
3 | scripts/flow/*/.flowconfig
4 | .flowconfig
5 | *~
6 | *.pyc
7 | .grunt
8 | _SpecRunner.html
9 | __benchmarks__
10 | build/
11 | build2/
12 | remote-repo/
13 | coverage/
14 | .module-cache
15 | fixtures/dom/public/react-dom.js
16 | fixtures/dom/public/react.js
17 | test/the-files-to-test.generated.js
18 | *.log*
19 | chrome-user-data
20 | *.sublime-project
21 | *.sublime-workspace
22 | .idea
23 | *.iml
24 | .vscode
25 | *.swp
26 | *.swo
27 |
28 | packages/react-devtools-core/dist
29 | packages/react-devtools-extensions/chrome/build
30 | packages/react-devtools-extensions/chrome/*.crx
31 | packages/react-devtools-extensions/chrome/*.pem
32 | packages/react-devtools-extensions/firefox/build
33 | packages/react-devtools-extensions/firefox/*.xpi
34 | packages/react-devtools-extensions/firefox/*.pem
35 | packages/react-devtools-extensions/shared/build
36 | packages/react-devtools-extensions/.tempUserDataDir
37 | packages/react-devtools-inline/dist
38 | packages/react-devtools-shell/dist
39 | packages/react-devtools-scheduling-profiler/dist
40 |
--------------------------------------------------------------------------------
/src/components/Draggable/index.js:
--------------------------------------------------------------------------------
1 | import './style.css';
2 | import _ from "lodash";
3 | import React from "react";
4 |
5 | const Draggable = (props) => {
6 | const { debounceTime = 0 } = props;
7 | const ref = React.useRef();
8 | const [mouseLoc, setMouseLoc] = React.useState([0, 0]);
9 | const [isDraggable, setIsDraggable] = React.useState(false);
10 | const onMouseMove = (e) => {
11 | if (isDraggable) setMouseLoc([e.clientX, e.clientY]);
12 | };
13 | const onMouseMoveDebounced = _.debounce(onMouseMove, debounceTime);
14 | const enableDragging = (e) => setIsDraggable(true);
15 | const disableDragging = (e) => setIsDraggable(false);
16 |
17 | React.useEffect(() => {
18 | // console.log(mouseLoc);
19 | if (ref.current) {
20 | const width = ref.current.offsetWidth;
21 | const height = ref.current.offsetHeight;
22 | ref.current.style.left = `calc(${mouseLoc[0]}px - ${width}px/2)`;
23 | ref.current.style.top = `calc(${mouseLoc[1]}px - ${height}px/2)`;
24 | }
25 | }, [mouseLoc]);
26 | return (
27 |
33 |
44 | {props.children}
45 |
46 |
47 | );
48 | };
49 |
50 | export default Draggable;
51 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-components",
3 | "version": "0.1.0",
4 | "description": "React Components built as a hobby",
5 | "private": true,
6 | "repository": {
7 | "type": "git",
8 | "url": "git+https://github.com/rachitiitr/react-components.git"
9 | },
10 | "keywords": [
11 | "react",
12 | "react-hooks",
13 | "javascript",
14 | "react-components"
15 | ],
16 | "author": "Rachit Jain",
17 | "license": "ISC",
18 | "bugs": {
19 | "url": "https://github.com/rachitiitr/react-components/issues"
20 | },
21 | "homepage": "https://rachitiitr.github.io/react-components/",
22 | "dependencies": {
23 | "@testing-library/jest-dom": "^5.11.4",
24 | "@testing-library/react": "^11.1.0",
25 | "@testing-library/user-event": "^12.1.10",
26 | "lodash": "^4.17.20",
27 | "react": "^17.0.1",
28 | "react-dom": "^17.0.1",
29 | "react-scripts": "4.0.2",
30 | "web-vitals": "^1.0.1"
31 | },
32 | "scripts": {
33 | "start": "react-scripts start",
34 | "build": "react-scripts build",
35 | "test": "react-scripts test",
36 | "eject": "react-scripts eject",
37 | "predeploy": "npm run build",
38 | "deploy": "gh-pages -d build"
39 | },
40 | "eslintConfig": {
41 | "extends": [
42 | "react-app",
43 | "react-app/jest"
44 | ]
45 | },
46 | "browserslist": {
47 | "production": [
48 | ">0.2%",
49 | "not dead",
50 | "not op_mini all"
51 | ],
52 | "development": [
53 | "last 1 chrome version",
54 | "last 1 firefox version",
55 | "last 1 safari version"
56 | ]
57 | },
58 | "devDependencies": {
59 | "gh-pages": "^3.1.0"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------