@festo-ui/react 10.1.1-dev.918 → 10.1.1-dev.920
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,7 +7,7 @@ import { IconWrapper } from "../icon-wrapper/IconWrapper.js";
|
|
|
7
7
|
import { useTabScroll } from "./useTabScroll.js";
|
|
8
8
|
let nextId = 0;
|
|
9
9
|
const Tabs = /*#__PURE__*/ forwardRef(({ config, children, className, onChange, viewType = 'responsive', showDivider = false, ...props }, ref)=>{
|
|
10
|
-
const [useCompactDensity,
|
|
10
|
+
const [useCompactDensity, setUseCompactDensity] = useState(true);
|
|
11
11
|
const componentId = useRef(`tabs-${++nextId}`);
|
|
12
12
|
const elRef = useRef(null);
|
|
13
13
|
const combinedRef = useForkRef(ref, elRef);
|
|
@@ -20,7 +20,7 @@ const Tabs = /*#__PURE__*/ forwardRef(({ config, children, className, onChange,
|
|
|
20
20
|
if ('' === activeId || element.props.active) activeId = `${componentId.current}-tab-panel-${i}`;
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
const [currentId,
|
|
23
|
+
const [currentId, setCurrentId] = useState(activeId);
|
|
24
24
|
const innerChildren = react.Children.map(children, (element, i)=>{
|
|
25
25
|
if (/*#__PURE__*/ isValidElement(element)) {
|
|
26
26
|
const newId = `${componentId.current}-tab-panel-${i}`;
|
|
@@ -42,16 +42,16 @@ const Tabs = /*#__PURE__*/ forwardRef(({ config, children, className, onChange,
|
|
|
42
42
|
const { current } = scrollArea;
|
|
43
43
|
if (current) {
|
|
44
44
|
const initialWidth = current.offsetWidth;
|
|
45
|
-
if (initialWidth > 768)
|
|
45
|
+
if (initialWidth > 768) setUseCompactDensity(false);
|
|
46
46
|
observer.current = new ResizeObserver(()=>{
|
|
47
47
|
const width = current.offsetWidth;
|
|
48
|
-
if (width > 768 && useCompactDensity)
|
|
49
|
-
else if (width <= 768 && !useCompactDensity)
|
|
48
|
+
if (width > 768 && useCompactDensity) setUseCompactDensity(false);
|
|
49
|
+
else if (width <= 768 && !useCompactDensity) setUseCompactDensity(true);
|
|
50
50
|
});
|
|
51
|
-
|
|
51
|
+
observer.current.observe(current);
|
|
52
52
|
}
|
|
53
53
|
return ()=>{
|
|
54
|
-
if (current && observer
|
|
54
|
+
if (current && observer?.current) observer.current.unobserve(current);
|
|
55
55
|
};
|
|
56
56
|
}, [
|
|
57
57
|
useCompactDensity
|
|
@@ -62,7 +62,7 @@ const Tabs = /*#__PURE__*/ forwardRef(({ config, children, className, onChange,
|
|
|
62
62
|
previous: currentId,
|
|
63
63
|
current: id
|
|
64
64
|
});
|
|
65
|
-
|
|
65
|
+
setCurrentId(id);
|
|
66
66
|
};
|
|
67
67
|
function handleClick(e, index, id) {
|
|
68
68
|
handleTabScroll(e, index);
|
|
@@ -4,7 +4,7 @@ const useTabScroll = (tabLength, componentId, refs)=>{
|
|
|
4
4
|
const [style, setStyle] = useState({});
|
|
5
5
|
const [classes, setClasses] = useState('');
|
|
6
6
|
function getScrollContentStyleValue(propName) {
|
|
7
|
-
return scrollContent.current ?
|
|
7
|
+
return scrollContent.current ? globalThis.getComputedStyle(scrollContent.current).getPropertyValue(propName) : '';
|
|
8
8
|
}
|
|
9
9
|
function calculateCurrentTranslateX() {
|
|
10
10
|
const transformValue = getScrollContentStyleValue('transform');
|
|
@@ -13,7 +13,7 @@ const useTabScroll = (tabLength, componentId, refs)=>{
|
|
|
13
13
|
if (!match) return 0;
|
|
14
14
|
const matrixParams = match[1];
|
|
15
15
|
const [_a, _b, _c, _d, tx, _ty] = matrixParams.split(',');
|
|
16
|
-
return parseFloat(tx);
|
|
16
|
+
return Number.parseFloat(tx);
|
|
17
17
|
}
|
|
18
18
|
function getScrollPosition() {
|
|
19
19
|
const currentTranslateX = calculateCurrentTranslateX();
|
|
@@ -42,13 +42,8 @@ const useTabScroll = (tabLength, componentId, refs)=>{
|
|
|
42
42
|
scrollDelta
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
function getAnimatingScrollPosition() {
|
|
46
|
-
const currentTranslateX = calculateCurrentTranslateX();
|
|
47
|
-
const scrollLeft = scrollArea.current?.scrollLeft ?? 0;
|
|
48
|
-
return scrollLeft - currentTranslateX;
|
|
49
|
-
}
|
|
50
45
|
function stopScrollAnimation() {
|
|
51
|
-
const currentScrollPosition =
|
|
46
|
+
const currentScrollPosition = getScrollPosition();
|
|
52
47
|
setClasses('');
|
|
53
48
|
setStyle({
|
|
54
49
|
transform: 'translateX(0px)'
|
|
@@ -75,19 +70,6 @@ const useTabScroll = (tabLength, componentId, refs)=>{
|
|
|
75
70
|
const scrollOperation = getIncrementScrollOperation(scrollXIncrement);
|
|
76
71
|
animate(scrollOperation);
|
|
77
72
|
}
|
|
78
|
-
function computeDimensions(tab) {
|
|
79
|
-
const rootWidth = tab.offsetWidth;
|
|
80
|
-
const rootLeft = tab.offsetLeft;
|
|
81
|
-
const tabContent = tab.querySelector('.fr-tab-content');
|
|
82
|
-
const contentWidth = tabContent?.offsetWidth ?? 0;
|
|
83
|
-
const contentLeft = tabContent?.offsetLeft ?? 0;
|
|
84
|
-
return {
|
|
85
|
-
contentLeft: rootLeft + contentLeft,
|
|
86
|
-
contentRight: rootLeft + contentLeft + contentWidth,
|
|
87
|
-
rootLeft,
|
|
88
|
-
rootRight: rootLeft + rootWidth
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
73
|
function calculateScrollIncrement(index, nextIndex, scrollPosition, barWidth) {
|
|
92
74
|
const nextTab = elRef.current?.querySelector(`#${componentId}-tab-${nextIndex}`);
|
|
93
75
|
if (null == nextTab) return 0;
|
|
@@ -99,16 +81,6 @@ const useTabScroll = (tabLength, componentId, refs)=>{
|
|
|
99
81
|
if (nextIndex < index) return Math.min(leftIncrement, 0);
|
|
100
82
|
return Math.max(rightIncrement, 0);
|
|
101
83
|
}
|
|
102
|
-
function findAdjacentTabIndexClosestToEdge(index, tabDimensions, scrollPosition, barWidth) {
|
|
103
|
-
const relativeRootLeft = tabDimensions.rootLeft - scrollPosition;
|
|
104
|
-
const relativeRootRight = tabDimensions.rootRight - scrollPosition - barWidth;
|
|
105
|
-
const relativeRootDelta = relativeRootLeft + relativeRootRight;
|
|
106
|
-
const leftEdgeIsCloser = relativeRootLeft < 0 || relativeRootDelta < 0;
|
|
107
|
-
const rightEdgeIsCloser = relativeRootRight > 0 || relativeRootDelta > 0;
|
|
108
|
-
if (leftEdgeIsCloser) return index - 1;
|
|
109
|
-
if (rightEdgeIsCloser) return index + 1;
|
|
110
|
-
return -1;
|
|
111
|
-
}
|
|
112
84
|
function indexIsInRange(index) {
|
|
113
85
|
return index >= 0 && index < tabLength;
|
|
114
86
|
}
|
|
@@ -148,4 +120,27 @@ const useTabScroll = (tabLength, componentId, refs)=>{
|
|
|
148
120
|
style
|
|
149
121
|
];
|
|
150
122
|
};
|
|
123
|
+
function computeDimensions(tab) {
|
|
124
|
+
const rootWidth = tab.offsetWidth;
|
|
125
|
+
const rootLeft = tab.offsetLeft;
|
|
126
|
+
const tabContent = tab.querySelector('.fr-tab-content');
|
|
127
|
+
const contentWidth = tabContent?.offsetWidth ?? 0;
|
|
128
|
+
const contentLeft = tabContent?.offsetLeft ?? 0;
|
|
129
|
+
return {
|
|
130
|
+
contentLeft: rootLeft + contentLeft,
|
|
131
|
+
contentRight: rootLeft + contentLeft + contentWidth,
|
|
132
|
+
rootLeft,
|
|
133
|
+
rootRight: rootLeft + rootWidth
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function findAdjacentTabIndexClosestToEdge(index, tabDimensions, scrollPosition, barWidth) {
|
|
137
|
+
const relativeRootLeft = tabDimensions.rootLeft - scrollPosition;
|
|
138
|
+
const relativeRootRight = tabDimensions.rootRight - scrollPosition - barWidth;
|
|
139
|
+
const relativeRootDelta = relativeRootLeft + relativeRootRight;
|
|
140
|
+
const leftEdgeIsCloser = relativeRootLeft < 0 || relativeRootDelta < 0;
|
|
141
|
+
const rightEdgeIsCloser = relativeRootRight > 0 || relativeRootDelta > 0;
|
|
142
|
+
if (leftEdgeIsCloser) return index - 1;
|
|
143
|
+
if (rightEdgeIsCloser) return index + 1;
|
|
144
|
+
return -1;
|
|
145
|
+
}
|
|
151
146
|
export { useTabScroll };
|
|
@@ -15,11 +15,10 @@ const Segment = /*#__PURE__*/ forwardRef(({ children, legend, config, onChange,
|
|
|
15
15
|
let useIconAndText = false;
|
|
16
16
|
let tmpValue = '';
|
|
17
17
|
Children.forEach(children, (child, index)=>{
|
|
18
|
-
if (!/*#__PURE__*/ isValidElement(child)) return
|
|
18
|
+
if (!/*#__PURE__*/ isValidElement(child)) return;
|
|
19
19
|
if (0 === index && null !== child.props.icon) if (innerConfig.iconOnly) useIcon = true;
|
|
20
20
|
else useIconAndText = true;
|
|
21
21
|
if (child.props.checked) tmpValue = child.props.value;
|
|
22
|
-
return null;
|
|
23
22
|
});
|
|
24
23
|
const [value, setValue] = useControlled({
|
|
25
24
|
controlled: valueProps,
|
package/package.json
CHANGED