All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lucuma.ui.utils.ReactUtils.scala Maven / Gradle / Ivy

There is a newer version: 0.123.0
Show newest version
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package lucuma.ui.utils

import eu.timepit.refined.api.Refined
import japgolly.scalajs.react.*
import japgolly.scalajs.react.util.DefaultEffects.Sync as DefaultS
import japgolly.scalajs.react.vdom.*

def linkOverride(f: => DefaultS[Unit]): ReactMouseEvent => Callback =
  e => {
    val forward = linkOverride[Unit](f)
    forward(e, ())
  }

def linkOverride[A](f: => DefaultS[Unit]): (ReactMouseEvent, A) => Callback =
  (e: ReactMouseEvent, _: A) =>
    (e.preventDefaultCB *> f)
      .unless_(e.ctrlKey || e.metaKey)

given [T, P](using f: T => VdomNode): Conversion[T Refined P, VdomNode] = v => f(v.value)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy