-
Notifications
You must be signed in to change notification settings - Fork 149
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
20 changed files
with
203 additions
and
71 deletions.
There are no files selected for viewing
Binary file added
BIN
+1.86 KB
packages/fuselage/.loki/reference/chrome_iphone7_Data_Display_Chip_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.43 KB
packages/fuselage/.loki/reference/chrome_iphone7_Data_Display_Chip_Dismissible.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.14 KB
packages/fuselage/.loki/reference/chrome_iphone7_Data_Display_Chip_Example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.67 KB
packages/fuselage/.loki/reference/chrome_iphone7_Data_Display_Chip_With_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-22.1 KB
packages/fuselage/.loki/reference/chrome_iphone7_Misc_Chip_Default.png
Binary file not shown.
Binary file added
BIN
+862 Bytes
packages/fuselage/.loki/reference/chrome_laptop_Data_Display_Chip_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.07 KB
packages/fuselage/.loki/reference/chrome_laptop_Data_Display_Chip_Dismissible.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.31 KB
packages/fuselage/.loki/reference/chrome_laptop_Data_Display_Chip_Example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.25 KB
packages/fuselage/.loki/reference/chrome_laptop_Data_Display_Chip_With_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-4.12 KB
packages/fuselage/.loki/reference/chrome_laptop_Misc_Chip_Default.png
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createElement } from 'react'; | ||
|
||
import { useStyleSheet } from '../../hooks/useStyleSheet'; | ||
import { useStylingProps } from './stylingProps'; | ||
|
||
export const withBoxStyling = (component) => { | ||
const render = (props) => { | ||
if (typeof component === 'function') { | ||
return component(props); | ||
} | ||
|
||
return createElement(component, props); | ||
}; | ||
|
||
const WithBoxStyling = (props) => { | ||
useStyleSheet(); | ||
props = useStylingProps(props); | ||
return render(props); | ||
}; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
WithBoxStyling.displayName = `WithBoxStyling(${ component.displayName || component.name || 'Component' })`; | ||
} | ||
|
||
return WithBoxStyling; | ||
}; |
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,52 +1,50 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import { prependClassName } from '../../helpers/prependClassName'; | ||
import { Avatar } from '../Avatar'; | ||
import { Box, Flex } from '../Box'; | ||
import { withBoxStyling } from '../Box/withBoxStyling'; | ||
import { Icon } from '../Icon'; | ||
import Margins from '../Margins'; | ||
|
||
const ThumbDefault = ({ url }) => <Avatar size='x20' url={url}/>; | ||
const RemoveDefault = () => <Icon name='cross' size='x16' />; | ||
const defaultRenderThumb = ({ url }) => <Avatar size='x20' url={url} />; | ||
const defaultRenderDismissSymbol = () => <Icon name='cross' size='x16' />; | ||
|
||
export const Chip = ({ | ||
const Chip = ({ | ||
children, | ||
className, | ||
thumbUrl, | ||
Thumb = ThumbDefault, | ||
onClick, | ||
onMouseDown, | ||
Remove = RemoveDefault, | ||
...props | ||
}) => ( | ||
<Flex.Container> | ||
<Box rcx-chip is='button' type='button' disabled={!(onClick || onMouseDown)} onClick={onClick || onMouseDown} {...props}> | ||
{Thumb && thumbUrl && <Margins all='x4'> | ||
<Thumb url={thumbUrl} /> | ||
</Margins>} | ||
{children && <Flex.Item shrink={1}> | ||
<Margins all='x4'> | ||
<Box is='span' fontScale='p1' color='default' rcx-chip__text>{children}</Box> | ||
</Margins> | ||
</Flex.Item>} | ||
{Remove && (onClick || onMouseDown) && <Margins all='x4'> | ||
<Box> | ||
<Remove/> | ||
</Box> | ||
</Margins>} | ||
</Box> | ||
</Flex.Container> | ||
); | ||
renderThumb = defaultRenderThumb, | ||
renderDismissSymbol = defaultRenderDismissSymbol, | ||
...rest | ||
}) => { | ||
const onDismiss = onClick || onMouseDown; | ||
|
||
Chip.Wrapper = ({ children, width, alignItems = 'center', wrap = 'wrap', ...props }) => | ||
<Margins all='neg-x4'> | ||
<Flex.Container alignItems={alignItems} wrap={wrap}> | ||
<Box rcx-chip__wrapper is='div' {...props}> | ||
{children.map((children, i) => | ||
<Flex.Item key={i} shrink={1}> | ||
<Margins all='x4'> | ||
{children} | ||
</Margins> | ||
</Flex.Item>, | ||
)} | ||
</Box> | ||
</Flex.Container> | ||
</Margins>; | ||
return <button | ||
type='button' | ||
className={prependClassName(className, 'rcx-box rcx-chip')} | ||
disabled={!onDismiss} | ||
onClick={onDismiss} | ||
{...rest} | ||
> | ||
<Margins all='x4'> | ||
{thumbUrl && renderThumb && renderThumb({ url: thumbUrl })} | ||
{children && <span className='rcx-box rcx-chip__text'>{children}</span>} | ||
{onDismiss && renderDismissSymbol && renderDismissSymbol()} | ||
</Margins> | ||
</button>; | ||
}; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
Chip.displayName = 'Chip'; | ||
|
||
Chip.propTypes = { | ||
thumbUrl: PropTypes.string, | ||
renderThumb: PropTypes.func, | ||
renderDismissSymbol: PropTypes.func, | ||
}; | ||
} | ||
|
||
export default withBoxStyling(Chip); |
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,22 +1,49 @@ | ||
import { Meta, Preview, Props, Story } from '@storybook/addon-docs/blocks'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { exampleAvatar, blankAvatar } from '../../../.storybook/helpers'; | ||
import { Box, Chip, Margins } from '../..'; | ||
|
||
import { Chip, Margins } from '../..'; | ||
const thumb = 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; | ||
|
||
<Meta title='Misc/Chip' parameters={{ jest: ['Chip/spec'] }} /> | ||
<Meta title='Data Display/Chip' parameters={{ jest: ['Chip/spec'] }} /> | ||
|
||
# Chip | ||
|
||
<Preview> | ||
<Story name='Default'> | ||
<Chip.Wrapper> | ||
<Chip onClick={action('click')} thumbUrl={thumb}>Chip</Chip> | ||
<Chip thumbUrl={thumb}>Chip Chip Chip Chip Chip</Chip> | ||
<Chip onClick={action('click')} >Chip Chip Chip Chip Chip Chip Chip Chip Chip Chip</Chip> | ||
<Chip>Chip Chip Chip Chip Chip Chip Chip Chip Chip Chip</Chip> | ||
</Chip.Wrapper> | ||
<Story name='Example'> | ||
<Chip thumbUrl={exampleAvatar} onClick={action('click')}>Marie Rowe</Chip> | ||
</Story> | ||
</Preview> | ||
|
||
<Props of={Chip} /> | ||
|
||
### Default | ||
|
||
<Preview> | ||
<Story name='Default'> | ||
<Chip>Chip</Chip> | ||
</Story> | ||
</Preview> | ||
|
||
### Dismissible | ||
|
||
<Preview> | ||
<Story name='Dismissible'> | ||
<Chip onClick={action('click')}>Chip</Chip> | ||
</Story> | ||
</Preview> | ||
|
||
### With thumb | ||
|
||
<Preview> | ||
<Story name='With thumb' decorators={[ | ||
(storyFn) => <Box display='flex' margin='-x4'> | ||
<Margins all='x4'> | ||
{storyFn()} | ||
</Margins> | ||
</Box>, | ||
]}> | ||
<> | ||
<Chip thumbUrl={blankAvatar}>Chip</Chip> | ||
<Chip thumbUrl={blankAvatar} onClick={action('click')}>Chip</Chip> | ||
</> | ||
</Story> | ||
</Preview> |
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