-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Renamed to typescript files * WIP Tabslist * First working component * Added fallback and tests for if missing children
- Loading branch information
Showing
13 changed files
with
207 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { forwardRef, ReactElement, useContext } from 'react' | ||
import { TabsContext } from './Tabs.context' | ||
|
||
type Props = React.HTMLAttributes<HTMLDivElement> | ||
|
||
const TabPanels = forwardRef<HTMLDivElement, Props>(function TabPanels( | ||
{ children, ...props }, | ||
ref, | ||
) { | ||
const { activeTab, tabsId } = useContext(TabsContext) | ||
|
||
const Panels = React.Children.map(children, (child: ReactElement, index) => | ||
React.cloneElement(child, { | ||
id: `${tabsId}-panel-${index + 1}`, | ||
'aria-labelledby': `${tabsId}-tab-${index + 1}`, | ||
hidden: activeTab !== index, | ||
}), | ||
) | ||
return ( | ||
<div ref={ref} {...props}> | ||
{Panels} | ||
</div> | ||
) | ||
}) | ||
|
||
export { TabPanels } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createContext } from 'react' | ||
import { Variants } from './Tabs.types' | ||
|
||
type State = { | ||
variant: Variants | ||
handleChange: (index: number) => void | ||
activeTab: number | ||
tabsId: string | ||
tabsFocused: boolean | ||
} | ||
|
||
const TabsContext = createContext<State>({ | ||
variant: 'minWidth', | ||
handleChange: () => null, | ||
activeTab: 0, | ||
tabsId: '', | ||
tabsFocused: false, | ||
}) | ||
|
||
const TabsProvider = TabsContext.Provider | ||
const TabsConsumer = TabsContext.Consumer | ||
|
||
export { TabsContext, TabsProvider, TabsConsumer } |
Oops, something went wrong.