forked from nervosnetwork/ckb-explorer-frontend
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor Capacity component
- Loading branch information
Showing
28 changed files
with
286 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.container { | ||
display: inline-flex; | ||
align-items: flex-end; | ||
font-size: 1rem; | ||
|
||
span[data-role='dec'] { | ||
font-size: 0.875em; | ||
} | ||
|
||
.unit { | ||
margin-left: 5px; | ||
} | ||
|
||
&[data-type='value'] { | ||
span[data-role='dec'] { | ||
color: var(--decimal-color); | ||
} | ||
} | ||
|
||
&[data-type='diff'] { | ||
&[data-diff-status='positive'] { | ||
color: var(--primary-color); | ||
|
||
&::before { | ||
content: '+'; | ||
} | ||
} | ||
|
||
&[data-diff-status='negative'] { | ||
color: var(--accent-color); | ||
} | ||
} | ||
|
||
&[data-layout='responsive'] { | ||
// FIXME: use css variable later | ||
@media screen and (width <= 1000px) { | ||
font-size: 0.75rem; | ||
|
||
span[data-role='dec'] { | ||
font-size: 0.9em; | ||
} | ||
|
||
.unit { | ||
font-size: 1rem; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import BigNumber from 'bignumber.js' | ||
import { useMemo } from 'react' | ||
import styles from './Capacity.module.scss' | ||
|
||
interface CapacityProps { | ||
capacity: string | ||
type?: 'value' | 'diff' | ||
layout?: 'responsive' | 'fixed' | ||
unit?: 'CKB' | null | ||
display?: 'full' | 'short' | ||
} | ||
|
||
const Capacity: React.FC<CapacityProps> = ({ | ||
capacity, | ||
type = 'value', | ||
layout = 'fixed', | ||
unit = 'CKB', | ||
display = 'full', | ||
}) => { | ||
const [int, dec, diffStatus] = useMemo(() => { | ||
const c = new BigNumber(capacity) | ||
const [int, dec] = c.toFormat(display === 'full' ? 8 : undefined).split('.') | ||
if (type !== 'diff' || c.isZero()) return [int, dec] | ||
if (c.isPositive()) return [int, dec, 'positive'] | ||
return [int, dec, 'negative'] | ||
}, [capacity, display, type]) | ||
|
||
return ( | ||
<div className={styles.container} data-type={type} data-diff-status={diffStatus} data-layout={layout}> | ||
<span data-role="int">{int}</span> | ||
{dec ? ( | ||
<span data-role="dec" className="monospace"> | ||
{`.${dec}`} | ||
</span> | ||
) : null} | ||
{unit && <span className={`${styles.unit} monospace`}>{unit}</span>} | ||
</div> | ||
) | ||
} | ||
|
||
export default Capacity |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.