mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 12:43:09 -05:00
56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
import { type ComponentProps, type ReactNode, type CSSProperties } from 'react';
|
|
|
|
import { Block } from './Block';
|
|
import { View } from './View';
|
|
|
|
type AlignedTextProps = ComponentProps<typeof View> & {
|
|
left: ReactNode;
|
|
right: ReactNode;
|
|
style?: CSSProperties;
|
|
leftStyle?: CSSProperties;
|
|
rightStyle?: CSSProperties;
|
|
truncate?: 'left' | 'right';
|
|
};
|
|
export function AlignedText({
|
|
left,
|
|
right,
|
|
style,
|
|
leftStyle,
|
|
rightStyle,
|
|
truncate = 'left',
|
|
...nativeProps
|
|
}: AlignedTextProps) {
|
|
const truncateStyle: CSSProperties = {
|
|
textOverflow: 'ellipsis',
|
|
whiteSpace: 'nowrap',
|
|
overflow: 'hidden',
|
|
};
|
|
|
|
return (
|
|
<View
|
|
style={{ flexDirection: 'row', alignItems: 'center', ...style }}
|
|
{...nativeProps}
|
|
>
|
|
<Block
|
|
style={{
|
|
marginRight: 10,
|
|
...(truncate === 'left' && truncateStyle),
|
|
...leftStyle,
|
|
}}
|
|
>
|
|
{left}
|
|
</Block>
|
|
<Block
|
|
style={{
|
|
flex: 1,
|
|
textAlign: 'right',
|
|
...(truncate === 'right' && truncateStyle),
|
|
...rightStyle,
|
|
}}
|
|
>
|
|
{right}
|
|
</Block>
|
|
</View>
|
|
);
|
|
}
|