Skip to content

Commit bfc0382

Browse files
manatokbluetidepro
authored andcommitted
Feat: Made the mounting point id configurable. (#1050)
* Feat: Made the mounting point id configurable. * Removed default container name. * Removed nonsensical test.
1 parent c475be8 commit bfc0382

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
@@ -21,6 +21,7 @@ By default, Styleguidist will look for `styleguide.config.js` file in your proje
2121
- [`handlers`](#handlers)
2222
- [`ignore`](#ignore)
2323
- [`logger`](#logger)
24+
- [`mountPointId`](#mountPointId)
2425
- [`pagePerSection`](#pagepersection)
2526
- [`printBuildInstructions`](#printbuildinstructions)
2627
- [`printServerInstructions`](#printserverinstructions)
@@ -277,6 +278,12 @@ module.exports = {
277278
}
278279
```
279280

281+
#### `mountPointId`
282+
283+
Type: `string`, defaults: `rsg-root`
284+
285+
The ID of the DOM element that React-Styleguidist mounts.
286+
280287
#### `pagePerSection`
281288

282289
Type: `Boolean`, default: `false`

loaders/styleguide-loader.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const CLIENT_CONFIG_OPTIONS = [
2525
'editorConfig',
2626
'ribbon',
2727
'pagePerSection',
28+
'mountPointId',
2829
];
2930

3031
module.exports = function() {};

scripts/__tests__/config.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,8 @@ it('should throw when old template as a string option passed', () => {
228228
});
229229
expect(fn).toThrow('format has been changed');
230230
});
231+
232+
it('mountPointId should have default value', () => {
233+
const result = getConfig();
234+
expect(result.mountPointId).toEqual('rsg-root');
235+
});

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

+13
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,16 @@ it('should not overwrite NODE_ENV', () => {
192192
makeWebpackConfig(styleguideConfig, 'production');
193193
expect(process.env.NODE_ENV).toBe(process$env$nodeEnv);
194194
});
195+
196+
it('should pass specified mountPointId to HTML plugin', () => {
197+
const result = makeWebpackConfig(
198+
{
199+
...styleguideConfig,
200+
mountPointId: 'foo-bar',
201+
},
202+
'development'
203+
);
204+
expect(getClasses(result.plugins, 'MiniHtmlWebpackPlugin')[0].options.context.container).toEqual(
205+
'foo-bar'
206+
);
207+
});

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
@@ -134,6 +134,10 @@ module.exports = {
134134
logger: {
135135
type: 'object',
136136
},
137+
mountPointId: {
138+
type: 'string',
139+
default: 'rsg-root',
140+
},
137141
pagePerSection: {
138142
type: 'boolean',
139143
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)