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

feat: add fill functionality for background color #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
name="description"
content="Web site created using create-react-app"
/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class Header extends React.Component {
WHITEBOARD
</div>
</div>
<div className="header__right">
{/* <div className="header__right">
{
this.props.theme === 'light' ?
<MoonIcon className="icon themeIcon moonIcon" onClick={this.changeTheme} /> :
<LightModeIcon className="icon themeIcon" onClick={this.changeTheme} />
}
</div>
</div> */}
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Header/Header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
z-index: 100;

display: flex;
justify-content: space-between;
justify-content: center;
align-items: center;

-webkit-box-shadow: 1px 1px 10px 3px white;
Expand All @@ -37,7 +37,7 @@
animation-iteration-count: infinite;
animation-timing-function: linear;

font-size: 32px;
font-size: 40px;
font-weight: bold;

cursor: pointer;
Expand Down
34 changes: 26 additions & 8 deletions src/Components/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import PaletteIcon from '@mui/icons-material/Palette';
import BrushIcon from '@mui/icons-material/Brush';
import RectangleIcon from '@mui/icons-material/Crop169';
import CircleIcon from '@mui/icons-material/CircleOutlined';
import MenuIcon from '@mui/icons-material/Menu';
import EraserIcon from '../Eraser/Eraser';
// import MenuIcon from '@mui/icons-material/Menu';
// import EraserIcon from '../Eraser/Eraser';
import ClearIcon from '@mui/icons-material/DeleteForever';
import { Icon } from '@iconify/react';
import ZoomInIcon from '@mui/icons-material/ZoomIn';
import ZoomOutIcon from '@mui/icons-material/ZoomOut';
import AllScroll from '../AllScroll/AllScroll';
// import AllScroll from '../AllScroll/AllScroll';
import ShareIcon from '@mui/icons-material/IosShare';
import CancelPresentationIcon from '@mui/icons-material/CancelPresentation';

Expand All @@ -40,9 +40,10 @@ class Main extends React.Component {
changingBoard: false,
loading: false,
tool: Tools.Pencil,
color: '#fff',
color: 'white',
showColorPicker: false,
backgroundColor: 'transparent',
showBgColorPicker: false,
backgroundColor: 'black',
active: 'Pencil',
lineWidth: 3,
eraserWidth: 30,
Expand All @@ -57,9 +58,11 @@ class Main extends React.Component {
}

this.setColor = this.setColor.bind(this);
this.setBackgroundColor = this.setBackgroundColor.bind(this);
this.sketchField = React.createRef();
this.manipulateBoard = this.manipulateBoard.bind(this);
this.toggleColorPicker = this.toggleColorPicker.bind(this);
this.toggleBgColorPicker = this.toggleBgColorPicker.bind(this);
this.maxLength = 0;

this.toolChange = this.toolChange.bind(this);
Expand Down Expand Up @@ -143,12 +146,23 @@ class Main extends React.Component {
this.setState({color:color})
}

setBackgroundColor(backgroundColor) {
console.log('state-changed', backgroundColor)
this.setState({backgroundColor:backgroundColor})
}

toggleColorPicker() {
this.setState(prevState => ({
showColorPicker: !prevState.showColorPicker
}))
}

toggleBgColorPicker() {
this.setState(prevState => ({
showBgColorPicker: !prevState.showBgColorPicker
}))
}

clearBoard() {
// this.sketchField.current.zoom(Number.MAX_SAFE_INTEGER)
this.sketchField.current.clear();
Expand Down Expand Up @@ -331,7 +345,7 @@ class Main extends React.Component {
currLineColor = this.state.color;

else
currLineColor = '#000';
currLineColor = this.state.backgroundColor;

if(this.state.active !== 'Eraser')
currLineWidth = this.state.lineWidth;
Expand All @@ -340,7 +354,7 @@ class Main extends React.Component {
currLineWidth = this.state.eraserWidth;

const currTool = this.state.receiverConnected ? Tools.Select : this.state.tool;
console.log(this.state.iAmReciever)
// console.log(this.state.iAmReciever)

const whiteboard = (
<SketchField
Expand All @@ -362,7 +376,7 @@ class Main extends React.Component {
disabled={this.state.iAmReciever}
// defaultValue={this.state.defaultValue}
// backgroundColor={this.props.theme === 'light' ? '#fff' : '#000'}
backgroundColor={'#000'}
backgroundColor={this.state.backgroundColor}
onChange={this.manipulateBoard}

/>
Expand All @@ -384,6 +398,10 @@ class Main extends React.Component {
<PaletteIcon onClick={this.toggleColorPicker} className = 'header--item'/>
{ this.state.showColorPicker && <HexColorPicker className='color__palette' color={this.state.color} onChange={this.setColor} />}
</span>
<span className = "bg_color__picker">
<i onClick={this.toggleBgColorPicker} className = 'fa-solid fa-fill-drip header--item'></i>
{ this.state.showBgColorPicker && <HexColorPicker className='bg_color__palette' color={this.state.backgroundColor} onChange={this.setBackgroundColor} />}
</span>
<ClearIcon className = 'header--item' onClick = {this.clearBoard}/>
<UndoIcon onClick = {this.undoStep} className='undo header--item' />
<RedoIcon onClick = {this.redoStep} className='redo header--item'/></>}
Expand Down
22 changes: 21 additions & 1 deletion src/Components/Main/Main.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.main {
min-height: 90vh;
position: relative;
background-color: green;
background-color: green !important;

.sidebar {
display: flex;
Expand Down Expand Up @@ -91,6 +91,26 @@
height: 100%;
}
}

.bg_color__picker {
cursor: pointer;
position: relative;
font-size: 20px;
height: 0%;
margin-bottom: 40px;

.bg_color__palette {
position: absolute;
top: -80px;
left: 50px;
}

.visible--palette {
height: 100%;
}
}



}

Expand Down
2 changes: 1 addition & 1 deletion src/Components/SketchField/SketchField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class SketchField extends PureComponent {
};

static defaultProps = {
lineColor: "black",
lineWidth: 10,
fillColor: "transparent",
backgroundColor: "transparent",
lineColor: "transparent",
opacity: 1.0,
undoSteps: 25,
tool: null,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const hexToRgbA = (hex) => {
var c;
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
c = hex.substring(1).split("");
if (c.length == 3) {
if (c.length === 3) {
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c = "0x" + c.join("");
Expand Down