-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
91 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
resources/js/game/components/actions/partials/actions/actions.tsx
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { ReactNode } from 'react'; | ||
|
||
import { IconSection } from '../icon-section/icon-section'; | ||
import MonsterSection from '../monster-section/monster-section'; | ||
import { useManageMonsterStatSectionVisibility } from '../monster-stat-section/hooks/use-manage-monster-stat-section-visibility'; | ||
import { MonsterStatSection } from '../monster-stat-section/monster-stat-section'; | ||
import { useScrollIconMenu } from './hooks/use-scroll-icon-menu'; | ||
|
||
import Card from 'ui/cards/card'; | ||
|
||
const Actions = (): ReactNode => { | ||
const { showMonsterStatsSection, showMonsterStats } = | ||
useManageMonsterStatSectionVisibility(); | ||
|
||
const { scrollY, isMobile } = useScrollIconMenu(); | ||
|
||
return ( | ||
<Card> | ||
<div className="w-full flex flex-col lg:flex-row"> | ||
<div className="relative"> | ||
{isMobile ? ( | ||
<div> | ||
<IconSection /> | ||
</div> | ||
) : ( | ||
<div | ||
style={{ | ||
position: 'absolute', | ||
top: `${scrollY + 10}px`, | ||
left: '10px', | ||
transition: 'top 0.2s', | ||
}} | ||
> | ||
<IconSection /> | ||
</div> | ||
)} | ||
</div> | ||
<div className="flex flex-col items-center lg:items-start w-full"> | ||
{showMonsterStatsSection ? ( | ||
<MonsterStatSection /> | ||
) : ( | ||
<MonsterSection show_monster_stats={showMonsterStats} /> | ||
)} | ||
</div> | ||
</div> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default Actions; |
4 changes: 4 additions & 0 deletions
4
.../components/actions/partials/actions/hooks/definitions/use-scroll-icon-menu-definition.ts
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default interface UseScrollIconMenuDefinition { | ||
scrollY: number; | ||
isMobile: boolean; | ||
} |
4 changes: 4 additions & 0 deletions
4
...ces/js/game/components/actions/partials/actions/hooks/types/use-scroll-icon-menu-state.ts
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default interface UseScrollIconMenuState { | ||
scrollY: number; | ||
isMobile: boolean; | ||
} |
31 changes: 31 additions & 0 deletions
31
resources/js/game/components/actions/partials/actions/hooks/use-scroll-icon-menu.ts
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import UseScrollIconMenuDefinition from './definitions/use-scroll-icon-menu-definition'; | ||
import UseScrollIconMenuState from './types/use-scroll-icon-menu-state'; | ||
|
||
export const useScrollIconMenu = (): UseScrollIconMenuDefinition => { | ||
const [scrollY, setScrollY] = useState<UseScrollIconMenuState['scrollY']>(0); | ||
const [isMobile, setIsMobile] = | ||
useState<UseScrollIconMenuState['isMobile']>(false); | ||
|
||
const handleScroll = () => setScrollY(window.scrollY); | ||
|
||
useEffect(() => { | ||
window.addEventListener('scroll', handleScroll); | ||
|
||
const checkMobile = () => setIsMobile(window.innerWidth < 768); | ||
|
||
checkMobile(); | ||
window.addEventListener('resize', checkMobile); | ||
|
||
return () => { | ||
window.removeEventListener('scroll', handleScroll); | ||
window.removeEventListener('resize', checkMobile); | ||
}; | ||
}, []); | ||
|
||
return { | ||
scrollY, | ||
isMobile, | ||
}; | ||
}; |
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
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