Skip to content

Commit

Permalink
Change title according to the date picker display mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shivathapaa committed Oct 28, 2024
1 parent 7f4f807 commit 05ef14c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ fun NepaliDatePicker(
title: (@Composable () -> Unit)? = {
NepaliDatePickerDefaults.NepaliDatePickerTitle(
modifier = Modifier.padding(NepaliDatePickerTitlePadding),
language = state.locale.language
language = state.locale.language,
displayMode = state.displayMode
)
},
headline: (@Composable () -> Unit)? = {
NepaliDatePickerDefaults.NepaliDatePickerHeadline(
selectedDate = state.selectedDate,
modifier = Modifier.padding(NepaliDatePickerHeadlinePadding),
locale = state.locale
locale = state.locale,
displayMode = state.displayMode
)
},
showModeToggle: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ fun NepaliDatePickerWithEnglishDate(
title: (@Composable () -> Unit)? = {
NepaliDatePickerDefaults.NepaliDatePickerTitle(
modifier = Modifier.padding(NepaliDatePickerTitlePadding),
language = state.locale.language
language = state.locale.language,
displayMode = state.displayMode
)
},
headline: (@Composable () -> Unit)? = {
Expand All @@ -131,7 +132,8 @@ fun NepaliDatePickerWithEnglishDate(
selectedDate = state.selectedDate,
selectedEnglishDate = state.selectedEnglishDate,
locale = state.locale,
englishLocale = englishDateLocale
englishLocale = englishDateLocale,
displayMode = state.displayMode
)
},
showModeToggle: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ fun NepaliDateRangePicker(
title: (@Composable () -> Unit)? = {
NepaliDatePickerDefaults.NepaliDateRangePickerTitle(
modifier = Modifier.padding(NepaliDateRangePickerTitlePadding),
language = state.locale.language
language = state.locale.language,
displayMode = state.displayMode
)
},
headline: (@Composable () -> Unit)? = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ fun NepaliDateRangePickerWithEnglishDate(
title: (@Composable () -> Unit)? = {
NepaliDatePickerDefaults.NepaliDateRangePickerTitle(
modifier = Modifier.padding(NepaliDateRangePickerTitlePadding),
language = state.locale.language
language = state.locale.language,
displayMode = state.displayMode
)
},
headline: (@Composable () -> Unit)? = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import dev.shivathapaa.nepalidatepickerkmp.DisplayMode
import dev.shivathapaa.nepalidatepickerkmp.NepaliSelectableDates
import dev.shivathapaa.nepalidatepickerkmp.annotations.ExperimentalNepaliDatePickerApi
import dev.shivathapaa.nepalidatepickerkmp.data.CustomCalendar
Expand Down Expand Up @@ -186,27 +187,36 @@ object NepaliDatePickerDefaults {

@Composable
internal fun NepaliDatePickerTitle(
modifier: Modifier = Modifier, language: NepaliDatePickerLang
modifier: Modifier = Modifier, language: NepaliDatePickerLang, displayMode: DisplayMode
) {
Text(
text = language.datePickerTitle,
modifier = modifier
)
when (displayMode) {
DisplayMode.Picker ->
Text(text = language.datePickerTitle, modifier = modifier)

DisplayMode.Input ->
Text(text = language.dateInputTitle, modifier = modifier)
}
}

@Composable
internal fun NepaliDateRangePickerTitle(
modifier: Modifier = Modifier, language: NepaliDatePickerLang
modifier: Modifier = Modifier, language: NepaliDatePickerLang, displayMode: DisplayMode
) {
Text(
text = language.dateRangePickerTitle,
modifier = modifier
)
when (displayMode) {
DisplayMode.Picker ->
Text(text = language.dateRangePickerTitle, modifier = modifier)

DisplayMode.Input ->
Text(text = language.dateRangeInputTitle, modifier = modifier)
}
}

@Composable
internal fun NepaliDatePickerHeadline(
selectedDate: CustomCalendar?, modifier: Modifier = Modifier, locale: NepaliDateLocale
selectedDate: CustomCalendar?,
locale: NepaliDateLocale,
displayMode: DisplayMode,
modifier: Modifier = Modifier
) {
val calendarModel = NepaliCalendarModel(locale)

Expand All @@ -218,7 +228,11 @@ object NepaliDatePickerDefaults {
dayOfWeek = date.dayOfWeek,
locale = locale
)
} ?: locale.language.selectDateText
} ?: if (displayMode == DisplayMode.Input) {
locale.language.writeDateText
} else {
locale.language.selectDateText
}

Text(
text = formattedDate,
Expand All @@ -234,6 +248,7 @@ object NepaliDatePickerDefaults {
selectedEnglishDate: CustomCalendar?,
locale: NepaliDateLocale,
englishLocale: NepaliDateLocale,
displayMode: DisplayMode,
modifier: Modifier = Modifier
) {
val calendarModel = NepaliCalendarModel(locale)
Expand All @@ -246,7 +261,11 @@ object NepaliDatePickerDefaults {
dayOfWeek = date.dayOfWeek,
locale = locale
)
} ?: locale.language.selectDateText
} ?: if (displayMode == DisplayMode.Input) {
locale.language.writeDateText
} else {
locale.language.selectDateText
}


val formattedEnglishDate = selectedEnglishDate?.let { date ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ enum class NepaliDatePickerLang {
override val months: List<NepaliMonthName> = nepaliMonthsInEnglish
override val englishMonths: List<NepaliMonthName> = englishMonthsInEnglish
override val selectDateText: String = "Select Date"
override val writeDateText: String = "Write Date"
override val datePickerTitle: String = "Select Nepali Date"
override val dateInputTitle: String = "Write Nepali Date"
override val dateRangePickerTitle: String = "Select Nepali Dates"
override val dateRangeInputTitle: String = "Write Nepali Dates"
override val cancelText: String = "Cancel"
override val okText: String = "OK"
override val today: String = "TODAY"
Expand All @@ -115,8 +118,11 @@ enum class NepaliDatePickerLang {
override val months: List<NepaliMonthName> = nepaliMonths
override val englishMonths: List<NepaliMonthName> = englishMonthsInNepali
override val selectDateText: String = "मिति चयन गर्नुहोस्"
override val writeDateText: String = "मिति लेख्नुहोस्"
override val datePickerTitle: String = "नेपाली मिति चयन गर्नुहोस्"
override val dateInputTitle: String = "नेपाली मिति लेख्नुहोस्"
override val dateRangePickerTitle: String = "नेपाली मितिहरु चयन गर्नुहोस्"
override val dateRangeInputTitle: String = "नेपाली मितिहरु लेख्नुहोस्"
override val cancelText: String = "रद्द गर्नुहोस्"
override val okText: String = "भयो"
override val today: String = "आज"
Expand All @@ -139,8 +145,11 @@ enum class NepaliDatePickerLang {
abstract val months: List<NepaliMonthName>
abstract val englishMonths: List<NepaliMonthName>
abstract val selectDateText: String
abstract val writeDateText: String
abstract val datePickerTitle: String
abstract val dateInputTitle: String
abstract val dateRangePickerTitle: String
abstract val dateRangeInputTitle: String
abstract val cancelText: String
abstract val okText: String
abstract val today: String
Expand Down

0 comments on commit 05ef14c

Please sign in to comment.