How to use @s-ui/js - 7 common examples

To help you get started, we’ve selected a few @s-ui/js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SUI-Components / sui-components / components / molecule / select / src / index.js View on Github external
const handleKeyDown = ev => {
    ev.persist()
    const isEnabledKey = ENABLED_KEYS.includes(ev.key)
    const options = refsMoleculeSelectOptions.current.map(getTarget)
    const domSourceEvent = ev.target
    const domMoleculeSelect = refMoleculeSelect.current

    if (!isOpen && isEnabledKey) {
      domSourceEvent === domMoleculeSelect && handleToggle(ev)
    } else {
      const currentElementFocused = getCurrentElementFocused()
      const isSomeOptionFocused = [...options].includes(currentElementFocused)
      if (ev.key === 'Escape') closeList(ev)
      if (ev.key === 'ArrowDown' && !isSomeOptionFocused)
        focusFirstOption(ev, {options})
    }
  }
github SUI-Components / sui-components / components / molecule / autosuggest / src / index.js View on Github external
setTimeout(() => {
      const currentElementFocused = getCurrentElementFocused()
      const focusOutFromOutside = ![domInnerInput, ...options].includes(
        currentElementFocused
      )
      if (focusOutFromOutside) {
        isOpen ? closeList(ev) : setFocus(false)
      }
    }, 1)
    setFocus(true)
github SUI-Components / sui-components / components / molecule / select / src / index.js View on Github external
setTimeout(() => {
      const currentElementFocused = getCurrentElementFocused()
      const isSomeOptionFocused = [...options].includes(currentElementFocused)
      const isOptionListFocused = firstOption
        ? currentElementFocused.isSameNode(firstOption.parentNode)
        : false

      if (!isSomeOptionFocused && !isOptionListFocused && isOpen) {
        closeList(ev)
      }
    }, 1)
    setFocus(false)
github SUI-Components / sui-components / components / atom / backToTop / src / index.js View on Github external
const scrollStep = () => {
    const container = getTarget(refContainer)
    const {scrollTop} = container
    const {current: intervalId} = intervalRef

    if (scrollTop === 0) clearInterval(intervalId)
    if (scrollTop) container.scrollTop = scrollTop - scrollSteps
  }
github SUI-Components / sui-components / components / atom / backToTop / src / index.js View on Github external
useEffect(() => {
    const container = getTarget(refContainer)
    const {scrollHeight, clientHeight} = container
    const halfHeight = Math.floor((scrollHeight - clientHeight) / 2)

    const handleScroll = () => {
      const {scrollTop} = container
      if (scrollTop > halfHeight) {
        if (!show) {
          setShow(true)
        }
      } else {
        if (show) {
          setShow(false)
          setHover(false)
        }
      }
    }
github SUI-Components / sui / packages / sui-decorators / src / decorators / cache / index.js View on Github external
return (...args) => {
    if (
      (typeof window !== 'undefined' && window.__SUI_CACHE_DISABLED__) ||
      (typeof global !== 'undefined' && global.__SUI_CACHE_DISABLED__)
    ) {
      return original.apply(instance, args)
    }

    const key = `${target.constructor.name}::${fnName}::${createHash(
      JSON.stringify(args)
    )}`
    const now = Date.now()
    if (cache.get(key) === undefined) {
      cache.set(key, {createdAt: now, returns: original.apply(instance, args)})
    }

    if (isPromise(cache.get(key).returns)) {
      cache.get(key).returns.catch(() => cache.del(key))
    }

    if (now - cache.get(key).createdAt > ttl) {
      cache.del(key)
    }

    return cache.get(key) !== undefined
github SUI-Components / sui / packages / sui-i18n / src / i18n.js View on Github external
      .map(token => slugify(this.t(token), allowQueryParams))
      .join('/')

@s-ui/js

Set of JS utilities

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis