Skip to content

Commit f0e99ee

Browse files
dylankisssapegin
authored andcommitted
Fix: Only use primary style for top level sections (styleguidist#555)
Fixes styleguidist#554
1 parent b7b2dc4 commit f0e99ee

File tree

9 files changed

+138
-8
lines changed

9 files changed

+138
-8
lines changed

src/rsg-components/Section/Section.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Components from 'rsg-components/Components';
55
import Sections from 'rsg-components/Sections';
66
import SectionRenderer from 'rsg-components/Section/SectionRenderer';
77

8-
export default function Section({ section }, { isolatedSection = false }) {
8+
export default function Section({ section, primary }, { isolatedSection = false }) {
99
const { name, slug, content, components, sections } = section;
1010

1111
const contentJsx = content && <Examples examples={content} name={name} />;
@@ -20,12 +20,14 @@ export default function Section({ section }, { isolatedSection = false }) {
2020
components={componentsJsx}
2121
sections={sectionsJsx}
2222
isolated={isolatedSection}
23+
primary={primary}
2324
/>
2425
);
2526
}
2627

2728
Section.propTypes = {
2829
section: PropTypes.object.isRequired,
30+
primary: PropTypes.bool,
2931
};
3032

3133
Section.contextTypes = {

src/rsg-components/Section/Section.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ it('should render component renderer', () => {
3030
expect(actual).toMatchSnapshot();
3131
});
3232

33+
it('should render component renderer with primary title', () => {
34+
const actual = shallow(<Section section={section} primary />);
35+
36+
expect(actual).toMatchSnapshot();
37+
});
38+
3339
it('should render components list', () => {
3440
const actual = shallow(
3541
<Section
@@ -110,3 +116,9 @@ it('render should render title if name is set', () => {
110116

111117
expect(actual).toMatchSnapshot();
112118
});
119+
120+
it('render should render primary title if primary is set', () => {
121+
const actual = shallow(<SectionRenderer classes={{}} name="test" slug="test" primary />);
122+
123+
expect(actual).toMatchSnapshot();
124+
});

src/rsg-components/Section/SectionRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const styles = ({ space }) => ({
1010
});
1111

1212
export function SectionRenderer(allProps) {
13-
const { classes, name, slug, content, components, sections } = allProps;
13+
const { classes, name, slug, content, components, sections, primary } = allProps;
1414
return (
1515
<section className={classes.root}>
1616
{name &&
17-
<SectionHeading primary id={slug} slotName="sectionToolbar" slotProps={allProps}>
17+
<SectionHeading primary={primary} id={slug} slotName="sectionToolbar" slotProps={allProps}>
1818
{name}
1919
</SectionHeading>}
2020
{content}

src/rsg-components/Section/__snapshots__/Section.spec.js.snap

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`render should render component 1`] = `
66
<section>
77
<SectionHeading
88
id="foo"
9-
primary={true}
109
slotName="sectionToolbar"
1110
slotProps={
1211
Object {
@@ -65,12 +64,31 @@ exports[`render should render component 1`] = `
6564
</section>
6665
`;
6766

68-
exports[`render should render title if name is set 1`] = `
67+
exports[`render should render primary title if primary is set 1`] = `
6968
<section>
7069
<SectionHeading
7170
id="test"
7271
primary={true}
7372
slotName="sectionToolbar"
73+
slotProps={
74+
Object {
75+
"classes": Object {},
76+
"name": "test",
77+
"primary": true,
78+
"slug": "test",
79+
}
80+
}
81+
>
82+
test
83+
</SectionHeading>
84+
</section>
85+
`;
86+
87+
exports[`render should render title if name is set 1`] = `
88+
<section>
89+
<SectionHeading
90+
id="test"
91+
slotName="sectionToolbar"
7492
slotProps={
7593
Object {
7694
"classes": Object {},
@@ -136,6 +154,43 @@ exports[`should render component renderer 1`] = `
136154
/>
137155
`;
138156

157+
exports[`should render component renderer with primary title 1`] = `
158+
<Styled(Section)
159+
components={
160+
<Components
161+
components={Array []}
162+
/>
163+
}
164+
content={
165+
<Examples
166+
examples={
167+
Array [
168+
Object {
169+
"content": "<button>OK</button>",
170+
"evalInContext": [Function],
171+
"type": "code",
172+
},
173+
Object {
174+
"content": "Hello *world*!",
175+
"type": "markdown",
176+
},
177+
]
178+
}
179+
name="Foo"
180+
/>
181+
}
182+
isolated={false}
183+
name="Foo"
184+
primary={true}
185+
sections={
186+
<Sections
187+
sections={Array []}
188+
/>
189+
}
190+
slug="foo"
191+
/>
192+
`;
193+
139194
exports[`should render components list 1`] = `
140195
<Styled(Section)
141196
components={

src/rsg-components/Sections/Sections.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import PropTypes from 'prop-types';
33
import Section from 'rsg-components/Section';
44
import SectionsRenderer from 'rsg-components/Sections/SectionsRenderer';
55

6-
export default function Sections({ sections }) {
6+
export default function Sections({ sections, root }) {
77
return (
88
<SectionsRenderer>
9-
{sections.map((section, idx) => <Section key={idx} section={section} />)}
9+
{sections.map((section, idx) => <Section key={idx} section={section} primary={root} />)}
1010
</SectionsRenderer>
1111
);
1212
}
1313

1414
Sections.propTypes = {
1515
sections: PropTypes.array.isRequired,
16+
root: PropTypes.bool,
1617
};

src/rsg-components/Sections/Sections.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ it('should render component renderer', () => {
4646
expect(actual).toMatchSnapshot();
4747
});
4848

49+
it('should render component renderer with primary sections if root is true', () => {
50+
const actual = shallow(<Sections sections={sections} root />);
51+
52+
expect(actual).toMatchSnapshot();
53+
});
54+
4955
it('render should render styled component', () => {
5056
const actual = shallow(
5157
<StyledSectionsRenderer classes={{}}>

src/rsg-components/Sections/__snapshots__/Sections.spec.js.snap

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,56 @@ exports[`should render component renderer 1`] = `
155155
/>
156156
</Styled(Sections)>
157157
`;
158+
159+
exports[`should render component renderer with primary sections if root is true 1`] = `
160+
<Styled(Sections)>
161+
<Section
162+
primary={true}
163+
section={
164+
Object {
165+
"components": Array [],
166+
"content": Array [
167+
Object {
168+
"content": "<button>OK</button>",
169+
"evalInContext": [Function],
170+
"type": "code",
171+
},
172+
],
173+
"name": "Foo",
174+
}
175+
}
176+
/>
177+
<Section
178+
primary={true}
179+
section={
180+
Object {
181+
"components": Array [],
182+
"content": Array [
183+
Object {
184+
"content": "Hello *world*!",
185+
"type": "markdown",
186+
},
187+
],
188+
"name": "Bar",
189+
}
190+
}
191+
/>
192+
<Section
193+
primary={true}
194+
section={
195+
Object {
196+
"sections": Array [
197+
Object {
198+
"content": Array [],
199+
"name": "One",
200+
},
201+
Object {
202+
"content": Array [],
203+
"name": "Two",
204+
},
205+
],
206+
}
207+
}
208+
/>
209+
</Styled(Sections)>
210+
`;

src/rsg-components/StyleGuide/StyleGuide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class StyleGuide extends Component {
5757
toc={<TableOfContents sections={sections} />}
5858
hasSidebar={config.showSidebar && !isolatedComponent}
5959
>
60-
<Sections sections={sections} />
60+
<Sections sections={sections} root />
6161
</StyleGuideRenderer>
6262
);
6363
}

src/rsg-components/StyleGuide/__snapshots__/StyleGuide.spec.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ exports[`should render components list 1`] = `
8585
}
8686
>
8787
<Sections
88+
root={true}
8889
sections={
8990
Array [
9091
Object {

0 commit comments

Comments
 (0)