|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | const path = require('path');
|
|---|
| 4 | const camelcase = require('camelcase');
|
|---|
| 5 |
|
|---|
| 6 | // This is a custom Jest transformer turning file imports into filenames.
|
|---|
| 7 | // http://facebook.github.io/jest/docs/en/webpack.html
|
|---|
| 8 |
|
|---|
| 9 | module.exports = {
|
|---|
| 10 | process(src, filename) {
|
|---|
| 11 | const assetFilename = JSON.stringify(path.basename(filename));
|
|---|
| 12 |
|
|---|
| 13 | if (filename.match(/\.svg$/)) {
|
|---|
| 14 | // Based on how SVGR generates a component name:
|
|---|
| 15 | // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
|
|---|
| 16 | const pascalCaseFilename = camelcase(path.parse(filename).name, {
|
|---|
| 17 | pascalCase: true,
|
|---|
| 18 | });
|
|---|
| 19 | const componentName = `Svg${pascalCaseFilename}`;
|
|---|
| 20 | return `const React = require('react');
|
|---|
| 21 | module.exports = {
|
|---|
| 22 | __esModule: true,
|
|---|
| 23 | default: ${assetFilename},
|
|---|
| 24 | ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
|
|---|
| 25 | return {
|
|---|
| 26 | $$typeof: Symbol.for('react.element'),
|
|---|
| 27 | type: 'svg',
|
|---|
| 28 | ref: ref,
|
|---|
| 29 | key: null,
|
|---|
| 30 | props: Object.assign({}, props, {
|
|---|
| 31 | children: ${assetFilename}
|
|---|
| 32 | })
|
|---|
| 33 | };
|
|---|
| 34 | }),
|
|---|
| 35 | };`;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | return `module.exports = ${assetFilename};`;
|
|---|
| 39 | },
|
|---|
| 40 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.