Skip to content

Commit 99c0a8c

Browse files
timsnaddensapegin
authored andcommitted
Fix: Allow font theming (monospace) for CodeMirror (#415)
1 parent 3e072c3 commit 99c0a8c

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"jss-camel-case": "^4.0.0",
5353
"jss-compose": "^3.0.1",
5454
"jss-default-unit": "^6.1.1",
55+
"jss-global": "^1.0.1",
5556
"jss-isolate": "^2.0.1",
5657
"jss-nested": "^4.0.1",
5758
"leven": "^2.1.0",

src/rsg-components/Editor/EditorLoaderRenderer.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import Styled from 'rsg-components/Styled';
44

5-
const styles = ({ font, light, codeBackground }) => ({
5+
const styles = ({ font, monospace, light, codeBackground }) => ({
66
root: {
77
padding: [[7, 16, 10, 7]],
88
fontFamily: font,
99
fontSize: 12,
1010
color: light,
1111
backgroundColor: codeBackground,
1212
},
13+
// Tweak CodeMirror styles. Duplicate selectors are for increased specificity
14+
'@global': {
15+
'.CodeMirror.CodeMirror': {
16+
fontFamily: monospace,
17+
height: 'auto',
18+
padding: [[5, 12]],
19+
fontSize: 12,
20+
},
21+
'.CodeMirror-scroll.CodeMirror-scroll': {
22+
height: 'auto',
23+
overflowY: 'hidden',
24+
overflowX: 'auto',
25+
},
26+
'.cm-error.cm-error': {
27+
background: 'none',
28+
},
29+
},
1330
});
1431

1532
export function EditorLoaderRenderer({ classes }) {

src/rsg-components/Playground/Playground.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import Playground from './Playground';
3+
import '../../styles/setupjss';
34
import { PlaygroundRenderer } from './PlaygroundRenderer';
45

56
const code = '<button>OK</button>';

src/styles/setupjss.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import nested from 'jss-nested';
1010
import camelCase from 'jss-camel-case';
1111
import defaultUnit from 'jss-default-unit';
1212
import compose from 'jss-compose';
13+
import global from 'jss-global';
1314

1415
jss.setup({
1516
plugins: [
17+
global(),
1618
isolate({
1719
reset: {
1820
// Reset all inherited and non-inherited properties

src/styles/styles.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,6 @@ const styles = {
77
margin: 0,
88
padding: 0,
99
border: 0,
10-
11-
// Tweak CodeMirror styles
12-
'& .CodeMirror': {
13-
isolate: false,
14-
height: 'auto',
15-
padding: [[5, 12]],
16-
fontSize: 12,
17-
},
18-
'& .CodeMirror-scroll': {
19-
isolate: false,
20-
height: 'auto',
21-
overflowY: 'hidden',
22-
overflowX: 'auto',
23-
},
24-
'& .cm-error': {
25-
isolate: false,
26-
background: 'none !important',
27-
},
2810
},
2911
};
3012

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,6 +4100,10 @@ jss-default-unit@^6.1.1:
41004100
version "6.1.1"
41014101
resolved "https://registry.yarnpkg.com/jss-default-unit/-/jss-default-unit-6.1.1.tgz#a9a04887a3860d2a8ceb73ddfbc2ddcf808bacb2"
41024102

4103+
jss-global@^1.0.1:
4104+
version "1.0.1"
4105+
resolved "https://registry.yarnpkg.com/jss-global/-/jss-global-1.0.1.tgz#36731778f6d8649110611f7c178dbcd60fd92b24"
4106+
41034107
jss-isolate@^2.0.1:
41044108
version "2.0.1"
41054109
resolved "https://registry.yarnpkg.com/jss-isolate/-/jss-isolate-2.0.1.tgz#7ee5591e0dc5d358a2fbed25ccf0f2510413c896"

0 commit comments

Comments
 (0)