Skip to content

Importless css #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import japgolly.scalajs.benchmark._
import japgolly.scalajs.benchmark.gui._
import scalatags.JsDom.all._

object CssStylesApply extends CssView {
object CssStylesApply {

val styles = Benchmark("three styles") {
div(
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import scalatags.JsDom.all._
final class DismissibleUdashAlert private[alert](
alertStyle: ReadableProperty[BootstrapStyles.Color], override val componentId: ComponentId
)(content: Binding.NestedInterceptor => Modifier) extends UdashAlertBase(alertStyle, componentId) {
import io.udash.css.CssView._

private val _dismissed = Property[Boolean](false)

Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ package alert
import io.udash._
import io.udash.bindings.modifiers.Binding
import io.udash.bootstrap.utils.{BootstrapStyles, UdashBootstrapComponent}
import io.udash.css.CssView._
import io.udash.wrappers.jquery.{JQuery, jQ}
import org.scalajs.dom.html.Div
import scalatags.JsDom.TypedTag
Original file line number Diff line number Diff line change
@@ -15,8 +15,6 @@ class UdashBadge private[badge](
)(content: Binding.NestedInterceptor => Modifier)
extends UdashBootstrapComponent {

import io.udash.css.CssView._

protected def baseTag: TypedTag[Element] = span

override val render: Element = {
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@ final class UdashBreadcrumbs[ItemType, ElemType <: ReadableProperty[ItemType]] p
isActive: ItemType => Boolean
) extends UdashBootstrapComponent {

import io.udash.css.CssView._

override val render: Element = {
import scalatags.JsDom.all._
import scalatags.JsDom.tags2.nav
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ final class UdashButton private(
override val componentId: ComponentId,
tag: UdashButton.ButtonTag
)(content: Binding.NestedInterceptor => Modifier) extends UdashBootstrapComponent with Listenable[UdashButton, ButtonClickEvent] {
import io.udash.css.CssView._

private val classes: List[Modifier] = {
(BootstrapStyles.Button.btn: Modifier) ::
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@ final class UdashButtonGroup[ItemType, ElemType <: ReadableProperty[ItemType]] p
override val componentId: ComponentId
)(itemFactory: (ElemType, Binding.NestedInterceptor) => Seq[Element]) extends UdashBootstrapComponent {

import io.udash.css.CssView._

private def buttonFullWidth: Binding =
BootstrapStyles.Sizing.width100.styleIf(justified)

Original file line number Diff line number Diff line change
@@ -13,8 +13,6 @@ final class UdashButtonToolbar[ItemType, ElemType <: ReadableProperty[ItemType]]
override val componentId: ComponentId
)(itemFactory: (ElemType, Binding.NestedInterceptor) => Seq[Element]) extends UdashBootstrapComponent {

import io.udash.css.CssView._

override val render: Element =
div(role := "toolbar", BootstrapStyles.Button.toolbar, id := componentId)(
repeatWithNested(items)(itemFactory)
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import io.udash.bindings.modifiers.Binding
import io.udash.bootstrap.list.UdashListGroup
import io.udash.bootstrap.nav.UdashNav
import io.udash.bootstrap.utils.{BootstrapStyles, UdashBootstrapComponent}
import io.udash.css.CssView._
import org.scalajs.dom.Element
import scalatags.JsDom.all._

@@ -98,19 +97,19 @@ final class UdashCard private(
/** Puts the provided list group into the card with additional `list-group-flush` style.
* More: <a href="http://getbootstrap.com/docs/4.1/components/card/#list-groups">Bootstrap Docs</a>. */
def listGroup(list: Binding.NestedInterceptor => UdashListGroup[_, _]): Modifier = {
list(externalBinding).render.styles(BootstrapStyles.ListGroup.flush)
list(externalBinding).render +: BootstrapStyles.ListGroup.flush
}

/** Puts the provided navigation tabs into the card with additional `card-header-tabs` style.
* More: <a href="http://getbootstrap.com/docs/4.1/components/card/#navigation">Bootstrap Docs</a>. */
def navigationTabs(navigation: Binding.NestedInterceptor => UdashNav[_, _]): Modifier = {
navigation(externalBinding).render.styles(BootstrapStyles.Card.navTabs)
navigation(externalBinding).render +: BootstrapStyles.Card.navTabs
}

/** Puts the provided navigation tabs into the card with additional `card-header-pills` style.
* More: <a href="http://getbootstrap.com/docs/4.1/components/card/#navigation">Bootstrap Docs</a>. */
def navigationPills(navigation: Binding.NestedInterceptor => UdashNav[_, _]): Modifier = {
navigation(externalBinding).render.styles(BootstrapStyles.Card.navPills)
navigation(externalBinding).render +: BootstrapStyles.Card.navPills
}
}

Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ final class UdashCarousel[ItemType, ElemType <: ReadableProperty[ItemType]] priv
import UdashCarousel._
import io.udash.bootstrap.utils.BootstrapStyles.Carousel
import io.udash.bootstrap.utils.BootstrapTags._
import io.udash.css.CssView._
import io.udash.wrappers.jquery._

if (activeSlide.get >= slides.size) activeSlide.set(slides.size - 1)
@@ -300,7 +299,7 @@ object UdashCarousel {
* @param caption Slide caption content.
*/
case class UdashCarouselSlide(imgSrc: Url)(caption: Modifier*) {
import io.udash.css.CssView._


lazy val render: Node = {
Seq(
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ final class UdashAccordion[ItemType, ElemType <: ReadableProperty[ItemType]] pri
with Listenable[UdashAccordion[ItemType, ElemType], UdashAccordion.AccordionEvent[ItemType, ElemType]] {

import io.udash.bootstrap.utils.BootstrapTags._
import io.udash.css.CssView._
import scalatags.JsDom.all._

private val collapses = mutable.Map.empty[ElemType, UdashCollapse]
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ final class UdashCollapse private(

import UdashCollapse._
import io.udash.bootstrap.utils.BootstrapTags._
import io.udash.css.CssView._
import io.udash.wrappers.jquery._

/** Toggle state of this collapse. */
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ final class UdashDatePicker private[datepicker](
) extends UdashBootstrapComponent with Listenable[UdashDatePicker, UdashDatePicker.DatePickerEvent] with CrossLogging {

import UdashDatePicker._
import io.udash.css.CssView._
import scalatags.JsDom.all._

private val inp = input(
Original file line number Diff line number Diff line change
@@ -30,7 +30,6 @@ final class UdashDropdown[ItemType, ElemType <: ReadableProperty[ItemType]] priv

import UdashDropdown._
import io.udash.bootstrap.dropdown.UdashDropdown.DropdownEvent._
import io.udash.css.CssView._

/** Dropdown menu list ID. */
val menuId: ComponentId = componentId.subcomponent("menu")
@@ -144,7 +143,7 @@ object UdashDropdown {
/** Renders DOM element for [[io.udash.bootstrap.dropdown.UdashDropdown.DefaultDropdownItem]]. */
def defaultItemFactory(item: DefaultDropdownItem, nested: Binding.NestedInterceptor): Element = {
import DefaultDropdownItem._
import io.udash.css.CssView._

item match {
case Text(text) =>
span(BootstrapStyles.Dropdown.itemText, text).render
@@ -157,7 +156,7 @@ object UdashDropdown {
case Header(title) =>
h6(BootstrapStyles.Dropdown.header)(title).render
case Disabled(item) =>
val res = defaultItemFactory(item, nested).styles(BootstrapStyles.disabled)
val res = defaultItemFactory(item, nested) +: BootstrapStyles.disabled
res.addEventListener("click", (ev: Event) => {
ev.preventDefault()
ev.stopPropagation()
Original file line number Diff line number Diff line change
@@ -29,8 +29,6 @@ final class UdashForm private(
)(content: FormElementsFactory => Modifier)
extends UdashBootstrapComponent with Listenable[UdashForm, UdashForm.FormEvent] with CrossLogging {

import io.udash.css.CssView._

private[form] val validationProperties: MSet[Property[Option[ValidationResult]]] = MSet.empty

def clearValidationResults(): Unit = {
@@ -134,7 +132,7 @@ final class FormElementsFactory(
form: OptArg[UdashForm] = OptArg.Empty
) extends CrossLogging {

import io.udash.css.CssView._


/** Use this method to bond the external binding's lifecycle with the lifecycle of the elements created via this factory. */
def externalBinding[T <: Binding](binding: T): T = {
@@ -582,7 +580,7 @@ final class FormElementsFactory(

override val render: Element = div(
id := groupId, BootstrapStyles.Form.customControl, BootstrapStyles.Form.customCheckbox,
input.render.styles(BootstrapStyles.Form.customControlInput),
input.render +: BootstrapStyles.Form.customControlInput,
nestedInterceptor(BootstrapStyles.Form.customControlInline.styleIf(inline)),
label(`for` := inputId, BootstrapStyles.Form.customControlLabel)(
labelContent.map(_.apply(nestedInterceptor)).getOrElse(span("\u00a0"))
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ final class UdashInputGroup private(
override val componentId: ComponentId
)(content: Modifier*) extends UdashBootstrapComponent {

import io.udash.css.CssView._

override val render: Element =
div(
BootstrapStyles.InputGroup.inputGroup,
@@ -21,7 +19,7 @@ final class UdashInputGroup private(
}

object UdashInputGroup {
import io.udash.css.CssView._


/**
* Creates an inputs group.
@@ -42,15 +40,15 @@ object UdashInputGroup {

/** Adds `form-control` style to provided element. It's required to properly display input as part of group. */
def input(el: Element): Element =
el.styles(BootstrapStyles.Form.control)
el +: BootstrapStyles.Form.control

/** Adds `custom-select` style to provided element. It's required to properly display select as part of group. */
def select(el: Element): Element =
el.styles(BootstrapStyles.Form.control, BootstrapStyles.InputGroup.customSelect)
(el +: BootstrapStyles.Form.control) +: BootstrapStyles.InputGroup.customSelect

/** Adds `custom-file` style to provided element. It's required to properly display file input as part of group. */
def file(el: Element): Element =
el.styles(BootstrapStyles.Form.control, BootstrapStyles.InputGroup.customFile)
(el +: BootstrapStyles.Form.control) +: BootstrapStyles.InputGroup.customFile

/** Creates an element to be prepended to the input of this input group. */
def prepend(content: Modifier*): Modifier =
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ final class UdashJumbotron private(
override val componentId: ComponentId
)(content: Binding.NestedInterceptor => Modifier) extends UdashBootstrapComponent {

import io.udash.css.CssView._

override val render: Element = {
div(
id := componentId,
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ final class UdashListGroup[ItemType, ElemType <: ReadableProperty[ItemType]] pri
flush: ReadableProperty[Boolean],
override val componentId: ComponentId
)(itemFactory: (ElemType, Binding.NestedInterceptor) => Element) extends UdashBootstrapComponent {
import io.udash.css.CssView._
import scalatags.JsDom.all._

override val render: Element =
@@ -22,7 +21,7 @@ final class UdashListGroup[ItemType, ElemType <: ReadableProperty[ItemType]] pri
)(
nestedInterceptor(
repeatWithNested(items) { (item, nested) =>
itemFactory(item, nested).styles(BootstrapStyles.ListGroup.item)
itemFactory(item, nested) +: BootstrapStyles.ListGroup.item
}
)
).render
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ final class UdashModal private(
) extends UdashBootstrapComponent with Listenable[UdashModal, UdashModal.ModalEvent] {

import UdashModal._
import io.udash.css.CssView._
import io.udash.wrappers.jquery._
import scalatags.JsDom.all._

@@ -44,7 +43,7 @@ final class UdashModal private(
(bodyFactory, BootstrapStyles.Modal.body),
(footerFactory, BootstrapStyles.Modal.footer)
).collect { case (Some(factory), styleName) =>
factory(nestedInterceptor).styles(styleName)
factory(nestedInterceptor) +: styleName
}

val el = div(
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ final class UdashNav[ItemType, ElemType <: ReadableProperty[ItemType]] private(
isDisabled: ElemType => ReadableProperty[Boolean],
isDropdown: ElemType => ReadableProperty[Boolean]
) extends UdashBootstrapComponent {
import io.udash.css.CssView._

override val render: Element = {
ul(
@@ -67,7 +66,7 @@ final class UdashNav[ItemType, ElemType <: ReadableProperty[ItemType]] private(
}

object UdashNav {
import io.udash.css.CssView._


/** Default navigation model. */
class NavItem(val name: String, val link: Url)
Original file line number Diff line number Diff line change
@@ -19,11 +19,9 @@ final class UdashNavbar[ItemType, ElemType <: ReadableProperty[ItemType]] privat
)(
navigationFactory: Binding.NestedInterceptor => Modifier,
brand: Modifier
)
extends UdashBootstrapComponent {
) extends UdashBootstrapComponent {

import io.udash.bootstrap.utils.BootstrapTags._
import io.udash.css.CssView._

private val collapseId = ComponentId.newId()

@@ -87,9 +85,9 @@ object UdashNavbar {
navigationFactory: Binding.NestedInterceptor => UdashNav[ItemType, ElemType],
brand: Modifier = ()
): UdashNavbar[ItemType, ElemType] = {
import io.udash.css.CssView._

new UdashNavbar(expandBreakpoint, darkStyle, backgroundStyle, position, componentId)(
interceptor => navigationFactory(interceptor).render.styles(BootstrapStyles.NavigationBar.nav),
interceptor => navigationFactory(interceptor).render +: BootstrapStyles.NavigationBar.nav,
brand
)
}
Original file line number Diff line number Diff line change
@@ -24,8 +24,6 @@ final class UdashPagination[PageType : PropertyCreator, ElemType <: ReadableProp
additionalListModifiers: Binding.NestedInterceptor => Modifier
) extends UdashBootstrapComponent {

import io.udash.css.CssView._

// keep track of pages sequence changes and update selected page
propertyListeners += pages.listenStructure { patch =>
if (patch.idx <= selectedPageIdx.get && patch.idx + patch.removed.size > selectedPageIdx.get) {
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ final class UdashProgressBar private[progressbar](
override val componentId: ComponentId
)(labelFactory: (ReadableProperty[Int], ReadableProperty[Int], ReadableProperty[Int], Binding.NestedInterceptor) => Modifier) extends UdashBootstrapComponent {

import io.udash.css.CssView._

protected def barModifiers: Seq[Modifier] = Seq[Modifier](
role := "progressbar", BootstrapStyles.ProgressBar.progressBar,
Original file line number Diff line number Diff line change
@@ -24,8 +24,6 @@ final class UdashTable[ItemType, ElemType <: ReadableProperty[ItemType]] private
rowFactory: (ElemType, Binding.NestedInterceptor) => Element
) extends UdashBootstrapComponent {

import io.udash.css.CssView._

override val render: Element = {
div(
nestedInterceptor((BootstrapStyles.Table.responsive _).reactiveOptionApply(responsive)),
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@ object UdashPopover extends TooltipUtils[UdashPopover] {

override protected val defaultPlacement = Placement.Right
override protected val defaultTemplate: String = {
import io.udash.css.CssView._
import scalatags.Text.all._
div(BootstrapStyles.Popover.popover, role := "tooltip")(
div(BootstrapStyles.arrow),
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ object UdashTooltip extends TooltipUtils[UdashTooltip] {

override protected val defaultPlacement = Placement.Top
override protected val defaultTemplate: String = {
import io.udash.css.CssView._
import scalatags.Text.all._
div(BootstrapStyles.Tooltip.tooltip, role := "tooltip")(
div(BootstrapStyles.Tooltip.arrow),
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import io.udash.testing.UdashCoreFrontendTest
import org.scalajs.dom.Element

class BootstrapImplicitsTest extends UdashCoreFrontendTest {
import io.udash.css.CssView._

"StyleOps" should {
"apply style conditionally" in {
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import scalatags.JsDom.all._

import scala.concurrent.Future

class UdashIconsTest extends AsyncUdashCoreFrontendTest with CssView {
class UdashIconsTest extends AsyncUdashCoreFrontendTest {
override protected def beforeAll(): Unit = document.body.appendChild(UdashBootstrap.loadFontAwesome())

"Bootstrap icons" should {
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import org.openqa.selenium.firefox.{FirefoxDriverLogLevel, FirefoxOptions}
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
import org.scalajs.jsenv.selenium.SeleniumJSEnv
import org.scalajs.sbtplugin.JSModuleID
import sbt.Def

name := "udash"

@@ -127,7 +128,7 @@ val aggregateProjectSettings = noPublishSettings ++ Seq(
crossScalaVersions := Nil,
)

def sourceDirsSettings(baseMapper: File => File) = {
def sourceDirsSettings(baseMapper: File => File): Seq[Def.Setting[Seq[File]]] = {
def mkSourceDirs(base: File, scalaBinary: String, conf: String): Seq[File] = Seq(
base / "src" / conf / "scala",
base / "src" / conf / s"scala-$scalaBinary",
Loading