gristlabs_grist-core/app/client/widgets/Switch.js
Paul Fitzpatrick 1654a2681f (core) move client code to core
Summary:
This moves all client code to core, and makes minimal fix-ups to
get grist and grist-core to compile correctly.  The client works
in core, but I'm leaving clean-up around the build and bundles to
follow-up.

Test Plan: existing tests pass; server-dev bundle looks sane

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2627
2020-10-02 13:24:21 -04:00

38 lines
946 B
JavaScript

var dom = require('../lib/dom');
var dispose = require('../lib/dispose');
var _ = require('underscore');
var kd = require('../lib/koDom');
var AbstractWidget = require('./AbstractWidget');
/**
* Switch - A bi-state Switch widget
*/
function Switch(field) {
AbstractWidget.call(this, field);
}
dispose.makeDisposable(Switch);
_.extend(Switch.prototype, AbstractWidget.prototype);
Switch.prototype.buildConfigDom = function() {
return null;
};
Switch.prototype.buildDom = function(row) {
var value = row[this.field.colId()];
return dom('div.field_clip',
dom('div.widget_switch',
kd.toggleClass('switch_on', value),
kd.toggleClass('switch_transition', row._isRealChange),
dom('div.switch_slider'),
dom('div.switch_circle'),
dom.on('click', () => {
if (!this.field.column().isRealFormula()) {
value.setAndSave(!value.peek());
}
})
)
);
};
module.exports = Switch;