Skip to content

Commit

Permalink
Update AccordionItemState API to use object for render prop args
Browse files Browse the repository at this point in the history
  • Loading branch information
ryami333 committed Mar 12, 2019
1 parent cb2db5e commit eca8d4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -148,7 +148,7 @@ Class(es) to apply to element.
### AccordionItemState
#### children : `(expanded: boolean): JSX.Element` [**required**]
#### children : `({ expanded: boolean, disabled: boolean }): JSX.Element` [**required**]
---
Expand Down
12 changes: 10 additions & 2 deletions src/components/AccordionItemState.spec.tsx
Expand Up @@ -30,7 +30,11 @@ describe('ItemContext', () => {
<Accordion preExpanded={[UUIDS.FOO]}>
<AccordionItem uuid={UUIDS.FOO}>
<AccordionItemState>
{(expanded: boolean): JSX.Element => (
{({
expanded,
}: {
expanded: boolean;
}): JSX.Element => (
<div data-testid={UUIDS.FOO}>
{expanded && 'expanded'}
</div>
Expand All @@ -39,7 +43,11 @@ describe('ItemContext', () => {
</AccordionItem>
<AccordionItem uuid={UUIDS.BAR}>
<AccordionItemState>
{(expanded: boolean): JSX.Element => (
{({
expanded,
}: {
expanded: boolean;
}): JSX.Element => (
<div data-testid={UUIDS.BAR}>
{expanded && 'expanded'}
</div>
Expand Down
12 changes: 9 additions & 3 deletions src/components/AccordionItemState.tsx
Expand Up @@ -3,14 +3,20 @@ import { DivAttributes } from '../helpers/types';
import { Consumer as ItemConsumer, ItemContext } from './ItemContext';

type Props = Pick<DivAttributes, Exclude<keyof DivAttributes, 'children'>> & {
children(expanded?: boolean): React.ReactNode;
children(
args: Partial<{ expanded: boolean; disabled: boolean }>,
): React.ReactNode;
};

export default class AccordionItemState extends React.Component<Props> {
renderChildren = (itemContext: ItemContext): JSX.Element => {
const { expanded } = itemContext;
const { expanded, disabled } = itemContext;

return <React.Fragment>{this.props.children(expanded)}</React.Fragment>;
return (
<React.Fragment>
{this.props.children({ expanded, disabled })}
</React.Fragment>
);
};

render(): JSX.Element {
Expand Down

0 comments on commit eca8d4c

Please sign in to comment.