Skip to content

Commit

Permalink
feat: added colorizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Opty1712 committed Feb 9, 2023
1 parent 9db12d2 commit a918a59
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 31 deletions.
40 changes: 20 additions & 20 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:@next/next/recommended',
'plugin:@next/next/recommended'
],
plugins: ['@typescript-eslint', 'import', 'react-hooks'],
parserOptions: {
"warnOnUnsupportedTypeScriptVersion": false,
warnOnUnsupportedTypeScriptVersion: false,
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
modules: true,
modules: true
},
project: ["./tsconfig.eslint.json", "./tsconfig.json"],
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json', './tsconfig.json'],
tsconfigRootDir: __dirname
},
env: {
browser: true,
node: true,
es6: true,
jest: true,
jest: true
},
settings: {
react: {
version: 'detect',
},
version: 'detect'
}
},
rules: {
'no-mixed-spaces-and-tabs': 'error',
Expand All @@ -49,13 +49,13 @@ module.exports = {
'@typescript-eslint/no-empty-function': 'error',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: '*', next: 'return' }
],
'no-console': [
'error',
{
allow: ['warn', 'error'],
},
allow: ['warn', 'error']
}
],
'@typescript-eslint/explicit-module-boundary-types': 0
},
Expand All @@ -64,8 +64,8 @@ module.exports = {
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
},
'@typescript-eslint/explicit-function-return-type': 'off'
}
},
{
files: ['*.tsx', '*.ts'],
Expand All @@ -88,13 +88,13 @@ module.exports = {
variables: false,
enums: false,
typedefs: false,
ignoreTypeReferences: false,
},
],
},
},
ignoreTypeReferences: false
}
]
}
}
],
globals: {
nameof: 'readonly',
},
nameof: 'readonly'
}
};
6 changes: 1 addition & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Project
node_modules/
.*
!.babelrc

*.log
*.sh
*.tsbuildinfo
Expand All @@ -18,6 +17,3 @@ yarn.lock
*.jpg
*.png
*.cur

# markdown
*.md
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"linaria": "^4.1.11",
"near-api-js": "^1.1.0",
"react": "^18.2.0",
"react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
"typescript": "^4.9.5"
}
Expand Down
1 change: 0 additions & 1 deletion pages/index.ts

This file was deleted.

81 changes: 81 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { styled } from 'linaria/react';
import { ChangeEvent, useState } from 'react';
import { RgbColorPicker } from 'react-colorful';
import { Wallet } from './components';
import { getKeys } from './utils';

export const App = () => {
const [selectedColor, setSelectedColor] = useState<RgbColor>(initialColor);

const getOnInputChange =
(part: keyof RgbColor) => (event: ChangeEvent<HTMLInputElement>) => {
const newPartValue = event.target.value;
setSelectedColor((value) => ({ ...value, [part]: newPartValue }));
};

return (
<Page selectedColor={selectedColor}>
<Wallet />

<ColorRoot>
<RgbColorPicker color={selectedColor} onChange={setSelectedColor} />
<Inputs>
{getKeys(selectedColor).map((key) => (
<Input
key={key}
value={selectedColor[key]}
onChange={getOnInputChange(key)}
/>
))}
</Inputs>
</ColorRoot>
</Page>
);
};

const Page = styled.div<{ selectedColor: RgbColor }>`
width: 100%;
height: 100vh;
display: flex;
align-items: center;
background-color: ${({ selectedColor: { b, g, r } }) =>
`rgb(${r},${g},${b})`};
`;

const Input = styled.input`
border-radius: 5px;
height: 50px;
width: 50px;
text-align: center;
font-size: 30px;
border-color: #eee;
`;

const initialColor: RgbColor = {
r: 255,
g: 255,
b: 255
};

const Inputs = styled.div`
display: flex;
justify-content: space-between;
margin-top: 10px;
`;

const ColorRoot = styled.div`
margin: 0 auto;
display: inline-block;
padding: 20px;
background-color: #fff;
border-radius: 10px;
border: 5px solid #444;
box-shadow: 0 0 69px -16px #fff;
`;

type RgbColor = {
r: number;
g: number;
b: number;
};
5 changes: 5 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

body {
margin: 0;
padding: 0;
}
5 changes: 0 additions & 5 deletions src/index.tsx

This file was deleted.

18 changes: 18 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { AppProps } from 'next/app';
import Head from 'next/head';
import '../global.css';

const App = ({ Component, pageProps }: AppProps) => {
return (
<>
<Head>
<title>Near frontend app</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>

<Component {...pageProps} />
</>
);
};

export default App;
1 change: 1 addition & 0 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { App as default } from '../App';
6 changes: 6 additions & 0 deletions src/utils/getKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** returns literal string instead of «string» for the concrete objects */
export function getKeys<T extends Record<string | number, unknown>>(
object: T
): (keyof T)[] {
return Object.keys(object) as (keyof T)[];
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { getKeys } from './getKeys';
export { isClientSide } from './isClientSide';
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7780,6 +7780,11 @@ rc-virtual-list@^3.4.13, rc-virtual-list@^3.4.8:
rc-resize-observer "^1.0.0"
rc-util "^5.15.0"

react-colorful@^5.6.1:
version "5.6.1"
resolved "https://registry.yarnpkg.com/react-colorful/-/react-colorful-5.6.1.tgz#7dc2aed2d7c72fac89694e834d179e32f3da563b"
integrity sha512-1exovf0uGTGyq5mXQT0zgQ80uvj2PCwvF8zY1RN9/vbJVSjSo3fsB/4L3ObbF7u70NduSiK4xu4Y6q1MHoUGEw==

react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
Expand Down

0 comments on commit a918a59

Please sign in to comment.