-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Feat: Forkme ribbon option #647
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
Changes from all commits
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,11 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import RibbonRenderer from 'rsg-components/Ribbon/RibbonRenderer'; | ||
|
||
export default function Ribbon({}, { config }) { | ||
return <RibbonRenderer {...config.ribbon} />; | ||
} | ||
|
||
Ribbon.contextTypes = { | ||
config: PropTypes.object, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { RibbonRenderer, styles } from './RibbonRenderer'; | ||
|
||
const props = { | ||
classes: classes(styles), | ||
}; | ||
|
||
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(); | ||
}); | ||
|
||
it('should render ribbon with custom background and color', () => { | ||
const actual = shallow( | ||
<RibbonRenderer | ||
{...props} | ||
url="http://example.com" | ||
text="Share the repo" | ||
background="#cdcdcd" | ||
color="#aa00bb" | ||
/> | ||
); | ||
|
||
expect(actual).toMatchSnapshot(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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', | ||
textAlign: 'center', | ||
color: 'white', | ||
fontSize: fontSize.base, | ||
background: color.ribbonBackground, | ||
textDecoration: 'none', | ||
textShadow: '0 -1px 0 rgba(0,0,0,.15)', | ||
transformOrigin: '0 0', | ||
transform: 'rotate(45deg)', | ||
}, | ||
}); | ||
|
||
export function RibbonRenderer({ classes, url, text, color, background }) { | ||
return ( | ||
<div className={classes.root}> | ||
<a href={url} className={classes.link} style={{ color, background }}> | ||
{text || 'Fork me on GitHub'} | ||
</a> | ||
</div> | ||
); | ||
} | ||
|
||
RibbonRenderer.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
url: PropTypes.string.isRequired, | ||
text: PropTypes.string, | ||
color: PropTypes.string, | ||
background: PropTypes.string, | ||
}; | ||
|
||
export default Styled(styles)(RibbonRenderer); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render ribbon with a text 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<a | ||
className="link" | ||
href="http://example.com" | ||
style={ | ||
Object { | ||
"background": undefined, | ||
"color": undefined, | ||
} | ||
} | ||
> | ||
Share the repo | ||
</a> | ||
</div> | ||
`; | ||
|
||
exports[`should render ribbon with custom background and color 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<a | ||
className="link" | ||
href="http://example.com" | ||
style={ | ||
Object { | ||
"background": "#cdcdcd", | ||
"color": "#aa00bb", | ||
} | ||
} | ||
> | ||
Share the repo | ||
</a> | ||
</div> | ||
`; | ||
|
||
exports[`should render ribbon with url 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<a | ||
className="link" | ||
href="http://example.com" | ||
style={ | ||
Object { | ||
"background": undefined, | ||
"color": undefined, | ||
} | ||
} | ||
> | ||
Fork me on GitHub | ||
</a> | ||
</div> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Ribbon.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ export default class StyleGuide extends Component { | |
homepageUrl={HOMEPAGE} | ||
toc={<TableOfContents sections={sections} />} | ||
hasSidebar={config.showSidebar && !isolatedComponent} | ||
ribbon={config.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. You don’t need this because all config is accessible in the context. 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. I think we still need this here as we're passing it down to the component to check if we need to render a ribbon (just like 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. No if you’ll read config from the context as I’m suggesting ;-) |
||
> | ||
<Sections sections={sections} depth={1} /> | ||
</StyleGuideRenderer> | ||
|
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.
Please take a look at https://react-styleguidist.js.org/docs/development.html This component should be split into two: Ribbon that will read config for a React context and RibbonRenderer — this component that prints actual HTML.
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.
Ok, please take a look now and see if it's correct now.