Skip to content

Commit

Permalink
feat: avatar button issue devhatt#18
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosbryanp committed Jan 9, 2024
1 parent 6fa036c commit 4009756
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
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.
23 changes: 23 additions & 0 deletions src/components/Avatar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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">
<img class="plus" data-select="image" src="${icon}" alt="" />
</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));
}

AvatarButton.prototype = Object.assign(AvatarButton.prototype, Component.prototype);
16 changes: 16 additions & 0 deletions src/components/Avatar/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
body {
background: #111;
}

.plus {
padding: 18px;
border-radius: 9999px;
border: 1.5px solid #fff;
background: rgba(32, 35, 38, 1);
}

.plus: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);
});

0 comments on commit 4009756

Please sign in to comment.