-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tabs): make test pass and fix tabs props type
- Loading branch information
1 parent
8f03c1a
commit e2f9710
Showing
3 changed files
with
33 additions
and
17 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -1,31 +1,47 @@ | ||
import TabsStateless, { TabsStatelessProps } from './TabsStateless'; | ||
|
||
import * as React from "react"; | ||
import {useState} from "react"; | ||
import * as React from 'react'; | ||
import { useState } from 'react'; | ||
import TabsStateless from './TabsStateless'; | ||
import { TabProps } from './Tab'; | ||
|
||
export type TabsContainerState = { | ||
activeIndex: string; | ||
} | ||
|
||
export const defaultState = { activeIndex: '0' }; | ||
}; | ||
|
||
export type TabsCoreProps = Tabs & TabsStatelessProps; | ||
const defaultState = { activeIndex: '0' }; | ||
|
||
export type Tabs = { | ||
onChange: (e:string)=>void; | ||
} | ||
export type TabsCoreProps = { | ||
children: React.ReactElement<TabProps>[]; | ||
onChange?: (e: string) => void; | ||
className?: string; | ||
classModifier?: string; | ||
}; | ||
|
||
export const onChangeEvent = (onChange:Function) => (setState:Function) => (state: any) => (e:any) => { | ||
onChange(e.id); | ||
setState ({ | ||
export const onChangeEvent = (onChange: Function) => (setState: Function) => ( | ||
state: any | ||
) => (e: any) => { | ||
if (onChange) { | ||
onChange(e.id); | ||
} | ||
setState({ | ||
...state, | ||
activeIndex: e.id, | ||
}); | ||
}; | ||
|
||
const TabsCore = ({ onChange, ...otherProps }: TabsCoreProps) => { | ||
const TabsCore: React.FunctionComponent<TabsCoreProps> = ({ | ||
onChange, | ||
className = '', | ||
...otherProps | ||
}) => { | ||
const [state, setState] = useState<TabsContainerState>(defaultState); | ||
return <TabsStateless {...state} {...otherProps} onChange={onChangeEvent(onChange)(setState)(state)} />; | ||
return ( | ||
<TabsStateless | ||
className={className} | ||
{...state} | ||
{...otherProps} | ||
onChange={onChangeEvent(onChange)(setState)(state)} | ||
/> | ||
); | ||
}; | ||
|
||
export default TabsCore; |
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