rahisi
Version:
UI library for prototyping ideas for reactive programming.
67 lines • 2.56 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const factory_1 = require("./factory");
const index_1 = require("./index");
exports.CheckBox = (props) => {
const { onCheckChanged } = props, rest = __rest(props, ["onCheckChanged"]);
const attributes = factory_1.React.getAttributes(rest);
if (onCheckChanged) {
attributes.push(new index_1.OnHandlerA("click", (e) => onCheckChanged(e.currentTarget.checked)));
}
attributes.push(new index_1.NativeAttribute("type", "checkbox"));
return new index_1.BaseElement("input", attributes);
};
exports.TextBox = (props) => {
const { onTextChanged } = props, rest = __rest(props, ["onTextChanged"]);
const attributes = factory_1.React.getAttributes(rest);
if (onTextChanged) {
const handler = (() => {
let val = "";
const onKeyUp = (e) => {
if (e.currentTarget.value === val) {
return;
}
val = e.currentTarget.value;
onTextChanged(val);
};
return onKeyUp;
})();
attributes.push(new index_1.OnHandlerA("input", handler));
}
attributes.push(new index_1.NativeAttribute("type", "text"));
return new index_1.BaseElement("input", attributes);
};
exports.doScroll = (o, element, to, duration) => {
const start = element.scrollTop;
const change = (to || o.offsetTop - 10) - start;
const increment = 20;
let currentTime = 0;
const easeInOutQuad = (t, b, c, d) => {
t /= d / 2;
if (t < 1) {
return c / 2 * t * t + b;
}
t--;
return -c / 2 * (t * (t - 2) - 1) + b;
};
const animateScroll = () => {
currentTime += increment;
const d = duration || 300;
const val = easeInOutQuad(currentTime, start, change, d);
element.scrollTop = val;
if (currentTime < d) {
setTimeout(animateScroll, increment);
}
};
animateScroll();
};
//# sourceMappingURL=control-extensions.js.map