Skip to content
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

Update font size of BalanceInput #26

Merged
merged 3 commits into from
May 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions src/components/balance-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Asset, Cross } from "@/types";
import Input from "@/ui/input";
import { BN, BN_ZERO, bnToBn } from "@polkadot/util";
import AssetSelect from "./asset-select";
import { ChangeEventHandler, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { ChangeEventHandler, useCallback, useEffect, useMemo, useRef } from "react";
import { formatBalance } from "@/utils";
import { formatUnits, parseUnits } from "viem";
import { InputAlert } from "./input-alert";
Expand Down Expand Up @@ -43,7 +43,6 @@ export default function BalanceInput({
const assetRef = useRef(asset);
const spanRef = useRef<HTMLSpanElement | null>(null);
const inputRef = useRef<HTMLInputElement | null>(null);
const [dynamicStyle, setDynamicStyle] = useState("");

const _placeholder = useMemo(() => {
if (balance && asset) {
Expand Down Expand Up @@ -80,25 +79,6 @@ export default function BalanceInput({
assetRef.current = asset;
}, [value, asset, min, balance, assetLimit, assetSupply, onChange]);

useEffect(() => {
const inputWidth = inputRef.current?.clientWidth || 1;
const spanWidth = spanRef.current?.clientWidth || 0;
const percent = (spanWidth / inputWidth) * 100;
if (percent < 20) {
setDynamicStyle("text-[2.25rem] font-light");
} else if (percent < 30) {
setDynamicStyle("text-[1.875rem] font-light");
} else if (percent < 40) {
setDynamicStyle("text-[1.5rem] font-normal");
} else if (percent < 50) {
setDynamicStyle("text-[1.25rem] font-normal");
} else if (percent < 60) {
setDynamicStyle("text-[1.125rem] font-medium");
} else {
setDynamicStyle("text-[1rem] font-medium");
}
}, [value]);

const insufficient = balance && value?.input && balance.lt(value.amount) ? true : false;
const requireMin = min && value?.input && value.amount.lt(min) ? true : false;
const requireLimit = isExcess(assetLimit, assetSupply, value?.amount);
Expand All @@ -112,9 +92,7 @@ export default function BalanceInput({
<Input
disabled={disabled}
placeholder={_placeholder}
className={`h-full w-full bg-transparent px-1 transition-[font-weight,font-size,line-height] duration-300 ${
value?.input ? `leading-none ${dynamicStyle}` : ""
}`}
className="h-full w-full bg-transparent px-1"
ref={inputRef}
value={value?.input}
onChange={handleInputChange}
Expand Down
Loading