-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(home-button): introduce a button to go to a default extent
style(home-button): match esri style
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/utah-design-system/src/components/HomeButton.stories.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,57 @@ | ||
import Map from '@arcgis/core/Map'; | ||
import MapView from '@arcgis/core/views/MapView'; | ||
import type { Meta } from '@storybook/react'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { HomeButton as Component } from './HomeButton'; | ||
|
||
import '@arcgis/core/assets/esri/themes/light/main.css'; | ||
|
||
const meta: Meta<typeof Component> = { | ||
component: Component, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
argTypes: {}, | ||
args: {}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Example = { | ||
render: () => { | ||
const viewDivRef = useRef<HTMLDivElement | null>(null); | ||
const view = useRef<__esri.MapView | null>(null); | ||
const [ready, setReady] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (view.current) { | ||
return; | ||
} | ||
|
||
view.current = new MapView({ | ||
container: viewDivRef.current!, | ||
map: new Map({ | ||
basemap: 'topo', | ||
}), | ||
zoom: 15, | ||
center: [-111.5, 39.5], | ||
}); | ||
|
||
view.current.when(() => { | ||
setReady(true); | ||
}); | ||
}, [view.current, viewDivRef.current]); | ||
|
||
return ( | ||
<> | ||
<div | ||
ref={viewDivRef} | ||
className="border rounded-lg size-96 overflow-hidden" | ||
> | ||
{ready && <Component view={view.current!} />} | ||
</div> | ||
</> | ||
); | ||
}, | ||
}; |
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,37 @@ | ||
import '@arcgis/core/interfaces.d.ts'; | ||
import { useDefaultExtent, useViewUiPosition } from '@ugrc/utilities/hooks'; | ||
import { HomeIcon } from 'lucide-react'; | ||
import { Button } from './Button'; | ||
|
||
export const HomeButton = ({ | ||
view, | ||
position, | ||
initialExtent, | ||
}: { | ||
view: __esri.MapView; | ||
position: __esri.UIAddComponent['position']; | ||
initialExtent?: __esri.Extent; | ||
}) => { | ||
const goHome = useDefaultExtent(view, initialExtent); | ||
const uiPosition = useViewUiPosition(view, position ?? 'top-left'); | ||
|
||
return ( | ||
<div | ||
ref={uiPosition} | ||
className="group flex items-center justify-center size-[32px] bg-white shadow-[0_1px_2px_#0000004d]" | ||
> | ||
<Button | ||
variant="icon" | ||
className="focus:min-h-0 focus:outline-offset-[-2px] will-change-transform transition-colors duration-150 ease-in-out p-0 size-full stroke-[4] group-hover:bg-[#f3f3f3]" | ||
aria-label="Default extent" | ||
onPress={() => goHome()} | ||
> | ||
<HomeIcon | ||
className="will-change-transform transition-colors duration-150 ease-in-out size-5 text-[#6e6e6e] group-hover:text-[#151515] stroke-[1.5]" | ||
aria-hidden | ||
/> | ||
<span className="sr-only">Go Home</span> | ||
</Button> | ||
</div> | ||
); | ||
}; |
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