Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-js
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Soumya Sree Sridharala
react-js
Commits
5e2b3276
Commit
5e2b3276
authored
Mar 03, 2022
by
Soumya Sree Sridharala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial commit
parent
122e06a9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
239 additions
and
16 deletions
+239
-16
App.css
src/App.css
+65
-0
App.js
src/App.js
+81
-16
Item.css
src/components/Item.css
+15
-0
Item.js
src/components/Item.js
+76
-0
index.css
src/index.css
+2
-0
No files found.
src/App.css
View file @
5e2b3276
.App
{
max-width
:
400px
;
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
text-align
:
center
;
margin
:
auto
;
}
h1
{
color
:
#007ACE
;
font-size
:
45px
;
}
.App-logo
{
height
:
40vmin
;
pointer-events
:
none
;
...
...
@@ -36,3 +48,56 @@
transform
:
rotate
(
360deg
);
}
}
.btn
{
cursor
:
pointer
;
font-size
:
1.2rem
;
height
:
2.3rem
;
border-radius
:
0.5em
;
border
:
none
;
color
:
#fff
;
background
:
#8a2387
;
background
:
-webkit-linear-gradient
(
to
right
,
#f27121
,
#e94057
,
#8a2387
);
/* Chrome 10-25, Safari 5.1-6 */
background
:
linear-gradient
(
to
right
,
#f27121
,
#e94057
,
#8a2387
);
/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
outline
:
none
;
padding
:
0.3rem
1.8rem
0.3rem
1.8rem
;
}
.btn
:hover
{
filter
:
brightness
(
110%
);
border
:
none
;
outline
:
0
;
}
.btn
:focus
{
filter
:
brightness
(
110%
);
border
:
none
;
outline
:
0
;
}
.btn
:active
{
border
:
none
;
}
.input
{
background-color
:
whitesmoke
;
color
:
black
;
padding
:
1em
2em
;
border-radius
:
0.5em
;
border
:
none
;
outline
:
none
;
position
:
relative
;
margin
:
5px
;
height
:
0.7rem
;
}
src/App.js
View file @
5e2b3276
import
logo
from
'./logo.svg'
;
import
'./App.css'
;
import
React
,
{
useState
}
from
"react"
;
import
"./App.css"
;
import
Item
from
"./components/Item"
;
import
{
v4
as
uuidv4
}
from
"uuid"
;
const
arr
=
()
=>
{
let
data
=
localStorage
.
getItem
(
"data"
);
if
(
data
)
return
JSON
.
parse
(
localStorage
.
getItem
(
"data"
));
else
return
[];
};
function
App
()
{
const
[
item
,
setItem
]
=
useState
(
""
);
const
[
edit
,
setEdit
]
=
useState
(
false
);
const
[
editId
,
setEditId
]
=
useState
();
const
[
list
,
setList
]
=
useState
(
arr
);
const
[
error
,
setError
]
=
useState
(
""
);
const
handleSubmit
=
(
e
)
=>
{
const
newItem
=
{
id
:
uuidv4
(),
item
:
item
,
complete
:
false
,
};
e
.
preventDefault
();
if
(
item
&&
item
.
length
<=
25
&&
!
edit
)
{
setList
([...
list
,
newItem
]);
setItem
(
""
);
setError
(
""
);
}
else
if
(
item
&&
item
.
length
<=
25
&&
edit
&&
editId
)
{
setList
(
list
.
map
((
el
)
=>
{
if
(
el
.
id
===
editId
)
{
return
{
...
el
,
item
:
item
};
}
return
el
;
})
);
setItem
(
""
);
setEditId
(
null
);
setEdit
(
false
);
setError
(
""
);
}
else
if
(
!
item
)
setError
(
"Item cannot be blank."
);
else
if
(
item
.
length
>
25
)
setError
(
"Character limit is 25."
);
};
React
.
useEffect
(()
=>
{
localStorage
.
setItem
(
"data"
,
JSON
.
stringify
(
list
));
},
[
list
]);
const
handleChange
=
(
e
)
=>
{
setItem
(
e
.
target
.
value
);
};
return
(
<
div
className
=
"App"
>
<
header
className
=
"App-header"
>
<
img
src
=
{
logo
}
className
=
"App-logo"
alt
=
"logo"
/>
<
p
>
Edit
<
code
>
src
/
App
.
js
<
/code> and save to reload
.
<
/p
>
<
a
className
=
"App-link"
href
=
"https://reactjs.org"
target
=
"_blank"
rel
=
"noopener noreferrer"
>
Learn
React
<
/a
>
<
/header
>
<
h1
>
Grocery
List
<
/h1
>
<
form
onSubmit
=
{
handleSubmit
}
>
<
input
className
=
"input"
type
=
"text"
value
=
{
item
}
placeholder
=
"Enter the items"
onChange
=
{
handleChange
}
/
>
<
button
className
=
"btn"
type
=
"submit"
>
Add
Items
<
/button
>
{
error
&&
<
p
style
=
{{
color
:
"red"
}}
>
{
error
}
<
/p>
}
<
/form
>
<
div
>
{
list
.
map
((
c
,
id
)
=>
(
<
Item
key
=
{
id
}
id
=
{
c
.
id
}
item
=
{
c
.
item
}
list
=
{
list
}
setList
=
{
setList
}
complete
=
{
c
.
complete
}
setItem
=
{
setItem
}
setEdit
=
{
setEdit
}
setEditId
=
{
setEditId
}
/
>
))}
<
/div
>
<
/div
>
);
}
...
...
src/components/Item.css
0 → 100644
View file @
5e2b3276
.complete
{
text-decoration
:
line-through
;
text-decoration-color
:
navy
;
}
.item
{
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
color
:
white
;
}
p
{
font-family
:
cursive
;
}
src/components/Item.js
0 → 100644
View file @
5e2b3276
import
React
from
"react"
;
import
"./Item.css"
;
const
Item
=
({
id
,
item
,
list
,
setEdit
,
setEditId
,
setItem
,
setList
,
complete
,
})
=>
{
const
remove
=
(
id
)
=>
{
setList
(
list
.
filter
((
el
)
=>
el
.
id
!==
id
));
};
const
handleComplete
=
(
id
)
=>
{
setList
(
list
.
map
((
item
)
=>
{
if
(
item
.
id
===
id
)
{
return
{
...
item
,
complete
:
!
item
.
complete
,
};
}
return
item
;
})
);
};
//Edit Todo
const
handleItem
=
(
id
)
=>
{
const
editItem
=
list
.
find
((
el
)
=>
el
.
id
===
id
);
setItem
(
editItem
.
item
);
setEdit
(
true
);
setEditId
(
id
);
};
return
(
<
div
className
=
"item"
>
<
input
type
=
"text"
value
=
{
item
}
style
=
{{
border
:
"none"
,
outline
:
"none"
,
backgroundColor
:
"transparent"
,
color
:
"black"
,
fontSize
:
"20px"
,
}}
className
=
{
complete
?
"complete"
:
""
}
/
>
<
img
style
=
{{
cursor
:
"pointer"
}}
src
=
"https://img.icons8.com/emoji/36/000000/pencil-emoji.png"
onClick
=
{()
=>
handleItem
(
id
)}
alt
=
"edit item"
/>
<
img
style
=
{{
cursor
:
"pointer"
}}
onClick
=
{()
=>
handleComplete
(
id
)}
src
=
"https://img.icons8.com/offices/40/000000/checked-2--v2.png"
alt
=
"mark item complete"
/>
<
img
style
=
{{
cursor
:
"pointer"
}}
onClick
=
{()
=>
remove
(
id
)}
src
=
"https://img.icons8.com/color/48/000000/trash.png"
alt
=
"delete item"
/>
<
/div
>
);
};
export
default
Item
;
src/index.css
View file @
5e2b3276
...
...
@@ -5,6 +5,8 @@ body {
sans-serif
;
-webkit-font-smoothing
:
antialiased
;
-moz-osx-font-smoothing
:
grayscale
;
background-color
:
#
#000000
;
}
code
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment