Sean Keane
06/03/2022, 9:16 PMStyleSheet
from Styled CSS to Emotion CSS.
Example:
object Main : StyleSheet("MainStyle") {
val headingBoldGrey by css {
color = Colors.darkGrey
+Font.quicksandBold
fontSize = titleFontSizeMobile
}
}
}
What would be the best way to convert something like this?turansky
06/03/2022, 9:23 PMemotion.css.css
function will return you ClassName
if you need it directly
cc @Sergei GrishchenkoSean Keane
06/04/2022, 12:52 AMturansky
06/04/2022, 1:49 AMimport emotion.css.css
object Main {
val headingBoldGrey:ClassName = css {
color = Colors.darkGrey
fontSize = titleFontSizeMobile
}
}
}
turansky
06/04/2022, 2:09 AMemotion.styled.styled
will be fine solution for you 🙂Sean Keane
06/04/2022, 4:41 PMturansky
06/04/2022, 4:44 PMinline fun ClassName(
crossinline block: PropertiesBuilder.() -> Unit,
): ClassName =
emotion.css.css(jso(block))
turansky
06/04/2022, 4:45 PMturansky
06/04/2022, 4:46 PMemotion.css
Sean Keane
06/04/2022, 5:18 PMval heading = ClassName {
display = Display.flex
flexDirection = FlexDirection.row
whiteSpace = WhiteSpace.pre
alignItems = AlignItems.center
+Font.quickSandRegular
fontSize = font_medium
+desktopHeadingFontSize
}
val titleGrey = ClassName {
+heading
color = Colors.darkGrey
}
In styled
it was done with a plus but I'm getting errors on the +
?turansky
06/04/2022, 5:19 PMcx
for class names mergeSean Keane
06/04/2022, 5:20 PMturansky
06/04/2022, 5:20 PMturansky
06/04/2022, 5:21 PMcss
extension with “base” class namesSean Keane
06/04/2022, 5:21 PMval heading = ClassName {
display = Display.flex
flexDirection = FlexDirection.row
whiteSpace = WhiteSpace.pre
alignItems = AlignItems.center
+Font.quickSandRegular
fontSize = font_medium
cx(desktopHeadingFontSize)
}
Sean Keane
06/04/2022, 5:21 PMturansky
06/04/2022, 5:23 PMClassName
:
inline fun ClassName(
vararg classNames: ClassName?,
crossinline block: PropertiesBuilder.() -> Unit,
): ClassName =
// impl (css + cx)
turansky
06/04/2022, 5:24 PMSean Keane
06/04/2022, 5:26 PM+
operator on the cx
function so it would autocorrect globally?
example:
val titleGrey = ClassName {
+heading
color = Colors.darkGrey
}
turansky
06/04/2022, 5:33 PM+
usagesturansky
06/04/2022, 5:37 PM+heading
will require additional runtime, which we don’t wantSean Keane
06/04/2022, 6:09 PMturansky
06/04/2022, 6:11 PMClassName
factories are fine for you - probably we will mark them as public
turansky
06/05/2022, 12:54 PMSean Keane
06/05/2022, 2:07 PMSean Keane
06/05/2022, 2:12 PMmedia
tags in emotion kotlin?turansky
06/06/2022, 8:43 PMpre.342
turansky
06/06/2022, 8:43 PMHow do we deal withDo you mean media queries?tags in emotion kotlin?media
aerialist
06/06/2022, 8:58 PMSean Keane
06/07/2022, 12:05 AMDirk
06/10/2022, 3:47 PMSergei Grishchenko
06/10/2022, 6:19 PMDirk
06/11/2022, 6:05 PMprivate val footer_inner = ClassName {
display = Display.flex
flexDirection = FlexDirection.columnReverse
....
"@media (min-width: 48em)" {
flexDirection = FlexDirection.row
justifyContent = JustifyContent.spaceBetween
paddingBottom = 4.2.rem
paddingTop = 4.2.rem
}
}
Sergei Grishchenko
06/12/2022, 2:08 PMuseMediaQuery
from MUI wraps this API and returns boolean flag that indicates if query is applicable or not.
But I guess, it is not what you are looking for 🙂
Let's do next thing, you will write CSS code you want to implement and will try to help writing the same one but in Kotlin + EmotionSergei Grishchenko
06/12/2022, 2:10 PMSean Keane
06/20/2022, 10:41 AMval common = ClassName(Font.quicksandBold) {
borderStyle = BorderStyle.none
transition(duration = 0.3.s)
focus {
outline = Outline.none
}
hover {
boxShadow += BoxShadow(
false,
dropShadow_xs,
dropShadow_s,
dropShadow_sm,
-dropShadow_s,
Colors.hoverShadowButton.darken(small_shadow_percentage)
)
transform {
scale(small_scale)
}
}
active {
boxShadow += BoxShadow(
false,
dropShadow_xxs,
dropShadow_xs,
dropShadow_s,
dropShadow_xxs,
color = Colors.hoverShadowButton.darken(xsmall_percentage)
)
transform {
scale(xsmall_scale)
}
}
}
Florent Martin
06/28/2022, 7:23 PMval heading = ClassName {
display = Display.flex
flexDirection = FlexDirection.row
whiteSpace = WhiteSpace.pre
alignItems = AlignItems.center
+Font.quickSandRegular
fontSize = font_medium
+desktopHeadingFontSize
}
@turansky Is it possible to also get the name of the class in the html markup? Right now i am getting something like class=“uqqe9” but i want:
div class="heading"
Florent Martin
06/29/2022, 7:03 AMinline fun ClassName(
crossinline block: PropertiesBuilder.() -> Unit,
): ClassName =
emotion.css.css(jso(block))
@turansky are you re-pasting this in every component which needds it?
Are there advantages using emotion vs. MUI or do you use both?turansky
06/29/2022, 8:17 AMAre there advantages using emotion vs. MUI or do you use both?I use
emotion
In case of MUI recommended ‘CSS in JS’ engine - emotion
- we use it in our examplesturansky
06/29/2022, 8:27 AMIs it possible to also get the name of the class in the html markup?We know only about this option - https://emotion.sh/docs/labels (check required) Will it work for you? Or you need exact name?
Florent Martin
06/29/2022, 10:41 AMFlorent Martin
06/30/2022, 10:48 AMClassName(Font.quicksandBold) {
active {
...
Sean Keane
07/01/2022, 3:08 PMSean Keane
07/01/2022, 3:09 PMFlorent Martin
07/01/2022, 3:39 PMFlorent Martin
07/01/2022, 3:41 PMcss {
width = 100.pct
color = Color("#FFF")
"&.active" {
color = Color("green")
Sean Keane
08/10/2022, 5:07 PMjs {
browser {
commonWebpackConfig {
cssSupport {
enabled = true
}
}
runTask {
cssSupport {
enabled = true
}
}
}
binaries.executable()
}
Am I missing something here?
I also get an IR error when compiling with IR... So swapped to legacy for now.Sean Keane
08/11/2022, 3:50 AMcss {
cx(OverviewStyles.heading)
}
Do this:
css(OverviewStyles.heading){}