Skip to content
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

Add expand and allow custom root section options #1689

Merged
merged 6 commits into from Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/Configuration.md
Expand Up @@ -136,6 +136,12 @@ Defines the initial state of the example code tab:
- `hide`: hide the tab and it can´t be toggled in the UI.
- `expand`: expand the tab by default.

## `expand`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused: this isn't a global configuration option, right? If so, we should document it here:

https://github.com/styleguidist/react-styleguidist/blob/master/docs/Components.md#sections

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!


Type: `Boolean`, default: `false`

Used within sections to determine if a section should be expanded or collapsed even when `tocMode` for all sections is set to `collapse`.

## `getComponentPathLine`

Type: `Function`, default: component filename
Expand Down
28 changes: 28 additions & 0 deletions src/client/rsg-components/TableOfContents/TableOfContents.spec.tsx
Expand Up @@ -302,3 +302,31 @@ it('should detect sections containing current selection when tocMode is collapse

expect(getByText('1.1')).not.toBeEmpty();
});

it('should show sections with expand: true when tocMode is collapse', () => {
const { getByText } = render(
<TableOfContents
tocMode="collapse"
sections={[
{
sections: [
{
visibleName: '1',
expand: true,
href: '#/components',
sections: [{ visibleName: '1.1', href: '#/button' }],
},
{
visibleName: '2',
href: '#/chap',
content: 'chapter.md',
sections: [{ visibleName: '2.1', href: '#/chapter-1' }],
},
{ visibleName: '3', href: 'http://react-styleguidist.com' },
],
},
]}
/>
);
expect(getByText('1.1')).toBeVisible();
});
Expand Up @@ -66,7 +66,7 @@ export default class TableOfContents extends Component<TableOfContentsProps> {
content,
selected,
shouldOpenInNewTab: !!section.external && !!section.externalLink,
initialOpen: this.props.tocMode !== 'collapse' || containsSelected,
initialOpen: this.props.tocMode !== 'collapse' || containsSelected || section.expand,
forcedOpen: !!this.state.searchTerm.length,
};
});
Expand Down
Expand Up @@ -173,6 +173,7 @@ Array [
"exampleMode": "collapse",
"external": undefined,
"href": undefined,
"ignore": "**/components/Annotation/*",
"name": "Ignore",
"sectionDepth": 0,
"sections": Array [],
Expand Down Expand Up @@ -395,6 +396,7 @@ Object {
"exampleMode": "collapse",
"external": undefined,
"href": undefined,
"ignore": "**/components/Annotation/*",
"name": "Ignore",
"sectionDepth": 0,
"sections": Array [],
Expand Down
7 changes: 7 additions & 0 deletions src/loaders/utils/__tests__/getSections.spec.ts
Expand Up @@ -47,6 +47,7 @@ const sectionsWithDepth = [
},
{
name: 'Components',
expand: true,
sections: [
{
name: 'Buttons',
Expand Down Expand Up @@ -148,6 +149,12 @@ it('getSections() should return an array of sectionsWithDepth with sectionDepth
]);
});

it('getSections() should make custom options by user available', () => {
const result = getSections(sectionsWithDepth, config);
const expandSection = result.find(section => section.name === 'Components');
expect(expandSection).toHaveProperty('expand');
});

it('getSections() should return an array of sectionsWithBadDepth taking the sectionDepth of the first depth of the sections', () => {
const result = getSections(sectionsWithBadDepth, config);

Expand Down
2 changes: 1 addition & 1 deletion src/loaders/utils/__tests__/highlightCode.spec.ts
Expand Up @@ -17,7 +17,7 @@ it('should warn when language not found', () => {
const actual = highlightCode(code, 'pizza');
expect(actual).toBe(code);
expect(warn).toBeCalledWith(
'Syntax highlighting for “pizza” isn’t supported. Supported languages are: markup, xml, html, mathml, svg, css, clike, javascript, js, markdown, md, scss, less, flow, typescript, ts, jsx, tsx, graphql, json, bash, shell, diff.'
'Syntax highlighting for “pizza” isn’t supported. Supported languages are: markup, html, mathml, svg, xml, ssml, atom, rss, css, clike, javascript, js, markdown, md, scss, less, flow, typescript, ts, jsx, tsx, graphql, json, webmanifest, bash, shell, diff.'
);
});

Expand Down
1 change: 1 addition & 0 deletions src/loaders/utils/getSections.ts
Expand Up @@ -88,6 +88,7 @@ export function processSection(
}

return {
...section,
name: section.name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this line anymore, and also description and external below.

exampleMode: section.exampleMode || config.exampleMode,
usageMode: section.usageMode || config.usageMode,
Expand Down
1 change: 1 addition & 0 deletions src/typings/RsgSection.ts
Expand Up @@ -12,6 +12,7 @@ export interface BaseSection {
href?: string;
sectionDepth?: number;
external?: boolean;
expand?: boolean;
}

export interface ProcessedSection extends BaseSection {
Expand Down