-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
views: modularize setting components
Makes testing each individual component significantly easier.
- Loading branch information
Showing
7 changed files
with
289 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
const h = require('virtual-dom/h') | ||
const inherits = require('util').inherits | ||
const Base = require('vdelement') | ||
|
||
module.exports = Checkbox | ||
|
||
function Checkbox(target) { | ||
if (!(this instanceof Checkbox)) | ||
return new Checkbox(target) | ||
|
||
Base.call(this, target) | ||
} | ||
inherits(Checkbox, Base) | ||
|
||
Checkbox.prototype.render = function render(opts) { | ||
return h('.form-group', [ | ||
h('.checkbox', [ | ||
h('label', [ | ||
h('input', { | ||
type: 'checkbox' | ||
, id: opts.id | ||
, checked: this.target.settings.get(opts.id) | ||
, onchange: (e) => { | ||
this.target.settings.set(opts.id, e.target.checked) | ||
this.target.needsLayout() | ||
} | ||
}) | ||
, h('.setting-title', ` ${opts.title}`) | ||
, h('p.form-control-static', opts.note) | ||
]) | ||
]) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict' | ||
|
||
const h = require('virtual-dom/h') | ||
const inherits = require('util').inherits | ||
const Base = require('vdelement') | ||
|
||
module.exports = ColorPicker | ||
|
||
function ColorPicker(target) { | ||
if (!(this instanceof ColorPicker)) | ||
return new ColorPicker(target) | ||
|
||
Base.call(this, target) | ||
} | ||
inherits(ColorPicker, Base) | ||
|
||
ColorPicker.prototype.render = function render(opts) { | ||
const id = opts.id | ||
const val = this.target.settings.get(id) | ||
|
||
return h('.form-group', [ | ||
h('label.control-label', { | ||
for: id | ||
}, opts.title) | ||
, h('.input-group', [ | ||
h('span.input-group-addon', { | ||
style: { | ||
backgroundColor: val | ||
} | ||
}) | ||
, h('input.form-control', { | ||
type: 'text' | ||
, id: id | ||
, onkeyup: (e) => { | ||
this.target.settings.set(id, e.target.value) | ||
this.target.needsLayout() | ||
} | ||
, value: val | ||
}) | ||
]) | ||
, h('p.form-control-static', opts.note) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict' | ||
|
||
const h = require('virtual-dom/h') | ||
const inherits = require('util').inherits | ||
const Base = require('vdelement') | ||
|
||
module.exports = ThemeSelect | ||
|
||
function ThemeSelect(target) { | ||
if (!(this instanceof ThemeSelect)) | ||
return new ThemeSelect(target) | ||
|
||
Base.call(this, target) | ||
} | ||
inherits(ThemeSelect, Base) | ||
|
||
ThemeSelect.prototype.render = function render(opts) { | ||
const id = opts.id | ||
|
||
const settings = this.target.settings | ||
const themes = this.target.themes.themes | ||
const items = new Array(themes.size) | ||
let i = 0 | ||
for (const item of themes.values()) { | ||
items[i++] = h('option', { | ||
selected: item.active | ||
}, item.name) | ||
} | ||
|
||
return h('.form-group', [ | ||
h('label.control-label', { | ||
attributes: { | ||
for: id | ||
} | ||
}, opts.title) | ||
, h('select.form-control', { | ||
onchange: (e) => { | ||
this.target.themes.activate(e.target.value) | ||
} | ||
}, items) | ||
, h('p.form-control-static', [ | ||
opts.note | ||
, h('button.btn.btn-link', { | ||
onclick: (e) => { | ||
e.target.blur() | ||
const currentTheme = settings.get('theme.active') | ||
this.target.themes.load(currentTheme, () => { | ||
this.target.needsLayout() | ||
}) | ||
return false | ||
} | ||
, tabindex: '-1' | ||
, attributes: { | ||
tabindex: '-1' | ||
} | ||
}, 'Reload') | ||
]) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.