Skip to content

Commit 3dd4b6d

Browse files
committed
added styles for forms and its wrapper
created function with regexp to find dates in text
1 parent 4a0f23c commit 3dd4b6d

File tree

5 files changed

+86
-6
lines changed

5 files changed

+86
-6
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h1>Hometask #1 | JavaScript</h1>
4040
<table>
4141
<thead>
4242
<tr>
43-
<th class="category-icon">&nbsp;</th>
43+
<th class="stats-icon">&nbsp;</th>
4444
<th class="category2">Note Category</th>
4545
<th class="active">Active</th>
4646
<th class="archived">Archived</th>

scripts/HTMLBuilder.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { notes, categories, icons } from './data.js';
2+
import { makeID, getDatesFromText } from "./functions.js";
23
// import { makeID } from "./functions";
34

45
let statisticsTable = document.getElementById('stats-table'),
@@ -20,15 +21,34 @@ function buildForm(name, created, category, content){
2021

2122
form.innerHTML = `
2223
<input type="text" name="name" value="${typeof name === "string"? name : ''}" placeholder="Name">
23-
<input type="date" name="date" value="${created}">
24+
<!-- <input type="date" name="date" value="${created}">-->
2425
<select name="categories">
25-
` + categories.map(c => `<option value="${c}">${c}</option>`) + `
26+
` + Object.keys(categories).map(c => `<option value="${c}">${c}</option>`) + `
2627
</select>
2728
<input type="text" name="content" value="${content? content : ''}" placeholder="Content">
28-
<button type="submit" >Submit</button>
29+
<input type="submit" value="Submit">
2930
`;
3031

31-
document.body.append(form);
32+
form.onsubmit = (event)=>{
33+
event.preventDefault();
34+
35+
createNote({
36+
id: makeID(10),
37+
name: event.target.name.value,
38+
created: new Date(),
39+
category: event.target.categories.value,
40+
content: event.target.content.value,
41+
dates: getDatesFromText(event.target.content.value),
42+
archived: false
43+
});
44+
};
45+
46+
47+
let wrapperDiv = document.createElement('div');
48+
wrapperDiv.className = 'wrapper-div';
49+
wrapperDiv.append(form);
50+
51+
document.body.append(wrapperDiv);
3252
}
3353

3454
//Note function
@@ -94,7 +114,7 @@ function buildStatisticTable(){
94114
function buildStatTr(category, active, total){
95115
return `
96116
<tr>
97-
<td className="category-icon">${ categories[category] }</td>
117+
<td className="category-icon stats-icon">${ categories[category] }</td>
98118
<td className="category2">${ category }</td>
99119
<td className="active">${ active }</td>
100120
<td className="archived">${ total-active }</td>

scripts/functions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ export function makeID (length) {
77

88
return result;
99
}
10+
export function getDatesFromText(text){
11+
let results = text.match(/[0-9]{1,2}([\-\/ \.])[0-9]{1,2}([\-\/ \.])((19)|(20))[0-9]{2}/g);
12+
13+
if (results.length)
14+
return results;
15+
return;
16+
}

styles/form-styles.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,38 @@
1212
background-color: #b6d7d7;
1313
border: 1px solid cadetblue;
1414
}
15+
.wrapper-div{
16+
position: absolute;
17+
top: 0;
18+
left: 0;
19+
height: 100vh;
20+
width: 100vw;
21+
display: flex;
22+
flex-direction: column;
23+
justify-content: center;
24+
align-items: center;
25+
box-sizing: border-box;
26+
background-color: rgba(0,0,0,0.5);
27+
}
28+
form *{
29+
box-sizing: border-box;
30+
border: 1px solid rgba(0,0,0,0.1);
31+
}
32+
form{
33+
width: 20em;
34+
display: flex;
35+
flex-direction: column;
36+
justify-content: center;
37+
align-items: center;
38+
background-color: white;
39+
border-radius: 0.5em;
40+
padding: 1em;
41+
}
42+
form > *:not(:last-child){
43+
margin-bottom: 0.5em;
44+
}
45+
input, select{
46+
width: 100%;
47+
padding: 10px;
48+
49+
}

styles/table-styles.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ tr td:last-child, tr th:last-child{
3434
/*min-width: 1.5em;*/
3535
min-width: 2em;
3636
}
37+
.stats-icon td {
38+
width: 4%;
39+
/*fill: ghostwhite;*/
40+
min-width: 1.5em;
41+
min-height: 1.5em;
42+
max-width: 3em;
43+
}
44+
.stats-icon svg{
45+
width: 2em;
46+
height: 2em;
47+
min-width: 3em;
48+
}
3749
.name{
3850
width: 20%;
3951
/*min-width: 20%;*/
@@ -62,6 +74,12 @@ tr td:last-child, tr th:last-child{
6274
.active, .archived{
6375
width: 20%;
6476
}
77+
.category-icon, svg{
78+
width: 2em;
79+
height: 2em;
80+
max-width: 2em;
81+
max-height: 2em;
82+
}
6583
@media screen and (max-width: 800px) {
6684
.created, .dates{
6785
display: none;

0 commit comments

Comments
 (0)