vdux-css-emulator
Emulate CSS UI states (hover, active, focus)
Last updated 5 years ago by ashaffer88 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install vdux-css-emulator 
SYNC missed versions from official npm registry.

css-emulator

js-standard-style

Emulate CSS UI state change events (hover, active, focus)

Installation

$ npm install vdux-css-emulator

Usage

This is a low level library intended to simulate the hover/active/focus CSS selectors using local component state and DOM events. Here's how you use it:

function render ({local}) {
  return <CSSEmulator tag='button' onHoverChange={local(highlightButton)}>Hover me</CSSEmulator>
}

API - props

  • tag - The HTML tag or component that you want to render (e.g. button)
  • onHoverChange - Receives a boolean for hover state
  • onActiveChange - Receives a bool for active state
  • onFocusChange - Receives a bool for focus state
  • onLingerChange - Receives a bool for linger state
  • lingerDelay - How long to wait to trigger the lingerChange event. Defaults to 500 milliseconds.

Linger state

Sometimes you want to do something only if the user hovers for a short period of time (i.e. not immediately). onLingerChange provides this primitive for you, and allows you to do something in response to the mouse 'lingering' over an element.

Why can't I just use onMouseEnter/onMouseLeave?

Unfortunately this is not robust. Under certain circumstances if the mouse is moving quickly or if you do weird things like switch tabs while the mouse is hovering, you may not get a mouseleave event, and your hovered thing will stay open forever (or until you mouse back over and off again). This addresses this issue and similar issues with the 'active' state.

License

MIT

Current Tags

  • 2.0.5                                ...           latest (5 years ago)

7 Versions

  • 2.0.5                                ...           5 years ago
  • 2.0.4                                ...           5 years ago
  • 2.0.3                                ...           5 years ago
  • 2.0.2                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 2
Dependencies (7)
Dev Dependencies (11)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |