-
Notifications
You must be signed in to change notification settings - Fork 17
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
views: prop for optionally displaying value on ValueViewComponent #1923
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@penumbra-zone/ui': patch | ||
--- | ||
|
||
showValue prop for ValueViewComponent to display amounts |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ export interface ValueViewComponentProps<SelectedContext extends Context> { | |
* If true, the displayed amount will be shortened. | ||
*/ | ||
abbreviate?: boolean; | ||
/** | ||
* If false, the amount will not be displayed. | ||
*/ | ||
showValue?: boolean; | ||
} | ||
|
||
/** | ||
|
@@ -58,19 +62,22 @@ export const ValueViewComponent = <SelectedContext extends Context = 'default'>( | |
priority = 'primary', | ||
hideSymbol = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: hmm, maybe we should have called this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that’s clearer now — it’s been renamed to |
||
abbreviate = false, | ||
showValue = true, | ||
}: ValueViewComponentProps<SelectedContext>) => { | ||
const density = useDensity(); | ||
|
||
if (!valueView) { | ||
return null; | ||
} | ||
|
||
let formattedAmount: string; | ||
if (abbreviate) { | ||
const amount = getFormattedAmtFromValueView(valueView, false); | ||
formattedAmount = shortify(Number(amount)); | ||
} else { | ||
formattedAmount = getFormattedAmtFromValueView(valueView, true); | ||
let formattedAmount: string | undefined; | ||
if (showValue) { | ||
if (abbreviate) { | ||
const amount = getFormattedAmtFromValueView(valueView, false); | ||
formattedAmount = shortify(Number(amount)); | ||
} else { | ||
formattedAmount = getFormattedAmtFromValueView(valueView, true); | ||
} | ||
TalDerei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const metadata = getMetadata.optional(valueView); | ||
|
@@ -109,9 +116,11 @@ export const ValueViewComponent = <SelectedContext extends Context = 'default'>( | |
getGap(density), | ||
)} | ||
> | ||
<div className='shrink grow' title={formattedAmount}> | ||
<ValueText density={density}>{formattedAmount}</ValueText> | ||
</div> | ||
{showValue && ( | ||
<div className='shrink grow' title={formattedAmount ?? undefined}> | ||
<ValueText density={density}>{formattedAmount}</ValueText> | ||
</div> | ||
)} | ||
{!hideSymbol && ( | ||
<div className='shrink grow truncate' title={symbol}> | ||
<ValueText density={density}>{symbol}</ValueText> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please review the storybook preview link