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 - Componente de Calendário #302

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
04b094b
chore: update branch
gustavogularte Apr 26, 2024
652302e
chore: update branch
gustavogularte Apr 26, 2024
9f2bc3a
chore: update branch
DominMFD May 8, 2024
44e4b10
chore: colors adjusted
DominMFD May 8, 2024
0a8adab
chore: index.scss adjusted
DominMFD May 8, 2024
301414d
chore: update main
DominMFD May 8, 2024
4cb88f1
fix: add color gray250
DominMFD Jun 6, 2024
f5816d2
chore: add lodash
DominMFD Jun 13, 2024
7116331
refactor: init calendar refactor
DominMFD Jul 21, 2024
8dd27fc
feat: calendar content done
DominMFD Jul 21, 2024
0ea029d
feat: implements month selector
DominMFD Jul 22, 2024
d850b24
feat: implements date modal
DominMFD Jul 23, 2024
1fc7b5f
chore: implements year selector
DominMFD Jul 24, 2024
05c07d5
chore: remove sliding
DominMFD Jul 25, 2024
67ceede
feat: add hover in date selector
DominMFD Jul 29, 2024
6fb4f94
chore: init virtual scroll
DominMFD Jul 30, 2024
74828a6
chore: complete virtual scroll
DominMFD Jul 31, 2024
5bc0720
fix: month selector array
DominMFD Aug 1, 2024
7835018
chore: trying make central scroll
DominMFD Aug 16, 2024
8f267aa
fix: align active item in center
DominMFD Aug 21, 2024
217d0aa
chore: implements scroll snap
DominMFD Sep 3, 2024
19b2854
chore: year selector scroll
DominMFD Sep 5, 2024
a4c87dc
chore: implements scroll selectors
DominMFD Sep 6, 2024
03c18a8
fix: scroll fixes
DominMFD Sep 6, 2024
7369e00
fix: rerender fix
DominMFD Sep 8, 2024
0c79f10
fix: adjust modal height
DominMFD Sep 8, 2024
a7a3098
fix: week days abbreviation fix
DominMFD Sep 9, 2024
3bf7c70
fix: media query day composer fixed
DominMFD Sep 11, 2024
f149258
fix: bug mobile selector fixed
DominMFD Sep 11, 2024
8e68afe
fix: object properties
DominMFD Sep 16, 2024
3759f75
fix: add bem
DominMFD Sep 16, 2024
eaaba8a
fix: array fixed
DominMFD Sep 19, 2024
924b63d
fix: css
DominMFD Sep 19, 2024
f64c702
feat: actual day implemented
DominMFD Sep 19, 2024
621a929
fix: organize setters and getters
DominMFD Oct 1, 2024
54abad3
Merge branch 'main' into issue#27
DominMFD Oct 1, 2024
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Component } from 'pet-dex-utilities';
import './index.scss';

const events = ['item:click'];

const html = `
<span class="date-selected" data-select="date-selected"></span>
`;

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

this.$dateSelected = this.selected.get('date-selected');
this.setDate(date);

this.emitClickevent = () => {
this.emit('item:click');
};

this.$dateSelected.addEventListener('click', this.emitClickevent);
}

DateSelected.prototype = Object.assign(
DateSelected.prototype,
Component.prototype,
{
setDate(date) {
this.$dateSelected.innerText = date;
},
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@use '~styles/base.scss';
@use '~styles/colors.scss' as colors;
@use '~styles/fonts.scss' as fonts;
@use '~styles/breakpoints.scss' as breakpoints;

.date-selected {
font-family: fonts.$primaryFont;
color: colors.$gray800;
font-size: fonts.$lg;
font-weight: fonts.$regular;

&:hover {
color: colors.$primary200;
font-weight: fonts.$semiBold;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { Component } from 'pet-dex-utilities';
import { makeSwipable } from '../../../../../../utils/swiper';
import SelectorItem from '../SelectorItem';
import { MONTHS } from '../../../../utils/months';
import './index.scss';

const events = ['month:change', 'selector:click'];

const html = `
<div class="month-selector" data-select="month-selector">
<div>
<div data-select="month-list">
<ul data-select="list-content">
</ul>
</div>
</div>
</div>
`;

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

this.dateArray = dateArray;
this.$monthSelector = this.selected.get('month-selector');
this.$dateList = this.selected.get('month-list');
this.$listContent = this.selected.get('list-content');

this.itemCount = this.dateArray.length;
this.columnWidth = 150;
this.nodePadding = 6;
this.scrollLeft = this.$monthSelector.scrollLeft;

const swiper = makeSwipable(this.$monthSelector);

const handleItemClick = (index) => {
const itemScroll =
index * this.columnWidth -
(this.viewportWidth / 2 - this.columnWidth / 2);
this.$monthSelector.scrollLeft = itemScroll;
};

const emitMonthChangeEvent = (month) => {
const newMonth = MONTHS.indexOf(month);
this.emit('month:change', newMonth);
};

setTimeout(() => {
this.viewportWidth = this.$monthSelector.offsetWidth;

const renderWindow = () => {
this.totalContentWidth = (this.itemCount - 1) * this.columnWidth + 176;

this.startNode =
Math.floor(this.scrollLeft / this.columnWidth) - this.nodePadding;
this.startNode = Math.max(0, this.startNode);

this.visibleNodesCount =
Math.ceil(this.viewportWidth / this.columnWidth) + 2 * this.nodePadding;
this.visibleNodesCount = Math.min(
this.itemCount - this.startNode,
this.visibleNodesCount,
);

this.offsetX = this.startNode * this.columnWidth;

this.$dateList.style.width = `${this.totalContentWidth}px`;
this.$listContent.style.transform = `translateX(${this.offsetX}px)`;

this.$listContent.innerHTML = '';
this.visibleChildren = new Array(this.visibleNodesCount)
.fill(null)
.map(
(_, index) =>
new SelectorItem(this.dateArray[index + this.startNode]),
);

this.visibleChildren.forEach((selectorItem, index) => {
selectorItem.mount(this.$listContent);
selectorItem.listen('item:click', () =>
handleItemClick(index + this.startNode),
);
selectorItem.listen('item:change', (item) =>
emitMonthChangeEvent(item),
);

if (index === 7) {
selectorItem.active();
}
});
};

this.$monthSelector.addEventListener('scroll', (e) => {
if (this.animationFrame) {
cancelAnimationFrame(this.animationFrame);
}
this.animationFrame = requestAnimationFrame(() => {
this.scrollLeft = e.target.scrollLeft;
renderWindow();

const activeItem = this.$dateList.querySelector(
'selector-item--active',
);
if (activeItem) {
activeItem.scrollIntoView({
inline: 'center',
behavior: 'smooth',
});
}
});
});

swiper.left(() => {
this.scrollLeft = Math.max(this.scrollLeft - this.columnWidth, 0);
this.$monthSelector.scrollLeft = this.scrollLeft;
renderWindow();
});

swiper.right(() => {
this.scrollLeft = Math.min(
this.scrollLeft + this.columnWidth,
this.totalContentWidth - this.viewportWidth,
);
this.$monthSelector.scrollLeft = this.scrollLeft;
renderWindow();
});

const scrollToMiddle = () => {
this.scrollLeft = this.totalContentWidth / 2 - this.viewportWidth / 2;
this.$monthSelector.scrollLeft = this.scrollLeft;
};

renderWindow();
scrollToMiddle();
}, 0);
}

MonthSelector.prototype = Object.assign(
MonthSelector.prototype,
Component.prototype,
{},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@use '~styles/base.scss';
@use '~styles/colors.scss' as colors;
@use '~styles/fonts.scss' as fonts;
@use '~styles/breakpoints.scss' as breakpoints;

.month-selector {
overflow: auto;

display: flex;
flex-direction: row;

margin-bottom: 2.4rem;

padding-bottom: 2.4rem;

border-bottom: 0.1rem solid colors.$gray150;

box-sizing: border-box;

scroll-snap-type: x proximity;

scrollbar-width: none;

[data-select='list-content'] {
width: fit-content;

display: flex;

align-items: center;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Component } from 'pet-dex-utilities';
import './index.scss';

const events = ['item:change', 'item:click'];

const html = `
<li class="selector-item" data-select="selector-item"></li>
`;

export default function SelectorItem(item) {
Component.call(this, { html, events });
this.item = item;
this.$selectorItem = this.selected.get('selector-item');
this.$selectorItem.innerText = this.item;

if (typeof this.item === 'string') this.$selectorItem.style.width = '150px';

if (typeof this.item === 'number') this.$selectorItem.style.width = '70px';

this.emitClickEvent = () => {
this.emit('item:click');
};

this.$selectorItem.addEventListener('click', this.emitClickEvent);
}

SelectorItem.prototype = Object.assign(
SelectorItem.prototype,
Component.prototype,
{
active() {
this.$selectorItem.classList.add('selector-item--active');
this.emit('item:change', this.item);
},
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@use '~styles/base.scss';
@use '~styles/colors.scss' as colors;
@use '~styles/fonts.scss' as fonts;
@use '~styles/breakpoints.scss' as breakpoints;

.selector-item {
font-family: fonts.$primaryFont;
color: colors.$gray700;

text-align: center;
font-size: fonts.$xs;
font-weight: fonts.$medium;

scroll-snap-align: center;

&--active {
color: colors.$primary200;
font-size: fonts.$lg;
font-weight: fonts.$semiBold;

padding: 0.6rem 1.2rem;
border: 1px solid colors.$blue100;

background-color: rgba(209, 230, 255, 0.5);
border-radius: 1.4rem;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Component } from 'pet-dex-utilities';
import './index.scss';

const events = ['item:change', 'item:click'];

const html = `
<li class="selector-modal__item" data-select="modal-item"></li>
`;

export default function ModalItem(item) {
Component.call(this, { html, events });

this.item = item;
this.$modalItem = this.selected.get('modal-item');
this.$modalItem.innerText = this.item;

const emitEventClick = () => {
this.emit('item:click', this.item);
};

this.$modalItem.addEventListener('click', () => emitEventClick());
}

ModalItem.prototype = Object.assign(ModalItem.prototype, Component.prototype, {
active() {
this.$modalItem.classList.add('selector-modal__item--active');
this.emit('item:change', this.item);
},
});
Loading
Loading