Skip to content

Commit 3407c3f

Browse files
committed
#15 - Custom color config & handling
1 parent c1ce7d8 commit 3407c3f

File tree

7 files changed

+134
-4
lines changed

7 files changed

+134
-4
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ new Typester({
4343
configs: {
4444
toolbar: {
4545
buttons: ['bold', 'italic', 'h1', 'h2', 'orderedlist', 'unorderedlist', 'quote', 'link']
46+
},
47+
48+
styles: {
49+
colors: {
50+
flyoutBg: 'rgb(32, 31, 32)',
51+
menuItemIcon: 'rgb(255, 255, 255)',
52+
menuItemHover: 'rgb(0, 174, 239)',
53+
menuItemActive: 'rgb(0, 156, 215)'
54+
}
4655
}
4756
}
4857
});

src/scripts/config/styles.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
colors: {
3+
flyoutBg: 'rgb(32, 31, 32)',
4+
menuItemIcon: 'rgb(255, 255, 255)',
5+
menuItemHover: 'rgb(0, 174, 239)',
6+
menuItemActive: 'rgb(0, 156, 215)'
7+
}
8+
};

src/scripts/containers/UIContainer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Container from '../core/Container';
1919
import Toolbar from '../modules/Toolbar';
2020
import Flyout from '../modules/Flyout';
2121
import Mouse from '../modules/Mouse';
22+
import Styles from '../modules/Styles';
2223

2324
/**
2425
* @constructor UIContainer
@@ -32,7 +33,7 @@ const UIContainer = Container({
3233
/**
3334
* Child Modules: [{@link modules/Flyout}, {@link modules/Toolbar}]
3435
* Note: The Toobar is instantiated with the document body set as it's dom.el.
35-
* @enum {Array<{class:Module}>} modules
36+
* @enum {Array<{class:Module}>} modules
3637
*/
3738
modules: [
3839
{
@@ -48,6 +49,9 @@ const UIContainer = Container({
4849
},
4950
{
5051
class: Mouse
52+
},
53+
{
54+
class: Styles
5155
}
5256
]
5357
});

src/scripts/modules/Config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Module from '../core/Module';
22
import toolbarConfig from '../config/toolbar';
33
import config from '../config/config';
4+
import stylesConfig from '../config/styles';
45

56
const Config = Module({
67
name: 'Config',
78
props: {},
8-
acceptsConfigs: ['toolbar'],
9+
acceptsConfigs: ['toolbar', 'styles'],
910

1011
handlers: {
1112
requests: {
@@ -16,7 +17,8 @@ const Config = Module({
1617
'config:toolbar:listTags' : 'getToolbarListTags',
1718
'config:toolbar:preventNewlineDefault' : 'getToolbarPreventNewlineDefault',
1819
'config:blockElementNames' : 'getConfigBlockElementNames',
19-
'config:defaultBlock' : 'getDefaultBlock'
20+
'config:defaultBlock' : 'getDefaultBlock',
21+
'config:styles': 'getStyles'
2022
}
2123
},
2224

@@ -70,6 +72,13 @@ const Config = Module({
7072

7173
getDefaultBlock () {
7274
return config.defaultBlock;
75+
},
76+
77+
getStyles () {
78+
const { configs } = this;
79+
return {
80+
colors: Object.assign({}, stylesConfig.colors, configs.styles.colors)
81+
};
7382
}
7483
}
7584
});

src/scripts/modules/Styles.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// jshint strict: false
2+
3+
/**
4+
* Styles -
5+
* Handle the creation and embedding of custom styles.
6+
* @access protected
7+
* @module modules/Styles
8+
*/
9+
10+
import Module from '../core/Module';
11+
12+
const Styles = Module({
13+
name: 'Styles',
14+
15+
props: {
16+
stylesheet: null,
17+
},
18+
19+
handlers: {},
20+
21+
methods: {
22+
setup () {
23+
this.createStylesheet();
24+
},
25+
26+
init () {
27+
const { mediator } = this;
28+
const config = mediator.get('config:styles');
29+
let stylesheetContent = this.stylesTemplate(config);
30+
31+
this.appendStylesheet();
32+
this.updateStylesheet(stylesheetContent);
33+
},
34+
35+
stylesTemplate (config) {
36+
return `
37+
.typester-toolbar .typester-menu-item,
38+
.typester-input-form input[type=text],
39+
.typester-link-display a,
40+
.typester-input-form button {
41+
color: ${config.colors.menuItemIcon};
42+
}
43+
44+
.typester-toolbar .typester-menu-item svg,
45+
.typester-link-display .typester-link-edit svg,
46+
.typester-input-form button svg {
47+
fill: ${config.colors.menuItemIcon};
48+
}
49+
50+
.typester-input-form button svg {
51+
stroke: ${config.colors.menuItemIcon};
52+
}
53+
54+
.typester-toolbar .typester-menu-item:hover,
55+
.typester-link-display .typester-link-edit:hover
56+
.typester-input-form button:hover {
57+
background: ${config.colors.menuItemHover};
58+
}
59+
60+
.typester-toolbar .typester-menu-item.s--active {
61+
background: ${config.colors.menuItemActive};
62+
}
63+
64+
.typester-flyout .typester-flyout-content {
65+
background: ${config.colors.flyoutBg};
66+
}
67+
68+
.typester-flyout.place-above .typester-flyout-arrow {
69+
border-top-color: ${config.colors.flyoutBg};
70+
}
71+
72+
.typester-flyout.place-below .typester-flyout-arrow {
73+
border-bottom-color: ${config.colors.flyoutBg};
74+
}
75+
`;
76+
},
77+
78+
createStylesheet () {
79+
this.stylesheet = document.createElement('style');
80+
},
81+
82+
appendStylesheet () {
83+
document.head.appendChild(this.stylesheet);
84+
},
85+
86+
updateStylesheet (stylesheetContent) {
87+
this.stylesheet.textContent = stylesheetContent;
88+
}
89+
}
90+
});
91+
92+
export default Styles;

src/templates/inputForm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<button type='submit'>
44
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
55
viewBox="0 180 20 20" enable-background="new 0 180 20 20" xml:space="preserve" height="20px" width="20px">
6-
<polyline class="checkmark-2" fill="none" stroke="#FFFFFF" stroke-width="5.3" stroke-miterlimit="10" points="1.9,188.8 7.5,194.4 18.1,183.9 "/>
6+
<polyline class="checkmark-2" fill="none" stroke-width="5.3" stroke-miterlimit="10" points="1.9,188.8 7.5,194.4 18.1,183.9 "/>
77
</svg>
88
</button>
99
<button type='cancel'>

test/server/html/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ <h1>Typester test server</h1>
120120
// toolbar: {
121121
// buttons: ['bold', 'italic', 'h1', 'h2', 'orderedlist', 'unorderedlist', 'quote', 'link']
122122
// }
123+
styles: {
124+
colors: {
125+
flyoutBg: '#C00',
126+
menuItemIcon: '#00C',
127+
menuItemHover: '#0C0',
128+
menuItemActive: '#0A0'
129+
}
130+
}
123131
}
124132
});
125133
</script>

0 commit comments

Comments
 (0)