同步操作将从 robergroup/chiner 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import React, { useRef, useEffect, useState } from 'react';import Icon from '../icon';import { addOnResize, removeOnResize } from '../../lib/listener';import hoistNonReactStatics from '../../lib/statics';import {getPrefix} from '../../lib/prefixUtil'; // 将组件的静态属性转移到新组件上export const AutoCompose = (Com) => {// 对tab自动适应显示箭头的拓展方法const Tab = React.memo(({prefix, position = 'left', ...restProps}) => {const currentPrefix = getPrefix(prefix);const tabHeaderWidth = 100;const [tabId] = useState(() => {return Math.uuid();});const domRef = useRef(null);const leftIcon = useRef(null);const rightIcon = useRef(null);const _validateScroll = () => {// 判断tab标题内容是否溢出let offset = 0;if (domRef.current) {const headerDom = domRef.current.querySelector(`.${currentPrefix}-tab-header`);offset = headerDom.offsetWidth - headerDom.scrollWidth;}return offset;};const _setArrowStatus = () => {// 根据内容调整箭头是否显示const leftDom = leftIcon.current;const rightDom = rightIcon.current;if (_validateScroll() < 0) {const headerDom = domRef.current.querySelector(`.${currentPrefix}-tab-header`);if (headerDom.scrollLeft <= 0) {// 左侧内容已经到底 无法继续向左滚动 隐藏左侧图标leftDom.style.display = 'none';} else {leftDom.style.display = 'inline';}if (headerDom.scrollLeft + headerDom.clientWidth >= headerDom.scrollWidth) {// 右侧内容已经到底 无法继续向右滚动 隐藏右侧图标rightDom.style.display = 'none';} else {rightDom.style.display = 'inline';}} else {leftDom.style.display = 'none';rightDom.style.display = 'none';}};const _validateTabInView = () => {const headerDom = domRef.current.querySelector(`.${currentPrefix}-tab-header`);const activeDom = domRef.current.querySelector(`.${currentPrefix}-tab-header-item-show`);if (headerDom && activeDom) {const activeRect = activeDom.getBoundingClientRect();const headerReact = headerDom.getBoundingClientRect();if (activeRect.right < headerReact.x) {headerDom.scrollLeft = 0;} else if (activeRect.right < headerReact.right){// 在可视内容内 无需任何操作} else {headerDom.scrollLeft = activeRect.right - headerReact.right + headerDom.scrollLeft;}}};useEffect(() => {if (position === 'top') {_validateTabInView();_setArrowStatus();}});useEffect(() => {if (position === 'top') {_setArrowStatus();addOnResize(tabId, () => {_setArrowStatus();});return () => {removeOnResize(tabId);};}return () => {};}, [tabId]);const _move = (type) => {const headerDom = domRef.current.querySelector(`.${currentPrefix}-tab-header`);if (type === 'left') {headerDom.scrollLeft -= tabHeaderWidth;} else {headerDom.scrollLeft += tabHeaderWidth;}_setArrowStatus();};const _iconClick = (type) => {_move(type);};return <div className={`${currentPrefix}-auto-compose-tab-${position}`}><IcononClick={() => _iconClick('left')}style={{display: 'none'}}ref={leftIcon}type='fa-angle-left'className={`${currentPrefix}-auto-compose-tab-${position}-left-${position === 'top' ? 'show' : 'hidden'}`}/><Com prefix={currentPrefix} position={position} {...restProps} forwardRef={domRef}/><IcononClick={() => _iconClick('right')}style={{display: 'none'}}ref={rightIcon}type='fa-angle-right'className={`${currentPrefix}-auto-compose-tab-${position}-right-${position === 'top' ? 'show' : 'hidden'}`}/></div>;});hoistNonReactStatics(Tab, Com);return Tab;};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。