Skip to content

Commit

Permalink
fix(tabs): make test pass and fix tabs props type
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbirgand committed May 28, 2020
1 parent 8f03c1a commit e2f9710
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
File renamed without changes.
48 changes: 32 additions & 16 deletions packages/tabs/src/TabsCore.tsx
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;
2 changes: 1 addition & 1 deletion packages/tabs/src/TabsStateless.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const TabsStateless: React.SFC<TabsStatelessProps & TabsStatelessHandlers> = ({
</ul>
<div className="af-tabs__content">
{children.map((item, index) => (
<Pane active={activeIndex === index.toString()} key={`pane -${index}`}>
<Pane active={activeIndex === index.toString()} key={`pane-${index}`}>
{item.props.children}
</Pane>
))}
Expand Down

0 comments on commit e2f9710

Please sign in to comment.