Skip to content

Commit 917831d

Browse files
manatokArtem Sapegin
authored and
Artem Sapegin
committed
Feat: Made the mounting point id configurable. (#1050)
* Feat: Made the mounting point id configurable. * Removed default container name. * Removed nonsensical test.
1 parent 949a21a commit 917831d

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

docs/Configuration.md

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ By default, Styleguidist will look for `styleguide.config.js` file in your proje
2020
- [`handlers`](#handlers)
2121
- [`ignore`](#ignore)
2222
- [`logger`](#logger)
23+
- [`mountPointId`](#mountPointId)
2324
- [`pagePerSection`](#pagepersection)
2425
- [`printBuildInstructions`](#printbuildinstructions)
2526
- [`printServerInstructions`](#printserverinstructions)
@@ -270,6 +271,12 @@ module.exports = {
270271
}
271272
```
272273

274+
#### `mountPointId`
275+
276+
Type: `string`, defaults: `rsg-root`
277+
278+
The ID of the DOM element that React-Styleguidist mounts.
279+
273280
#### `pagePerSection`
274281

275282
Type: `Boolean`, default: `false`

loaders/styleguide-loader.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const slugger = require('./utils/slugger');
1414
// Config options that should be passed to the client
1515
const CLIENT_CONFIG_OPTIONS = [
1616
'compilerConfig',
17+
'mountPointId',
1718
'pagePerSection',
1819
'previewDelay',
1920
'ribbon',

scripts/__tests__/config.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,8 @@ it('should throw when editorConfig option passed', () => {
219219
});
220220
expect(fn).toThrow('config option was removed');
221221
});
222+
223+
it('mountPointId should have default value', () => {
224+
const result = getConfig();
225+
expect(result.mountPointId).toEqual('rsg-root');
226+
});

scripts/__tests__/make-webpack-config.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,16 @@ it('should not overwrite NODE_ENV', () => {
173173
makeWebpackConfig(styleguideConfig, 'production');
174174
expect(process.env.NODE_ENV).toBe(process$env$nodeEnv);
175175
});
176+
177+
it('should pass specified mountPointId to HTML plugin', () => {
178+
const result = makeWebpackConfig(
179+
{
180+
...styleguideConfig,
181+
mountPointId: 'foo-bar',
182+
},
183+
'development'
184+
);
185+
expect(getClasses(result.plugins, 'MiniHtmlWebpackPlugin')[0].options.context.container).toEqual(
186+
'foo-bar'
187+
);
188+
});

scripts/make-webpack-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function(config, env) {
2727
const htmlPluginOptions = {
2828
context: Object.assign({}, templateContext, {
2929
title: config.title,
30-
container: 'rsg-root',
30+
container: config.mountPointId,
3131
trimWhitespace: true,
3232
}),
3333
template,

scripts/schemas/config.js

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ module.exports = {
117117
logger: {
118118
type: 'object',
119119
},
120+
mountPointId: {
121+
type: 'string',
122+
default: 'rsg-root',
123+
},
120124
pagePerSection: {
121125
type: 'boolean',
122126
default: false,

src/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import ReactDOM from 'react-dom';
55
import renderStyleguide from './utils/renderStyleguide';
66
import { getParameterByName, hasInHash } from './utils/handleHash';
77

8-
const CONTAINER_ID = 'rsg-root';
9-
108
// Examples code revision to rerender only code examples (not the whole page) when code changes
119
// eslint-disable-next-line no-unused-vars
1210
let codeRevision = 0;
@@ -38,7 +36,7 @@ const render = () => {
3836
const styleguide = require('!!../loaders/styleguide-loader!./index.js');
3937
ReactDOM.render(
4038
renderStyleguide(styleguide, codeRevision),
41-
document.getElementById(CONTAINER_ID)
39+
document.getElementById(styleguide.config.mountPointId)
4240
);
4341
};
4442

0 commit comments

Comments
 (0)