This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Mixins are now a function that takes props and return another function.
- Loading branch information
Showing
7 changed files
with
154 additions
and
6 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,69 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import classNames from 'classnames' | ||
import styled, { css } from 'styled-components' | ||
import handleRef from './internal/handleRef' | ||
import setWithComponent from './internal/setWithComponent' | ||
import * as defaultTheme from './style/defaultTheme' | ||
import { th, mixin } from './utils' | ||
|
||
const variants = [ | ||
'primary', | ||
'secondary', | ||
'success', | ||
'danger', | ||
'warning', | ||
'info', | ||
'light', | ||
'dark', | ||
] | ||
|
||
const AlertComponent = ({ | ||
className, | ||
component: Component = 'div', | ||
theme, | ||
variant, | ||
...props | ||
}) => ( | ||
<Component | ||
{...props} | ||
className={classNames( | ||
'sui-alert', | ||
{ | ||
[`sui-alert-${variant}`]: variant, | ||
}, | ||
className, | ||
)} | ||
/> | ||
) | ||
|
||
const Alert = styled(handleRef(AlertComponent))` | ||
position: relative; | ||
padding: ${th('alertPaddingY')} ${th('alertPaddingX')}; | ||
margin-bottom: ${th('alertMarginBottom')}; | ||
border: 1px solid transparent; | ||
border-radius: ${th('borderRadius')}; | ||
${variants.map( | ||
variant => css` | ||
&.sui-alert-${variant} { | ||
${mixin('alertVariant', variant)}; | ||
} | ||
`, | ||
)}; | ||
` | ||
|
||
Alert.propTypes = { | ||
variant: PropTypes.oneOf(variants), | ||
theme: PropTypes.object, | ||
} | ||
|
||
Alert.defaultProps = { | ||
variant: 'primary', | ||
theme: defaultTheme, | ||
} | ||
|
||
setWithComponent(Alert, AlertComponent) | ||
|
||
/** @component */ | ||
export default Alert |
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,32 @@ | ||
### Variants | ||
|
||
Set sizes using `variant` prop. | ||
|
||
```js | ||
<div> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="primary">Primary</Alert> | ||
</span> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="secondary">Secondary</Alert> | ||
</span> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="success">Success</Alert> | ||
</span> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="danger">Danger</Alert> | ||
</span> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="warning">Warning</Alert> | ||
</span> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="info">Info</Alert> | ||
</span> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="light">Light</Alert> | ||
</span> | ||
<span style={{ margin: '5px' }}> | ||
<Alert variant="dark">Dark</Alert> | ||
</span> | ||
</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
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