Browse Source

Merge branch 'master' of ssh://code.fineres.com:7999/~dailer/fineui

es6
zsmj 2 years ago
parent
commit
ca8b57f3ee
  1. 99
      examples/ThemeProvider.html
  2. 2
      package.json
  3. 20
      src/base/context.js

99
examples/ThemeProvider.html

@ -0,0 +1,99 @@
<html>
<head>
<meta charset="utf-8">
<title></title>
<!-- <link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.min.css"/>
<script src="../dist/2.0/fineui.js"></script> -->
<link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css"/>
<!-- <script src="http://fanruan.design/fineui/2.0/fineui.min.js"></script>-->
<script src="http://localhost:9001/fineui.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script>
var Model = BI.inherit(BI.Model, {
state: function () {
return {
theme: "light"
};
},
childContext: ["theme"],
actions: {
toggle: function () {
this.model.theme = this.model.theme === "light" ? "dark" : "light";
}
}
});
BI.model("demo.model", Model);
var Child = BI.inherit(BI.Widget, {
render: function () {
var label;
return {
type: "bi.context",
context: "theme",
watch: function (newValue, oldValue) {
label.setText(newValue);
},
items: [(context) => {
return {
type: "bi.label",
height: 30,
ref: function (_ref) {
label = _ref;
},
text: context.model.theme
}
}]
};
}
});
BI.shortcut("demo.child", Child);
var Widget = BI.inherit(BI.Widget, {
props: {
baseCls: "my-parent"
},
_store: function () {
return BI.Models.getModel("demo.model");
},
setup: function () {
var child;
var store = BI.useStore();
return function () {
return {
type: "bi.vertical",
vgap: 20,
items: [{
type: "demo.child",
ref: function (_ref) {
child = _ref;
}
}, {
type: "bi.button",
text: "改变主题",
handler: function () {
store.toggle();
}
}]
};
};
}
});
BI.shortcut("demo.parent", Widget);
BI.createWidget({
type: "bi.absolute",
items: [{
el: {
type: "demo.parent"
},
top: 100,
left: 100
}],
element: "#wrapper"
});
</script>
</body>
</html>

2
package.json

@ -1,6 +1,6 @@
{
"name": "fineui",
"version": "2.0.20221023144426",
"version": "2.0.20221024105424",
"description": "fineui",
"main": "dist/fineui_without_conflict.min.js",
"types": "dist/lib/index.d.ts",

20
src/base/context.js

@ -15,31 +15,33 @@ BI.Context = BI.inherit(BI.Widget, {
render: function () {
var self = this, o = this.options;
this.context = BI.createWidget(o.items[0] || o.el, {
if (o.context) {
this.context = BI.useContext(o.context);
}
this.widget = BI.createWidget((o.items[0] || o.el)(this.context), {
element: this,
});
this.context.on(BI.Controller.EVENT_CHANGE, function () {
this.widget.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
},
created: function () {
__initWatch: function () {
BI.Context.superclass.__initWatch.call(this);
var o = this.options;
if (o.context) {
BI.watch(o.context, o.watch);
}
BI.watch(this.context, o.context, o.watch);
},
setValue: function (v) {
this.context.setValue(v);
this.widget.setValue(v);
},
getValue: function () {
return this.context.getValue();
return this.widget.getValue();
},
populate: function () {
this.context.populate.apply(this, arguments);
this.widget.populate.apply(this, arguments);
},
});
BI.shortcut("bi.context", BI.Context);

Loading…
Cancel
Save