Skip to content

Commit 746f69d

Browse files
committed
Feat: Forkme ribbon option
1 parent e0f576d commit 746f69d

File tree

8 files changed

+164
-1
lines changed

8 files changed

+164
-1
lines changed

loaders/styleguide-loader.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const CLIENT_CONFIG_OPTIONS = [
2323
'theme',
2424
'styles',
2525
'compilerConfig',
26+
'ribbon',
2627
];
2728

2829
module.exports = function() {};

scripts/schemas/config.js

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ module.exports = {
109109
type: 'function',
110110
default: reactDocgen.resolver.findAllExportedComponentDefinitions,
111111
},
112+
ribbon: {
113+
type: 'object',
114+
example: {
115+
url: 'http://example.com/',
116+
text: 'Fork me on GitHub',
117+
color: '#fff',
118+
background: '#24292e',
119+
},
120+
},
112121
sections: {
113122
type: 'array',
114123
default: [],

src/rsg-components/Ribbon/Ribbon.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import Styled from 'rsg-components/Styled';
4+
5+
export const styles = ({ fontFamily }) => ({
6+
forkme: {
7+
position: 'fixed',
8+
top: 0,
9+
right: 0,
10+
width: '149px',
11+
height: '149px',
12+
zIndex: 999,
13+
},
14+
forkmeIcon: {
15+
fontFamily: fontFamily.base,
16+
position: 'relative',
17+
right: -37,
18+
top: -22,
19+
display: 'block',
20+
width: 190,
21+
padding: '5px 15px',
22+
textAlign: 'center',
23+
fontSize: 14,
24+
background: '#f9970d',
25+
textDecoration: 'none',
26+
textShadow: '0 -1px 0 black(.15)',
27+
transformOrigin: '0 0',
28+
transform: 'rotate(45deg)',
29+
},
30+
});
31+
32+
export function Ribbon({ classes, url, text, color, background }) {
33+
return (
34+
<div className={classes.forkme}>
35+
<a href={url} className={classes.forkmeIcon} style={{ color, background }}>
36+
{text || 'Fork me on GitHub'}
37+
</a>
38+
</div>
39+
);
40+
}
41+
42+
Ribbon.propTypes = {
43+
classes: PropTypes.object.isRequired,
44+
url: PropTypes.string.isRequired,
45+
text: PropTypes.string,
46+
color: PropTypes.string,
47+
background: PropTypes.string,
48+
};
49+
50+
export default Styled(styles)(Ribbon);
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { Ribbon, styles } from './Ribbon';
3+
4+
const props = {
5+
classes: classes(styles),
6+
};
7+
8+
it('should render ribbon with url', () => {
9+
const actual = shallow(<Ribbon {...props} url="http://example.com" />);
10+
11+
expect(actual).toMatchSnapshot();
12+
});
13+
14+
it('should render ribbon with a text', () => {
15+
const actual = shallow(<Ribbon {...props} url="http://example.com" text="Share the repo" />);
16+
17+
expect(actual).toMatchSnapshot();
18+
});
19+
20+
it('should render ribbon with custom background and color', () => {
21+
const actual = shallow(
22+
<Ribbon
23+
{...props}
24+
url="http://example.com"
25+
text="Share the repo"
26+
background="#cdcdcd"
27+
color="#aa00bb"
28+
/>
29+
);
30+
31+
expect(actual).toMatchSnapshot();
32+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should render ribbon with a text 1`] = `
4+
<div
5+
className="forkme"
6+
>
7+
<a
8+
className="forkmeIcon"
9+
href="http://example.com"
10+
style={
11+
Object {
12+
"background": undefined,
13+
"color": undefined,
14+
}
15+
}
16+
>
17+
Share the repo
18+
</a>
19+
</div>
20+
`;
21+
22+
exports[`should render ribbon with custom background and color 1`] = `
23+
<div
24+
className="forkme"
25+
>
26+
<a
27+
className="forkmeIcon"
28+
href="http://example.com"
29+
style={
30+
Object {
31+
"background": "#cdcdcd",
32+
"color": "#aa00bb",
33+
}
34+
}
35+
>
36+
Share the repo
37+
</a>
38+
</div>
39+
`;
40+
41+
exports[`should render ribbon with url 1`] = `
42+
<div
43+
className="forkme"
44+
>
45+
<a
46+
className="forkmeIcon"
47+
href="http://example.com"
48+
style={
49+
Object {
50+
"background": undefined,
51+
"color": undefined,
52+
}
53+
}
54+
>
55+
Fork me on GitHub
56+
</a>
57+
</div>
58+
`;

src/rsg-components/Ribbon/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Ribbon.js';

src/rsg-components/StyleGuide/StyleGuide.js

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default class StyleGuide extends Component {
7373
homepageUrl={HOMEPAGE}
7474
toc={<TableOfContents sections={sections} />}
7575
hasSidebar={config.showSidebar && !isolatedComponent}
76+
ribbon={config.ribbon}
7677
>
7778
<Sections sections={sections} depth={1} />
7879
</StyleGuideRenderer>

src/rsg-components/StyleGuide/StyleGuideRenderer.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Logo from 'rsg-components/Logo';
44
import Markdown from 'rsg-components/Markdown';
55
import Styled from 'rsg-components/Styled';
66
import cx from 'classnames';
7+
import Ribbon from '../Ribbon';
78

89
const styles = ({ color, fontFamily, fontSize, sidebarWidth, mq, space, maxWidth }) => ({
910
root: {
@@ -54,7 +55,15 @@ const styles = ({ color, fontFamily, fontSize, sidebarWidth, mq, space, maxWidth
5455
},
5556
});
5657

57-
export function StyleGuideRenderer({ classes, title, homepageUrl, children, toc, hasSidebar }) {
58+
export function StyleGuideRenderer({
59+
classes,
60+
title,
61+
homepageUrl,
62+
children,
63+
toc,
64+
hasSidebar,
65+
ribbon,
66+
}) {
5867
return (
5968
<div className={cx(classes.root, hasSidebar && classes.hasSidebar)}>
6069
<main className={classes.content}>
@@ -71,6 +80,7 @@ export function StyleGuideRenderer({ classes, title, homepageUrl, children, toc,
7180
{toc}
7281
</div>
7382
)}
83+
{ribbon && <Ribbon {...ribbon} />}
7484
</div>
7585
);
7686
}
@@ -82,6 +92,7 @@ StyleGuideRenderer.propTypes = {
8292
children: PropTypes.node.isRequired,
8393
toc: PropTypes.node.isRequired,
8494
hasSidebar: PropTypes.bool,
95+
ribbon: PropTypes.object,
8596
};
8697

8798
export default Styled(styles)(StyleGuideRenderer);

0 commit comments

Comments
 (0)