Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixel Editor</title>
<link rel="stylesheet" href="styles.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Pixelify+Sans:[email protected]&display=swap" rel="stylesheet">
</head>
<body>
<div id="app">
<h1>Pixel Editor</h1>
</div>
<script src="index.js" type="module"></script>
</body>
Expand Down
38 changes: 21 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// Step 1: HTML Structure Initialization
const app = document.getElementById("app");
app.innerHTML = `
<h1>Pixel Editor</h1>
<header>PIXEL PALETTE<header>
`;

// Step 2: State Management
const state = {
backgroundColor: "#555",
column: 5,
row: 5,
backgroundColor: "white",
color: "#ff0000",
column: 10,
row: 10,
};

// Step 3: Utility Functions
const resetState = () => {
state.backgroundColor = "#555";
state.column = 5;
state.row = 5;
state.backgroundColor = "white";
state.column = 10;
state.row = 10;
}

const inputChangeHandler = (key, value) => {
Expand All @@ -29,7 +30,7 @@ const createContainerDiv = (containerId) => {
return container;
};

const createLabeledInput = (labelText, inputId, inputType = "text") => {
const createLabeledInput = (labelText, inputId, inputType = "text", inputValue) => {
const container = document.createElement("div");
const label = document.createElement("label");
const input = document.createElement("input");
Expand All @@ -38,7 +39,8 @@ const createLabeledInput = (labelText, inputId, inputType = "text") => {
label.innerHTML = labelText;
input.id = inputId;
input.type = inputType;
container.id = 'labeledInputContainer'
input.value = inputValue;
container.classList = 'labeledInputContainer'

container.appendChild(label);
container.appendChild(input);
Expand All @@ -56,7 +58,7 @@ const createGrid = () => {
const pixel = document.createElement("div");
pixel.classList.add("pixel");
pixel.style.backgroundColor = state.backgroundColor;
pixel.addEventListener("click", (e) => {
pixel.addEventListener("mousedown", (e) => {
const selectedColor = inputColor.value;
e.target.style.backgroundColor = selectedColor;
});
Expand All @@ -72,20 +74,21 @@ const createLayout = () => {

app.appendChild(appContainer);
appContainer.appendChild(operationContainer);
operationContainer.appendChild(btnContainer);
appContainer.appendChild(pixelContainer);

const {container: inputColorContainer, input: inputColor} = createLabeledInput(
"Color: ",
"Color ",
"inputColor",
"color"
"color",
"#ff0000"
);

const { container: inputRowContainer, input: inputRow } = createLabeledInput("Row: ", "inputRow", "number");
const { container: inputRowContainer, input: inputRow } = createLabeledInput("Row ", "inputRow", "number", 10);
const { container: inputColumnContainer, input: inputColumn } = createLabeledInput(
"Column: ",
"Column ",
"inputColumn",
"number"
"number",
10
);

const resetBtn = document.createElement("button");
Expand All @@ -101,6 +104,7 @@ const createLayout = () => {
inputSizeContainer.appendChild(inputRowContainer);
inputContainer.appendChild(inputSizeContainer);
btnContainer.appendChild(resetBtn);
operationContainer.appendChild(btnContainer);

createGrid();

Expand All @@ -124,6 +128,6 @@ resetBtn.addEventListener("click", () => {
resetState();
inputRow.value = state.row;
inputColumn.value = state.column;
inputColor.value = state.backgroundColor;
inputColor.value = state.color;
createGrid();
});
88 changes: 71 additions & 17 deletions src/styles.css
Original file line number Diff line number Diff line change
@@ -1,35 +1,89 @@
body {
font-family: sans-serif;
font-family: "Pixelify Sans", sans-serif;
color: white;
font-size: 32px;
margin: 0;
}

header {
position: fixed;
width: 100%;
font-size: 64px;
background-color: #6B6B6B;
text-align: center;
box-shadow: 0 3px 3px #333;
}

#appContainer {
display: flex;
flex-direction: row;
height: 500px;
height: 800px;
}

#operationContainer {
display: flex;
flex-direction: column;
align-items: center;
width: 40%;
background-color: #6B6B6B;
padding-top: 20%;
}


#inputContainer {
display: flex;
flex-direction: column;
margin-bottom: 50px;
margin: 0 0 80px 0;
padding: 0;
}

#operationContainer {
width: 200px;
#inputColor {
padding:0;
border: none;
background: none;
height: 36px;
}

#pixelContainer {

#inputColumn, #inputRow{
font-family: "Pixelify Sans", sans-serif;
font-size: 24px;
width: 40px;
color: #6B6B6B;
}

.labeledInputContainer {
display: grid;
margin-left: 100px;
gap: 10px;
grid-template-columns: 100px auto;
align-items: center;
gap: 30px;
margin-bottom: 20px;
}

#inputRow,
#inputColumn {
width: 30px;

#resetBtn {
font-family: "Pixelify Sans", sans-serif;
font-size: 16px;
padding: 10px 20px;
background-color: white;
border: none;
border-radius: 10px;
color: #6B6B6B;
}

.pixel {
background-color: #555;

#resetBtn:hover{
font-family: "Pixelify Sans", sans-serif;
font-size: 16px;
padding: 10px 20px;
background-color: #ddd;
border: none;
border-radius: 10px;
color: #6B6B6B;
}


#pixelContainer {
display: grid;
gap: 2px;
width: 60%;
background-color: #444;
padding-top: 15%;
justify-content: center;
}
Loading