forked from devhatt/pet-dex-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create pet avatar component (devhatt#261)
* feat: create pet avatar component * feat: create pet avatar component * feat: create pet avatar component * feat: create pet avatar component * feat: create pet avatar component * feat: create pet avatar component * feat: create pet avatar component --------- Co-authored-by: Alexandre Gomes <[email protected]>
- Loading branch information
1 parent
72dbfc8
commit 1852a4e
Showing
5 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Component } from 'pet-dex-utilities'; | ||
import './index.scss'; | ||
import { routeLocation } from 'vanilla-routing'; | ||
|
||
const events = ['active']; | ||
|
||
const html = ` | ||
<a class="pet-avatar" data-select="pet-avatar" href="/petperfil/"> | ||
<img class="pet-avatar__img" data-select="pet-image" src="" alt=""/> | ||
<p class="pet-avatar__title" data-select="pet-title"></p> | ||
</a> | ||
`; | ||
|
||
export default function PetAvatar({ id, title, imgSrc, imgAlt } = {}) { | ||
Component.call(this, { html, events }); | ||
|
||
if (id) this.setHref(id); | ||
if (title) this.setTitle(title); | ||
if (imgSrc) this.setImgSrc(imgSrc); | ||
if (imgAlt) this.setImgAlt(imgAlt); | ||
|
||
if (routeLocation().pathname === `/petperfil/${id}`) { | ||
this.activate(); | ||
} | ||
} | ||
|
||
PetAvatar.prototype = Object.assign(PetAvatar.prototype, Component.prototype, { | ||
setTitle(text) { | ||
this.selected.get('pet-title').textContent = text; | ||
}, | ||
setImgSrc(src) { | ||
this.selected.get('pet-image').src = src; | ||
}, | ||
setImgAlt(alt) { | ||
this.selected.get('pet-image').alt = alt; | ||
}, | ||
setHref(id) { | ||
this.selected.get('pet-avatar').href += id; | ||
}, | ||
activate() { | ||
const image = this.selected.get('pet-image'); | ||
const title = this.selected.get('pet-title'); | ||
image.classList.add('pet-avatar__img--active'); | ||
title.classList.add('pet-avatar__title--active'); | ||
this.emit('active'); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@use '~styles/colors' as colors; | ||
@use '~styles/fonts' as fonts; | ||
|
||
.pet-avatar { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
|
||
align-items: center; | ||
|
||
text-decoration: none; | ||
aspect-ratio: 1/1; | ||
|
||
opacity: 0.85; | ||
|
||
transition: 0.3s ease-in-out; | ||
|
||
&__img { | ||
height: 100%; | ||
|
||
outline: 0.15rem solid colors.$gray500; | ||
|
||
border-radius: 50%; | ||
object-fit: cover; | ||
aspect-ratio: 1/1; | ||
|
||
transition: 0.3s ease-in-out; | ||
|
||
&--active { | ||
outline: 0.3rem solid colors.$primary200; | ||
} | ||
} | ||
|
||
&__title { | ||
font-family: fonts.$fourthFont; | ||
|
||
color: colors.$gray200; | ||
text-align: center; | ||
font-size: 1.4rem; | ||
font-weight: fonts.$regular; | ||
|
||
transition: 0.3s ease-in-out; | ||
|
||
&--active { | ||
color: colors.$primary200; | ||
font-weight: fonts.$semiBold; | ||
} | ||
} | ||
|
||
&:hover { | ||
transform: scale(1.02); | ||
opacity: 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import PetAvatar from '../components/PetAvatar'; | ||
|
||
import akita from './assets/petRegisterPage/akita.svg'; | ||
|
||
export default { | ||
title: 'Components/PetAvatar', | ||
render: (args) => { | ||
const $container = document.createElement('div'); | ||
$container.style.width = '60px'; | ||
$container.style.height = '90px'; | ||
$container.style.overflow = 'visible'; | ||
const petAvatar = new PetAvatar(args); | ||
petAvatar.mount($container); | ||
|
||
return $container; | ||
}, | ||
argTypes: { | ||
id: { control: 'text', description: 'Pet id' }, | ||
title: { control: 'text', description: 'Pet name' }, | ||
imgSrc: { control: 'text', description: 'url source for a image pet' }, | ||
imgAlt: { control: 'text', description: 'Pet name alt description' }, | ||
}, | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
id: '1', | ||
title: 'Carlos', | ||
imgSrc: akita, | ||
imgAlt: 'breed alt description', | ||
}, | ||
}; |