-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { FC } from 'react' | ||
import useCollapsibleState from './useCollapsibleState' | ||
import Clickable, { ClickableProps } from '../Clickable' | ||
|
||
const CollapsibleToggle: FC<CollapsibleToggleProps> = ({ | ||
toggle, | ||
children, | ||
...props | ||
}) => { | ||
return ( | ||
<Clickable onClick={toggle} {...props}> | ||
{children} | ||
</Clickable> | ||
) | ||
} | ||
|
||
export type CollapsibleToggleProps = ReturnType<typeof useCollapsibleState> & | ||
ClickableProps | ||
|
||
export default CollapsibleToggle |
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,20 @@ | ||
import React from 'react' | ||
import Collapsible from './index' | ||
import CollapsibleToggle from './CollapsibleToggle' | ||
import { AdaptProvider } from '..' | ||
import useCollapsibleState from './useCollapsibleState' | ||
|
||
export default { | ||
title: 'Collapsible', | ||
decorators: [storyFn => <AdaptProvider>{storyFn()}</AdaptProvider>], | ||
} | ||
|
||
export const basic = () => { | ||
const collapse = useCollapsibleState() | ||
return ( | ||
<> | ||
<CollapsibleToggle {...collapse}>Toggle</CollapsibleToggle> | ||
<Collapsible {...collapse}>Hello Button</Collapsible> | ||
</> | ||
) | ||
} |
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,14 @@ | ||
import React, { FC } from 'react' | ||
import Box, { BoxProps } from '../Box' | ||
|
||
const Collapsible: FC<CollapsibleProps> = ({ | ||
collapsed, | ||
children, | ||
...props | ||
}) => { | ||
return collapsed ? <Box {...props}>{children}</Box> : null | ||
} | ||
|
||
export type CollapsibleProps = { collapsed?: boolean } & BoxProps | ||
|
||
export default Collapsible |
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,24 @@ | ||
import { useState, useCallback } from 'react' | ||
|
||
export default function useCollapsibleState(initalState: boolean = false) { | ||
const [collapsed, setCollapsed] = useState<boolean>(initalState) | ||
|
||
const toggle = useCallback(() => { | ||
setCollapsed(!collapsed) | ||
}, [collapsed]) | ||
|
||
const collapse = useCallback(() => { | ||
setCollapsed(true) | ||
}, [collapsed]) | ||
|
||
const uncollapse = useCallback(() => { | ||
setCollapsed(false) | ||
}, [collapsed]) | ||
|
||
return { | ||
collapsed, | ||
toggle, | ||
collapse, | ||
uncollapse, | ||
} | ||
} |
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