-
Notifications
You must be signed in to change notification settings - Fork 159
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
13 changed files
with
174 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { warn, error } = console; | ||
|
||
global.console.warn = (message) => { | ||
warn.call(console, message); | ||
throw (message instanceof Error ? message : new Error(message)); | ||
} | ||
|
||
global.console.error = (message) => { | ||
error.call(console, message); | ||
throw (message instanceof Error ? message : new Error(message)); | ||
} |
Binary file added
BIN
+31.6 KB
packages/fuselage/.loki/reference/chrome_iphone7_Misc_Callout_Default_Story.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
+58.7 KB
packages/fuselage/.loki/reference/chrome_iphone7_Misc_Callout_With_Description.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
+14.9 KB
packages/fuselage/.loki/reference/chrome_laptop_Misc_Callout_Default_Story.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
+25.5 KB
packages/fuselage/.loki/reference/chrome_laptop_Misc_Callout_With_Description.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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,49 @@ | ||
import { useClassName } from '@rocket.chat/fuselage-hooks'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import { useTheme } from '../../hooks/useTheme'; | ||
import { Icon } from '../Icon'; | ||
import { StyledCallout, Wrapper, Title } from './styles'; | ||
|
||
export const Callout = React.forwardRef(function Callout({ | ||
children, | ||
className, | ||
title, | ||
type = 'info', | ||
...props | ||
}, ref) { | ||
const classNames = { | ||
container: useClassName('rcx-callout', { type }, className), | ||
wrapper: useClassName('rcx-callout__wrapper'), | ||
title: useClassName('rcx-callout__title'), | ||
description: useClassName('rcx-callout__description'), | ||
}; | ||
const theme = useTheme(); | ||
|
||
const iconName = (type === 'info' && 'info-circled') | ||
|| (type === 'success' && 'checkmark-circled') | ||
|| (type === 'warning' && 'warning') | ||
|| (type === 'danger' && 'ban'); | ||
|
||
return <StyledCallout className={classNames.container} ref={ref} theme={theme} type={type} {...props}> | ||
<Icon name={iconName} /> | ||
<Wrapper theme={theme}> | ||
<Title hasChildren={!!children} theme={theme}>{title}</Title> | ||
{children} | ||
</Wrapper> | ||
</StyledCallout>; | ||
}); | ||
|
||
Callout.defaultProps = { | ||
type: 'info', | ||
}; | ||
|
||
Callout.displayName = 'Callout'; | ||
|
||
Callout.propTypes = { | ||
children: PropTypes.node, | ||
invisible: PropTypes.bool, | ||
title: PropTypes.string.isRequired, | ||
type: PropTypes.oneOf(['info', 'success', 'warning', 'danger']).isRequired, | ||
}; |
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,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import { Callout } from '../..'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<Callout title='' />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
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,45 @@ | ||
import { Meta, Preview, Props, Story } from '@storybook/addon-docs/blocks'; | ||
import LinkTo from '@storybook/addon-links/react'; | ||
|
||
import { Callout } from '../..'; | ||
|
||
<Meta title='Misc|Callout' parameters={{ jest: ['Callout/spec'] }} /> | ||
|
||
# Callout | ||
|
||
The <LinkTo kind='Misc|Callout' story='Default Story'>`Callout`</LinkTo> is used to get the user's attention explaining | ||
something important in the content of the current page. | ||
|
||
<Preview> | ||
<Story name='Default'> | ||
<> | ||
<Callout title='This is a generic message' /> | ||
<Callout title='This is a successful message' type='success' /> | ||
<Callout title='This is a warning message' type='warning' /> | ||
<Callout title='This is a danger message' type='danger' /> | ||
</> | ||
</Story> | ||
</Preview> | ||
|
||
<Props of={Callout} /> | ||
|
||
## With description | ||
|
||
<Preview> | ||
<Story name='With Description'> | ||
<> | ||
<Callout title='This is a generic message'> | ||
This is a generic description. | ||
</Callout> | ||
<Callout title='This is a successful message' type='success'> | ||
This is a successful description. | ||
</Callout> | ||
<Callout title='This is a warning message' type='warning'> | ||
This is a warning description. | ||
</Callout> | ||
<Callout title='This is a danger message' type='danger'> | ||
This is a danger description. | ||
</Callout> | ||
</> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import styled, { css } from 'styled-components'; | ||
import colors from '@rocket.chat/fuselage-tokens/colors'; | ||
|
||
import box from '../../styles/box'; | ||
import { truncate, caption, captionBold } from '../../styles/utilities/typography'; | ||
import { StyledIcon } from '../Icon/styles'; | ||
|
||
export const StyledCallout = styled.div` | ||
${ box } | ||
display: flex; | ||
margin: 0 0 ${ ({ theme }) => theme.spaces.x24 }; | ||
padding: ${ ({ theme }) => theme.spaces.x16 }; | ||
border-radius: ${ ({ theme }) => theme.borders.radius.x2 }; | ||
${ ({ type }) => | ||
(type === 'info' && css` | ||
background-color: ${ colors.blue200 }; | ||
`) | ||
|| (type === 'success' && css` | ||
background-color: ${ colors.green200 }; | ||
`) | ||
|| (type === 'warning' && css` | ||
background-color: ${ colors.yellow200 }; | ||
`) | ||
|| (type === 'danger' && css` | ||
background-color: ${ colors.red200 }; | ||
`) } | ||
& > ${ StyledIcon } { | ||
font-size: ${ ({ theme }) => theme.sizes.x16 }; | ||
} | ||
`; | ||
|
||
export const Wrapper = styled.div` | ||
${ box } | ||
flex: 1 1 0; | ||
display: flex; | ||
flex-flow: column nowrap; | ||
margin: 0 ${ ({ theme }) => theme.spaces.x8 }; | ||
color: ${ ({ theme }) => theme.textColors.default }; | ||
${ ({ theme }) => caption(theme) } | ||
`; | ||
|
||
export const Title = styled.div` | ||
${ box } | ||
${ ({ theme }) => captionBold(theme) } | ||
${ ({ hasChildren, theme }) => hasChildren && css` | ||
margin-bottom: ${ theme.spaces.x4 }; | ||
` } | ||
${ truncate } | ||
`; |
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