Skip to content

Commit

Permalink
Merge pull request #140 from japgolly/grid-gaps
Browse files Browse the repository at this point in the history
Add rowGap and gap properties
  • Loading branch information
japgolly committed Apr 25, 2019
2 parents 11e3bab + e3e9891 commit bbb4297
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 50 deletions.
61 changes: 42 additions & 19 deletions core/shared/src/main/scala/scalacss/internal/Attrs.scala
Expand Up @@ -50,6 +50,9 @@ object Attrs {
caretColor, fontVariantionSettings, hangingPunctuation, initialLetter,
overscrollBehavior, overscrollBehaviorX, overscrollBehaviorY,

// 0.5.6
gap, rowGap,

// =================================================================================================================
// ==================================== SVG Attributes =============================================================
// =================================================================================================================
Expand Down Expand Up @@ -123,7 +126,7 @@ object Attrs {
*/
object animationDirection extends TypedAttrBase {
override val attr: Attr = Attr.real("animation-direction", Transform keys CanIUse.animation)
def normal = av(L.normal)
def normal = avl(LT.normal)
def reverse = av(L.reverse)
def alternate = av(L.alternate)
def alternateReverse = av(L.alternateReverse)
Expand Down Expand Up @@ -686,9 +689,8 @@ object Attrs {
*
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap">MDN</a>
*/
object columnGap extends TypedAttrT1[Len] with ZeroLit {
object columnGap extends TypedAttrT1[GapStyle] with GapStyleOps {
override val attr = Attr.real("column-gap", Transform keys CanIUse.multicolumn)
def normal = av(L.normal)
}

/**
Expand Down Expand Up @@ -1054,7 +1056,7 @@ object Attrs {
override val attr = Attr.real("font-kerning", Transform keys CanIUse.fontKerning)
def auto = avl(LT.auto)
def none = avl(LT.none)
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand Down Expand Up @@ -1103,7 +1105,7 @@ object Attrs {
def expanded = av(L.expanded)
def extraCondensed = av(L.extraCondensed)
def extraExpanded = av(L.extraExpanded)
def normal = av(L.normal)
def normal = avl(LT.normal)
def semiCondensed = av(L.semiCondensed)
def semiExpanded = av(L.semiExpanded)
def ultraCondensed = av(L.ultraCondensed)
Expand All @@ -1118,7 +1120,7 @@ object Attrs {
object fontStyle extends TypedAttrBase {
override val attr = Attr.real("font-style")
def italic = av(L.italic)
def normal = av(L.normal)
def normal = avl(LT.normal)
def oblique = av(L.oblique)
}

Expand All @@ -1145,7 +1147,7 @@ object Attrs {
override val attr = Attr.real("font-variant-caps")
def allPetiteCaps = av(L.allPetiteCaps)
def allSmallCaps = av(L.allSmallCaps)
def normal = av(L.normal)
def normal = avl(LT.normal)
def petiteCaps = av(L.petiteCaps)
def smallCaps = av(L.smallCaps)
def titlingCaps = av(L.titlingCaps)
Expand Down Expand Up @@ -1180,7 +1182,7 @@ object Attrs {
*/
object fontVariantPosition extends TypedAttrBase {
override val attr = Attr.real("font-variant-position")
def normal = av(L.normal)
def normal = avl(LT.normal)
def sub = av(L.sub)
def super_ = av(L.super_)
}
Expand Down Expand Up @@ -1211,7 +1213,7 @@ object Attrs {
def bold = av(L.bold)
def bolder = av(L.bolder)
def lighter = av(L.lighter)
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand Down Expand Up @@ -1376,7 +1378,7 @@ object Attrs {
def auto = avl(LT.auto)
def disabled = av(L.disabled)
def inactive = av(L.inactive)
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand All @@ -1386,7 +1388,7 @@ object Attrs {
*/
object initialLetter extends TypedAttrBase {
override val attr = Attr.real("initial-letter", Transform keys CanIUse.initialLetter)
def normal : AV = av(L.normal)
def normal : AV = avl(LT.normal)
def apply(size: ValueT[Number]) : AV = av(size.value)
def apply(size: ValueT[Number], lines: Int): AV = av(s"${size.value} $lines")
}
Expand Down Expand Up @@ -1443,7 +1445,7 @@ object Attrs {
*/
object letterSpacing extends TypedAttrT1[Len] with ZeroLit {
override val attr = Attr.real("letter-spacing", Transform keys CanIUse.letterSpacing)
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand All @@ -1455,7 +1457,7 @@ object Attrs {
override val attr = Attr.real("line-break")
def auto = avl(LT.auto)
def loose = av(L.loose)
def normal = av(L.normal)
def normal = avl(LT.normal)
def strict = av(L.strict)
}

Expand All @@ -1466,7 +1468,7 @@ object Attrs {
*/
object lineHeight extends TypedAttrT1[LenPctNum] with ZeroLit {
override val attr = Attr.real("line-height")
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand Down Expand Up @@ -1936,6 +1938,15 @@ object Attrs {
override val attr = Attr.real("right")
}

/**
* The row-gap CSS property sets the size of the gap (gutter) between an element's grid rows.
*
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap">MDN</a>
*/
object rowGap extends TypedAttrT1[GapStyle] with GapStyleOps {
override val attr = Attr.real("row-gap", Transform keys CanIUse.multicolumn)
}

/**
* The ruby-align CSS property defines the distribution of the different ruby elements over the base.
*
Expand Down Expand Up @@ -2329,7 +2340,7 @@ object Attrs {
def embed = av(L.embed)
def isolate = av(L.isolate)
def isolateOverride = av(L.isolateOverride)
def normal = av(L.normal)
def normal = avl(LT.normal)
def plaintext = av(L.plaintext)
}

Expand Down Expand Up @@ -2390,7 +2401,7 @@ object Attrs {
*/
object whiteSpace extends TypedAttrBase {
override val attr = Attr.real("white-space")
def normal = av(L.normal)
def normal = avl(LT.normal)
def nowrap = av(L.nowrap)
def pre = av(L.pre)
def preLine = av(L.preLine)
Expand Down Expand Up @@ -2431,7 +2442,7 @@ object Attrs {
override val attr = Attr.real("word-break", Transform keys CanIUse.wordBreak)
def breakAll = av(L.breakAll)
def keepAll = av(L.keepAll)
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand All @@ -2441,7 +2452,7 @@ object Attrs {
*/
object wordSpacing extends TypedAttrT1[Len] with ZeroLit {
override val attr = Attr.real("word-spacing")
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand All @@ -2452,7 +2463,7 @@ object Attrs {
object wordWrap extends TypedAttrBase {
override val attr = Attr.real("word-wrap", Transform keys CanIUse.wordwrap)
def breakWord = av(L.breakWord)
def normal = av(L.normal)
def normal = avl(LT.normal)
}

/**
Expand Down Expand Up @@ -2851,6 +2862,18 @@ object Attrs {
fontVariantAlternates, fontVariantCaps, fontVariantEastAsian, fontVariantLigatures, fontVariantNumeric,
fontVariantPosition))

/**
* The gap CSS property sets the gaps (gutters) between rows and columns. It is a shorthand for row-gap and column-gap.
*
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/gap">MDN</a>
*/
object gap extends TypedAttrBase with GapStyleOps {
override val attr = Attr.alias("gap")(_(columnGap, rowGap))
type T = ValueT[GapStyle]
def apply(both: T) : AV = av(both.value)
def apply(row: T, col: T): AV = av(concat(" ", row, col))
}

/**
* @see <a href="http://www.w3.org/TR/css3-grid-layout/#grid-shorthand">css3-grid-layout#grid</a>
*/
Expand Down
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/scalacss/internal/Data.scala
Expand Up @@ -73,7 +73,7 @@ object FontFace {
def expanded = b(Literal.expanded)
def extraCondensed = b(Literal.extraCondensed)
def extraExpanded = b(Literal.extraExpanded)
def normal = b(Literal.normal)
def normal = b(Literal.Typed.normal.value)
def semiCondensed = b(Literal.semiCondensed)
def semiExpanded = b(Literal.semiExpanded)
def ultraCondensed = b(Literal.ultraCondensed)
Expand All @@ -82,7 +82,7 @@ object FontFace {

final class FontStyleBuilder[FF](private val b: Value => FontFace[FF]) extends AnyVal {
def italic = b(Literal.italic)
def normal = b(Literal.normal)
def normal = b(Literal.Typed.normal.value)
def oblique = b(Literal.oblique)
}

Expand All @@ -99,7 +99,7 @@ object FontFace {
def bold = b(Literal.bold)
def bolder = b(Literal.bolder)
def lighter = b(Literal.lighter)
def normal = b(Literal.normal)
def normal = b(Literal.Typed.normal.value)
}
}

Expand Down
12 changes: 11 additions & 1 deletion core/shared/src/main/scala/scalacss/internal/ValueT.scala
Expand Up @@ -47,6 +47,7 @@ object ValueT {
*/
sealed trait ValueClass

// Note: only ValueClass. Use the implicit rules below in place of subtyping.
sealed trait Integer extends ValueClass
sealed trait Number extends ValueClass
sealed trait Time extends ValueClass
Expand All @@ -61,7 +62,7 @@ object ValueT {
sealed trait WidStyCol extends ValueClass
sealed trait RepeatStyle extends ValueClass
sealed trait OverflowBehaviour extends ValueClass

sealed trait GapStyle extends ValueClass

// =========
// Rules
Expand Down Expand Up @@ -135,6 +136,10 @@ object ValueT {
@inline implicit def ruleRepeatStyle[L <: Literal with LT.RepeatStyle]: RepeatStyle <== L = Rule.literal
@inline implicit def ruleOverflowBehaviour[L <: Literal with LT.OverflowBehaviour]: OverflowBehaviour <== L = Rule.literal

@inline implicit def ruleGapStyle_l[L <: Literal with LT.GapStyle]: GapStyle <== L = Rule.literal
@inline implicit def ruleGapStyle_L: GapStyle <=< Len = Rule.retype
@inline implicit def ruleGapStyle_P: GapStyle <=< Pct = Rule.retype

// diverging implicit expansion requires these ↙ :(
@inline implicit def ruleWidStyCol_L : WidStyCol <=< Len = Rule.retype
@inline implicit def ruleWidStyCol_P : WidStyCol <=< Pct = Rule.retype
Expand Down Expand Up @@ -339,6 +344,11 @@ object ValueT {
final def outset = avl(LT.outset)
}

trait GapStyleOps extends ZeroLit {
this: TypedAttrBase =>
final def normal = avl(LT.normal)
}

trait RepeatStyleOps {
this: TypedAttrBase =>
def repeat : AV = avl(LT.repeat)
Expand Down
57 changes: 30 additions & 27 deletions core/shared/src/main/scala/scalacss/internal/Values.scala
Expand Up @@ -12,42 +12,42 @@ trait TypedLiteralAliases {
import Literal.Typed
import scalacss.internal.Literal.Typed.TimingFunctionDirection

final def inherit = Typed.inherit
final def initial = Typed.initial
final def unset = Typed.unset
final def `0` = Typed.`0`
final def auto = Typed.auto
final def hanging = Typed.hanging
final def eachLine = Typed.eachLine
final def thin = Typed.thin
final def medium = Typed.medium
final def thick = Typed.thick
final def none = Typed.none
final def hidden = Typed.hidden
final def dotted = Typed.dotted
final def contain = Typed.contain
final def cubicBezier(x1: Double, y1: Double, x2: Double, y2: Double) = new Typed.cubicBezier(x1, y1, x2, y2)
final def dashed = Typed.dashed
final def solid = Typed.solid
final def dotted = Typed.dotted
final def double = Typed.double
final def groove = Typed.groove
final def ridge = Typed.ridge
final def inset = Typed.inset
final def outset = Typed.outset
final def start = Typed.start
final def end = Typed.end
final def cubicBezier(x1: Double, y1: Double, x2: Double, y2: Double) = new Typed.cubicBezier(x1, y1, x2, y2)
final def steps(steps: Int, direction: TimingFunctionDirection = end) = new Typed.steps(steps, direction)
final def linear = Typed.linear
final def eachLine = Typed.eachLine
final def ease = Typed.ease
final def easeIn = Typed.easeIn
final def easeInOut = Typed.easeInOut
final def easeOut = Typed.easeOut
final def stepStart = Typed.stepStart
final def stepEnd = Typed.stepEnd
final def end = Typed.end
final def groove = Typed.groove
final def hanging = Typed.hanging
final def hidden = Typed.hidden
final def inherit = Typed.inherit
final def initial = Typed.initial
final def inset = Typed.inset
final def linear = Typed.linear
final def medium = Typed.medium
final def none = Typed.none
final def noRepeat = Typed.noRepeat
final def outset = Typed.outset
final def repeat = Typed.repeat
final def space = Typed.space
final def ridge = Typed.ridge
final def round = Typed.round
final def noRepeat = Typed.noRepeat
final def contain = Typed.contain
final def solid = Typed.solid
final def space = Typed.space
final def start = Typed.start
final def stepEnd = Typed.stepEnd
final def steps(steps: Int, direction: TimingFunctionDirection = end) = new Typed.steps(steps, direction)
final def stepStart = Typed.stepStart
final def thick = Typed.thick
final def thin = Typed.thin
final def unset = Typed.unset
}

/**
Expand Down Expand Up @@ -122,6 +122,10 @@ object Literal extends TypedLiteralAliases {
object stepStart extends Literal("step-start") with TimingFunction
object stepEnd extends Literal("step-end") with TimingFunction

// gap
sealed trait GapStyle
object normal extends Literal("normal") with GapStyle

// Multi-purpose
object none extends Literal("none") with BrStyle with OverflowBehaviour
}
Expand Down Expand Up @@ -248,7 +252,6 @@ object Literal extends TypedLiteralAliases {
def noCloseQuote : Value = "no-close-quote"
def noDrop : Value = "no-drop"
def noOpenQuote : Value = "no-open-quote"
def normal : Value = "normal"
def notAllowed : Value = "not-allowed"
def nowrap : Value = "nowrap"
def nResize : Value = "n-resize"
Expand Down
12 changes: 12 additions & 0 deletions core/shared/src/main/scala/scalacss/internal/generated.scala
Expand Up @@ -812,6 +812,12 @@ abstract class AttrAliasesAndValueTRules extends ValueT.Rules {
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight">MDN</a>
*/
@inline final def fontWeight = Attrs.fontWeight
/**
* The gap CSS property sets the gaps (gutters) between rows and columns. It is a shorthand for row-gap and column-gap.
*
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/gap">MDN</a>
*/
@inline final def gap = Attrs.gap
/**
* @see <a href="http://www.w3.org/TR/css3-grid-layout/#grid-shorthand">css3-grid-layout#grid</a>
*/
Expand Down Expand Up @@ -1390,6 +1396,12 @@ abstract class AttrAliasesAndValueTRules extends ValueT.Rules {
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/right">MDN</a>
*/
@inline final def right = Attrs.right
/**
* The row-gap CSS property sets the size of the gap (gutter) between an element's grid rows.
*
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap">MDN</a>
*/
@inline final def rowGap = Attrs.rowGap
/**
* The ruby-align CSS property defines the distribution of the different ruby elements over the base.
*
Expand Down

0 comments on commit bbb4297

Please sign in to comment.