-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
c88b281
commit aa0c212
Showing
18 changed files
with
173 additions
and
96 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 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 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 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,2 +1 @@ | ||
declare module '@component-controls/loader/story-store-data'; | ||
declare module '@theme-ui/presets'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import { Box } from 'theme-ui'; | ||
import { ActionBar } from './ActionBar'; | ||
import { ThemeProvider } from '../ThemeContext'; | ||
import { ExternalLink } from '../ExternalLink'; | ||
|
||
export default { | ||
title: 'Components/ActionBar', | ||
component: ActionBar, | ||
}; | ||
|
||
const Container: React.FC = ({ children }) => ( | ||
<ThemeProvider> | ||
<Box | ||
style={{ | ||
height: 100, | ||
backgroundColor: 'red', | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
</ThemeProvider> | ||
); | ||
export const simple = () => ( | ||
<Container> | ||
<ActionBar | ||
actionItems={[ | ||
{ | ||
title: 'action 1', | ||
onClick: () => console.log('clicked'), | ||
}, | ||
{ | ||
title: 'action 2', | ||
onClick: () => console.log('clicked'), | ||
}, | ||
]} | ||
/> | ||
</Container> | ||
); | ||
|
||
export const disabled = () => ( | ||
<Container> | ||
<ActionBar | ||
actionItems={[ | ||
{ | ||
title: 'click action', | ||
onClick: () => console.log('clicked'), | ||
disabled: true, | ||
}, | ||
]} | ||
/> | ||
</Container> | ||
); | ||
|
||
export const link = () => ( | ||
<Container> | ||
<ActionBar | ||
actionItems={[ | ||
{ | ||
title: <ExternalLink href="https://google.com">google</ExternalLink>, | ||
}, | ||
]} | ||
/> | ||
</Container> | ||
); |
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,83 +1,66 @@ | ||
/** @jsx jsx */ | ||
import React, { FunctionComponent, MouseEvent } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Theme } from 'theme-ui'; | ||
|
||
const Container = styled.div(({ theme }: { theme?: Theme }) => ({ | ||
bottom: 0, | ||
right: 0, | ||
maxWidth: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'flex-end', | ||
background: theme?.colors?.background, | ||
})); | ||
|
||
interface ActionButtonProps { | ||
disabled?: boolean; | ||
} | ||
export const ActionButton = styled.button<ActionButtonProps>( | ||
({ theme }: { theme: Theme } & ActionButtonProps) => ({ | ||
border: '0 none', | ||
padding: '4px 10px', | ||
cursor: 'pointer', | ||
display: 'flex', | ||
alignItems: 'center', | ||
color: theme?.colors?.text, | ||
background: theme?.colors?.background, | ||
|
||
fontSize: 12, | ||
lineHeight: '16px', | ||
fontWeight: 'bold', | ||
|
||
borderBottom: `1px solid ${theme?.colors?.muted}`, | ||
borderLeft: `1px solid ${theme?.colors?.muted}`, | ||
borderRight: `1px solid ${theme?.colors?.muted}`, | ||
marginLeft: -1, | ||
|
||
borderRadius: `4px 0 0 0`, | ||
|
||
'&:not(:last-child)': { borderRight: `1px solid ${theme?.colors?.muted}` }, | ||
'& + *': { | ||
borderLeft: `1px solid ${theme?.colors?.muted}`, | ||
borderRadius: 0, | ||
}, | ||
|
||
'&:focus': { | ||
boxShadow: `${theme?.colors?.secondary} 0 -3px 0 0 inset`, | ||
outline: '0 none', | ||
}, | ||
}), | ||
({ disabled }) => | ||
disabled && { | ||
cursor: 'not-allowed', | ||
opacity: 0.5, | ||
}, | ||
); | ||
ActionButton.displayName = 'ActionButton'; | ||
import { Box, Button, jsx } from 'theme-ui'; | ||
|
||
export interface ActionItem { | ||
title: React.ReactNode; | ||
onClick?: (e: MouseEvent<HTMLButtonElement>) => void; | ||
disabled?: boolean; | ||
hidden?: boolean; | ||
} | ||
|
||
export interface ActionBarProps { | ||
actionItems: ActionItem[]; | ||
} | ||
|
||
const StyledContainer = styled.div` | ||
position: relative; | ||
`; | ||
|
||
const StyledFlex = styled.div` | ||
display: flex; | ||
position: absolute; | ||
flex-direction: row-reverse; | ||
width: 100%; | ||
`; | ||
|
||
const ActionColors = (disabled: boolean | undefined) => ({ | ||
backgroundColor: 'highlight', | ||
color: disabled ? '#ddd' : 'background', | ||
cursor: disabled ? 'not-allowed' : undefined, | ||
px: 2, | ||
py: 1, | ||
lineHeight: 1, | ||
borderRadius: 0, | ||
border: 'none', | ||
}); | ||
export const ActionBar: FunctionComponent<ActionBarProps> = ({ | ||
actionItems, | ||
...props | ||
}) => ( | ||
<Container {...props}> | ||
{actionItems.map(({ title, onClick, disabled }, index: number) => ( | ||
<ActionButton | ||
key={`${typeof title === 'string' ? title : 'item'}_${index}`} | ||
onClick={onClick} | ||
disabled={disabled} | ||
> | ||
{title} | ||
</ActionButton> | ||
))} | ||
</Container> | ||
<StyledContainer> | ||
<StyledFlex> | ||
{actionItems | ||
.filter(({ hidden }) => !hidden) | ||
.map(({ title, onClick, disabled }, index: number) => ( | ||
<Box | ||
key={`${typeof title === 'string' ? title : 'item'}_${index}`} | ||
sx={{ | ||
ml: 1, | ||
fontSize: 1, | ||
a: ActionColors(disabled), | ||
button: ActionColors(disabled), | ||
}} | ||
> | ||
{typeof title === 'string' ? ( | ||
<Button onClick={onClick} disabled={disabled}> | ||
{title} | ||
</Button> | ||
) : ( | ||
title | ||
)} | ||
</Box> | ||
))} | ||
</StyledFlex> | ||
</StyledContainer> | ||
); |
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,20 +1,36 @@ | ||
import React from 'react'; | ||
import { Box, Button } from 'theme-ui'; | ||
import { Collapsible } from './Collapsible'; | ||
import { Collapsible, CollapsibleProps } from './Collapsible'; | ||
|
||
export default { | ||
title: 'Components/Collapsible', | ||
component: Collapsible, | ||
}; | ||
|
||
export const simple = () => { | ||
export const simple = ({ easing }: CollapsibleProps) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
return ( | ||
<Box> | ||
<Button onClick={() => setIsOpen(!isOpen)}> | ||
{isOpen ? 'close' : 'open'} | ||
</Button> | ||
<Collapsible isOpen={isOpen}>content</Collapsible> | ||
<Collapsible isOpen={isOpen} easing={easing}> | ||
content | ||
</Collapsible> | ||
</Box> | ||
); | ||
}; | ||
|
||
simple.story = { | ||
parameters: { | ||
addonControls: { | ||
smart: false, | ||
}, | ||
controls: { | ||
easing: { | ||
type: 'options', | ||
options: ['ease', 'linear', 'ease-in', 'ease-out', 'ease-in-out'], | ||
}, | ||
}, | ||
}, | ||
}; |
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
File renamed without changes.
Oops, something went wrong.