From 83e8503df1cc65c0da5bdb2a72341ed9e38df4f5 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 3 Aug 2015 14:35:51 +0930 Subject: [PATCH] Rough implementation of appearance settings --- js/admin/src/components/AppearancePage.js | 74 ++++++++++++++++++- js/admin/src/components/EditCustomCssModal.js | 51 +++++++++++++ less/admin/AppearancePage.less | 34 +++++++++ less/admin/app.less | 1 + less/lib/Modal.less | 9 +-- src/Admin/Actions/UpdateConfigAction.php | 8 ++ src/Support/ClientAction.php | 4 +- 7 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 js/admin/src/components/EditCustomCssModal.js create mode 100644 less/admin/AppearancePage.less diff --git a/js/admin/src/components/AppearancePage.js b/js/admin/src/components/AppearancePage.js index 448d9abba..18d080c5f 100644 --- a/js/admin/src/components/AppearancePage.js +++ b/js/admin/src/components/AppearancePage.js @@ -1,9 +1,81 @@ import Component from 'flarum/Component'; +import Button from 'flarum/components/Button'; +import Switch from 'flarum/components/Switch'; +import EditCustomCssModal from 'flarum/components/EditCustomCssModal'; +import saveConfig from 'flarum/utils/saveConfig'; export default class AppearancePage extends Component { + constructor(...args) { + super(...args); + + this.primaryColor = m.prop(app.config.theme_primary_color); + this.secondaryColor = m.prop(app.config.theme_secondary_color); + this.darkMode = m.prop(app.config.theme_dark_mode === '1'); + this.coloredHeader = m.prop(app.config.theme_colored_header === '1'); + } + view() { return ( -
+
+
+
+
+ Colors +
+ Choose two colors to theme your forum with. The first will be used as a highlight color, while the second will be used to style background elements. +
+ +
+ + +
+ + {Switch.component({ + state: this.darkMode(), + children: 'Dark Mode', + onchange: this.darkMode + })} + + {Switch.component({ + state: this.coloredHeader(), + children: 'Colored Header', + onchange: this.coloredHeader + })} + + {Button.component({ + className: 'Button Button--primary', + children: 'Save Changes', + loading: this.loading + })} +
+
+ +
+ Custom Styles +
+ Customize your forum's appearance by adding your own LESS/CSS code to be applied on top of Flarum's default styles. +
+ {Button.component({ + className: 'Button', + children: 'Edit Custom CSS', + onclick: () => app.modal.show(new EditCustomCssModal()) + })} +
+
+
); } + + onsubmit(e) { + e.preventDefault(); + + this.loading = true; + + saveConfig({ + theme_primary_color: this.primaryColor(), + theme_secondary_color: this.secondaryColor(), + theme_dark_mode: this.darkMode(), + theme_colored_header: this.coloredHeader() + }).then(() => window.location.reload()); + } } diff --git a/js/admin/src/components/EditCustomCssModal.js b/js/admin/src/components/EditCustomCssModal.js new file mode 100644 index 000000000..1619a66ec --- /dev/null +++ b/js/admin/src/components/EditCustomCssModal.js @@ -0,0 +1,51 @@ +import Modal from 'flarum/components/Modal'; +import Button from 'flarum/components/Button'; +import saveConfig from 'flarum/utils/saveConfig'; + +export default class EditCustomCssModal extends Modal { + constructor(...args) { + super(...args); + + this.customLess = m.prop(app.config.custom_less || ''); + } + + className() { + return 'EditCustomCssModal Modal--large'; + } + + title() { + return 'Edit Custom CSS'; + } + + content() { + return ( +
+

Customize your forum's appearance by adding your own LESS/CSS code to be applied on top of Flarum's default styles. Read the documentation for more information.

+ +
+
+