-
-
Notifications
You must be signed in to change notification settings - Fork 10k
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
💄 style: Update token tag popover style #2631
Changes from all commits
ff6d467
0c0b1e2
36ce4e1
5987c5c
b1fa6bd
a4b7551
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,80 @@ | ||
import { Divider } from 'antd'; | ||
import { useTheme } from 'antd-style'; | ||
import numeral from 'numeral'; | ||
import { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
interface TokenProgressItem { | ||
color: string; | ||
id: string; | ||
title: string; | ||
value: number; | ||
} | ||
|
||
interface TokenProgressProps { | ||
data: TokenProgressItem[]; | ||
showIcon?: boolean; | ||
showTotal?: string; | ||
} | ||
|
||
const format = (number: number) => numeral(number).format('0,0'); | ||
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. Tip Codebase Verification The
To ensure robust number formatting, consider adding checks for edge cases within the Analysis chainEnsure the Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that the `format` function handles edge cases like very large numbers or negative values.
# Test: Search for the function usage. Expect: Proper handling of edge cases.
rg --type typescript $'format'
Length of output: 64 Script: #!/bin/bash
# Description: Verify that the `format` function handles edge cases like very large numbers or negative values.
# Test: Search for the function usage. Expect: Proper handling of edge cases.
rg --type ts 'format'
Length of output: 9755 Script: #!/bin/bash
# Description: Extract relevant lines and surrounding context from TokenProgress.tsx to verify edge case handling in the format function.
# Extract lines around the format function definition and its usage.
rg --type ts --context 5 'const format = (number: number) => numeral(number).format' src/features/ChatInput/ActionBar/Token/TokenProgress.tsx
Length of output: 143 Script: #!/bin/bash
# Description: Extract the entire content of TokenProgress.tsx to verify edge case handling in the format function.
# Extract the entire content of the file.
cat src/features/ChatInput/ActionBar/Token/TokenProgress.tsx
Length of output: 2411 |
||
|
||
const TokenProgress = memo<TokenProgressProps>(({ data, showIcon, showTotal }) => { | ||
const theme = useTheme(); | ||
const total = data.reduce((acc, item) => acc + item.value, 0); | ||
return ( | ||
<Flexbox gap={8} style={{ position: 'relative' }} width={'100%'}> | ||
<Flexbox | ||
height={6} | ||
horizontal | ||
style={{ | ||
background: total === 0 ? theme.colorFill : undefined, | ||
borderRadius: 3, | ||
overflow: 'hidden', | ||
position: 'relative', | ||
}} | ||
width={'100%'} | ||
> | ||
{data.map((item) => ( | ||
<Flexbox | ||
height={'100%'} | ||
key={item.id} | ||
style={{ background: item.color, flex: item.value }} | ||
/> | ||
))} | ||
</Flexbox> | ||
<Flexbox> | ||
{data.map((item) => ( | ||
<Flexbox align={'center'} gap={4} horizontal justify={'space-between'} key={item.id}> | ||
<Flexbox align={'center'} gap={4} horizontal> | ||
{showIcon && ( | ||
<div | ||
style={{ | ||
background: item.color, | ||
borderRadius: '50%', | ||
flex: 'none', | ||
height: 6, | ||
width: 6, | ||
}} | ||
/> | ||
)} | ||
<div style={{ color: theme.colorTextSecondary }}>{item.title}</div> | ||
</Flexbox> | ||
<div style={{ fontWeight: 500 }}>{format(item.value)}</div> | ||
</Flexbox> | ||
))} | ||
{showTotal && ( | ||
<> | ||
<Divider style={{ marginBlock: 8 }} /> | ||
<Flexbox align={'center'} gap={4} horizontal justify={'space-between'}> | ||
<div style={{ color: theme.colorTextSecondary }}>{showTotal}</div> | ||
<div style={{ fontWeight: 500 }}>{format(total)}</div> | ||
</Flexbox> | ||
</> | ||
)} | ||
</Flexbox> | ||
</Flexbox> | ||
); | ||
}); | ||
|
||
export default TokenProgress; |
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.
Consider changing the type of
showTotal
fromstring
toboolean
.This change aligns with the typical usage of a boolean flag to control visibility, rather than using a string.
Committable suggestion