djust tabs
This commit is contained in:
parent
82045d5f67
commit
a63701f7d0
@ -1,4 +1,5 @@
|
|||||||
import "./Tabs.css";
|
import "./Tabs.css";
|
||||||
|
import { useMemo } from "react";
|
||||||
import useHorizontalScroll from "Hooks/useHorizontalScroll";
|
import useHorizontalScroll from "Hooks/useHorizontalScroll";
|
||||||
import { CSSProperties } from "react";
|
import { CSSProperties } from "react";
|
||||||
|
|
||||||
@ -18,8 +19,20 @@ interface TabElementProps extends Omit<TabsProps, "tabs"> {
|
|||||||
t: Tab;
|
t: Tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clamp(n: number, min: number, max: number) {
|
||||||
|
if (n < min) {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
if (n > max) {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
export const TabElement = ({ t, tab, setTab }: TabElementProps) => {
|
export const TabElement = ({ t, tab, setTab }: TabElementProps) => {
|
||||||
const style = { minWidth: `${t.text.length * 0.6}em` } as CSSProperties;
|
const style = useMemo(() => {
|
||||||
|
return { minWidth: `${clamp(t.text.length, 2, 7)}em` } as CSSProperties;
|
||||||
|
}, [t.text]);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`tab ${tab.value === t.value ? "active" : ""} ${t.disabled ? "disabled" : ""}`}
|
className={`tab ${tab.value === t.value ? "active" : ""} ${t.disabled ? "disabled" : ""}`}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user