Skip to content

Commit

Permalink
Merge pull request #71 from mori-atsushi/refactor
Browse files Browse the repository at this point in the history
Refactor component style builders
  • Loading branch information
mori-atsushi authored Jan 4, 2024
2 parents 5433dc8 + b7f332c commit 97b833a
Show file tree
Hide file tree
Showing 31 changed files with 211 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package com.moriatsushi.compose.stylesheet.appbar

import androidx.compose.runtime.Immutable
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.content.ContentStyle

/**
* A style for [TopAppBar].
*/
@Immutable
sealed interface TopAppBarStyle : ComponentStyle {
sealed interface TopAppBarStyle {
val layout: TopAppBarLayout
val contentStyle: ContentStyle
val commonStyle: ComponentCommonStyle

companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.moriatsushi.compose.stylesheet.appbar

import com.moriatsushi.compose.stylesheet.component.ComponentStyleBuilder
import com.moriatsushi.compose.stylesheet.StyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleHelper
import com.moriatsushi.compose.stylesheet.content.ContentStyleBuilder

/**
* A builder for [TopAppBarStyle].
*/
class TopAppBarStyleBuilder internal constructor() : ComponentStyleBuilder<TopAppBarStyle>() {
class TopAppBarStyleBuilder internal constructor(
private val commonStyleHelper: ComponentCommonStyleHelper = ComponentCommonStyleHelper(),
) : StyleBuilder<TopAppBarStyle>, ComponentCommonStyleBuilder by commonStyleHelper {
/**
* A layout of the top app bar.
*/
Expand All @@ -25,7 +29,7 @@ class TopAppBarStyleBuilder internal constructor() : ComponentStyleBuilder<TopAp

override fun build(): TopAppBarStyle = TopAppBarStyle(
layout = layout.build(),
commonStyle = buildCommonStyle(),
commonStyle = commonStyleHelper.buildCommonStyle(),
contentStyle = content.build(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.moriatsushi.compose.stylesheet.button

import androidx.compose.runtime.Immutable
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.content.ContentStyle

/**
* A style for each [Button] state, such as pressed, focused, etc.
*/
@Immutable
sealed interface ButtonStateStyle : ComponentStyle {
sealed interface ButtonStateStyle {
val contentStyle: ContentStyle
val commonStyle: ComponentCommonStyle

companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package com.moriatsushi.compose.stylesheet.button

import com.moriatsushi.compose.stylesheet.StyleSheetBuilderMarker
import com.moriatsushi.compose.stylesheet.component.ComponentStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleHelper
import com.moriatsushi.compose.stylesheet.content.ContentStyleBuilder

/**
* A builder for [ButtonStateStyle].
*/
@StyleSheetBuilderMarker
class ButtonStateStyleBuilder internal constructor() : ComponentStyleBuilder<ButtonStateStyle>() {
class ButtonStateStyleBuilder internal constructor(
private val commonStyleHelper: ComponentCommonStyleHelper = ComponentCommonStyleHelper(),
) : ComponentCommonStyleBuilder by commonStyleHelper {
/**
* A content style.
*/
val content: ContentStyleBuilder = ContentStyleBuilder()

override fun plusAssign(other: ButtonStateStyle) {
operator fun plusAssign(other: ButtonStateStyle) {
this += other.commonStyle
content += other.contentStyle
}
Expand All @@ -23,8 +26,8 @@ class ButtonStateStyleBuilder internal constructor() : ComponentStyleBuilder<But
builder()
}

override fun build(): ButtonStateStyle = ButtonStateStyle(
commonStyle = buildCommonStyle(),
fun build(): ButtonStateStyle = ButtonStateStyle(
commonStyle = commonStyleHelper.buildCommonStyle(),
contentStyle = content.build(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package com.moriatsushi.compose.stylesheet.button

import androidx.compose.runtime.Immutable
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.content.ContentStyle
import com.moriatsushi.compose.stylesheet.indication.IndicationStyle

/**
* A style for [Button].
*/
@Immutable
sealed interface ButtonStyle : ComponentStyle {
sealed interface ButtonStyle {
val layout: ButtonLayout
val indication: IndicationStyle?
val commonStyle: ComponentCommonStyle
val contentStyle: ContentStyle
val pressedStyle: ButtonStateStyle
val hoveredStyle: ButtonStateStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.moriatsushi.compose.stylesheet.button

import com.moriatsushi.compose.stylesheet.StyleBuilder
import com.moriatsushi.compose.stylesheet.StyleSheetBuilderMarker
import com.moriatsushi.compose.stylesheet.component.ComponentStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleHelper
import com.moriatsushi.compose.stylesheet.content.ContentStyleBuilder
import com.moriatsushi.compose.stylesheet.indication.IndicationSetter

/**
* A builder for [ButtonStyle].
*/
@StyleSheetBuilderMarker
class ButtonStyleBuilder internal constructor() : ComponentStyleBuilder<ButtonStyle>() {
class ButtonStyleBuilder internal constructor(
private val commonStyleHelper: ComponentCommonStyleHelper = ComponentCommonStyleHelper(),
) : StyleBuilder<ButtonStyle>, ComponentCommonStyleBuilder by commonStyleHelper {
/**
* A layout of the button.
*/
Expand Down Expand Up @@ -66,7 +70,7 @@ class ButtonStyleBuilder internal constructor() : ComponentStyleBuilder<ButtonSt
override fun build(): ButtonStyle = ButtonStyle(
layout = layout.build(),
indication = indication.value,
commonStyle = buildCommonStyle(),
commonStyle = commonStyleHelper.buildCommonStyle(),
contentStyle = content.build(),
pressedStyle = pressed.build(),
hoveredStyle = hovered.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.moriatsushi.compose.stylesheet.button
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.token.Token

/**
* A style for each [IconButton] state, such as pressed, focused, etc.
*/
@Immutable
sealed interface IconButtonStateStyle : ComponentStyle {
sealed interface IconButtonStateStyle {
val color: Token<Color>?
val commonStyle: ComponentCommonStyle

companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ package com.moriatsushi.compose.stylesheet.button

import androidx.compose.ui.graphics.Color
import com.moriatsushi.compose.stylesheet.StyleSheetBuilderMarker
import com.moriatsushi.compose.stylesheet.component.ComponentStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleHelper
import com.moriatsushi.compose.stylesheet.token.TokenSetter

/**
* A builder for [IconButtonStateStyle].
*/
@StyleSheetBuilderMarker
class IconButtonStateStyleBuilder internal constructor() :
ComponentStyleBuilder<IconButtonStateStyle>() {
class IconButtonStateStyleBuilder internal constructor(
private val commonStyleHelper: ComponentCommonStyleHelper = ComponentCommonStyleHelper(),
) : ComponentCommonStyleBuilder by commonStyleHelper {

/**
* A color of the icon.
*/
val color = TokenSetter<Color>()

override fun plusAssign(other: IconButtonStateStyle) {
operator fun plusAssign(other: IconButtonStateStyle) {
color += other.color
this += other.commonStyle
}
Expand All @@ -31,8 +33,8 @@ class IconButtonStateStyleBuilder internal constructor() :
builder()
}

override fun build(): IconButtonStateStyle = IconButtonStateStyle(
fun build(): IconButtonStateStyle = IconButtonStateStyle(
color = color.token,
commonStyle = buildCommonStyle(),
commonStyle = commonStyleHelper.buildCommonStyle(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package com.moriatsushi.compose.stylesheet.button
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.indication.IndicationStyle
import com.moriatsushi.compose.stylesheet.token.Token

/**
* A style for [IconButton].
*/
@Immutable
sealed interface IconButtonStyle : ComponentStyle {
sealed interface IconButtonStyle {
val color: Token<Color>?
val indication: IndicationStyle?
val commonStyle: ComponentCommonStyle
val pressedStyle: IconButtonStateStyle
val hoveredStyle: IconButtonStateStyle
val focusedStyle: IconButtonStateStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.moriatsushi.compose.stylesheet.button

import androidx.compose.ui.graphics.Color
import com.moriatsushi.compose.stylesheet.StyleBuilder
import com.moriatsushi.compose.stylesheet.StyleSheetBuilderMarker
import com.moriatsushi.compose.stylesheet.component.ComponentStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleHelper
import com.moriatsushi.compose.stylesheet.indication.IndicationSetter
import com.moriatsushi.compose.stylesheet.token.TokenSetter

/**
* A builder for [IconButtonStyle].
*/
@StyleSheetBuilderMarker
class IconButtonStyleBuilder internal constructor() : ComponentStyleBuilder<IconButtonStyle>() {
class IconButtonStyleBuilder internal constructor(
private val commonStyleHelper: ComponentCommonStyleHelper = ComponentCommonStyleHelper(),
) : StyleBuilder<IconButtonStyle>, ComponentCommonStyleBuilder by commonStyleHelper {
/**
* A color of the icon.
*/
Expand Down Expand Up @@ -61,7 +65,7 @@ class IconButtonStyleBuilder internal constructor() : ComponentStyleBuilder<Icon
override fun build(): IconButtonStyle = IconButtonStyle(
color = color.token,
indication = indication.value,
commonStyle = buildCommonStyle(),
commonStyle = commonStyleHelper.buildCommonStyle(),
pressedStyle = pressed.build(),
hoveredStyle = hovered.build(),
focusedStyle = focused.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.token.Token

/**
* A style for [Divider].
*/
@Immutable
sealed interface DividerStyle : ComponentStyle {
sealed interface DividerStyle {
val thickness: Token<Dp>?
val color: Token<Color>?
val orientation: DividerOrientation?
val commonStyle: ComponentCommonStyle

companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package com.moriatsushi.compose.stylesheet.divider

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import com.moriatsushi.compose.stylesheet.StyleBuilder
import com.moriatsushi.compose.stylesheet.StyleBuilder.ValueSetter
import com.moriatsushi.compose.stylesheet.StyleSheetBuilderMarker
import com.moriatsushi.compose.stylesheet.component.ComponentStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleHelper
import com.moriatsushi.compose.stylesheet.token.TokenSetter

/**
* A builder for [DividerStyle].
*/
@StyleSheetBuilderMarker
class DividerStyleBuilder internal constructor() : ComponentStyleBuilder<DividerStyle>() {
class DividerStyleBuilder internal constructor(
private val commonStyleHelper: ComponentCommonStyleHelper = ComponentCommonStyleHelper(),
) : StyleBuilder<DividerStyle>, ComponentCommonStyleBuilder by commonStyleHelper {
/**
* A thickness of the divider.
*/
Expand All @@ -38,6 +42,6 @@ class DividerStyleBuilder internal constructor() : ComponentStyleBuilder<Divider
thickness = thickness.token,
color = color.token,
orientation = orientation.value,
commonStyle = buildCommonStyle(),
commonStyle = commonStyleHelper.buildCommonStyle(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.token.Token

/**
* A style for [Icon].
*/
@Stable
sealed interface IconStyle : ComponentStyle {
sealed interface IconStyle {
val color: Token<Color>?
val commonStyle: ComponentCommonStyle

companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.moriatsushi.compose.stylesheet.icon

import androidx.compose.ui.graphics.Color
import com.moriatsushi.compose.stylesheet.StyleBuilder
import com.moriatsushi.compose.stylesheet.StyleSheetBuilderMarker
import com.moriatsushi.compose.stylesheet.component.ComponentStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleBuilder
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyleHelper
import com.moriatsushi.compose.stylesheet.token.TokenSetter

/**
* A builder for [IconStyle].
*/
@StyleSheetBuilderMarker
class IconStyleBuilder internal constructor() : ComponentStyleBuilder<IconStyle>() {
class IconStyleBuilder internal constructor(
private val commonStyleHelper: ComponentCommonStyleHelper = ComponentCommonStyleHelper(),
) : StyleBuilder<IconStyle>, ComponentCommonStyleBuilder by commonStyleHelper {
/**
* A tint color.
*/
Expand All @@ -21,7 +25,7 @@ class IconStyleBuilder internal constructor() : ComponentStyleBuilder<IconStyle>
}

override fun build(): IconStyle = IconStyle(
commonStyle = buildCommonStyle(),
commonStyle = commonStyleHelper.buildCommonStyle(),
color = color.token,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.moriatsushi.compose.stylesheet.surface
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import com.moriatsushi.compose.stylesheet.component.ComponentCommonStyle
import com.moriatsushi.compose.stylesheet.component.ComponentStyle
import com.moriatsushi.compose.stylesheet.content.ContentStyle

/**
* A style for [Surface].
*/
@Stable
sealed interface SurfaceStyle : ComponentStyle {
sealed interface SurfaceStyle {
val commonStyle: ComponentCommonStyle
val contentStyle: ContentStyle

companion object {
Expand Down
Loading

0 comments on commit 97b833a

Please sign in to comment.