1.0.3 • Published 2 years ago

nodes-navigation-focus v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

nodes-navigation-focus

nodes-navigation-focus is a JS library which automates the focus moviment in the screen.

The library uses the react-hooks to manipulate the DOM and recieve and return infomation about the state of the element.

Installation

Install nodes-navigation-focus with npm

  npm install nodes-navigation-focus

Features

  • Manage state of DOM elements
  • Move focus state of a complex layout structure
  • Allows you recive informartion about the elemenet that is currently focused

API Reference

We have to understand that we will have 2 types of 'uneNavigation' instance.

One that it will be reference to a DOM element that contains an agrupation of elements that will recive the focus.

And another intance that will reference the specific DOM elements that will recive the focus.

Types

You can extract them from the library

  import useNavigation, { types } from 'nodes-navigation-focus'
TypeDescription
singleUsed to refere to a single DOM element without parent
lineUsed to refere to an array of elements
matrixUsed to refere to an a array of elements that will be displayed like a matrix
listUsed to refere to a list of items,
objectUsed to refere to an object

Parameters

  • Common params
ParameterTypeDescription
focusKeystringElement key
extraPropsobjectobject that stores element information
  • Common params for PARENT reference
ParameterTypeDescription
typestringRequired. type of layout structure that
rememberLastFocusedbooleanAdd this option to remember the las element focused in the structure
onFocusedChildNodeChangesfuncTriggers when the focus in the structure changes
onOutobjectTriggers when the focus wants to go out of the element
preferredChildFocusKeystringDefault son key that it will be focused if the references is not specified
  • Common params for SON reference
ParameterTypeDescription
parentrefRequired. the 'useNavigation' hook will recieve the reference of the parent generated with 'useNavigation' hook
onMouseOverfunctriggers when mouse over of the element
onMouseOutfunctriggers when mouse out of the element
onClickfunctriggers when element is clicked
onFocusedNodefuncIt will triggers when the element is with focus
onEnterPressedNodefuncTriggers when the element is pressed with enter
onArrowPressfuncTrigger when element is pulses a key moviment
  • Single type

This type can't have son elements

ParameterTypeDescription
onMovefuncTriggers when focus wants to go another element
  • Line type
ParameterTypeDescription
positionnumberposition order
flowstringIf the structure is gonna be in horizontal or in vertical
  • List type

For son:

ParameterTypeDescription
rownumberrow order
positionnumberposition order

For parent:

ParameterTypeDescription
startPositionnumberstart position of the lsit
rememberLastFocusedbooleanremember last list focused
rememberLastRowPositionbooleanremember last son reference where focused when the focus is moving into the lists
  • Matrix type
ParameterTypeDescription
rowstringrow order
columnobjectcolumn order

Navigation utilities

ParameterTypeDescription
refstringRequired. The use of this property returned by 'useNavigation' is required to set the reference with the DOM node
focusSelffunca function to focus the current element
focusSelffunca function to focus the current element
setFocusfunca function to change focus between structures
focusedbooleangives you information if node is currently focused or not
hasFocusedChildbooleangives you information about if it has some son element node focused
focusKeystringreturn the key of the node
getFocusedNodefuncreturn information about focused node
getPressedNodefuncreturns information about las pressed node

useNavigation()

Recieves a ref of a DOM element with a specific configuration and returns a DOM element ref and the state of the element.

Usage/Examples

import useNavigation, { types } from 'nodes-navigation-focus';

const [matrixRef, { focused, setFocus, hasFocusedChild }] = useNavigation({
        type: types.MATRIX,
        focusKey: 'matrix',
        preferredChildFocusKey: 'item-1-1',
        onFocusedChildNodeChanges: (config) => {
            console.log(config)
        },
        onOut: {
            top: () => {
                setFocus('slider')
            },
            left: () => {
                setFocus('menu')
            },
        }
    })

Demo

This is an example of how the focus looks in an application example. Click here to see the full demo.

App Screenshot

Authors

License

Added GNU General Public License v3.0

GPLv3 License