Skip to content

Repository files navigation

React DMS input

React component for Degrees, Minutes and Seconds (DMS) coordinates input. Mainly focussed on the maritime industry.

Installation

yarn add react-dms-input
npm install react-dms-input --save

Demo

https://phalkone.github.io/react-dms-input/

Basic usage

importReact,{useState}from'react'importDMSInputfrom'react-dms-input'import'react-dms-input/style.css'functionApp(){const[value,setValue]=useState(0)return(<DMSInputmode="DMS"type="lat"// Required propertyvalue={value}locale={'en-US'}fractionDigits={1}onChange={setValue}/>)}

Properties

PropertyTypeDefaultDescription
mode'DMS' | 'DM' | 'D''DM'Display mode of input.
type'lat' | 'long'Latitude or longitude input.
fractionDigits[0-4]1Fraction digits of degrees (D mode) or minutes (DM mode) input. Ignored in DMS mode.
localestring(host locale)Locale of input. Affects the decimal separator of the minutes.
valuenumberValue in degrees.
onnChange(val: number | undefined) => voidCalled when the degrees value changes.
nextFocusHTMLInputElement | HTMLSelectElementUI element to focus on once the sign once the sign has been entered.
refReact.RefObjectReference to the input component
classesDMSInputClassesCustom css classes for all containers
styleReact.CSSPropertiesInline styles for the root container

Styling Reference

CSS Class Hierarchy

.DMSInput (root container)
├── .input-wrapper (generic input group)
│ ├── input (number input element)
│ └── span (degree symbol)
├── .degrees-wrapper (specific to degrees)
├── .minutes-wrapper (specific to minutes)
├── .seconds-wrapper (specific to seconds)
└── .sign-input (container for N/S/E/W selector)
└── select(sign dropdown element)

DMSInputClasses

Class NameLocationContains
rootRoot containerAll coordinate inputs and sign selector
inputWrapperInput group containerInput field + measurement symbol
degreesWrapperDegrees-specific containerDegrees input + ° symbol
minutesWrapperMinutes-specific containerMinutes input + ' symbol
secondsWrapperSeconds-specific containerSeconds input + " symbol
signInputCardinal direction containerN/S/E/W dropdown selector

CSS variables

Variable NameDefault ValueDescription
border-color#cccBorder color for input fields
focus-background-color#eef6ffBorder color for focused input fields
symbol-color#6c757dColor for measurement symbols

License

MIT

About

React component for Degrees, Minutes and Seconds (DMS) coordinates input.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages