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

Issue 27 - Calendar component #219

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
72 changes: 36 additions & 36 deletions src/components/Button/index.scss
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
@use '~styles/colors.scss' as colors;
.button {
font-family: 'Noto Sans', sans-serif;
color: rgb(255, 255, 255);
font-size: 1.6rem;
font-weight: 500;
padding: 1.6rem;
border: unset;
background-color: colors.$primary200;
border-radius: 1.4rem;
transition: 0.3s ease-in-out;
cursor: pointer;
appearance: none;
&--block {
width: 100%;
display: block;
}
&:hover:not(:disabled) {
background: colors.$primary600;
transform: scale(1.02);
}
&:disabled {
background: colors.$gray600;
cursor: not-allowed;
}
}
@use '~styles/colors.scss' as colors;

.button {
font-family: 'Noto Sans', sans-serif;
color: rgb(255, 255, 255);
font-size: 1.6rem;
font-weight: 500;

padding: 1.6rem;
border: unset;

background-color: colors.$primary200;
border-radius: 1.4rem;

transition: 0.3s ease-in-out;

cursor: pointer;
appearance: none;

&--block {
width: 100%;

display: block;
}

&:hover:not(:disabled) {
background: colors.$primary600;
transform: scale(1.02);
}

&:disabled {
background: colors.$gray600;

cursor: not-allowed;
}
}
23 changes: 23 additions & 0 deletions src/components/Calendar/components/DateButton/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';

const html = `
<li data-select="date" class="date"><button class="date__button"></button></li>
`;

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

const $button = this.selected.get('date').children[0];
$button.innerText = date;
}

DateButton.prototype = Object.assign(
DateButton.prototype,
Component.prototype,
{
active() {
this.selected.get('date').classList.add('active');
},
},
);
64 changes: 64 additions & 0 deletions src/components/Calendar/components/DateButton/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@use '~styles/base.scss';
@use '~styles/colors.scss' as colors;
@use '~styles/fonts.scss' as fonts;
@use '~styles/breakpoints.scss' as breakpoints;

.date {
&__button {
font-family: fonts.$primaryFont;
color: colors.$gray500;
font-size: 1.4rem;
font-weight: fonts.$medium;
line-height: 2.5;

border: 0;

background-color: transparent;

cursor: pointer;
}
}

.date.active {
&__button {
color: colors.$primary200;
font-size: 2.6rem;
font-weight: fonts.$bold;
line-height: 1.3;

padding: 0.6rem 1.2rem;
border: 0.1rem solid colors.$gray100;

background-color: colors.$gray150;

border-radius: 1.4rem;
}
}

@include breakpoints.from667 {
.date {
display: none;

&__button {
width: 100%;

font-size: fonts.$md;
line-height: 1.8;
}
}

.date.active {
display: flex;

&__button {
color: colors.$gray800;
font-size: 2.6rem;
font-weight: fonts.$regular;

padding: 0.6rem;
border: 0;

background-color: transparent;
}
}
}
219 changes: 219 additions & 0 deletions src/components/Calendar/components/DateSelector/index.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Acredito que tudo que ta feito aqui poderia ser dividido em mais funcionalidades, arquivos e funções

Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import { Component } from 'pet-dex-utilities';
import './index.scss';
Copy link
Contributor

Choose a reason for hiding this comment

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

Importar o css depois dos componentes

Copy link
Contributor

Choose a reason for hiding this comment

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

Importar o css depois dos componentes

import { listenBreakpoint } from '../../../../utils/breakpoints/breakpoints';
import DateButton from '../DateButton';

const events = ['changeMonth', 'changeYear'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Mudar o name pattern dos eventos


const html = `
<ul data-select="date-selector" class="date-selector"></ul>
`;

const monthsBR = [
'Janeiro',
'Fevereiro',
'Março',
'Abril',
'Maio',
'Junho',
'Julho',
'Agosto',
'Setembro',
'Outubro',
'Novembro',
'Dezembro',
];

let handleTouchStart;
let handleTouchMove;
Comment on lines +27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

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

Remover as variaveis

function addTouchEvents(selector) {
let startTouch;

handleTouchStart = (event) => {
startTouch = selector.isDesktop
? event.touches[0].clientY
: event.touches[0].clientX;
};

handleTouchMove = (event) => {
event.preventDefault();
const currentTouch = selector.isDesktop
? event.touches[0].clientY
: event.touches[0].clientX;
let move = 0;
const moveRange = 20;
move = currentTouch - startTouch;

if (Math.abs(move) > moveRange) {
const isSlideNext = move < 0;
const nextYear = +selector.dates[3].children[0].innerText;
const prevYear = +selector.dates[1].children[0].innerText;
const nextMonth = monthsBR.indexOf(
selector.dates[3].children[0].innerText,
);
const prevMonth = monthsBR.indexOf(
selector.dates[1].children[0].innerText,
);
if (isSlideNext && selector.isYear) selector.setYear(nextYear);
if (!isSlideNext && selector.isYear) selector.setYear(prevYear);
if (isSlideNext && !selector.isYear) selector.setMonth(nextMonth);
if (!isSlideNext && !selector.isYear) selector.setMonth(prevMonth);
startTouch = currentTouch;
}
};
Comment on lines +32 to +63
Copy link
Contributor

Choose a reason for hiding this comment

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

Toda essa parte do touchstart e touchmove deveria ser feita com o módulo atual de swipe, haviamos permitido deixar assim por enquanto pq a funcionalidade que precisavamos nao havia no modulo. Agora que será remanejado vamos revisitar isso e tentar usar o modulo de swipping.

selector.dateSelector.addEventListener('touchstart', handleTouchStart);
selector.dateSelector.addEventListener('touchmove', handleTouchMove);
}

let handleScroll;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remover a variavel

function scrollModal(selector) {
const $dateSelector = selector.dateSelector;

handleScroll = (event) => {
event.preventDefault();
const isScrollNext = event.deltaY > 0;

if (selector.isYear) {
const nextYear = +selector.dates[3].children[0].innerText;
const prevYear = +selector.dates[1].children[0].innerText;
const newYear = isScrollNext ? nextYear : prevYear;
selector.setYear(newYear);
} else {
const nextMonth = monthsBR.indexOf(
selector.dates[3].children[0].innerText,
);
const prevMonth = monthsBR.indexOf(
selector.dates[1].children[0].innerText,
);
const newMonth = isScrollNext ? nextMonth : prevMonth;
selector.setMonth(newMonth);
}
};

$dateSelector.addEventListener('wheel', handleScroll);
addTouchEvents(selector);
}
Comment on lines +69 to +95
Copy link
Contributor

Choose a reason for hiding this comment

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

Isso aqui seria removido usando o slider


function openModal(selector) {
const $dateSelector = selector.dateSelector;
$dateSelector.classList.add('active');
const $activeDate = selector.date;
$activeDate.scrollIntoView({
behavior: 'instant',
block: 'center',
inline: 'center',
});
}

function closeModal(selector, event) {
const $dateSelector = selector.dateSelector;
if (
$dateSelector.classList.contains('active') &&
!$dateSelector.contains(event.target)
) {
$dateSelector.classList.remove('active');
}
}

export default function DateSelector(dateArray) {
Component.call(this, { html, events });

this.dateSelector = this.selected.get('date-selector');
this.dateArray = dateArray;

this.dateArray.forEach((item, index) => {
const dateButton = new DateButton(item);
dateButton.mount(this.dateSelector);
if (index === 2) {
dateButton.active();
}
});

this.dates = this.dateSelector.querySelectorAll('li');
Copy link
Contributor

Choose a reason for hiding this comment

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

Aqui nao seria querySelectorAll no LI, seria?

this.date = this.dateSelector.querySelector('li.active');
this.isYear = !Number.isNaN(+this.date.innerText);
Copy link
Contributor

Choose a reason for hiding this comment

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

UAT?

listenBreakpoint('from667', (matches) => {
this.isDesktop = matches;
});

this.dateClickHandle = (index) => () => {
if (this.isYear) {
this.setYear(this.dateArray[index]);
} else {
this.setMonth(monthsBR.indexOf(this.dateArray[index]));
}
};
Comment on lines +139 to +145
Copy link
Contributor

Choose a reason for hiding this comment

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

Renomear o método


this.dates.forEach(($date, index) => {
$date.addEventListener('click', this.dateClickHandle(index));
});
this.openModalHandle = () => openModal(this);
this.dateSelector.addEventListener('click', this.openModalHandle);

this.closeModalHandle = (event) => closeModal(this, event);
window.addEventListener('click', this.closeModalHandle);

scrollModal(this);

setTimeout(() => {
this.date.scrollIntoView({
behavior: 'instant',
block: 'center',
inline: 'center',
});
});
Comment on lines +158 to +164
Copy link
Contributor

Choose a reason for hiding this comment

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

Estranho isso existir x.x


this.unmount(() => {
this.dateSelector.removeEventListener('click', this.openModalHandle);
window.removeEventListener('click', this.closeModalHandle);
this.dates.forEach(($date, index) => {
$date.removeEventListener('click', this.dateClickHandle(index));
});
this.dateSelector.removeEventListener('wheel', handleScroll);
this.dateSelector.removeEventListener('touchstart', handleTouchStart);
this.dateSelector.removeEventListener('touchmove', handleTouchMove);
});
}

DateSelector.prototype = Object.assign(
DateSelector.prototype,
Component.prototype,
{
setMonth(newMonth) {
for (let i = 0; i < this.dateArray.length; i += 1) {
const index = (newMonth - (2 - i) + 12) % 12;
this.dateArray[i] = monthsBR[index];
}

this.dateArray.forEach((item, index) => {
this.dates[index].children[0].innerText = item;
});

this.date.scrollIntoView({
behavior: 'instant',
block: 'center',
inline: 'center',
});

this.emit('changeMonth', newMonth);
},

Comment on lines +182 to +200
Copy link
Contributor

Choose a reason for hiding this comment

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

Acredito que essa função ta complexa demais pra só trocar o mes

setYear(newYear) {
for (let i = 0; i < this.dateArray.length; i += 1) {
this.dateArray[i] = newYear - (2 - i);
}

this.dateArray.forEach((item, index) => {
this.dates[index].children[0].innerText = item;
});

this.date.scrollIntoView({
behavior: 'instant',
block: 'center',
inline: 'center',
});

this.emit('changeYear', newYear);
},
},
Comment on lines +201 to +218
Copy link
Contributor

Choose a reason for hiding this comment

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

Acredito que essa funcao ta complexa demais pra so trocar o ano

);
Loading
Loading