hds-web 1.24.0 → 1.24.1
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.
- package/dist/index.css +2 -2
- package/dist/index.es.css +2 -2
- package/dist/index.es.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/HDS/components/Tabs/tab.js +24 -54
- package/src/styles/tailwind.css +4 -0
package/package.json
CHANGED
@@ -2,6 +2,7 @@ import React, { useState, useRef } from 'react';
|
|
2
2
|
import { HDSColor } from '../../foundation/ColorPalette';
|
3
3
|
import { Typography } from '../../foundation/Typography'
|
4
4
|
import PropTypes from 'prop-types';
|
5
|
+
import { motion } from 'framer-motion';
|
5
6
|
|
6
7
|
export default function Tab(props) {
|
7
8
|
const {
|
@@ -9,77 +10,46 @@ export default function Tab(props) {
|
|
9
10
|
onTabClick,
|
10
11
|
pillColor,
|
11
12
|
} = props;
|
12
|
-
const [activeTab, setActiveTab] = useState(tabs.find(tab => tab.current) || tabs[0]);
|
13
|
-
const pillRef = useRef(null);
|
13
|
+
const [activeTab, setActiveTab] = useState(tabs.find(tab => tab.current).name || tabs[0].name);
|
14
14
|
let pillColorClass = '';
|
15
15
|
if(pillColor){
|
16
16
|
pillColorClass = HDSColor(pillColor);
|
17
17
|
}
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
event.preventDefault();
|
22
|
-
setActiveTab(clickedTab);
|
19
|
+
const handleTabClick = (clickedTab) => {
|
20
|
+
setActiveTab(clickedTab.name);
|
23
21
|
if (onTabClick) {
|
24
22
|
onTabClick(clickedTab);
|
25
23
|
}
|
26
|
-
|
27
|
-
// Move the pill indicator to the clicked tab
|
28
|
-
const pill = pillRef.current;
|
29
|
-
if (pill) {
|
30
|
-
const pillWidth = event.currentTarget.offsetWidth;
|
31
|
-
const clickedTabOffset = event.currentTarget.offsetLeft;
|
32
|
-
const pillOffset = pill.parentElement.offsetLeft;
|
33
|
-
const translateX = clickedTabOffset;
|
34
|
-
|
35
|
-
pill.style.transform = `translateX(${translateX}px)`;
|
36
|
-
pill.style.width = `${pillWidth}px`;
|
37
|
-
}
|
24
|
+
|
38
25
|
};
|
39
26
|
let tabTextClass = '';
|
40
27
|
|
41
|
-
function tabClass(name) {
|
42
|
-
// console.log(currentTab['tabTextColorClass']);
|
43
|
-
|
44
|
-
if(activeTab['tabTextColorClass']){
|
45
|
-
tabTextClass = HDSColor(activeTab['tabTextColorClass']);
|
46
|
-
}
|
47
|
-
else tabTextClass = 'text-neutral-500'
|
48
|
-
|
49
|
-
let classActive = ' text-neutral-0 transition-all rounded-full ' + pillColorClass;
|
50
|
-
let clasnInActive = ' flex-nowrap rounded-full ' + tabTextClass;
|
51
|
-
if (activeTab.name === name) {
|
52
|
-
return classActive;
|
53
|
-
}
|
54
|
-
else {
|
55
|
-
return clasnInActive;
|
56
|
-
}
|
57
|
-
}
|
58
28
|
return (
|
59
|
-
<div className=
|
60
|
-
<div className="block">
|
61
|
-
<nav className="relative inline-flex gap-2 rounded-
|
62
|
-
{tabs.map(tab => (
|
63
|
-
<
|
29
|
+
<div className="">
|
30
|
+
<div className="block ">
|
31
|
+
<nav className="relative inline-flex gap-2 rounded-[32px] " aria-label="Tabs">
|
32
|
+
{tabs.map((tab) => (
|
33
|
+
<button
|
64
34
|
key={tab.name}
|
65
|
-
onClick={(
|
35
|
+
onClick={() => {
|
36
|
+
handleTabClick(tab);
|
37
|
+
}}
|
38
|
+
className={`${activeTab === tab.name ? ' text-neutral-0' : 'hover:text-neutral-0 hover:bg-neutral-0/20 text-neutral-300'} relative px-3 py-1 whitespace-nowrap rounded-full`}
|
66
39
|
>
|
67
|
-
|
68
|
-
|
69
|
-
|
40
|
+
{activeTab === tab.name && (
|
41
|
+
<motion.div
|
42
|
+
layoutId="active-pill"
|
43
|
+
className={`absolute inset-0 ${pillColorClass}`}
|
44
|
+
style={{ borderRadius: 32 }}
|
45
|
+
|
46
|
+
/>
|
47
|
+
)}
|
48
|
+
<Typography textStyle="body3c-medium" className="relative z-10 text-neutral-0 ">
|
70
49
|
{tab.name}
|
71
50
|
</Typography>
|
72
|
-
</
|
51
|
+
</button>
|
73
52
|
))}
|
74
|
-
<span
|
75
|
-
ref={pillRef}
|
76
|
-
className={`absolute left-0 z-[1] ${pillColorClass} rounded-full transition-all ease-in duration-150`}
|
77
|
-
style={{
|
78
|
-
left: `${activeTab.index * 100}%`,
|
79
|
-
width: `${activeTab.width}px`, // Use the width of the clicked tab
|
80
|
-
height: '28px' // Add desired height to make the pill visible
|
81
|
-
}}
|
82
|
-
/>
|
83
53
|
</nav>
|
84
54
|
</div>
|
85
55
|
</div>
|
package/src/styles/tailwind.css
CHANGED
@@ -9829,6 +9829,10 @@ select{
|
|
9829
9829
|
background-color: rgb(133 77 24 / var(--tw-bg-opacity));
|
9830
9830
|
}
|
9831
9831
|
|
9832
|
+
.hover\:bg-neutral-0\/20:hover{
|
9833
|
+
background-color: rgb(255 255 255 / 0.2);
|
9834
|
+
}
|
9835
|
+
|
9832
9836
|
.hover\:pl-\[9px\]:hover{
|
9833
9837
|
padding-left: 9px;
|
9834
9838
|
}
|