Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/components/PresetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ const styles = StyleSheet.create({
fontWeight: 'bold',
textAlignVertical: 'auto',
},
stationCodeParen: {
fontSize: RFValue(8),
fontWeight: 'bold',
textAlignVertical: 'auto',
},
lineDot: {
width: 16,
height: 16,
Expand All @@ -94,6 +99,26 @@ const styles = StyleSheet.create({
},
});

const renderTextWithSmallerParens = (
text: string,
_baseStyle: typeof styles.stationCode,
parenStyle: typeof styles.stationCodeParen,
color: string
) => {
const parts = text.split(/([(\uFF08][^)\uFF09]*[)\uFF09])/);
if (parts.length === 1) return text;
return parts.map((part, i) => {
const key = `${i}-${part}`;
return /^[(\uFF08]/.test(part) ? (
<Typography key={key} style={[parenStyle, { color }]}>
{part}
</Typography>
) : (
<React.Fragment key={key}>{part}</React.Fragment>
);
});
};

const BrokenIcon = () => (
<Svg width="34" height="34" viewBox="0 0 24 24">
{/* Icon from Material Symbols by Google - https://github.com/google/material-design-icons/blob/master/LICENSE */}
Expand Down Expand Up @@ -243,7 +268,12 @@ const PresetCardBase: React.FC<Props> = ({ title, from, to }) => {
{leftName}
</Typography>
<Typography style={[styles.stationCode, { color: metaFg }]}>
{leftCode}
{renderTextWithSmallerParens(
leftCode,
styles.stationCode,
styles.stationCodeParen,
metaFg
)}
</Typography>
</View>
<View style={styles.colCenter}>
Expand All @@ -268,7 +298,12 @@ const PresetCardBase: React.FC<Props> = ({ title, from, to }) => {
{rightName}
</Typography>
<Typography style={[styles.stationCode, { color: metaFg }]}>
{rightCode}
{renderTextWithSmallerParens(
rightCode,
styles.stationCode,
styles.stationCodeParen,
metaFg
)}
</Typography>
</View>
</View>
Expand Down