-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Tabs with Context and types support #336
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {createContext} from 'react'; | ||
|
||
const TabRootContext = createContext(null); | ||
|
||
export default TabRootContext; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
'use client'; | ||
import React from 'react'; | ||
import {customClassSwitcher} from '~/core'; | ||
import {Tab} from '../types'; | ||
import {TabProps} from '../types'; | ||
|
||
const COMPONENT_NAME = 'TabTrigger'; | ||
|
||
export type TabTriggerProps = { | ||
tab: Tab; | ||
tab: TabProps; | ||
setActiveTab: React.Dispatch<Tab>; | ||
activeTab: Tab; | ||
activeTab: TabProps; | ||
className?: string; | ||
customRootClass?: string; | ||
index: number; | ||
|
@@ -25,7 +25,10 @@ const TabTrigger = ({tab, setActiveTab, activeTab, className, customRootClass, i | |
}; | ||
|
||
return ( | ||
<button role="tab" key={index} className={`${rootClass} ${isActive?'active':''} ${className}`} {...props} onClick={() => handleClick(tab)}> | ||
<button | ||
role="tab" key={index} className={`${rootClass} ${isActive?'active':''} ${className}`} {...props} onKeyDown={(e) => { | ||
console.log(e.key); | ||
}} onClick={() => handleClick(tab)}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider removing the console log from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - const handleClick = (tab: Tab) => {
+ const handleClick = (tab: TabProps) => {
|
||
<span className={`${rootClass}-inner`}> | ||
{tab.label} | ||
</span> | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
type TabProps ={ | ||
label: string; | ||
value: string; | ||
content: React.ReactNode; | ||
} | ||
|
||
export default TabProps; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type TabRootProps = { | ||
children: React.ReactNode; | ||
customRootClass?: string; | ||
className?: string; | ||
color?: string; | ||
props?: Record<string, any>[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refining the type of the |
||
tabs: []; | ||
activeTab: any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of |
||
} | ||
|
||
export default TabRootProps; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import TabRootProps from './TabRootProps'; | ||
import TabProps from './TabProps'; | ||
|
||
|
||
export type {TabRootProps, TabProps}; |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
TabsContext.Provider
is given anull
value. Consider providing a meaningful default value or handling this scenario appropriately in the consumer components.