Skip to content

Commit 18bd15e

Browse files
committed
feat: mypets
1 parent 025cadc commit 18bd15e

File tree

8 files changed

+144
-29
lines changed

8 files changed

+144
-29
lines changed
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

src/components/MyPets/index.js

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,62 @@
11
import { Component } from 'pet-dex-utilities';
22
import MyPetsCard from '../MyPetsCard';
33
import Sliding from '../Sliding';
4-
import './index.scss';
54

6-
const events = [''];
5+
import arrowLeft from './images/arrowLeft.svg';
6+
import arrowRight from './images/arrowRight.svg';
7+
8+
import './index.scss';
79

810
const html = `
9-
<div class="my-pets" data-select="my-pets">
11+
<div class="my-pets">
12+
<button class="my-pets__button" data-select="button-previous">
13+
<img src=${arrowLeft}></img>
14+
</button>
15+
<div class="my-pets__cards-container" data-select="my-pets-cards-container"></div>
16+
<button class="my-pets__button" data-select="button-next">
17+
<img src=${arrowRight}></img>
18+
</button>
1019
</div>
1120
`;
1221

13-
export default function MyPets() {
14-
Component.call(this, { html, events });
15-
16-
const $myPetsContainer = this.selected.get('my-pets');
17-
18-
const myPetsCard = new MyPetsCard({
19-
name: 'Kelvo',
20-
gender: 'male',
21-
race: 'Cachorro',
22-
type: 'Humano',
23-
desc: 'Mistura marrom-escura-branca, com sobrancelhas claras e uma mancha em forma de coração na pata esquerda.',
22+
export default function MyPets({
23+
pets = [
24+
{
25+
name: '',
26+
gender: '',
27+
race: '',
28+
type: '',
29+
desc: '',
30+
},
31+
],
32+
}) {
33+
Component.call(this, { html });
34+
35+
const $myPetsContainer = this.selected.get('my-pets-cards-container');
36+
const $previousButton = this.selected.get('button-previous');
37+
const $nextButton = this.selected.get('button-next');
38+
39+
const cards = [];
40+
pets.forEach((pet) => {
41+
const petCard = new MyPetsCard(pet);
42+
const div = document.createElement('div');
43+
petCard.mount(div);
44+
cards.push(div);
45+
});
46+
const sliding = new Sliding({
47+
slides: cards,
48+
shuffleMode: true,
49+
slideSideSpacing: 80,
2450
});
25-
26-
const div = document.createElement('div');
27-
myPetsCard.mount(div);
28-
29-
const sliding = new Sliding({ slides: [div] });
3051

3152
sliding.mount($myPetsContainer);
53+
54+
$previousButton.onclick = () => {
55+
sliding.previous();
56+
};
57+
$nextButton.onclick = () => {
58+
sliding.next();
59+
};
3260
}
3361

3462
MyPets.prototype = Object.assign(MyPets.prototype, Component.prototype, {});

src/components/MyPets/index.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.my-pets {
2+
display: flex;
3+
4+
gap: 4rem;
5+
6+
align-items: center;
7+
8+
&__button {
9+
font: inherit;
10+
color: inherit;
11+
12+
padding: 0;
13+
14+
padding: 1.7rem;
15+
border: 0;
16+
17+
background: none;
18+
19+
box-shadow: 0 1px 4px 0 rgba(139, 158, 184, 0.2);
20+
outline: inherit;
21+
border-radius: 14px;
22+
23+
cursor: pointer;
24+
}
25+
}

src/components/MyPetsCard/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const html = `
1616
<span class="my-pets-card__pet-name" data-select="name"></span>
1717
<div class="my-pets-card__pet-info"/>
1818
<span data-select="race"></span>
19-
|
19+
<hr class="my-pets-card__divider"/>
2020
<span data-select="type"></span>
2121
</div>
2222
</div>
@@ -33,7 +33,7 @@ export default function MyPetsCard({
3333
race = '',
3434
desc = '',
3535
gender = 'male',
36-
avatar,
36+
avatar = akita,
3737
}) {
3838
Component.call(this, { html, events });
3939

@@ -53,7 +53,7 @@ MyPetsCard.prototype = Object.assign(
5353
MyPetsCard.prototype,
5454
Component.prototype,
5555
{
56-
insertText({ name, type, race, desc }) {
56+
insertText({ name, type, race, desc, avatar }) {
5757
const $name = this.selected.get('name');
5858
const $type = this.selected.get('type');
5959
const $race = this.selected.get('race');
@@ -62,7 +62,7 @@ MyPetsCard.prototype = Object.assign(
6262

6363
const petAvatar = new PetAvatar({
6464
imgAlt: 'breed alt description',
65-
imgSrc: akita,
65+
imgSrc: avatar,
6666
});
6767
petAvatar.mount($avatar);
6868

src/components/MyPetsCard/index.scss

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
@use '~styles/breakpoints.scss' as breakpoints;
44

55
.my-pets-card {
6-
max-width: 63.8rem;
7-
height: 100%;
86
max-height: 13.7rem;
7+
overflow: hidden;
98

109
display: flex;
1110

@@ -60,6 +59,18 @@
6059
border-radius: 50%;
6160
}
6261

62+
&__divider {
63+
width: 1px;
64+
height: 10px;
65+
66+
align-self: stretch;
67+
68+
border: 0;
69+
70+
background: rgb(116, 180, 255);
71+
margin-inline: 0.7rem;
72+
}
73+
6374
&__avatar {
6475
max-width: 50%;
6576
max-height: 50%;
@@ -130,5 +141,9 @@
130141

131142
background: colors.$white;
132143
}
144+
145+
&__divider {
146+
height: auto;
147+
}
133148
}
134149
}

src/stories/MyPets.stories.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
import MyPets from '../components/MyPets';
1+
import MyPets from '~src/components/MyPets';
22

33
export default {
44
title: 'Components/MyPets',
55
render: (args) => {
6-
const dropdown = new MyPets(args);
6+
const myPets = new MyPets(args);
77
const $container = document.createElement('div');
8-
dropdown.mount($container);
8+
myPets.mount($container);
99

1010
return $container;
1111
},
1212
};
1313

14-
export const Default = {};
14+
export const Default = {
15+
args: {
16+
pets: [
17+
{
18+
name: 'Um super cachorro',
19+
gender: 'male',
20+
race: 'Border Collie',
21+
type: 'Cachorro',
22+
desc: 'Mistura marrom-escura-branca, com sobrancelhas claras e uma mancha em forma de coração na pata esquerda.',
23+
},
24+
{
25+
name: 'Tobias',
26+
gender: 'male',
27+
race: 'Border Collie',
28+
type: 'Cachorro',
29+
desc: 'Mistura marrom-escura-branca, com sobrancelhas claras e uma mancha em forma de coração na pata esquerda.',
30+
},
31+
],
32+
},
33+
};

src/stories/MyPetsCard.stories.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import MyPetsCard from '../components/MyPetsCard';
2+
3+
export default {
4+
title: 'Components/MyPetsCard',
5+
render: (args) => {
6+
const myPetsCard = new MyPetsCard(args);
7+
const $container = document.createElement('div');
8+
myPetsCard.mount($container);
9+
10+
return $container;
11+
},
12+
};
13+
14+
export const Default = {
15+
args: {
16+
name: 'Jake',
17+
gender: 'male',
18+
race: 'Border Collie',
19+
type: 'Cachorro',
20+
desc: 'Mistura marrom-escura-branca, com sobrancelhas claras e uma mancha em forma de coração na pata esquerda.',
21+
},
22+
};

0 commit comments

Comments
 (0)