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

avatar button Issue 18 #55

Closed
wants to merge 3 commits 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
3 changes: 3 additions & 0 deletions src/components/Avatar/Icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/components/Avatar/iconHover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions src/components/Avatar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component } from 'pet-dex-utilities';
import './index.scss';
import icon from './Icon.svg';
import iconHover from './iconHover.svg';

const html = `
<a href="#" class="avatarButton" data-select="container">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O nome dessa classe não condiz com o BEM https://getbem.com/introduction/

<img class="plus" data-select="image" src="${icon}" alt="" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não nomeie a classe com seu conteudo, no caso icon é melhor que plus pq se o icone mudar a classe ainda faz sentido

</a>
`;

export default function AvatarButton() {
Component.call(this, { html });

const $image = this.selected.get('image');
const imageOriginal = icon;
const imageHover = iconHover;

$image.addEventListener('mouseover', () => ($image.src = imageHover));
$image.addEventListener('mouseout', () => ($image.src = imageOriginal));
}
Comment on lines +19 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pq precisou usar JS e não apenas um CSS?


AvatarButton.prototype = Object.assign(
AvatarButton.prototype,
Component.prototype
);
12 changes: 12 additions & 0 deletions src/components/Avatar/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.plus {
padding: 18px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não usar pixel para padding, margin e afins, explico melhor nesse artigo: https://www.linkedin.com/pulse/unidades-css-um-guia-completo-alexandre-gomes/

border-radius: 9999px;
border: 1.5px solid #fff;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pixel com ponto flutuante é bad

background: rgba(32, 35, 38, 1);

&:hover {
transition: 0.3s;
border: 1.5px solid #62dcf6;
cursor: pointer;
}
}
27 changes: 4 additions & 23 deletions src/home/main.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import { extractElements } from 'pet-dex-utilities';
import Card from '../components/Card';
import './index.scss';

function renderCards(qty, $container) {
for (let i = 0; i < qty; i += 1) {
const card = new Card();
card.mount($container);
card.setTitle(`Card ${i}`);
card.listen('purchase', () => {
console.log(`purchase de quem usa o componente, esse é o card ${i}`);
});

const $card = card.selected.get('card-button');

if (i === 2) {
card.disable();
$card.classList.add('card-container__button--disabled');
} else {
$card.classList.add('card-container__button--active');
}
}
}
import AvatarButton from '../components/Avatar';

document.addEventListener('DOMContentLoaded', () => {
const selected = extractElements([document.body]);
const $container = selected.get('container');

renderCards(5, $container);
const avatar = new AvatarButton();
avatar.mount($container);
});