Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kotAPI committed Jun 19, 2024
1 parent f6625cb commit ebde2e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/ui/Tabs/shards/TabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type TabContentProps ={
customRootClass?: string;
}

const TabContent = ({ className, customRootClass}: TabContentProps) => {
const TabContent = ({className, customRootClass}: TabContentProps) => {
const rootClass = customClassSwitcher(customRootClass, COMPONENT_NAME);

const {tabs, activeTab, setActiveTab} = useContext(TabsRootContext);
Expand Down
27 changes: 14 additions & 13 deletions src/components/ui/Tabs/shards/TabRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@ const TabRoot = ({children, defaultTab='', customRootClass, tabs=[], className,

const [activeTab, setActiveTab] = useState(defaultTab || tabs[0].value || '');

const nextTab = ()=>{
const currentIndex = tabs.findIndex(tab => tab.value === activeTab);
const nextTab = () => {
const currentIndex = tabs.findIndex((tab) => tab.value === activeTab);
const nextIndex = currentIndex + 1;
if (nextIndex < tabs.length) {
setActiveTab(tabs[nextIndex].value);
}
}
};

const previousTab = ()=>{
const currentIndex = tabs.findIndex(tab => tab.value === activeTab);
const previousTab = () => {
const currentIndex = tabs.findIndex((tab) => tab.value === activeTab);
const previousIndex = currentIndex - 1;
if (previousIndex >= 0) {
setActiveTab(tabs[previousIndex].value);
}
}
};


return (
<TabsRootContext.Provider value={{
activeTab,
setActiveTab,
nextTab,
previousTab,
tabs
}}>
<TabsRootContext.Provider
value={{
activeTab,
setActiveTab,
nextTab,
previousTab,
tabs,
}}>
<div className={`${rootClass} ${className}`} data-accent-color={color} {...props} >
{children}
</div>
Expand Down
21 changes: 10 additions & 11 deletions src/components/ui/Tabs/shards/TabTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export type TabTriggerProps = {
}

const TabTrigger = ({tab, setActiveTab, activeTab, className, customRootClass, index, ...props}: TabTriggerProps) => {

// use context
const {tabs, previousTab, nextTab} = useContext(TabsRootContext);
console.log(tabs);
Expand All @@ -35,22 +34,22 @@ const TabTrigger = ({tab, setActiveTab, activeTab, className, customRootClass, i

const handleKeyDownEvent = (e: React.KeyboardEvent) => {
console.log(e.key);
if(e.key=="ArrowLeft"){
if (e.key=='ArrowLeft') {
previousTab();
}
if(e.key=="ArrowRight"){
if (e.key=='ArrowRight') {
nextTab();
}
}
};

return (
<button
role="tab" key={index} className={`${rootClass} ${isActive?'active':''} ${className}`} {...props} onKeyDown={handleKeyDownEvent}
onClick={() => handleClick(tab)}>
<span className={`${rootClass}-inner`}>
{tab.label}
</span>
</button>
<button
role="tab" key={index} className={`${rootClass} ${isActive?'active':''} ${className}`} {...props} onKeyDown={handleKeyDownEvent}
onClick={() => handleClick(tab)}>
<span className={`${rootClass}-inner`}>
{tab.label}
</span>
</button>
);
};

Expand Down

0 comments on commit ebde2e9

Please sign in to comment.