Skip to content

Commit

Permalink
Move every component into a single Kotlin source file
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreckYe committed Dec 9, 2022
1 parent 8539226 commit 7470ab6
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable

expect /*value*/ class ButtonScope {
@Composable
fun Label(text: String)
}

@Composable
expect fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable

@Composable
expect fun Card(content: @Composable () -> Unit)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable
import com.huanshankeji.compose.material.icon.MaterialIcon

@Composable
expect fun Icon(materialIcon: MaterialIcon)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable

@Composable
expect fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit)
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@ package com.huanshankeji.compose.material
import androidx.compose.runtime.Composable
import com.huanshankeji.compose.material.icon.MaterialIcon

expect /*value*/ class ButtonScope {
@Composable
fun Label(text: String)
}

@Composable
expect fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit)


@Composable
expect fun Card(content: @Composable () -> Unit)


@Composable
expect fun Icon(materialIcon: MaterialIcon)


@Composable
expect fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit)


expect class NavigationIconScope {
@Composable
fun NavButton(onClick: () -> Unit, content: @Composable () -> Unit)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable
import dev.petuska.kmdc.button.Label
import dev.petuska.kmdc.button.MDCButton
import dev.petuska.kmdc.button.MDCButtonScope
import org.w3c.dom.HTMLButtonElement

actual class ButtonScope(val mdcButtonScope: MDCButtonScope<HTMLButtonElement>) {
@Composable
actual fun Label(text: String) =
mdcButtonScope.Label(text)
}

@Composable
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
MDCButton(attrs = { onClick { onClick() } }) { ButtonScope(this).content() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable
import dev.petuska.kmdc.card.MDCCard

@Composable
actual fun Card(content: @Composable () -> Unit) =
MDCCard { content() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable
import com.huanshankeji.compose.material.icon.MaterialIcon
import dev.petuska.kmdcx.icons.MDCIconSpan

/**
* There is often a better alternative of adding the CSS rule to the parent element to using this composable directly.
*/
@Composable
actual fun Icon(materialIcon: MaterialIcon) =
MDCIconSpan(materialIcon.mdcIcon)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable
import dev.petuska.kmdc.icon.button.MDCIconButton

@Composable
actual fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit) =
MDCIconButton(attrs = {
onClick { onClick() }
}) { content() }
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,8 @@ package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable
import com.huanshankeji.compose.material.icon.MaterialIcon
import dev.petuska.kmdc.button.Label
import dev.petuska.kmdc.button.MDCButton
import dev.petuska.kmdc.button.MDCButtonScope
import dev.petuska.kmdc.card.MDCCard
import dev.petuska.kmdc.icon.button.MDCIconButton
import dev.petuska.kmdc.top.app.bar.*
import dev.petuska.kmdcx.icons.MDCIconSpan
import dev.petuska.kmdcx.icons.mdcIcon
import org.jetbrains.compose.web.dom.Text
import org.w3c.dom.HTMLButtonElement

actual class ButtonScope(val mdcButtonScope: MDCButtonScope<HTMLButtonElement>) {
@Composable
actual fun Label(text: String) =
mdcButtonScope.Label(text)
}

@Composable
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
MDCButton(attrs = { onClick { onClick() } }) { ButtonScope(this).content() }


@Composable
actual fun Card(content: @Composable () -> Unit) =
MDCCard { content() }


/**
* There is often a better alternative of adding the CSS rule to the parent element to using this composable directly.
*/
@Composable
actual fun Icon(materialIcon: MaterialIcon) =
MDCIconSpan(materialIcon.mdcIcon)


@Composable
actual fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit) =
MDCIconButton(attrs = {
onClick { onClick() }
}) { content() }


actual class NavigationIconScope(val mdcTopAppBarSectionScope: MDCTopAppBarSectionScope) {
@Composable
Expand All @@ -51,7 +12,7 @@ actual class NavigationIconScope(val mdcTopAppBarSectionScope: MDCTopAppBarSecti

@Composable
actual fun MaterialIconNavButton(onClick: () -> Unit, materialIcon: MaterialIcon) =
mdcTopAppBarSectionScope.NavButton(attrs = { mdcIcon() }) { Text(materialIcon.mdcIcon.type) }
mdcTopAppBarSectionScope.NavButton(attrs = { mdcIcon() }) { org.jetbrains.compose.web.dom.Text(materialIcon.mdcIcon.type) }
}

actual class TopAppBarActionsScope(val mdcTopAppBarSectionScope: MDCTopAppBarSectionScope) {
Expand All @@ -64,7 +25,7 @@ actual class TopAppBarActionsScope(val mdcTopAppBarSectionScope: MDCTopAppBarSec
onClick: () -> Unit,
materialIcon: MaterialIcon
) =
mdcTopAppBarSectionScope.ActionButton(attrs = { mdcIcon() }) { Text(materialIcon.mdcIcon.type) }
mdcTopAppBarSectionScope.ActionButton(attrs = { mdcIcon() }) { org.jetbrains.compose.web.dom.Text(materialIcon.mdcIcon.type) }
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.huanshankeji.compose.material

import androidx.compose.foundation.layout.RowScope
import androidx.compose.runtime.Composable

actual class ButtonScope(val rowScope: RowScope) {
@Composable
actual fun Label(text: String) =
androidx.compose.material.Text(text)
}

@Composable
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
androidx.compose.material.Button(onClick) { ButtonScope(this).content() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable

@Composable
actual fun Card(content: @Composable () -> Unit) =
androidx.compose.material.Card { content() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable
import com.huanshankeji.compose.material.icon.MaterialIcon

@Composable
actual fun Icon(materialIcon: MaterialIcon) =
androidx.compose.material.Icon(materialIcon, null)
// no `contentDescription` for now
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.huanshankeji.compose.material

import androidx.compose.runtime.Composable

@Composable
actual fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit) =
androidx.compose.material.IconButton(onClick = onClick, content = content)
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,10 @@ package com.huanshankeji.compose.material

import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import com.huanshankeji.compose.material.icon.MaterialIcon

actual class ButtonScope(val rowScope: RowScope) {
@Composable
actual fun Label(text: String) =
Text(text)
}

@Composable
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
androidx.compose.material.Button(onClick) { ButtonScope(this).content() }


@Composable
actual fun Card(content: @Composable () -> Unit) =
androidx.compose.material.Card { content() }


@Composable
actual fun Icon(materialIcon: MaterialIcon) =
androidx.compose.material.Icon(materialIcon, null)
// no `contentDescription` for now


@Composable
actual fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit) =
androidx.compose.material.IconButton(onClick = onClick, content = content)


actual class NavigationIconScope private constructor() {
@Composable
actual fun NavButton(onClick: () -> Unit, content: @Composable () -> Unit) =
Expand Down

0 comments on commit 7470ab6

Please sign in to comment.