-
Notifications
You must be signed in to change notification settings - Fork 45
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
Size Selector #79
Closed
Closed
Size Selector #79
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8a24f4f
slider do pet-dex
buuninbee e280163
adicionando imgs de qaundo o item tiver ativo
buuninbee 03655b2
Component Slider com controle de naveção
buuninbee c640aec
trocando o nome do arquivo para Seletor de porte
buuninbee 44f6d89
Merge branch 'main' into issues-23
buuninbee f909b7b
adicionado cores e definindo font no arquivo de Seletor de porte
buuninbee c234671
changing file and component name
buuninbee 44ea00b
changing alt and aria-label name to english
buuninbee 643eb5c
Merge branch 'main' into issues-23
buuninbee 993ef80
refactoring functions and applying BEM
buuninbee 77e1447
receiving an object as a parameter
buuninbee 4e73a91
adding colors
buuninbee 972ea22
Merge branch 'main' into issues-23
buuninbee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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 | ||
---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||
import { Component } from 'pet-dex-utilities'; | ||||
import sizeSmall from './img/size-small.svg'; | ||||
import sizeMedium from './img/size-medium-active.svg'; | ||||
import sizeLarge from './img/size-large.svg'; | ||||
import sizeSmall from './images/size-small.svg'; | ||||
import sizeMedium from './images/size-medium.svg'; | ||||
import sizeLarge from './images/size-large.svg'; | ||||
import './index.scss'; | ||||
|
||||
const events = ['click', 'touchstart']; | ||||
|
@@ -10,93 +10,107 @@ const html = ` | |||
<div class="selector-wrapper" data-select="selector-wrapper"> | ||||
<ul role="listbox" class="selector-wrapper__slide" data-select="selector-wrapper__slide"> | ||||
<li role="option" aria-label="small pet size" aria-selected="false" class="selector-wrapper__item" data-select="slider-small"> | ||||
<img class="selector-wrapper__image" data-select="selector-wrapper__image" src="${sizeSmall}" alt="pet small size icon"> | ||||
<h3>Small</h3> | ||||
<p>under 14kg</p> | ||||
<img class="selector-wrapper__image" src="${sizeSmall}" alt="pet small size icon"> | ||||
<h3 class="selector-wrapper__title">Small</h3> | ||||
<p class="selector-wrapper__weight">under 14kg</p> | ||||
</li> | ||||
<li role="option" aria-label="medium pet size" aria-selected="true" class="selector-wrapper__item active" data-select="slider-medium"> | ||||
<li role="option" aria-label="medium pet size" aria-selected="true" class="selector-wrapper__item" data-select="slider-medium"> | ||||
<img class="selector-wrapper__image" src="${sizeMedium}" alt="pet medium size icon"> | ||||
<h3>Medium</h3> | ||||
<p>14-25kg</p> | ||||
<h3 class="selector-wrapper__title">Medium</h3> | ||||
<p class="selector-wrapper__weight">14-25kg</p> | ||||
</li> | ||||
<li role="option" aria-label="large pet size" aria-selected="false" class="selector-wrapper__item" data-select="slider-large"> | ||||
<img class="selector-wrapper__image" da src="${sizeLarge}" alt="pet large size icon"> | ||||
<h3>Large</h3> | ||||
<p>over 25kg</p> | ||||
<h3 class="selector-wrapper__title">Large</h3> | ||||
<p class="selector-wrapper__weight">over 25kg</p> | ||||
</li> | ||||
</ul> | ||||
</div> | ||||
`; | ||||
|
||||
export default function SizeSelector(slide) { | ||||
function classRemover(children) { | ||||
[...children].forEach((element) => { | ||||
element.classList.remove('selector-wrapper__item--active'); | ||||
}); | ||||
} | ||||
|
||||
function changeToDefault(children) { | ||||
[...children].forEach((element) => { | ||||
const srcValue = element.children[0].attributes.src.value; | ||||
const itemSrc = element.children[0].attributes.src; | ||||
|
||||
const srcMappings = { | ||||
'/components/SizeSelector/images/size-small-active.svg': | ||||
'/components/SizeSelector/images/size-small.svg', | ||||
'/components/SizeSelector/images/size-medium-active.svg': | ||||
'/components/SizeSelector/images/size-medium.svg', | ||||
'/components/SizeSelector/images/size-large-active.svg': | ||||
'/components/SizeSelector/images/size-large.svg', | ||||
}; | ||||
|
||||
const newValue = srcMappings[srcValue]; | ||||
|
||||
if (newValue) { | ||||
element.classList.remove('selector-wrapper__item--active'); | ||||
element.setAttribute('aria-selected', 'false'); | ||||
|
||||
itemSrc.value = newValue; | ||||
} | ||||
}); | ||||
} | ||||
|
||||
function changeToActive(element) { | ||||
const srcValue = element.children[0].attributes.src.value; | ||||
const itemSrc = element.children[0].attributes.src; | ||||
|
||||
const srcMappings = { | ||||
'/components/SizeSelector/images/size-small.svg': | ||||
'/components/SizeSelector/images/size-small-active.svg', | ||||
'/components/SizeSelector/images/size-medium.svg': | ||||
'/components/SizeSelector/images/size-medium-active.svg', | ||||
'/components/SizeSelector/images/size-large.svg': | ||||
'/components/SizeSelector/images/size-large-active.svg', | ||||
}; | ||||
|
||||
const newValue = srcMappings[srcValue]; | ||||
|
||||
if (newValue) { | ||||
element.classList.add('selector-wrapper__item--active'); | ||||
element.setAttribute('aria-selected', 'true'); | ||||
|
||||
itemSrc.value = newValue; | ||||
} | ||||
} | ||||
|
||||
function checkingTheElement(children) { | ||||
children.forEach((element) => { | ||||
element.addEventListener('click', () => { | ||||
const elementState = element.classList.contains( | ||||
'selector-wrapper__item--active', | ||||
); | ||||
changeToDefault(children); | ||||
if (elementState) { | ||||
changeToDefault(children); | ||||
} else { | ||||
changeToActive(element); | ||||
} | ||||
}); | ||||
}); | ||||
} | ||||
|
||||
export default function SizeSelector({ slide }) { | ||||
Component.call(this, { html, events }); | ||||
|
||||
const slideItems = this.selected.get(slide); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Essa seleção pelo data-select está muito estranha pra mim, o data-select não foi pensando pra isso |
||||
const children = [...slideItems.children]; | ||||
|
||||
const childrens = [...slideItems.children]; | ||||
this.startEvents(childrens); | ||||
classRemover(children); | ||||
changeToDefault(children); | ||||
checkingTheElement(children); | ||||
} | ||||
|
||||
SizeSelector.prototype = Object.assign( | ||||
SizeSelector.prototype, | ||||
Component.prototype, | ||||
{ | ||||
startEvents(childrens) { | ||||
childrens.map((element) => { | ||||
element.addEventListener('pointerdown', () => { | ||||
this.changeToDefault(childrens); | ||||
if (element.classList.contains('active')) { | ||||
element.classList.add('active'); | ||||
} else { | ||||
childrens.map((children) => { | ||||
children.classList.remove('active'); | ||||
return children; | ||||
}); | ||||
element.classList.add('active'); | ||||
} | ||||
this.changeToActive(element); | ||||
}); | ||||
return this; | ||||
}); | ||||
}, | ||||
|
||||
changeToDefault(childrens) { | ||||
childrens.map((element) => { | ||||
const srcValue = element.children[0].attributes.src.value; | ||||
const itemSrc = element.children[0].attributes.src; | ||||
|
||||
if (srcValue === '/components/SizeSelector/img/size-small-active.svg') { | ||||
itemSrc.value = '/components/SizeSelector/img/size-small.svg'; | ||||
element.setAttribute('aria-selected', 'false'); | ||||
} else if ( | ||||
srcValue === '/components/SizeSelector/img/size-medium-active.svg' | ||||
) { | ||||
itemSrc.value = '/components/SizeSelector/img/size-medium.svg'; | ||||
element.setAttribute('aria-selected', 'false'); | ||||
} else if ( | ||||
srcValue === '/components/SizeSelector/img/size-large-active.svg' | ||||
) { | ||||
itemSrc.value = '/components/SizeSelector/img/size-large.svg'; | ||||
element.setAttribute('aria-selected', 'false'); | ||||
} | ||||
return srcValue; | ||||
}); | ||||
}, | ||||
|
||||
changeToActive(element) { | ||||
const srcValue = element.children[0].attributes.src.value; | ||||
const itemSrc = element.children[0].attributes.src; | ||||
|
||||
if (srcValue === '/components/SizeSelector/img/size-small.svg') { | ||||
itemSrc.value = '/components/SizeSelector/img/size-small-active.svg'; | ||||
element.setAttribute('aria-selected', 'true'); | ||||
} else if (srcValue === '/components/SizeSelector/img/size-medium.svg') { | ||||
itemSrc.value = '/components/SizeSelector/img/size-medium-active.svg'; | ||||
element.setAttribute('aria-selected', 'true'); | ||||
} else if (srcValue === '/components/SizeSelector/img/size-large.svg') { | ||||
itemSrc.value = '/components/SizeSelector/img/size-large-active.svg'; | ||||
element.setAttribute('aria-selected', 'true'); | ||||
} | ||||
}, | ||||
}, | ||||
{}, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.