mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-04-06 01:25:33 +00:00
Implement fullscreen control feature
Co-authored-by: antontranelis <31516529+antontranelis@users.noreply.github.com>
This commit is contained in:
parent
d913e974a2
commit
291018ec34
@ -0,0 +1,41 @@
|
|||||||
|
import ArrowsPointingInIcon from '@heroicons/react/24/outline/ArrowsPointingInIcon'
|
||||||
|
import ArrowsPointingOutIcon from '@heroicons/react/24/outline/ArrowsPointingOutIcon'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
export const FullscreenControl = () => {
|
||||||
|
const [isFullscreen, setIsFullscreen] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleFullscreenChange = () => {
|
||||||
|
setIsFullscreen(document.fullscreenElement != null)
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('fullscreenchange', handleFullscreenChange)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('fullscreenchange', handleFullscreenChange)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const toggleFullscreen = () => {
|
||||||
|
if (!document.fullscreenElement) {
|
||||||
|
void document.documentElement.requestFullscreen()
|
||||||
|
} else {
|
||||||
|
void document.exitFullscreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='tw:card tw:bg-base-100 tw:shadow-xl tw:mt-2 tw:w-fit'>
|
||||||
|
<div
|
||||||
|
className='tw:card-body tw:hover:bg-slate-300 tw:card tw:p-2 tw:h-10 tw:w-10 tw:transition-all tw:duration-300 tw:hover:cursor-pointer'
|
||||||
|
onClick={toggleFullscreen}
|
||||||
|
>
|
||||||
|
{isFullscreen ? (
|
||||||
|
<ArrowsPointingInIcon className='tw:stroke-[2.5]' />
|
||||||
|
) : (
|
||||||
|
<ArrowsPointingOutIcon className='tw:stroke-[2.5]' />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -53,6 +53,7 @@ function UtopiaMap({
|
|||||||
showLayerControl = true,
|
showLayerControl = true,
|
||||||
showZoomControl = false,
|
showZoomControl = false,
|
||||||
showThemeControl = false,
|
showThemeControl = false,
|
||||||
|
showFullscreenControl = false,
|
||||||
defaultTheme,
|
defaultTheme,
|
||||||
donationWidget,
|
donationWidget,
|
||||||
expandLayerControl,
|
expandLayerControl,
|
||||||
@ -81,6 +82,8 @@ function UtopiaMap({
|
|||||||
showZoomControl?: boolean
|
showZoomControl?: boolean
|
||||||
/** show a widget to switch the theme */
|
/** show a widget to switch the theme */
|
||||||
showThemeControl?: boolean
|
showThemeControl?: boolean
|
||||||
|
/** show fullscreen control widget (default false) */
|
||||||
|
showFullscreenControl?: boolean
|
||||||
/** the defaut theme */
|
/** the defaut theme */
|
||||||
defaultTheme?: string
|
defaultTheme?: string
|
||||||
/** ask to donate to the Utopia Project OpenCollective campaign (default false) */
|
/** ask to donate to the Utopia Project OpenCollective campaign (default false) */
|
||||||
@ -106,6 +109,7 @@ function UtopiaMap({
|
|||||||
showFilterControl={showFilterControl}
|
showFilterControl={showFilterControl}
|
||||||
showGratitudeControl={showGratitudeControl}
|
showGratitudeControl={showGratitudeControl}
|
||||||
showLayerControl={showLayerControl}
|
showLayerControl={showLayerControl}
|
||||||
|
showFullscreenControl={showFullscreenControl}
|
||||||
donationWidget={donationWidget}
|
donationWidget={donationWidget}
|
||||||
showThemeControl={showThemeControl}
|
showThemeControl={showThemeControl}
|
||||||
defaultTheme={defaultTheme}
|
defaultTheme={defaultTheme}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import { useTags } from './hooks/useTags'
|
|||||||
import AddButton from './Subcomponents/AddButton'
|
import AddButton from './Subcomponents/AddButton'
|
||||||
import { Control } from './Subcomponents/Controls/Control'
|
import { Control } from './Subcomponents/Controls/Control'
|
||||||
import { FilterControl } from './Subcomponents/Controls/FilterControl'
|
import { FilterControl } from './Subcomponents/Controls/FilterControl'
|
||||||
|
import { FullscreenControl } from './Subcomponents/Controls/FullscreenControl'
|
||||||
import { GratitudeControl } from './Subcomponents/Controls/GratitudeControl'
|
import { GratitudeControl } from './Subcomponents/Controls/GratitudeControl'
|
||||||
import { LayerControl } from './Subcomponents/Controls/LayerControl'
|
import { LayerControl } from './Subcomponents/Controls/LayerControl'
|
||||||
import { SearchControl } from './Subcomponents/Controls/SearchControl'
|
import { SearchControl } from './Subcomponents/Controls/SearchControl'
|
||||||
@ -51,6 +52,7 @@ export function UtopiaMapInner({
|
|||||||
showFilterControl = false,
|
showFilterControl = false,
|
||||||
showGratitudeControl = false,
|
showGratitudeControl = false,
|
||||||
showLayerControl = true,
|
showLayerControl = true,
|
||||||
|
showFullscreenControl = false,
|
||||||
showThemeControl = false,
|
showThemeControl = false,
|
||||||
defaultTheme = '',
|
defaultTheme = '',
|
||||||
donationWidget,
|
donationWidget,
|
||||||
@ -63,6 +65,7 @@ export function UtopiaMapInner({
|
|||||||
showFilterControl?: boolean
|
showFilterControl?: boolean
|
||||||
showLayerControl?: boolean
|
showLayerControl?: boolean
|
||||||
showGratitudeControl?: boolean
|
showGratitudeControl?: boolean
|
||||||
|
showFullscreenControl?: boolean
|
||||||
donationWidget?: boolean
|
donationWidget?: boolean
|
||||||
showThemeControl?: boolean
|
showThemeControl?: boolean
|
||||||
defaultTheme?: string
|
defaultTheme?: string
|
||||||
@ -279,6 +282,7 @@ export function UtopiaMapInner({
|
|||||||
{showFilterControl && <FilterControl />}
|
{showFilterControl && <FilterControl />}
|
||||||
{showLayerControl && <LayerControl expandLayerControl={expandLayerControl ?? false} />}
|
{showLayerControl && <LayerControl expandLayerControl={expandLayerControl ?? false} />}
|
||||||
{showGratitudeControl && <GratitudeControl />}
|
{showGratitudeControl && <GratitudeControl />}
|
||||||
|
{showFullscreenControl && <FullscreenControl />}
|
||||||
</Control>
|
</Control>
|
||||||
<TileLayer
|
<TileLayer
|
||||||
maxZoom={19}
|
maxZoom={19}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user