Skip to content

Commit 663a2ca

Browse files
authored
Merge pull request #609 from curvefi/styling/value-metric-update
styling: update metric size and spacing according to figma
2 parents 6f8fd1d + 6028b7a commit 663a2ca

File tree

8 files changed

+108
-85
lines changed

8 files changed

+108
-85
lines changed

packages/curve-ui-kit/src/features/user-profile/UserProfile.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Box from '@mui/material/Box'
21
import Drawer from '@mui/material/Drawer'
32
import { SizesAndSpaces } from '@ui-kit/themes/design/1_sizes_spaces'
43

packages/curve-ui-kit/src/lib/model/query/chain-name-validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { enforce, group, test } from 'vest'
22
import { createValidationSuite } from '@ui-kit/lib/validation'
3-
import { ChainNameParams, ChainParams } from './root-keys'
3+
import { ChainNameParams } from './root-keys'
44

55
export const chainNameValidationGroup = ({ blockchainId }: ChainNameParams) =>
66
group('chainNameValidation', () => {

packages/curve-ui-kit/src/shared/ui/LinearProgress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MuiLinearProgress, { linearProgressClasses } from '@mui/material/LinearProgress'
1+
import MuiLinearProgress from '@mui/material/LinearProgress'
22
import { useEffect, useState } from 'react'
33

44
const SIZE_MAPPING = {

packages/curve-ui-kit/src/shared/ui/Metric.tsx

Lines changed: 100 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { useState } from 'react'
22

33
import Alert from '@mui/material/Alert'
4-
import Box from '@mui/material/Box'
4+
import Stack from '@mui/material/Stack'
55
import Skeleton from '@mui/material/Skeleton'
66
import Snackbar from '@mui/material/Snackbar'
77
import Tooltip from '@mui/material/Tooltip'
88
import Typography from '@mui/material/Typography'
99
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'
1010

1111
import { SizesAndSpaces } from '@ui-kit/themes/design/1_sizes_spaces'
12-
import { TypographyVariantKey, TYPOGRAPHY_VARIANTS } from '@ui-kit/themes/typography'
12+
import { TypographyVariantKey } from '@ui-kit/themes/typography'
1313
import { abbreviateNumber, scaleSuffix } from '@ui-kit/utils'
1414
import { Duration } from '../../themes/design/0_primitives'
1515
import AlertTitle from '@mui/material/AlertTitle'
1616

17-
const { Spacing } = SizesAndSpaces
17+
const { Spacing, IconSize } = SizesAndSpaces
1818

1919
// Correspond to flexbox align items values.
2020
export const ALIGNMENTS = ['start', 'center', 'end'] as const
@@ -27,6 +27,13 @@ const MetricSize = {
2727
extraLarge: 'highlightXxl',
2828
} as const satisfies Record<string, TypographyVariantKey>
2929

30+
const MetricUnitSize = {
31+
small: 'highlightXs',
32+
medium: 'highlightS',
33+
large: 'highlightM',
34+
extraLarge: 'highlightL',
35+
} as const satisfies Record<string, TypographyVariantKey>
36+
3037
export const SIZES = Object.keys(MetricSize) as (keyof typeof MetricSize)[]
3138

3239
type UnitOptions = {
@@ -79,27 +86,79 @@ const formatChange = (value: number) => {
7986
})
8087
}
8188

82-
type Props = {
83-
/** Label that goes above the value */
84-
label: string
85-
/** Optional tooltip content shown next to the label */
86-
tooltip?: string
87-
/** The text to display when the value is copied to the clipboard */
88-
copyText?: string
89+
type MetricValueProps = Required<Pick<Props, 'value' | 'formatter' | 'abbreviate'>> & {
90+
change?: number
91+
unit: UnitOptions | undefined
92+
fontVariant: TypographyVariantKey
93+
fontVariantUnit: TypographyVariantKey
94+
copyValue: () => void
95+
}
8996

97+
const MetricValue = ({
98+
value,
99+
formatter,
100+
change,
101+
abbreviate,
102+
unit,
103+
fontVariant,
104+
fontVariantUnit,
105+
copyValue,
106+
}: MetricValueProps) => (
107+
<Stack direction="row" gap={Spacing.xxs} alignItems="baseline">
108+
<Tooltip arrow placement="bottom" title={value.toLocaleString()} onClick={copyValue} sx={{ cursor: 'pointer' }}>
109+
<Stack direction="row" alignItems="baseline">
110+
{unit?.position === 'prefix' && (
111+
<Typography variant={fontVariantUnit} color="textSecondary">
112+
{unit.symbol}
113+
</Typography>
114+
)}
115+
116+
<Typography variant={fontVariant} color="textPrimary">
117+
{formatter(abbreviate ? abbreviateNumber(value) : value)}
118+
</Typography>
119+
120+
{abbreviate && (
121+
<Typography variant={fontVariant} color="textPrimary" textTransform="capitalize">
122+
{scaleSuffix(value)}
123+
</Typography>
124+
)}
125+
126+
{unit?.position === 'suffix' && (
127+
<Typography variant={fontVariantUnit} color="textSecondary">
128+
{unit.symbol}
129+
</Typography>
130+
)}
131+
</Stack>
132+
</Tooltip>
133+
134+
{(change || change === 0) && (
135+
<Typography variant="highlightM" color={change > 0 ? 'success' : change < 0 ? 'error' : 'textHighlight'}>
136+
{formatChange(change)}%
137+
</Typography>
138+
)}
139+
</Stack>
140+
)
141+
142+
type Props = {
90143
/** The actual metric value to display */
91144
value: number
92-
/** Optional formatter for metric value */
93-
formatter?: (value: number) => string
94-
/** If the value should be abbreviated to 1.23k or 3.45m */
95-
abbreviate?: boolean
145+
/** A unit can be a currency symbol or percentage, prefix or suffix */
146+
unit?: Unit | undefined
96147
/** The number of decimals the value should contain */
97148
decimals?: number
98-
/** A unit can be a currency symbol or percentage, prefix or suffix */
99-
unit?: Unit
100-
149+
/** If the value should be abbreviated to 1.23k or 3.45m */
150+
abbreviate?: boolean
101151
/** Optional value that denotes a change in metric value since 'last' time */
102152
change?: number
153+
/** Optional formatter for metric value */
154+
formatter?: (value: number) => string
155+
156+
/** Label that goes above the value */
157+
label: string
158+
/** Optional tooltip content shown next to the label */
159+
tooltip?: string
160+
/** The text to display when the value is copied to the clipboard */
161+
copyText?: string
103162

104163
/** Notional values give extra context to the metric, like underlying value */
105164
notional?: number
@@ -114,17 +173,16 @@ type Props = {
114173
}
115174

116175
export const Metric = ({
117-
label,
118-
tooltip,
119-
copyText,
120-
121176
value,
122-
formatter = (value: number) => formatValue(value, decimals),
123-
abbreviate,
124177
unit,
178+
abbreviate,
179+
change,
125180
decimals = 1,
181+
formatter = (value: number) => formatValue(value, decimals),
126182

127-
change,
183+
label,
184+
tooltip,
185+
copyText,
128186

129187
notional,
130188
notionalFormatter = (value: number) => formatNotionalValue(value, notionalDecimals),
@@ -149,74 +207,37 @@ export const Metric = ({
149207
setOpenCopyAlert(true)
150208
}
151209

210+
const metricValueProps = {
211+
value,
212+
unit,
213+
abbreviate,
214+
change,
215+
formatter,
216+
fontVariant: MetricSize[size],
217+
fontVariantUnit: MetricUnitSize[size],
218+
copyValue,
219+
}
220+
152221
return (
153-
<Box display="flex" flexDirection="column" alignItems={alignment} gap={Spacing.xs}>
222+
<Stack alignItems={alignment}>
154223
<Typography variant="bodyXsRegular" color="textTertiary">
155224
{label}
156225
{tooltip && (
157226
<Tooltip arrow placement="top" title={tooltip}>
158227
<span>
159228
{' '}
160-
<InfoOutlinedIcon sx={{ fontSize: '1.25em' }} />
229+
<InfoOutlinedIcon sx={{ width: IconSize.xs, height: IconSize.xs }} />
161230
</span>
162231
</Tooltip>
163232
)}
164233
</Typography>
165234

166235
{loading ? (
167-
<Skeleton
168-
variant="text"
169-
width="100%"
170-
sx={{
171-
fontSize: TYPOGRAPHY_VARIANTS[MetricSize[size]],
172-
}}
173-
/>
236+
<Skeleton variant="text">
237+
<MetricValue {...metricValueProps} />
238+
</Skeleton>
174239
) : (
175-
<Box display="flex" gap={Spacing.xs} alignItems="baseline">
176-
<Tooltip
177-
arrow
178-
placement="bottom"
179-
title={value.toLocaleString()}
180-
onClick={copyValue}
181-
sx={{
182-
cursor: 'pointer',
183-
}}
184-
>
185-
<Box display="flex" gap={Spacing.xxs} alignItems="baseline">
186-
{unit?.position === 'prefix' && (
187-
<Typography variant={MetricSize[size]} color="textSecondary">
188-
{unit.symbol}
189-
</Typography>
190-
)}
191-
192-
<Typography variant={MetricSize[size]} color="textPrimary">
193-
{formatter(abbreviate ? abbreviateNumber(value) : value)}
194-
</Typography>
195-
196-
{abbreviate && (
197-
<Typography variant={MetricSize[size]} color="textPrimary" textTransform="capitalize">
198-
{scaleSuffix(value)}
199-
</Typography>
200-
)}
201-
202-
{unit?.position === 'suffix' && (
203-
<Typography variant={MetricSize[size]} color="textSecondary">
204-
{unit.symbol}
205-
</Typography>
206-
)}
207-
</Box>
208-
</Tooltip>
209-
210-
{(change || change === 0) && (
211-
<Typography
212-
variant="highlightM"
213-
color={change > 0 ? 'success' : change < 0 ? 'error' : 'textHighlight'}
214-
sx={{ marginInlineStart: Spacing.xs }}
215-
>
216-
{formatChange(change)}%
217-
</Typography>
218-
)}
219-
</Box>
240+
<MetricValue {...metricValueProps} />
220241
)}
221242

222243
{notional !== undefined && (
@@ -234,6 +255,6 @@ export const Metric = ({
234255
{value}
235256
</Alert>
236257
</Snackbar>
237-
</Box>
258+
</Stack>
238259
)
239260
}

packages/curve-ui-kit/src/themes/button/override-buttons.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DesignSystem, DesignOptions } from './design'
1+
import { DesignSystem } from './design'
22

33
declare module '@mui/material/Button' {
44
type Buttons = Omit<DesignSystem['Button'], 'Focus_Outline'>

packages/curve-ui-kit/src/themes/typography/create-typography.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const variant = ({
5656
fontFamily,
5757
fontWeight: FontWeight[fontWeight ?? 'Medium'],
5858
letterSpacing,
59+
// Undo the letter spacing to the right of the last letter
60+
...(letterSpacing !== '0%' && {
61+
marginRight: `calc(${letterSpacing} * -1)`,
62+
}),
5963
textTransform: textCase,
6064
...(!(fontSize in FontSize) && { fontSize }),
6165
...(!(lineHeight in LineHeight) && { lineHeight }),

packages/curve-ui-kit/src/widgets/Disclaimer/Tabs/SCrvUsd.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ArrowOutwardIcon from '@mui/icons-material/ArrowOutward'
99

1010
import { SizesAndSpaces } from '@ui-kit/themes/design/1_sizes_spaces'
1111

12-
import { Section, Header, Title, Paragraph } from '../Section'
12+
import { Section, Header, Paragraph } from '../Section'
1313
import { List } from '../List'
1414

1515
const { Spacing } = SizesAndSpaces

packages/ui/src/InternalLinkButton/InternalLinkButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import styled from 'styled-components'
2-
import { ReactComponent as ExternalIcon } from 'ui/src/images/external.svg'
32

43
import Button from 'ui/src/Button'
54
import Icon from 'ui/src/Icon'

0 commit comments

Comments
 (0)