diff --git a/packages/utah-design-system/src/components/HomeButton.stories.tsx b/packages/utah-design-system/src/components/HomeButton.stories.tsx new file mode 100644 index 0000000..b5e029e --- /dev/null +++ b/packages/utah-design-system/src/components/HomeButton.stories.tsx @@ -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 = { + component: Component, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], + argTypes: {}, + args: {}, +}; + +export default meta; + +export const Example = { + render: () => { + const viewDivRef = useRef(null); + const view = useRef<__esri.MapView | null>(null); + const [ready, setReady] = useState(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 ( + <> +
+ {ready && } +
+ + ); + }, +}; diff --git a/packages/utah-design-system/src/components/HomeButton.tsx b/packages/utah-design-system/src/components/HomeButton.tsx new file mode 100644 index 0000000..c111970 --- /dev/null +++ b/packages/utah-design-system/src/components/HomeButton.tsx @@ -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 ( +
+ +
+ ); +}; diff --git a/packages/utah-design-system/src/index.ts b/packages/utah-design-system/src/index.ts index 93ee9af..b6c8d05 100644 --- a/packages/utah-design-system/src/index.ts +++ b/packages/utah-design-system/src/index.ts @@ -10,6 +10,7 @@ export * from './components/Footer'; export * from './components/FormErrors'; export * from './components/Geocode'; export * from './components/Header'; +export * from './components/HomeButton'; export * from './components/Link'; export * from './components/ListBox'; export * from './components/Menu';