auto tabs only on profile
This commit is contained in:
parent
0379e41f3b
commit
f590fd6081
@ -17,6 +17,7 @@ interface TabsProps {
|
|||||||
|
|
||||||
interface TabElementProps extends Omit<TabsProps, "tabs"> {
|
interface TabElementProps extends Omit<TabsProps, "tabs"> {
|
||||||
t: Tab;
|
t: Tab;
|
||||||
|
autoWidth?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clamp(n: number, min: number, max: number) {
|
function clamp(n: number, min: number, max: number) {
|
||||||
@ -29,10 +30,10 @@ function clamp(n: number, min: number, max: number) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TabElement = ({ t, tab, setTab }: TabElementProps) => {
|
export const TabElement = ({ autoWidth, t, tab, setTab }: TabElementProps) => {
|
||||||
const style = useMemo(() => {
|
const style = useMemo(() => {
|
||||||
return { minWidth: `${clamp(t.text.length, 3, 8) * 14}px` } as CSSProperties;
|
return autoWidth ? ({ minWidth: `${clamp(t.text.length, 3, 8) * 16}px` } as CSSProperties) : {};
|
||||||
}, [t.text]);
|
}, [t.text, autoWidth]);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`tab ${tab.value === t.value ? "active" : ""} ${t.disabled ? "disabled" : ""}`}
|
className={`tab ${tab.value === t.value ? "active" : ""} ${t.disabled ? "disabled" : ""}`}
|
||||||
|
@ -301,7 +301,7 @@ export default function ProfilePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderTab(v: Tab) {
|
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;
|
const w = window.document.querySelector(".page")?.clientWidth;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user