-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 'fork me' ribbon #861
Changes from 4 commits
458b14c
ffba4a0
4789ec3
ef6329c
614101f
9c9220d
d3b3d67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import RibbonRenderer from 'rsg-components/Ribbon/RibbonRenderer'; | ||
|
||
export default function Ribbon({}, { config }) { | ||
const { ribbon } = config; | ||
return ribbon ? <RibbonRenderer {...ribbon} /> : null; | ||
} | ||
|
||
Ribbon.contextTypes = { | ||
config: PropTypes.object, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import Ribbon from './Ribbon'; | ||
import { RibbonRenderer, styles } from './RibbonRenderer'; | ||
|
||
const props = { | ||
classes: classes(styles), | ||
}; | ||
|
||
describe('Ribbon', () => { | ||
it('should render ribbon if the ribbon is present in the config', () => { | ||
const actual = shallow(<Ribbon />, { context: { config: { ribbon: { url: 'foo.bar' } } } }); | ||
|
||
expect(actual).toMatchSnapshot(); | ||
}); | ||
|
||
it('should return null if the ribbon is not present in the config', () => { | ||
const actual = shallow(<Ribbon />, { context: { config: {} } }); | ||
|
||
expect(actual.type()).toBeNull(); | ||
}); | ||
}); | ||
describe('RibbonRenderer', () => { | ||
it('should render ribbon with url', () => { | ||
const actual = shallow(<RibbonRenderer {...props} url="http://example.com" />); | ||
|
||
expect(actual).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render ribbon with a text', () => { | ||
const actual = shallow( | ||
<RibbonRenderer {...props} url="http://example.com" text="Share the repo" /> | ||
); | ||
|
||
expect(actual).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Styled from 'rsg-components/Styled'; | ||
|
||
export const styles = ({ color, fontSize, fontFamily }) => ({ | ||
root: { | ||
position: 'fixed', | ||
top: 0, | ||
right: 0, | ||
width: '149px', | ||
height: '149px', | ||
zIndex: 999, | ||
}, | ||
link: { | ||
fontFamily: fontFamily.base, | ||
position: 'relative', | ||
right: -37, | ||
top: -22, | ||
display: 'block', | ||
width: 190, | ||
padding: '5px 15px', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to use |
||
textAlign: 'center', | ||
color: color.ribbonText, | ||
fontSize: fontSize.base, | ||
background: color.ribbonBackground, | ||
textDecoration: 'none', | ||
textShadow: '0 -1px 0 rgba(0,0,0,.15)', | ||
transformOrigin: '0 0', | ||
transform: 'rotate(45deg)', | ||
cursor: 'pointer', | ||
}, | ||
}); | ||
|
||
export function RibbonRenderer({ classes, url, text }) { | ||
return ( | ||
<div className={classes.root}> | ||
<a href={url} className={classes.link}> | ||
{text || 'Fork me on GitHub'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a |
||
</a> | ||
</div> | ||
); | ||
} | ||
|
||
RibbonRenderer.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
url: PropTypes.string.isRequired, | ||
text: PropTypes.string, | ||
color: PropTypes.string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't use |
||
background: PropTypes.string, | ||
}; | ||
|
||
export default Styled(styles)(RibbonRenderer); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Ribbon should render ribbon if the ribbon is present in the config 1`] = ` | ||
<Styled(Ribbon) | ||
url="foo.bar" | ||
/> | ||
`; | ||
|
||
exports[`RibbonRenderer should render ribbon with a text 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<a | ||
className="link" | ||
href="http://example.com" | ||
> | ||
Share the repo | ||
</a> | ||
</div> | ||
`; | ||
|
||
exports[`RibbonRenderer should render ribbon with url 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<a | ||
className="link" | ||
href="http://example.com" | ||
> | ||
Fork me on GitHub | ||
</a> | ||
</div> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Ribbon.js'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here should be a full path with |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import Logo from 'rsg-components/Logo'; | |
import Markdown from 'rsg-components/Markdown'; | ||
import Styled from 'rsg-components/Styled'; | ||
import cx from 'classnames'; | ||
import Ribbon from '../Ribbon'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
|
||
const styles = ({ color, fontFamily, fontSize, sidebarWidth, mq, space, maxWidth }) => ({ | ||
root: { | ||
|
@@ -71,6 +72,7 @@ export function StyleGuideRenderer({ classes, title, homepageUrl, children, toc, | |
{toc} | ||
</div> | ||
)} | ||
<Ribbon /> | ||
</div> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should work without
px
.