@smoothglue/smoothglue-coordinate-entry
v3.0.1
Published
A robust ๐๏ธ, type-safe ๐ก๏ธ React UI component library for interacting with and parsing geospatial coordinates ๐บ๏ธ in various formats. This library provides ready-to-use input fields, poppers, and utility hooks for seamless coordinate management in Smooth
Readme
๐ Smoothglue Coordinate Entry
A robust ๐๏ธ, type-safe ๐ก๏ธ React UI component library for interacting with and parsing geospatial coordinates ๐บ๏ธ in various formats. This library provides ready-to-use input fields, poppers, and utility hooks for seamless coordinate management in SmoothGlue applications.
Table of Contents ๐
โจ Features
- ๐บ๏ธ Multi-Format Support: Effortlessly parse and interact with multiple coordinate systems:
- Decimal Degrees (e.g.
12.4567ยฐS, 14ยฐW) - Decimal-Minutes Degrees (e.g.
32ยฐ57'S, 032ยฐ57'E) - Decimal-Minutes-Seconds Degrees (e.g.
32ยฐ57'28.08"S, 032ยฐ57'28.08"E) - Universal Transverse Mercator (UTM) (e.g.
23N330) - Military Grid Reference System (MGRS) (e.g.
02QGF100) - Global Area Reference System (GARS) (e.g.
004RT23)
- Decimal Degrees (e.g.
- ๐ก๏ธ Type-Safe: Built entirely in TypeScript with strict geospatial definitions.
- ๐จ Theming Support: Leverages Material UI (MUI) and ships with theme configurations.
- ๐งฉ React Hook Form Integration: Components are designed to work seamlessly with complex form state management.
- ๐ช Custom Hooks: Exposes utility hooks like
useCoordinateDispatcherfor managing dispatch events outside the main input component.
๐ Getting Started
๐ฆ Installation
Install the package using npm or yarn:
npm install @smoothglue/smoothglue-coordinate-entryPeer Dependencies ๐ค
This library relies on several peer dependencies that must be installed in your project ๐.
Ensure you have the core React and Material UI packages installed:
npm install react react-dom @mui/material @mui/icons-material @emotion/react @emotion/styled lodashNote: This package requires React 18+ and Material UI @mui/material v6+.
Usage ๐ฎ
SgCoordinateEntry ๐งญ
The SgCoordinateEntry is the primary UI component. It provides a text input that automatically parses strings into structured coordinate objects, and offers a popper overlay for discrete degree/minute/second editing.
import { useState } from 'react'
import { SgCoordinateEntry, CartographicDegree } from '@smoothglue/smoothglue-coordinate-entry'
export const CoordinateForm = () => {
const [coordinate, setCoordinate] = useState<CartographicDegree | null>(null)
const handleChange = (newCoordinate: CartographicDegree) => {
setCoordinate(newCoordinate)
console.log('Updated Coordinate:', newCoordinate)
}
return (
<SgCoordinateEntry
label="Object Location"
value={coordinate}
onChange={handleChange}
placeholder="e.g. 38ยฐ 53' 23 N, 77ยฐ 0' 32 W"
/>
)
}SgCoordinateEntry Props โ๏ธ
A brief overview of the primary props available on the main component.
| Prop | Type | Description |
| :------------- | :------------------------------------ | :-------------------------------------------------------------------- |
| value | CartographicDegree | The current coordinate value. |
| onChange | (coord: CartographicDegree) => void | Callback fired when the coordinate is successfully parsed or updated. |
| label | string | The label for the MUI TextField. |
| disabled | boolean | Disables the input field. |
| error | boolean | Flags the input in an error state. |
useCoordinateDispatcher Hook ๐ช
The useCoordinateDispatcher hook allows you to dispatch custom coordinate events to update the entry state externally.
import { useCoordinateDispatcher } from '@smoothglue/smoothglue-coordinate-entry'
import { Button } from '@mui/material'
const ExternalUpdater = () => {
const { dispatchCoordinate } = useCoordinateDispatcher()
const setWashingtonDC = () => {
dispatchCoordinate({
latitude: 38.8895,
longitude: -77.0353,
height: 0
})
}
return <Button onClick={setWashingtonDC}>Set to Washington D.C.</Button>
}๐ Running Storybook
This project uses Storybook to develop, document, and test UI components in isolation.
Install dependencies:
npm installStart the Storybook server:
npm run storybookOpen your browser: Navigate to
http://localhost:6006to view the interactive component stories.
Contributing ๐คฒ
๐ Project Structure
src/components/: Core React UI components, includingSgCoordinateEntryandSgDegreeFields.src/utilities/: Core business logic for geospatial math, coordinate conversions, and validation.src/themes/: Material UI theme definitions specific to SmoothGlue product lines.src/types/: Centralized TypeScript type definitions..storybook/: Configuration for the Storybook component explorer.
Available Scripts ๐
In the project directory, you can run:
npm run storybook: Starts the Storybook development server on port 6006 ๐จ.npm run build: Runs TypeScript type checking (tsc) and builds the library using Vite ๐ฆ.npm run test: Runs the unit test suite using Vitest (JSDom) ๐งช.npm run test:all: Runs both unit tests and browser-based component tests via Storybook Playwright integration ๐ญ.npm run lint: Runs ESLint to analyze the code for quality issues ๐งน.npm run coverage: Runs unit tests and outputs a coverage report ๐.
