0.0.5 • Published 6 months ago

react-dms-input v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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

import React, { useState } from 'react'
import DMSInput from 'react-dms-input'
import 'react-dms-input/style.css'

function App() {
  const [value, setValue] = useState(0)

  return (
    <DMSInput
      mode="DMS"
      type="lat" // Required property
      value={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.
fractionDigits0-41Fraction 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

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago