Badoo Styleguide
Work in progress: This is a styleguide used by the frontend team in Bumble, at the moment we are in the process of open sourcing it. Just working out some issues, cleaning up the API and adding documentation.
Table of contents
Getting started
run styleguide as npm executable
npx badoo-styleguide --dev
Create a styleguide config
Create a file called styleguide.config.js
in your project (The name doesn't really matter).
Add the following content to the file
module.exports = {
setDeviceFramesAsIframes: false,
hasResizableSandbox: false,
actionOnRender() {
if (document & !document.querySelector('body').classList) {
document.querySelector('body').classList.add('test')
}
},
noDefaultGlobalStyles: false,
noDefaultStyleguideStyles: false,
noDefaultNormalize: false,
useStylesForVRT: false,
sandboxMinWidth: 320,
sandboxMaxWidth: '100%',
getBabelConfig() {
return {...};
}
getBabelParserOptions() {
return ['classProperties'];
},
applyBabelToTypescriptCode: true,
tsConfigPath: path.resolve(process.cwd(), './tsconfig-new.json');
isSpecificationPath(componentMeta, path) {
return path.indexOf(`${componentMeta.fileNameWithoutPrefix}.spec`) !== -1;
},
browserSetup() {
window.parameters = true;
}
getComponentWrapper() {
return require('MyComponent');
},
getSections() {
return [
{
name: 'MyComponentSection',
components: [
require('MyComponent'),
],
},
];
},
getPublicPath() {
return '/';
}
getComponentRoots({ path }) {
return [
path.resolve(cwd, 'src')
];
},
getExceptionForLoaders({ path }) {
return {
jsLoader: path.resolve(cwd, 'src'),
tsLoader: /src/,
tsExtraLoader: /__tests__/,
};
},
getLoadersForComponents({ path }) {
return ['babel-loader'];
},
getWebpackConfig({ path }) {
const cwd = path.resolve(__dirname, '.');
return {
resolve: {
modules: [
path.resolve(cwd, 'src/'),
path.resolve(cwd, 'node_modules/'),
],
}
};
}
}
Running and compiling
The styleguide can be run as a local dev server or be compiled if you want to serve it from another host.
Running
npx badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js
Note: Styleguide benefits from caching results of initial build. It makes all subsequents recompilations much faster.
Compiling
npx badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js --buildDir=dist/
Or add it to your package.json "scripts" section
{
"scripts": {
"styleguide": "badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js",
"styleguide:compile": "badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js --buildDir=dist/"
}
}
The buildDir parameter switches off webpack-server and caching.
Note: The buildDir is resolved relative to where you ran "yarn" from
How to define and document components
Loaders js-component
and ts-component
use react-docgen
for documentation generation. We check for all exported definitions in files from getSections
components section. Firstly, we look for the the filename (any filename case or convention), comparing it to the found definitions. If we don't have any definition, we use fallback for the first found definition (previous behaviour). Please use --debug
for showing these fallbacks in console.
this is example of how to set component in section in config:
module.exports = {
getSections() {
return [
{
name: 'MyComponentSection',
components: [
require('MyComponent'),
],
},
];
},
};
this is a code of component:
interface MyComponentProps {
name: string;
}
const MyComponent: React.FunctionComponent<MyComponentProps> = props => {
const { name } = props;
return <div>The name is {name}!</div>;
};
export default MyComponent;
Examples
Visual helpers
Visual helpers for visual regression tests are available in separate package @bumble/styleguide-visual-helpers. In nearest major release direct export of src/visual-helpers
from this package will be removed.
Debugging
Pass --debug
flag to the command line to get additional debug information.
yarn badoo-styleguide --config=PATH_TO_STYLEGUIDE_CONFIG.js --debug
To Do