import {designComponent, onUpdated, reactive, useClasses, useRefs, useStyles} from "@peryl/react-compose"; import {TabCommonProps} from "../../tabs.utils"; import {TabsHeaderHorizontalText} from "./TabsHeaderHorizontalText"; import {TabsHeaderHorizontalCard} from "./TabsHeaderHorizontalCard"; import {TabsHeaderHorizontalShadow} from "./TabsHeaderHorizontalShadow"; import './tabs-header-horizontal.scss'; import {delay} from "@peryl/utils/delay"; import {unit} from "@peryl/utils/unit"; import {Button} from "../../../Button"; export const TabsHeaderHorizontal = designComponent({ name: 'tabs-header-horizontal', provideRefer: true, props: { ...TabCommonProps, }, slots: ['default'], setup({ props, slots }) { const { refs, onRef } = useRefs({ el: HTMLDivElement }); const state = reactive({ showMoreButton: false, scrollLeft: 0, offsetWidth: 0, scrollWidth: 0, }); const classes = useClasses(() => [ 'tabs-header', 'tabs-header-horizontal', `tabs-header-type-${props.headType}`, `tabs-header-pos-${props.headPosition}`, { 'tabs-header-show-more': state.showMoreButton } ]); const listStyles = useStyles(style => { if (state.showMoreButton) { style.left = unit(state.scrollLeft); } }); onUpdated(async () => { await delay(50); const { scrollWidth, offsetWidth } = refs.el!; let flag = scrollWidth > offsetWidth + 20; if (state.showMoreButton !== flag) { state.showMoreButton = flag; } state.offsetWidth = offsetWidth; state.scrollWidth = scrollWidth; }); const handler = { scrollLeft: () => { const scrollLeft = state.scrollLeft + state.offsetWidth; state.scrollLeft = Math.min(0, scrollLeft); }, scrollRight: () => { const scrollLeft = state.scrollLeft - state.offsetWidth; state.scrollLeft = Math.max(-(state.scrollWidth - state.offsetWidth), scrollLeft); }, }; return { refer: { refs, }, render: () => (