Skip to content

Commit

Permalink
Added state to each component
Browse files Browse the repository at this point in the history
  • Loading branch information
MRita443 committed Aug 8, 2023
1 parent 33d1395 commit ae2ff16
Showing 1 changed file with 54 additions and 39 deletions.
93 changes: 54 additions & 39 deletions src/lib/layout/hexagons/TeamMemberHexagon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,44 @@
export const orientation = 'horizontal';
export let teamMember = data as TeamMember;
const openHexagonAnimation = (
target: HTMLElement,
container: HTMLElement,
fullOpacityContainers: NodeListOf<HTMLElement>,
variableOpacityContainer: HTMLElement
) => {
container.style.top = '50%';
container.style.transform = 'translateY(-50%)';

Check warning on line 19 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L18-L19

Added lines #L18 - L19 were not covered by tests
fullOpacityContainers.forEach((i) => {
i.style.opacity = '100%';

Check warning on line 22 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L22

Added line #L22 was not covered by tests
});
variableOpacityContainer.style.opacity = '30%';

Check warning on line 25 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L25

Added line #L25 was not covered by tests
target.dataset.state = 'open';

Check warning on line 27 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L27

Added line #L27 was not covered by tests
};
const closeHexagonAnimation = (
target: HTMLElement,
container: HTMLElement,
fullOpacityContainers: NodeListOf<HTMLElement>,
variableOpacityContainer: HTMLElement
) => {
container.style.top = '';
container.style.transform = '';

Check warning on line 36 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L35-L36

Added lines #L35 - L36 were not covered by tests
fullOpacityContainers.forEach((i) => {
i.style.opacity = '0%';

Check warning on line 39 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L39

Added line #L39 was not covered by tests
});
variableOpacityContainer.style.opacity = '0%';

Check warning on line 42 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L42

Added line #L42 was not covered by tests
target.dataset.state = 'closed';

Check warning on line 44 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L44

Added line #L44 was not covered by tests
};
onMount(() => {
const listTargets: NodeListOf<HTMLElement> | null = document.querySelectorAll('.target');
let clickToggle = 0;
for (let target of listTargets) {
const container: HTMLElement | null = target.querySelector('.container');
const fullOpacityContainers: NodeListOf<HTMLElement> | null =
Expand All @@ -22,58 +55,41 @@
target.querySelector('.variable-opacity');
target.addEventListener('touchstart', () => {
if (!clickToggle) {
if (container) {
container.style.top = '50%';
container.style.transform = 'translateY(-50%)';
}
fullOpacityContainers.forEach((i) => {
i.style.opacity = '100%';
});
if (variableOpacityContainer) {
variableOpacityContainer.style.opacity = '30%';
if (container && fullOpacityContainers && variableOpacityContainer) {

Check warning on line 58 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L58

Added line #L58 was not covered by tests
if (target.dataset.state == 'closed') {
openHexagonAnimation(

Check warning on line 60 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L60

Added line #L60 was not covered by tests
target,
container,
fullOpacityContainers,
variableOpacityContainer
);
} else {
closeHexagonAnimation(

Check warning on line 67 in src/lib/layout/hexagons/TeamMemberHexagon.svelte

View check run for this annotation

Codecov / codecov/patch

src/lib/layout/hexagons/TeamMemberHexagon.svelte#L67

Added line #L67 was not covered by tests
target,
container,
fullOpacityContainers,
variableOpacityContainer
);
}
clickToggle++;
} else {
if (container) {
container.style.top = '';
container.style.transform = '';
}
fullOpacityContainers.forEach((i) => {
i.style.opacity = '0%';
});
if (variableOpacityContainer) {
variableOpacityContainer.style.opacity = '0%';
}
clickToggle = 0;
}
});
}
});
</script>

<Hexagon {orientation}>
<div class="target group relative" data-testid="hexagon">
<div class="target group relative" data-testid="hexagon" data-state="closed">
<div
class="container
absolute top-full z-20 w-full -translate-y-16 px-4 pb-4 duration-500 group-hover:top-1/2 group-hover:-translate-y-1/2"
class="container absolute top-full z-20 w-full -translate-y-16 px-4 pb-4 duration-500 group-hover:top-1/2 group-hover:-translate-y-1/2"
>
<p
class="mx-auto text-center text-sm font-bold leading-tight text-gray-100 transition-all sm:text-sm md:text-sm lg:text-base xl:text-xl"
>
{teamMember.name.split(' ')[0]}
<br />
{teamMember.name.split(' ')[0]} <br />
{teamMember.name.split(' ')[1]}
</p>
<p
class="full-opacity mx-auto
text-center text-xs leading-tight text-gray-100 opacity-0 transition-all duration-500 ease-out group-hover:opacity-100 sm:text-xs md:text-sm lg:text-base xl:text-lg"
class="full-opacity mx-auto text-center text-xs leading-tight text-gray-100 opacity-0 transition-all duration-500 ease-out group-hover:opacity-100 sm:text-xs md:text-sm lg:text-base xl:text-lg"
>
{teamMember.role}
</p>
Expand Down Expand Up @@ -116,7 +132,6 @@
{/if}
</div>
</div>

<div
class="variable-opacity absolute inset-0 z-10 bg-black text-lg opacity-0 transition-opacity duration-500 group-hover:opacity-30"
/>
Expand Down

0 comments on commit ae2ff16

Please sign in to comment.