auto tabs only on profile

This commit is contained in:
Alejandro Gomez 2023-02-14 00:30:50 +01:00 committed by Kieran
parent 0379e41f3b
commit f590fd6081
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 5 additions and 4 deletions

View File

@ -17,6 +17,7 @@ interface TabsProps {
interface TabElementProps extends Omit<TabsProps, "tabs"> {
t: Tab;
autoWidth?: boolean;
}
function clamp(n: number, min: number, max: number) {
@ -29,10 +30,10 @@ function clamp(n: number, min: number, max: number) {
return n;
}
export const TabElement = ({ t, tab, setTab }: TabElementProps) => {
export const TabElement = ({ autoWidth, t, tab, setTab }: TabElementProps) => {
const style = useMemo(() => {
return { minWidth: `${clamp(t.text.length, 3, 8) * 14}px` } as CSSProperties;
}, [t.text]);
return autoWidth ? ({ minWidth: `${clamp(t.text.length, 3, 8) * 16}px` } as CSSProperties) : {};
}, [t.text, autoWidth]);
return (
<div
className={`tab ${tab.value === t.value ? "active" : ""} ${t.disabled ? "disabled" : ""}`}

View File

@ -301,7 +301,7 @@ export default function ProfilePage() {
}
function renderTab(v: Tab) {
return <TabElement key={v.value} t={v} tab={tab} setTab={setTab} />;
return <TabElement autoWidth={true} key={v.value} t={v} tab={tab} setTab={setTab} />;
}
const w = window.document.querySelector(".page")?.clientWidth;