Skip to content

Commit

Permalink
Merge pull request #42 from marosseleng/feature/theme-customization
Browse files Browse the repository at this point in the history
Add support for easier theming.
  • Loading branch information
marosseleng authored Jan 14, 2023
2 parents 8633565 + c9b015c commit 3b37887
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,41 +188,6 @@ public interface DatePickerColors {
public val selectedMonthStroke: DatePickerStroke?
}

public data class DefaultDatePickerColors(
override val weekDayLabelTextColor: Color,
override val previousMonthDayLabelTextColor: Color,
override val previousMonthDayLabelBackgroundColor: Color,
override val previousMonthDayLabelStroke: DatePickerStroke?,
override val nextMonthDayLabelTextColor: Color,
override val nextMonthDayLabelBackgroundColor: Color,
override val nextMonthDayLabelStroke: DatePickerStroke?,
override val monthDayLabelUnselectedTextColor: Color,
override val monthDayLabelUnselectedBackgroundColor: Color,
override val monthDayLabelUnselectedStroke: DatePickerStroke?,
override val monthDayLabelSelectedTextColor: Color,
override val monthDayLabelSelectedBackgroundColor: Color,
override val monthDayLabelSelectedStroke: DatePickerStroke?,
override val monthDayInRangeLabelTextColor: Color,
override val monthDayInRangeBackgroundColor: Color,
override val todayLabelTextColor: Color,
override val todayLabelBackgroundColor: Color,
override val todayStroke: DatePickerStroke,
override val yearMonthTextColor: Color,
override val previousNextMonthIconColor: Color,
override val unselectedYearTextColor: Color,
override val unselectedYearBackgroundColor: Color,
override val unselectedYearStroke: DatePickerStroke?,
override val selectedYearTextColor: Color,
override val selectedYearBackgroundColor: Color,
override val selectedYearStroke: DatePickerStroke?,
override val unselectedMonthTextColor: Color,
override val unselectedMonthBackgroundColor: Color,
override val unselectedMonthStroke: DatePickerStroke?,
override val selectedMonthTextColor: Color,
override val selectedMonthBackgroundColor: Color,
override val selectedMonthStroke: DatePickerStroke?,
) : DatePickerColors

/**
* Simple structure for describing strokes.
*
Expand All @@ -236,38 +201,38 @@ public data class DatePickerStroke(
)

internal val LocalDatePickerColors: ProvidableCompositionLocal<DatePickerColors> = compositionLocalOf {
DefaultDatePickerColors(
weekDayLabelTextColor = Color(0),
previousMonthDayLabelTextColor = Color(0),
previousMonthDayLabelBackgroundColor = Color(0),
previousMonthDayLabelStroke = null,
nextMonthDayLabelTextColor = Color(0),
nextMonthDayLabelBackgroundColor = Color(0),
nextMonthDayLabelStroke = null,
monthDayLabelUnselectedTextColor = Color(0),
monthDayLabelUnselectedBackgroundColor = Color(0),
monthDayLabelUnselectedStroke = null,
monthDayLabelSelectedTextColor = Color(0),
monthDayLabelSelectedBackgroundColor = Color(0),
monthDayLabelSelectedStroke = null,
monthDayInRangeLabelTextColor = Color(0),
monthDayInRangeBackgroundColor = Color(0),
todayLabelTextColor = Color(0),
todayLabelBackgroundColor = Color(0),
todayStroke = DatePickerStroke(0.dp, Color(0)),
yearMonthTextColor = Color(0),
previousNextMonthIconColor = Color(0),
unselectedYearTextColor = Color(0),
unselectedYearBackgroundColor = Color(0),
unselectedYearStroke = null,
selectedYearTextColor = Color(0),
selectedYearBackgroundColor = Color(0),
selectedYearStroke = null,
unselectedMonthTextColor = Color(0),
unselectedMonthBackgroundColor = Color(0),
unselectedMonthStroke = null,
selectedMonthTextColor = Color(0),
selectedMonthBackgroundColor = Color(0),
selectedMonthStroke = null,
)
object : DatePickerColors {
override val weekDayLabelTextColor: Color = Color.Transparent
override val previousMonthDayLabelTextColor: Color = Color.Transparent
override val previousMonthDayLabelBackgroundColor: Color = Color.Transparent
override val previousMonthDayLabelStroke: DatePickerStroke? = null
override val nextMonthDayLabelTextColor: Color = Color.Transparent
override val nextMonthDayLabelBackgroundColor: Color = Color.Transparent
override val nextMonthDayLabelStroke: DatePickerStroke? = null
override val monthDayLabelUnselectedTextColor: Color = Color.Transparent
override val monthDayLabelUnselectedBackgroundColor: Color = Color.Transparent
override val monthDayLabelUnselectedStroke: DatePickerStroke? = null
override val monthDayLabelSelectedTextColor: Color = Color.Transparent
override val monthDayLabelSelectedBackgroundColor: Color = Color.Transparent
override val monthDayLabelSelectedStroke: DatePickerStroke? = null
override val monthDayInRangeLabelTextColor: Color = Color.Transparent
override val monthDayInRangeBackgroundColor: Color = Color.Transparent
override val todayLabelTextColor: Color = Color.Transparent
override val todayLabelBackgroundColor: Color = Color.Transparent
override val todayStroke: DatePickerStroke = DatePickerStroke(thickness = 0.dp, Color.Transparent)
override val yearMonthTextColor: Color = Color.Transparent
override val previousNextMonthIconColor: Color = Color.Transparent
override val unselectedYearTextColor: Color = Color.Transparent
override val unselectedYearBackgroundColor: Color = Color.Transparent
override val unselectedYearStroke: DatePickerStroke? = null
override val selectedYearTextColor: Color = Color.Transparent
override val selectedYearBackgroundColor: Color = Color.Transparent
override val selectedYearStroke: DatePickerStroke? = null
override val unselectedMonthTextColor: Color = Color.Transparent
override val unselectedMonthBackgroundColor: Color = Color.Transparent
override val unselectedMonthStroke: DatePickerStroke? = null
override val selectedMonthTextColor: Color = Color.Transparent
override val selectedMonthBackgroundColor: Color = Color.Transparent
override val selectedMonthStroke: DatePickerStroke? = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp

/**
Expand All @@ -31,73 +33,119 @@ public object DatePickerDefaults {
/**
* Default colors definitions.
*/
public val colors: DatePickerColors
@Composable
@ReadOnlyComposable
get() = DefaultDatePickerColors(
weekDayLabelTextColor = MaterialTheme.colorScheme.onSurface,
previousMonthDayLabelTextColor = MaterialTheme.colorScheme.onSurfaceVariant,
previousMonthDayLabelBackgroundColor = Color.Unspecified,
previousMonthDayLabelStroke = null,
nextMonthDayLabelTextColor = MaterialTheme.colorScheme.onSurfaceVariant,
nextMonthDayLabelBackgroundColor = Color.Unspecified,
nextMonthDayLabelStroke = null,
monthDayLabelUnselectedTextColor = MaterialTheme.colorScheme.onSurface,
monthDayLabelUnselectedBackgroundColor = Color.Unspecified,
monthDayLabelUnselectedStroke = null,
monthDayLabelSelectedTextColor = MaterialTheme.colorScheme.onPrimary,
monthDayLabelSelectedBackgroundColor = MaterialTheme.colorScheme.primary,
monthDayLabelSelectedStroke = null,
monthDayInRangeLabelTextColor = MaterialTheme.colorScheme.onPrimaryContainer,
monthDayInRangeBackgroundColor = MaterialTheme.colorScheme.primaryContainer,
todayLabelTextColor = MaterialTheme.colorScheme.primary,
todayLabelBackgroundColor = Color.Unspecified,
todayStroke = DatePickerStroke(1.dp, MaterialTheme.colorScheme.primary),
yearMonthTextColor = MaterialTheme.colorScheme.onSurface,
previousNextMonthIconColor = MaterialTheme.colorScheme.onSurface,
unselectedYearTextColor = MaterialTheme.colorScheme.onSurfaceVariant,
unselectedYearBackgroundColor = Color.Unspecified,
unselectedYearStroke = null,
selectedYearTextColor = MaterialTheme.colorScheme.onPrimary,
selectedYearBackgroundColor = MaterialTheme.colorScheme.primary,
selectedYearStroke = null,
unselectedMonthTextColor = MaterialTheme.colorScheme.onSurfaceVariant,
unselectedMonthBackgroundColor = Color.Unspecified,
unselectedMonthStroke = null,
selectedMonthTextColor = MaterialTheme.colorScheme.onPrimary,
selectedMonthBackgroundColor = MaterialTheme.colorScheme.primary,
selectedMonthStroke = null,
)
@Composable
@ReadOnlyComposable
public fun colors(
weekDayLabelTextColor: Color = MaterialTheme.colorScheme.onSurface,
previousMonthDayLabelTextColor: Color = MaterialTheme.colorScheme.onSurfaceVariant,
previousMonthDayLabelBackgroundColor: Color = Color.Unspecified,
previousMonthDayLabelStroke: DatePickerStroke? = null,
nextMonthDayLabelTextColor: Color = MaterialTheme.colorScheme.onSurfaceVariant,
nextMonthDayLabelBackgroundColor: Color = Color.Unspecified,
nextMonthDayLabelStroke: DatePickerStroke? = null,
monthDayLabelUnselectedTextColor: Color = MaterialTheme.colorScheme.onSurface,
monthDayLabelUnselectedBackgroundColor: Color = Color.Unspecified,
monthDayLabelUnselectedStroke: DatePickerStroke? = null,
monthDayLabelSelectedTextColor: Color = MaterialTheme.colorScheme.onPrimary,
monthDayLabelSelectedBackgroundColor: Color = MaterialTheme.colorScheme.primary,
monthDayLabelSelectedStroke: DatePickerStroke? = null,
monthDayInRangeLabelTextColor: Color = MaterialTheme.colorScheme.onPrimaryContainer,
monthDayInRangeBackgroundColor: Color = MaterialTheme.colorScheme.primaryContainer,
todayLabelTextColor: Color = MaterialTheme.colorScheme.primary,
todayLabelBackgroundColor: Color = Color.Unspecified,
todayStroke: DatePickerStroke = DatePickerStroke(1.dp, MaterialTheme.colorScheme.primary),
yearMonthTextColor: Color = MaterialTheme.colorScheme.onSurface,
previousNextMonthIconColor: Color = MaterialTheme.colorScheme.onSurface,
unselectedYearTextColor: Color = MaterialTheme.colorScheme.onSurfaceVariant,
unselectedYearBackgroundColor: Color = Color.Unspecified,
unselectedYearStroke: DatePickerStroke? = null,
selectedYearTextColor: Color = MaterialTheme.colorScheme.onPrimary,
selectedYearBackgroundColor: Color = MaterialTheme.colorScheme.primary,
selectedYearStroke: DatePickerStroke? = null,
unselectedMonthTextColor: Color = MaterialTheme.colorScheme.onSurfaceVariant,
unselectedMonthBackgroundColor: Color = Color.Unspecified,
unselectedMonthStroke: DatePickerStroke? = null,
selectedMonthTextColor: Color = MaterialTheme.colorScheme.onPrimary,
selectedMonthBackgroundColor: Color = MaterialTheme.colorScheme.primary,
selectedMonthStroke: DatePickerStroke? = null,
): DatePickerColors = object : DatePickerColors {
override val weekDayLabelTextColor = weekDayLabelTextColor
override val previousMonthDayLabelTextColor = previousMonthDayLabelTextColor
override val previousMonthDayLabelBackgroundColor = previousMonthDayLabelBackgroundColor
override val previousMonthDayLabelStroke = previousMonthDayLabelStroke
override val nextMonthDayLabelTextColor = nextMonthDayLabelTextColor
override val nextMonthDayLabelBackgroundColor = nextMonthDayLabelBackgroundColor
override val nextMonthDayLabelStroke = nextMonthDayLabelStroke
override val monthDayLabelUnselectedTextColor = monthDayLabelUnselectedTextColor
override val monthDayLabelUnselectedBackgroundColor = monthDayLabelUnselectedBackgroundColor
override val monthDayLabelUnselectedStroke = monthDayLabelUnselectedStroke
override val monthDayLabelSelectedTextColor = monthDayLabelSelectedTextColor
override val monthDayLabelSelectedBackgroundColor = monthDayLabelSelectedBackgroundColor
override val monthDayLabelSelectedStroke = monthDayLabelSelectedStroke
override val monthDayInRangeLabelTextColor = monthDayInRangeLabelTextColor
override val monthDayInRangeBackgroundColor = monthDayInRangeBackgroundColor
override val todayLabelTextColor = todayLabelTextColor
override val todayLabelBackgroundColor = todayLabelBackgroundColor
override val todayStroke = todayStroke
override val yearMonthTextColor = yearMonthTextColor
override val previousNextMonthIconColor = previousNextMonthIconColor
override val unselectedYearTextColor = unselectedYearTextColor
override val unselectedYearBackgroundColor = unselectedYearBackgroundColor
override val unselectedYearStroke = unselectedYearStroke
override val selectedYearTextColor = selectedYearTextColor
override val selectedYearBackgroundColor = selectedYearBackgroundColor
override val selectedYearStroke = selectedYearStroke
override val unselectedMonthTextColor = unselectedMonthTextColor
override val unselectedMonthBackgroundColor = unselectedMonthBackgroundColor
override val unselectedMonthStroke = unselectedMonthStroke
override val selectedMonthTextColor = selectedMonthTextColor
override val selectedMonthBackgroundColor = selectedMonthBackgroundColor
override val selectedMonthStroke = selectedMonthStroke
}

/**
* Default shapes definitions.
*/
public val shapes: DatePickerShapes
@Composable
@ReadOnlyComposable
get() = DefaultDatePickerShapes(
previousMonthDay = CircleShape,
currentMonthDaySelected = CircleShape,
currentMonthDayToday = CircleShape,
currentMonthDayUnselected = CircleShape,
nextMonthDay = CircleShape,
year = RoundedCornerShape(percent = 50),
month = RoundedCornerShape(percent = 50),
)
@Composable
@ReadOnlyComposable
public fun shapes(
previousMonthDay: Shape = CircleShape,
currentMonthDaySelected: Shape = CircleShape,
currentMonthDayToday: Shape = CircleShape,
currentMonthDayUnselected: Shape = CircleShape,
nextMonthDay: Shape = CircleShape,
year: Shape = RoundedCornerShape(percent = 50),
month: Shape = RoundedCornerShape(percent = 50),
): DatePickerShapes = object : DatePickerShapes {
override val previousMonthDay = previousMonthDay
override val currentMonthDaySelected = currentMonthDaySelected
override val currentMonthDayToday = currentMonthDayToday
override val currentMonthDayUnselected = currentMonthDayUnselected
override val nextMonthDay = nextMonthDay
override val year = year
override val month = month
}

/**
* Default typography definitions.
*/
public val typography: DatePickerTypography
@Composable
@ReadOnlyComposable
get() = DefaultDatePickerTypography(
dialogSingleSelectionTitle = MaterialTheme.typography.labelMedium,
headlineSingleSelection = MaterialTheme.typography.headlineLarge,
weekDay = MaterialTheme.typography.bodySmall,
day = MaterialTheme.typography.bodySmall,
monthYear = MaterialTheme.typography.labelLarge,
year = MaterialTheme.typography.bodyLarge,
month = MaterialTheme.typography.bodyLarge,
)
@Composable
@ReadOnlyComposable
public fun typography(
dialogSingleSelectionTitle: TextStyle = MaterialTheme.typography.labelMedium,
headlineSingleSelection: TextStyle = MaterialTheme.typography.headlineLarge,
weekDay: TextStyle = MaterialTheme.typography.bodySmall,
day: TextStyle = MaterialTheme.typography.bodySmall,
monthYear: TextStyle = MaterialTheme.typography.labelLarge,
year: TextStyle = MaterialTheme.typography.bodyLarge,
month: TextStyle = MaterialTheme.typography.bodyLarge,
): DatePickerTypography = object : DatePickerTypography {
override val dialogSingleSelectionTitle = dialogSingleSelectionTitle
override val headlineSingleSelection = headlineSingleSelection
override val weekDay = weekDay
override val day = day
override val monthYear = monthYear
override val year = year
override val month = month
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package com.marosseleng.compose.material3.datetimepickers.date.domain

import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CutCornerShape
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp

/**
* Interface describing shapes used in DatePicker.
Expand Down Expand Up @@ -61,24 +62,14 @@ public interface DatePickerShapes {
public val month: Shape
}

internal data class DefaultDatePickerShapes(
override val previousMonthDay: Shape,
override val currentMonthDaySelected: Shape,
override val currentMonthDayToday: Shape,
override val currentMonthDayUnselected: Shape,
override val nextMonthDay: Shape,
override val year: Shape,
override val month: Shape,
) : DatePickerShapes

internal val LocalDatePickerShapes: ProvidableCompositionLocal<DatePickerShapes> = compositionLocalOf {
DefaultDatePickerShapes(
previousMonthDay = CircleShape,
currentMonthDaySelected = CircleShape,
currentMonthDayToday = CircleShape,
currentMonthDayUnselected = CircleShape,
nextMonthDay = CircleShape,
year = CircleShape,
month = CircleShape,
)
object : DatePickerShapes {
override val previousMonthDay: Shape = CutCornerShape(4.dp)
override val currentMonthDaySelected: Shape = CutCornerShape(4.dp)
override val currentMonthDayToday: Shape = CutCornerShape(4.dp)
override val currentMonthDayUnselected: Shape = CutCornerShape(4.dp)
override val nextMonthDay: Shape = CutCornerShape(4.dp)
override val year: Shape = CutCornerShape(4.dp)
override val month: Shape = CutCornerShape(4.dp)
}
}
Loading

0 comments on commit 3b37887

Please sign in to comment.