├── .eslintcache
├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
└── src
├── App.js
├── App.test.js
├── SingleColor.js
├── index.css
├── index.js
├── reportWebVitals.js
├── setupTests.js
└── utils.js
/.eslintcache:
--------------------------------------------------------------------------------
1 | [{"C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\index.js":"1","C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\App.js":"2","C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\reportWebVitals.js":"3","C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\SingleColor.js":"4","C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\utils.js":"5"},{"size":500,"mtime":499162500000,"results":"6","hashOfConfig":"7"},{"size":1284,"mtime":1609068730280,"results":"8","hashOfConfig":"7"},{"size":362,"mtime":499162500000,"results":"9","hashOfConfig":"7"},{"size":923,"mtime":1609068762847,"results":"10","hashOfConfig":"7"},{"size":246,"mtime":1609067556519,"results":"11","hashOfConfig":"7"},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"14"},"1warmv9",{"filePath":"15","messages":"16","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"17","messages":"18","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"14"},{"filePath":"19","messages":"20","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"21","messages":"22","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\index.js",[],["23","24"],"C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\App.js",[],"C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\reportWebVitals.js",[],"C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\SingleColor.js",["25"],"C:\\Users\\shaon\\OneDrive\\Desktop\\react\\color_generator\\src\\utils.js",[],{"ruleId":"26","replacedBy":"27"},{"ruleId":"28","replacedBy":"29"},{"ruleId":"30","severity":1,"message":"31","line":7,"column":9,"nodeType":"32","messageId":"33","endLine":7,"endColumn":12},"no-native-reassign",["34"],"no-negated-in-lhs",["35"],"no-unused-vars","'hex' is assigned a value but never used.","Identifier","unusedVar","no-global-assign","no-unsafe-negation"]
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Color Generator
2 |
3 | Color value library: `https://github.com/noeldelgado/values.js`
4 |
5 | ## install
6 | ### npm
7 | `npm install values.js --save`
8 |
9 | ### Unpkg CDN
10 | ``
11 |
12 | ### jsDelivr CDN
13 | ``
14 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "color_generator",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.11.6",
7 | "@testing-library/react": "^11.2.2",
8 | "@testing-library/user-event": "^12.6.0",
9 | "react": "^17.0.1",
10 | "react-dom": "^17.0.1",
11 | "react-scripts": "4.0.1",
12 | "values.js": "^2.0.0",
13 | "web-vitals": "^0.2.4"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test",
19 | "eject": "react-scripts eject"
20 | },
21 | "eslintConfig": {
22 | "extends": [
23 | "react-app",
24 | "react-app/jest"
25 | ]
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/react_color_generator/d68d669af2f338ca5821a9a8d82b8327a69628e9/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | Color Generator
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/react_color_generator/d68d669af2f338ca5821a9a8d82b8327a69628e9/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rkshaon/react_color_generator/d68d669af2f338ca5821a9a8d82b8327a69628e9/public/logo512.png
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 | import SingleColor from './SingleColor'
3 |
4 | import Values from 'values.js'
5 |
6 | function App() {
7 | const [color, setColor] = useState('#f15025');
8 | const [error, setError] = useState(false);
9 | const [list, setList] = useState(new Values('#f15025').all(10));
10 |
11 | const handleSubmit = (e) => {
12 | e.preventDefault();
13 | try {
14 | let colors = new Values(color).all(10);
15 | setList(colors);
16 | // console.log(colors);
17 | } catch (e) {
18 | setError(true);
19 | console.log(e);
20 | }
21 | }
22 |
23 | return(
24 | <>
25 |
26 | color generator
27 |
36 |
37 |
38 | {list.map((color, index) => {
39 | console.log(color);
40 | return(
41 | );
45 | })}
46 |
47 | >
48 | );
49 | }
50 |
51 | export default App
52 |
--------------------------------------------------------------------------------
/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/SingleColor.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react'
2 | import rgbToHex from './utils'
3 |
4 | const SingleColor = ({rgb, weight, index, hexColor}) => {
5 | const [alert, setAlert] = useState(false);
6 | const bcg = rgb.join(',');
7 | const hex = rgbToHex(...rgb);
8 | const hexValue = `#${hexColor}`;
9 | console.log(bcg);
10 |
11 | useEffect(() => {
12 | const timeout = setTimeout(()=>{
13 | setAlert(false);
14 | }, 1000);
15 | return () => clearTimeout(timeout);
16 | }, [alert]);
17 |
18 | return(
19 | 10 && 'color-light'}`}
21 | style={{backgroundColor:`rgb(${bcg})`}}
22 | onClick={()=>{
23 | setAlert(true);
24 | navigator.clipboard.writeText(hexValue);
25 | }}>
26 | {weight}%
27 | {hexValue}
28 | {alert && copied to clipboard
}
29 |
30 | );
31 | }
32 |
33 | export default SingleColor
34 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | /*
2 | ===============
3 | Variables
4 | ===============
5 | */
6 |
7 | :root {
8 | /* dark shades of primary color*/
9 | --clr-primary-1: hsl(205, 86%, 17%);
10 | --clr-primary-2: hsl(205, 77%, 27%);
11 | --clr-primary-3: hsl(205, 72%, 37%);
12 | --clr-primary-4: hsl(205, 63%, 48%);
13 | /* primary/main color */
14 | --clr-primary-5: hsl(205, 78%, 60%);
15 | /* lighter shades of primary color */
16 | --clr-primary-6: hsl(205, 89%, 70%);
17 | --clr-primary-7: hsl(205, 90%, 76%);
18 | --clr-primary-8: hsl(205, 86%, 81%);
19 | --clr-primary-9: hsl(205, 90%, 88%);
20 | --clr-primary-10: hsl(205, 100%, 96%);
21 | /* darkest grey - used for headings */
22 | --clr-grey-1: hsl(209, 61%, 16%);
23 | --clr-grey-2: hsl(211, 39%, 23%);
24 | --clr-grey-3: hsl(209, 34%, 30%);
25 | --clr-grey-4: hsl(209, 28%, 39%);
26 | /* grey used for paragraphs */
27 | --clr-grey-5: hsl(210, 22%, 49%);
28 | --clr-grey-6: hsl(209, 23%, 60%);
29 | --clr-grey-7: hsl(211, 27%, 70%);
30 | --clr-grey-8: hsl(210, 31%, 80%);
31 | --clr-grey-9: hsl(212, 33%, 89%);
32 | --clr-grey-10: hsl(210, 36%, 96%);
33 | --clr-white: #fff;
34 | --clr-red-dark: hsl(360, 67%, 44%);
35 | --clr-red-light: hsl(360, 71%, 66%);
36 | --clr-green-dark: hsl(125, 67%, 44%);
37 | --clr-green-light: hsl(125, 71%, 66%);
38 | --clr-black: #222;
39 | --transition: all 0.3s linear;
40 | --spacing: 0.1rem;
41 | --radius: 0.25rem;
42 | --light-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
43 | --dark-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
44 | --max-width: 1170px;
45 | --fixed-width: 620px;
46 | }
47 | /*
48 | ===============
49 | Global Styles
50 | ===============
51 | */
52 |
53 | *,
54 | ::after,
55 | ::before {
56 | margin: 0;
57 | padding: 0;
58 | box-sizing: border-box;
59 | }
60 | body {
61 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
62 | Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
63 | background: var(--clr-grey-10);
64 | color: var(--clr-grey-1);
65 | line-height: 1.5;
66 | font-size: 0.875rem;
67 | }
68 | ul {
69 | list-style-type: none;
70 | }
71 | a {
72 | text-decoration: none;
73 | }
74 | h1,
75 | h2,
76 | h3,
77 | h4 {
78 | letter-spacing: var(--spacing);
79 | text-transform: capitalize;
80 | line-height: 1.25;
81 | margin-bottom: 0.75rem;
82 | }
83 | h1 {
84 | font-size: 3rem;
85 | }
86 | h2 {
87 | font-size: 2rem;
88 | }
89 | h3 {
90 | font-size: 1.25rem;
91 | }
92 | h4 {
93 | font-size: 0.875rem;
94 | }
95 | p {
96 | margin-bottom: 1.25rem;
97 | color: var(--clr-grey-5);
98 | }
99 | @media screen and (min-width: 800px) {
100 | h1 {
101 | font-size: 4rem;
102 | }
103 | h2 {
104 | font-size: 2.5rem;
105 | }
106 | h3 {
107 | font-size: 1.75rem;
108 | }
109 | h4 {
110 | font-size: 1rem;
111 | }
112 | body {
113 | font-size: 1rem;
114 | }
115 | h1,
116 | h2,
117 | h3,
118 | h4 {
119 | line-height: 1;
120 | }
121 | }
122 | /* global classes */
123 |
124 | /* section */
125 | .section {
126 | width: 90vw;
127 | margin: 0 auto;
128 | max-width: var(--max-width);
129 | }
130 |
131 | @media screen and (min-width: 992px) {
132 | .section {
133 | width: 95vw;
134 | }
135 | }
136 |
137 | /*
138 | ===============
139 | Color Generator
140 | ===============
141 | */
142 |
143 | .container {
144 | text-align: center;
145 | display: flex;
146 | align-items: center;
147 | height: 100px;
148 | padding-left: 2rem;
149 | }
150 | .container h3 {
151 | margin-bottom: 0;
152 | margin-right: 2rem;
153 | }
154 |
155 | input {
156 | border-color: transparent;
157 | padding: 0.5rem 1rem;
158 | font-size: 1.2rem;
159 | border-top-left-radius: var(--radius);
160 | border-bottom-left-radius: var(--radius);
161 | }
162 | .btn {
163 | background: var(--clr-primary-5);
164 | padding: 0.5rem 1rem;
165 | font-size: 1.2rem;
166 | border-color: transparent;
167 | border-top-right-radius: var(--radius);
168 | border-bottom-right-radius: var(--radius);
169 | text-transform: capitalize;
170 | color: var(--clr-white);
171 | cursor: pointer;
172 | }
173 | @media screen and (max-width: 576px) {
174 | .container h3 {
175 | font-size: 1rem;
176 | }
177 | input,
178 | .btn {
179 | font-size: 0.85rem;
180 | }
181 | }
182 | input.error {
183 | border: 2px solid var(--clr-red-dark);
184 | }
185 | .colors {
186 | min-height: calc(100vh - 100px);
187 | display: grid;
188 | grid-template-columns: repeat(auto-fit, minmax(223.33px, 1fr));
189 | grid-template-rows: repeat(auto-fit, minmax(96px, 1fr));
190 | }
191 | .color {
192 | padding: 1rem 2rem;
193 | cursor: pointer;
194 | font-size: 1rem;
195 | text-transform: none;
196 | }
197 | .percent-value {
198 | margin-bottom: 0;
199 | color: var(--clr-grey-1);
200 | }
201 | .color-value {
202 | color: var(--clr-grey-1);
203 | margin-bottom: 0;
204 | }
205 | .color-light .color-value {
206 | color: var(--clr-white);
207 | }
208 | .color-light .percent-value {
209 | color: var(--clr-white);
210 | }
211 |
212 | .alert {
213 | text-transform: uppercase;
214 | font-size: 0.85rem;
215 | margin-top: 0.5rem;
216 | }
217 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/utils.js:
--------------------------------------------------------------------------------
1 | function componentToHex(c) {
2 | var hex = c.toString(16);
3 | return hex.length === 1 ? '0' + hex : hex;
4 | }
5 |
6 | function rgbToHex(r, g, b) {
7 | return '#' + componentToHex(r) + componentToHex(g) + componentToHex(b);
8 | }
9 |
10 | export default rgbToHex;
11 |
--------------------------------------------------------------------------------