Skip to content

Commit

Permalink
tweak: styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Apr 8, 2024
1 parent 391c6f0 commit cbcd6ae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
13 changes: 11 additions & 2 deletions src/components/Header.tsx
@@ -1,4 +1,4 @@
import { type ReactNode, useMemo } from 'react'
import { type ReactNode, useLayoutEffect, useMemo, useState } from 'react'
import { Link } from 'react-router-dom'
import { type Hex, formatGwei } from 'viem'

Expand Down Expand Up @@ -128,6 +128,13 @@ function HomeButton() {
function Account() {
const { account } = useAccountStore()
if (!account) return null

// Hack to bypass truncated text mounting issues.
const [key, setKey] = useState(0)
useLayoutEffect(() => {
requestAnimationFrame(() => setKey((key) => key + 1))
}, [])

return (
<Link to="/" style={{ height: '100%' }}>
<Box
Expand All @@ -143,7 +150,9 @@ function Account() {
{account && (
<HeaderItem label="Account">
<Tooltip label={account.address}>
<Text.Truncated size="11px">{account.address}</Text.Truncated>
<Text.Truncated key={key} size="11px">
{account.address}
</Text.Truncated>
</Tooltip>
</HeaderItem>
)}
Expand Down
6 changes: 5 additions & 1 deletion src/design-system/components/Text.css.ts
Expand Up @@ -38,8 +38,12 @@ export const tabular = style({
letterSpacing: '0px',
})

export const overflow = style({
export const ellipsis = style({
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
})

export const overflow = style({
overflow: 'visible',
})
23 changes: 12 additions & 11 deletions src/design-system/components/Text.tsx
Expand Up @@ -92,6 +92,7 @@ export const TextWrapper = forwardRef<HTMLDivElement, TextWrapperProps>(
)

export type TextProps = TextWrapperProps & {
overflow?: boolean
tabular?: boolean
}

Expand All @@ -103,6 +104,7 @@ export const TextBase = forwardRef<HTMLDivElement, TextProps>(
children,
color,
family,
overflow,
size,
style,
tabular = false,
Expand All @@ -128,7 +130,11 @@ export const TextBase = forwardRef<HTMLDivElement, TextProps>(
>
<Box
as="span"
className={[tabular && styles.tabular, !wrap && styles.overflow]}
className={[
tabular && styles.tabular,
!wrap && styles.ellipsis,
overflow && styles.overflow,
]}
display={!wrap ? 'block' : undefined}
>
{children || '‎'}
Expand Down Expand Up @@ -185,15 +191,10 @@ export const TextTruncated = forwardRef<HTMLDivElement, TextTruncatedProps>(
}, [])

useLayoutEffect(() => {
setTimeout(() => {
setWidth(
(
(
wrapperRef.current as any
).getBoundingClientRect() as DOMRectReadOnly
).width,
)
}, 16)
setWidth(
((wrapperRef.current as any).getBoundingClientRect() as DOMRectReadOnly)
.width,
)
}, [])
useResizeObserver(wrapperRef, (entry) =>
mounted ? setWidth(entry.contentRect.width) : undefined,
Expand Down Expand Up @@ -227,7 +228,7 @@ export const TextTruncated = forwardRef<HTMLDivElement, TextTruncatedProps>(
<Box ref={wrapperRef}>
<Box
as="span"
className={[tabular && styles.tabular, styles.overflow]}
className={[tabular && styles.tabular, styles.ellipsis]}
position="relative"
>
{truncatedText || '‎'}
Expand Down
12 changes: 9 additions & 3 deletions src/screens/index.tsx
Expand Up @@ -464,8 +464,14 @@ function Blocks() {
TIMESTAMP
</Text>
</Column>
<Column alignVertical="center">
<Text color="text/tertiary" size="9px" wrap={false}>
<Column width="1/5" alignVertical="center">
<Text
color="text/tertiary"
size="9px"
overflow
wrap={false}
style={{ overflow: 'visible' }}
>
TRANSACTIONS
</Text>
</Column>
Expand Down Expand Up @@ -519,7 +525,7 @@ function Blocks() {
</Text>
)}
</Column>
<Column alignVertical="center">
<Column width="1/5" alignVertical="center">
<Text size="12px">
{block.transactions.length || '0'}
</Text>
Expand Down

0 comments on commit cbcd6ae

Please sign in to comment.