Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.0.0 #104

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add windows bar
Toinane committed Apr 26, 2022
commit caec885f7f3b34e7d3335e9bd73bf817fe1a8ae0
17 changes: 14 additions & 3 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -4,10 +4,15 @@ let mainWindow: BrowserWindow | null;

function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 500,
width: 500,
height: 250,
minWidth: 400,
minHeight: 250,
titleBarStyle: 'hidden',
show: false,
webPreferences: {
nodeIntegration: true,
preload: './dist/main_preload.js',
sandbox: true,
},
});

@@ -17,6 +22,11 @@ function createWindow() {
mainWindow.loadFile('./dist/index.html');
}

mainWindow.on('ready-to-show', () => {
mainWindow?.show();
mainWindow?.webContents.openDevTools();
});

mainWindow.on('closed', () => {
mainWindow = null;
});
@@ -26,3 +36,4 @@ app.on('ready', createWindow);

app.commandLine.appendSwitch('force-color-profile', 'srgb'); // generic-rgb & macos only
app.disableDomainBlockingFor3DAPIs();
app.disableHardwareAcceleration();
5 changes: 4 additions & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Fragment, render } from 'preact';
import RGBSlider from './components/sliders/RGBSlider';
import WindowBar from './components/windowBar';

import './style.css';

const App = () => (
<Fragment>
<h1>Colorpicker</h1>
<WindowBar />
<RGBSlider />
</Fragment>
);
45 changes: 37 additions & 8 deletions src/components/sliders/RGBSlider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import { FunctionComponent, JSX } from 'preact';
import { useEffect, useState } from 'preact/hooks';

import Slider from '../../slider';
import Slider from '../slider';

const RGBSlider: FunctionComponent = (): JSX.Element => (
<section>
<Slider type="red" min={0} max={255} value={0} />
<Slider type="green" min={0} max={255} value={0} />
<Slider type="blue" min={0} max={255} value={0} />
</section>
);
const RGBSlider: FunctionComponent = (): JSX.Element => {
const [red, setRed] = useState(0);
const [green, setGreen] = useState(0);
const [blue, setBlue] = useState(0);

useEffect(() => {
document.documentElement.style.setProperty(
'--colopicker-main-color',
`rgb(${red},${green},${blue})`,
);
}, [red, green, blue]);

const changeVal = (value: number, type: string): void => {
switch (type) {
case 'red':
setRed(value);
break;
case 'green':
setGreen(value);
break;
case 'blue':
setBlue(value);
break;
default:
}
};

return (
<section>
<Slider type="red" min={0} max={255} value={0} onUpdate={changeVal} />
<Slider type="green" min={0} max={255} value={0} onUpdate={changeVal} />
<Slider type="blue" min={0} max={255} value={0} onUpdate={changeVal} />
</section>
);
};

export default RGBSlider;
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { FunctionComponent, JSX } from 'preact';
import { useState } from 'preact/hooks';
import { useEffect, useState } from 'preact/hooks';

import style from './style.module.css';

type SliderProps = {
min?: number;
max?: number;
value?: number;
type?: string;
type: string;
onUpdate: (currentValue: number, type: string) => void;
};

const Slider: FunctionComponent<SliderProps> = ({
min = 0,
max = 255,
value = 0,
type,
onUpdate,
}): JSX.Element => {
const [currentValue, setValue] = useState(value);

useEffect(() => {
onUpdate(currentValue, type);
}, [currentValue, onUpdate, type]);

const changeValue = (event: Event) => {
setValue(event.target instanceof HTMLInputElement ? Number(event.target.value) : 0);
};
@@ -33,7 +39,7 @@ const Slider: FunctionComponent<SliderProps> = ({
onInput={changeValue}
/>
<progress
className={[style.progress, type && style[type]].join(' ')}
className={[style.progress, style[type]].join(' ')}
min={min}
max={max}
value={currentValue}
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
display: flex;
justify-content: center;
align-items: center;
height: 24px;
width: 50%;
}

.input {
@@ -29,18 +31,18 @@
.progress {
-webkit-appearance: none;
position: absolute;
width: 97%;
width: 99%;
height: 10px;
}

.progress::-webkit-progress-bar {
background-color: rgba(255, 255, 255, 0.9);
border-radius: 6px;
border-radius: 100px;
}

.progress::-webkit-progress-value {
background-color: rgba(0, 0, 0, 0.5);
border-radius: 6px;
border-radius: 100px;
}

.red::-webkit-progress-value {
15 changes: 15 additions & 0 deletions src/components/windowBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FunctionComponent, JSX } from 'preact';

import style from './style.module.css';

const WindowBar: FunctionComponent = (): JSX.Element => (
<section className={style.windowBar}>
<section className={style.windowButtons}>
<div className={style.minimize} />
<div className={style.maximize} />
<div className={style.close} />
</section>
</section>
);

export default WindowBar;
76 changes: 76 additions & 0 deletions src/components/windowBar/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.windowBar {
display: flex;
justify-content: space-between;
height: 36px;
width: 100%;
background: #2d2d3a;
-webkit-app-region: drag;
flex-direction: row-reverse;
}

.windowButtons {
-webkit-app-region: no-drag;
display: flex;
cursor: initial;
}

.windowButtons div {
position: relative;
width: 40px;
height: 100%;
transition: 0.3s background;
}

.windowButtons div:hover {
background: rgba(255, 255, 255, 0.2);
transition: 0.1s background;
}

.minimize::before {
content: '';
position: absolute;
top: 50%;
left: 38%;
width: 10px;
border-bottom: 1px solid white;
}

.maximize::before {
content: '';
position: absolute;
top: 37%;
left: 37%;
width: 10px;
height: 10px;
border: 1px solid white;
border-radius: 2px;
}

.close::before,
.close::after {
content: '';
position: absolute;
top: 50%;
left: 32%;
width: 13px;
height: 1px;
transform: rotate(45deg);
background: white;
}

.close::after {
transform: rotate(-45deg);
}

.windowButtons .close:hover {
background: #e81123;
}

.windowButtons .close:active {
background: #f1707a;
transition: 0s background;
}
.close:active::after,
.close:active::before {
background: black;
}
38 changes: 38 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Reset CSS */

*:where(:not(iframe, canvas, img, svg, video):not(svg *, symbol *)) {
all: unset;
display: revert;
}

*,
*::before,
*::after {
box-sizing: border-box;
}

a,
button {
cursor: revert;
}

ol,
ul,
menu {
list-style: none;
}

img {
max-width: 100%;
}

/* Global Style */

:root {
--colopicker-main-color: black;
}

body {
background: var(--colopicker-main-color);
user-select: none;
}