Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dynamic params to text #384

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 9 additions & 5 deletions src/ui/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { translate } from '@/core/i18n';

interface Props extends TextProps {
className?: string;
tx?: TxKeyPath;
tx?: TxKeyPath | { key: TxKeyPath; params: { [key: string]: any } };
}

export const Text = ({
Expand All @@ -22,9 +22,9 @@ export const Text = ({
() =>
twMerge(
'text-base text-black dark:text-white font-inter font-normal',
className
className,
),
[className]
[className],
);

const nStyle = React.useMemo(
Expand All @@ -35,11 +35,15 @@ export const Text = ({
},
style,
]) as TextStyle,
[style]
[style],
);
return (
<NNText className={textStyle} style={nStyle} {...props}>
{tx ? translate(tx) : children}
{tx
? typeof tx === 'string'
? translate(tx)
: translate(tx.key, tx.params)
: children}
</NNText>
);
};