Skip to content

Commit e9d6955

Browse files
fix: prettier
1 parent f4e18db commit e9d6955

File tree

6 files changed

+75
-77
lines changed

6 files changed

+75
-77
lines changed

src/Date/DatePickerModalContentHeader.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export default function DatePickerModalContentHeader(
7676
? theme.fonts.labelMedium
7777
: (theme as any as MD2Theme).fonts.medium
7878

79+
const collapsedIcon = theme.isV3 ? 'pencil-outline' : 'pencil'
80+
const expandedIcon = theme.isV3 ? 'calendar-blank' : 'calendar'
81+
const finalCollapsedIcon = editIcon ?? collapsedIcon
82+
const finalExpandedIcon = calendarIcon ?? expandedIcon
7983
return (
8084
<View style={styles.header}>
8185
<View>
@@ -104,15 +108,7 @@ export default function DatePickerModalContentHeader(
104108
<View style={styles.fill} />
105109
{isEditingEnabled ? (
106110
<IconButton
107-
icon={
108-
collapsed
109-
? editIcon ?? theme.isV3
110-
? 'pencil-outline'
111-
: 'pencil'
112-
: calendarIcon ?? theme.isV3
113-
? 'calendar-blank'
114-
: 'calendar'
115-
}
111+
icon={collapsed ? finalCollapsedIcon : finalExpandedIcon}
116112
accessibilityLabel={
117113
collapsed
118114
? getTranslation(props.locale, 'typeInDate')
@@ -217,16 +213,10 @@ export function HeaderContentRange({
217213
}, [locale])
218214

219215
const lighterColor = Color(color).fade(0.5).rgb().toString()
220-
const startColor = state.startDate
221-
? theme.isV3
222-
? theme.colors.onSurface
223-
: color
224-
: lighterColor
225-
const endColor = state.endDate
226-
? theme.isV3
227-
? theme.colors.onSurface
228-
: color
229-
: lighterColor
216+
const startColorFilled = theme.isV3 ? theme.colors.onSurface : color
217+
const endColorFilled = theme.isV3 ? theme.colors.onSurface : color
218+
const startColor = state.startDate ? startColorFilled : lighterColor
219+
const endColor = state.endDate ? endColorFilled : lighterColor
230220

231221
return (
232222
<>

src/Date/Day.tsx

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,44 @@ function Day(props: {
4747
onPressDate(new Date(year, month, day))
4848
}, [onPressDate, year, month, day])
4949

50-
const borderColor = theme.isV3
51-
? theme.colors.primary
52-
: selected || (inRange && theme.dark)
50+
// const borderColorV3 =
51+
const borderColorFallback = theme.dark ? '#fff' : '#000'
52+
const selectedOrInRangeDarkMode = selected || (inRange && theme.dark)
53+
const v2BorderColor = selectedOrInRangeDarkMode
5354
? textColorOnPrimary
54-
: theme.dark
55-
? '#fff'
56-
: '#000'
55+
: borderColorFallback
56+
const borderColor = theme.isV3 ? theme.colors.primary : v2BorderColor
5757

58-
const textColor =
59-
theme.isV3 && selected
60-
? theme.colors.onPrimary
61-
: theme.isV3 && inRange && theme.dark
62-
? theme.colors.onPrimaryContainer
63-
: selected || (inRange && theme.dark)
64-
? textColorOnPrimary
65-
: theme.isV3
66-
? theme.colors.onSurface
67-
: undefined
58+
// TODO: check if this can be simplified
59+
// converted with Chat-GPT for now from enormous conditional to if-else
60+
let baseTextColor
61+
let finalTextColor
62+
63+
if (theme.isV3) {
64+
// Theme V3 specific logic for base text color
65+
if (selected) {
66+
baseTextColor = theme.colors.onPrimary
67+
} else if (inRange && theme.dark) {
68+
baseTextColor = theme.colors.onPrimaryContainer
69+
} else {
70+
baseTextColor = theme.colors.onSurface
71+
}
72+
73+
// Theme V3 specific logic for final text color
74+
if (isToday) {
75+
finalTextColor = selected ? baseTextColor : theme.colors.primary
76+
} else {
77+
finalTextColor = baseTextColor
78+
}
79+
} else {
80+
// Logic for themes other than V3
81+
if (selected || (inRange && theme.dark)) {
82+
baseTextColor = textColorOnPrimary
83+
}
84+
// Since there's no additional logic provided for non-V3 themes in the step 2,
85+
// the final text color for non-V3 themes will simply be the base text color.
86+
finalTextColor = baseTextColor
87+
}
6888

6989
let textFont = theme?.isV3
7090
? theme.fonts.bodySmall
@@ -99,14 +119,9 @@ function Day(props: {
99119
<Text
100120
maxFontSizeMultiplier={1.5}
101121
style={[
102-
textColor
122+
baseTextColor
103123
? {
104-
color:
105-
theme.isV3 && isToday && selected
106-
? textColor
107-
: theme.isV3 && isToday
108-
? theme.colors.primary
109-
: textColor,
124+
color: finalTextColor,
110125
}
111126
: undefined,
112127
{ ...textFont },

src/Date/Month.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
254254
? theme.fonts.titleSmall
255255
: (theme as any as MD2Theme).fonts.medium
256256

257+
const iconColor = theme.isV3
258+
? theme.colors.onSurfaceVariant
259+
: theme.colors.onSurface
260+
261+
const iconSourceV3 = selectingYear ? 'menu-up' : 'menu-down'
262+
const iconSourceV2 = selectingYear ? 'chevron-up' : 'chevron-down'
263+
const iconSource = theme.isV3 ? iconSourceV3 : iconSourceV2
264+
257265
return (
258266
<View style={[styles.month, { height: getMonthHeight(scrollMode, index) }]}>
259267
<View
@@ -305,24 +313,10 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
305313
<View
306314
style={[
307315
styles.iconWrapper,
308-
isHorizontal ? styles.opacity1 : styles.opacity0
316+
isHorizontal ? styles.opacity1 : styles.opacity0,
309317
]}
310318
>
311-
<Icon
312-
size={24}
313-
color={theme.isV3
314-
? theme.colors.onSurfaceVariant
315-
: theme.colors.onSurface
316-
}
317-
source={selectingYear
318-
? theme.isV3
319-
? 'menu-up'
320-
: 'chevron-up'
321-
: theme.isV3
322-
? 'menu-down'
323-
: 'chevron-down'
324-
}
325-
/>
319+
<Icon size={24} color={iconColor} source={iconSource} />
326320
</View>
327321
</View>
328322
</TouchableRipple>
@@ -370,7 +364,7 @@ export const monthHeaderSingleHeight =
370364

371365
const styles = StyleSheet.create({
372366
iconWrapper: {
373-
padding: 8
367+
padding: 8,
374368
},
375369
week: {
376370
flexDirection: 'row',

src/Time/AnalogClock.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,19 @@ function AnalogClock({
121121
const dynamicSize = focused === clockTypes.hours && shortPointer ? 33 : 0
122122
const pointerNumber = focused === clockTypes.hours ? hours : minutes
123123
const degreesPerNumber = focused === clockTypes.hours ? 30 : 6
124+
125+
const v3Color = theme.colors.surfaceVariant
126+
const v2Color = theme.dark
127+
? Color(theme.colors.surface).lighten(1.4).hex()
128+
: Color(theme.colors.surface).darken(0.1).hex()
124129
return (
125130
<View
126131
ref={clockRef}
127132
{...panResponder.panHandlers}
128133
style={[
129134
styles.clock,
130135
{
131-
backgroundColor: theme.isV3
132-
? theme.colors.surfaceVariant
133-
: theme.dark
134-
? Color(theme.colors.surface).lighten(1.4).hex()
135-
: Color(theme.colors.surface).darken(0.1).hex(),
136+
backgroundColor: theme.isV3 ? v3Color : v2Color,
136137
},
137138
]}
138139
// @ts-ignore -> https://github.com/necolas/react-native-web/issues/506

src/Time/TimePickerModal.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ export function TimePickerModal({
130130
},
131131
[setFocused, setLocalHours, setLocalMinutes]
132132
)
133+
134+
const v3Color = theme.dark
135+
? theme.colors.elevation.level3
136+
: theme.colors.surface
137+
const v2Color = theme.dark
138+
? overlay(10, theme.colors.surface)
139+
: theme.colors.surface
140+
133141
return (
134142
<Modal
135143
animationType={animationType}
@@ -162,17 +170,7 @@ export function TimePickerModal({
162170
style={[
163171
styles.modalContent,
164172
{
165-
backgroundColor:
166-
theme.dark && theme.isV3
167-
? theme.colors.elevation.level3
168-
: theme.isV3
169-
? theme.colors.surface
170-
: theme.dark
171-
? overlay(10, theme.colors.surface)
172-
: theme.colors.surface,
173-
borderRadius: theme.isV3
174-
? theme.roundness * 6
175-
: theme.roundness,
173+
backgroundColor: theme.isV3 ? v3Color : v2Color,
176174
},
177175
]}
178176
>

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,7 +4202,7 @@ eslint-plugin-prettier@^4.2.1:
42024202

42034203
eslint-plugin-prettier@^5.1.3:
42044204
version "5.1.3"
4205-
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz#17cfade9e732cef32b5f5be53bd4e07afd8e67e1"
4205+
resolved "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz#17cfade9e732cef32b5f5be53bd4e07afd8e67e1"
42064206
integrity sha512-C9GCVAs4Eq7ZC/XFQHITLiHJxQngdtraXaM+LoUFoFp/lHNl2Zn8f3WQbe9HvTBBQ9YnKFB0/2Ajdqwo5D1EAw==
42074207
dependencies:
42084208
prettier-linter-helpers "^1.0.0"
@@ -7516,7 +7516,7 @@ prettier-linter-helpers@^1.0.0:
75167516

75177517
prettier@^3.2.5:
75187518
version "3.2.5"
7519-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
7519+
resolved "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
75207520
integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==
75217521

75227522
pretty-format@^26.5.2, pretty-format@^26.6.2:

0 commit comments

Comments
 (0)