-
Notifications
You must be signed in to change notification settings - Fork 1
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
DEAD-3: implement card component #3
base: dev
Are you sure you want to change the base?
Changes from all commits
6e86bf0
e2f2e5e
afa5121
8cfd62f
5cd114b
19dc91c
0f7d5fd
e54337d
591a96c
b9d8595
698185b
dbcb52c
ce52e08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ | |
|
||
# Node JS | ||
node_modules/ | ||
|
||
public/images | ||
*precompiled.js | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@import '/public/variables.css'; | ||
|
||
.card { | ||
background-color: var(--main-color); | ||
display: flex; | ||
padding: var(--space-xs); | ||
width: 100%; | ||
min-height: var(--card-min-height); | ||
max-height: var(--card-max-height); | ||
gap: var(--space-xs); | ||
border-radius: var(--border-radius-m); | ||
} | ||
|
||
.card-img { | ||
min-width: var(--card-img-min-width); | ||
max-width: var(--card-img-max-width); | ||
height: var(--card-img-height); | ||
overflow: hidden; | ||
position: relative; | ||
border-radius: var(--border-radius-m); | ||
} | ||
|
||
.card-img img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
|
||
.card-content { | ||
padding-bottom: var(--space-xs); | ||
overflow: hidden; | ||
} | ||
|
||
.card-content p { | ||
line-height: var(--line-height-s); | ||
font-family: var(--text-font); | ||
margin-top: var(--space-null); | ||
} | ||
|
||
.card-content__header { | ||
font-weight: var(--font-weight-bold); | ||
font-size: var(--text-size-xl); | ||
margin-bottom: var(--space-m); | ||
} | ||
|
||
.card-content__text { | ||
font-weight: var(--font-weight-semibold); | ||
font-size: var(--text-size); | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
width: 95%; | ||
overflow: hidden; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{#each items}} | ||
<div class='card'> | ||
{{#if imageUrl}} | ||
<div class="card-img"> | ||
<img src="{{imageUrl}}"> | ||
</div> | ||
{{/if}} | ||
<div class='card-content'> | ||
<p class='card-content__header'>{{title}}</p> | ||
<p class='card-content__text'>{{description}}</p> | ||
</div> | ||
</div> | ||
{{/each}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default class Cards { | ||
constructor(parent, items) { | ||
this.parent = parent; | ||
this.items = items; | ||
} | ||
|
||
render() { | ||
const template = Handlebars.templates['cards.hbs']; | ||
this.parent.innerHTML = template({ items: this.items }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. innerHTML лучше заменить на один из аналогов, так как он уязвим к XSS атакам There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут его нечем заменить, это же темплейт хендлбарса. XSS опасен когда есть какие-то пользовательские данные, в данном случае контент карточки. Если его отсанитайзить то проблемы с xss быть не должно |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@import './components/Cards/cards.css'; | ||
@import './variables.css'; | ||
|
||
body { | ||
margin: 0; | ||
background-color: var(--background-color); | ||
} | ||
|
||
.main-content { | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.main-content__feed { | ||
margin: var(--space-m); | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--space-xs); | ||
margin-left: var(--main-content-feed-margin-left); | ||
margin-right: var(--main-content-feed-margin-right); | ||
max-width: var(--main-content-feed-max-width); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Hello World!</title> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<title>DEAD VC.RU</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="stylesheet" href="index.css" /> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. шрифты лучше положить как статику и не использовать ссылки на гугл фонтс |
||
<link | ||
href="https://fonts.googleapis.com/css2?family=Play:wght@400;700&display=swap" | ||
rel="stylesheet" | ||
/> | ||
</head> | ||
<body> | ||
<h1>Hello World!</h1> | ||
<main class="main-content"> | ||
<div class="main-content__feed"></div> | ||
</main> | ||
|
||
<script src="/handlebars/dist/handlebars.runtime.js"></script> | ||
<script src="./components/Cards/cards.precompiled.js"></script> | ||
<script type="module" src="index.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Cards from './components/Cards/cards.js'; | ||
|
||
const cardsCollection = [ | ||
{ | ||
title: 'What is Lorem Ipsum? What is Lorem Ipsum?', | ||
description: `text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 | ||
text1 text1 text text1 text1 text1 text1 text1 text1 text text1 text1 | ||
text1 text1 text1 text1 text text1 text1 text1 text1 text1 text1 text | ||
text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 | ||
text1 text1 text text1 text1 text1 text1 text1 text1 text text1 text1 | ||
text1 text1 text1 text1 text text1 text1 text1 text1 text1 text1 text | ||
`, | ||
imageUrl: 'images/1.jpg', | ||
}, | ||
{ | ||
title: 'title2', | ||
description: `text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 | ||
text1 text1 text text1 text1 text1 text1 text1 text1 text text1 text1 | ||
`, | ||
}, | ||
{ | ||
title: 'title3', | ||
description: `text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 | ||
text1 text1 text text1 text1 text1 text1 text1 text1 text text1 text1 | ||
text1 text1 text1 text1 text text1 text1 text1 text1 text1 text1 text | ||
text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 text1 | ||
text1 text text1 text1 text1 text1 text1 text1 text`, | ||
imageUrl: 'images/1.jpg', | ||
}, | ||
{ | ||
title: 'title4', | ||
description: `text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 | ||
text1 text1 text text1 text1 text1 text1 text1 text1 text text1 text1 | ||
`, | ||
}, | ||
{ | ||
title: 'title3', | ||
description: `text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 | ||
text1 text1 text text1 text1 text1 text1 text1 text1 text text1 text1 | ||
text1 text1 text1 text1 text text1 text1 text1 text1 text1 text1 text | ||
text1 text1 text1 text1 text1 text1 text text1 text1 text1 text1 text1 | ||
text1 text text1 text1 text1 text1 text1 text1 text`, | ||
imageUrl: 'images/1.jpg', | ||
}, | ||
]; | ||
|
||
const feed = document.querySelector('.main-content__feed'); | ||
const cards = new Cards(feed, cardsCollection); | ||
cards.render(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
:root { | ||
--background-color: #edeef0; | ||
--accent-color: #9950f6; | ||
--main-color: #ffffff; | ||
--hover-color: #551aa0; | ||
--active-color: #b47cfb; | ||
--disabled-color: #dbbfff; | ||
|
||
--text-color: #000000; | ||
--text-font: 'Play', sans-serif; | ||
|
||
--space-null: 0px; | ||
--space-xxs: 5px; | ||
--space-xs: 10px; | ||
--space-s: 15px; | ||
--space-m: 20px; | ||
--space-l: 25px; | ||
|
||
--border-radius-s: 5px; | ||
--border-radius-m: 10px; | ||
--border-radius-l: 15px; | ||
|
||
--font-weight-thin: 100; | ||
--font-weight-semibold: 300; | ||
--font-weight-bold: 600; | ||
|
||
--text-size-xs: 12px; | ||
--text-size: 16px; | ||
--text-size-l: 18px; | ||
--text-size-xl: 20px; | ||
--text-size-h2: 24px; | ||
--text-size-h1: 40px; | ||
|
||
--line-height-s: 1.4; | ||
--line-height-m: 1.6; | ||
--line-height-l: 1.8; | ||
|
||
--card-min-height: 120px; | ||
--card-max-height: 150px; | ||
--card-img-min-width: 150px; | ||
--card-img-max-width: 150px; | ||
--card-img-height: 150px; | ||
Comment on lines
+38
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нужно ли это выносить отдельно? у @VladislavKirpichov нужно это уточнить |
||
--main-content-feed-margin-left: 30vw; | ||
--main-content-feed-margin-right: 30vw; | ||
--main-content-feed-max-width: 500px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
width 95% довольно странное значение, текст должен по всей ширине блока разъезжаться до паддингов. Просто задай паддинги корректные чтобы текст норм смотрелся