This is a lib to help you render the View of Yue in the react way.
Moreover, it's possible to utilize react-yue to a hot reload developing experience.
You may want to check do-space-client and react-yue-app as examples of using this lib.
| mac |
|---|
Use node v8 or v9 as they are supported by the builds of gui.
npm i react-yue react gui
Render your view into a container:
import React from 'react'
import gui from 'gui'
import { render } from 'react-yue'
// Create your react component:
function App() {
return (
<container
style={{
flexDirection: 'row',
flex: 1,
justifyContent: 'center',
}}
>
<label
text="hello"
/>
</container>
)
}
// Create a window and a root container:
const win = gui.Window.create({})
win.setContentSize({ width: 400, height: 250 })
const contentView = gui.Container.create()
contentView.setStyle({ flexDirection: 'row' })
win.setContentView(contentView)
win.center()
win.activate()
// Create your react elements and render them:
render(<App />, contentView)
// Start your app
if (!process.versions.yode) {
gui.MessageLoop.run()
process.exit(0)
}Check this ES5 example if you want to run it without any code transforming:
const React = require('react')
const gui = require('gui')
const { render } = require('react-yue')
// Create your react component:
function App() {
return React.createElement('container', {
style: {
flexDirection: 'row',
flex: 1,
justifyContent: 'center',
},
}, React.createElement('label', {
text: 'hello',
}))
}
// Create a window and a root container:
const win = gui.Window.create({})
win.setContentSize({ width: 400, height: 250 })
const contentView = gui.Container.create()
contentView.setStyle({ flexDirection: 'row' })
win.setContentView(contentView)
win.center()
win.activate()
// Create your react elements and render them:
render(React.createElement(App), contentView)
// Start your app
if (!process.versions.yode) {
gui.MessageLoop.run()
process.exit(0)
}Yue use yoga layout and you can use these properties in the style property. It's also possible to provide other styles via the style prop.
color: hex|rgb|rgba|hsl|hsla|name of a colorbackgroundColor: hex|rgb|rgba|hsl|hsla| name of a colorfontSize: number representing a pixel valuefontWeight: supports 100-900 and all values in https://libyue.com/docs/latest/js/api/font_weight.htmlfontFamily: name of a font to usefontStyle: normal|italictextAlign: left|center|rightverticalAlign: top|middle|bottom
import React from 'react'
export default function MyComp() {
return (
<container
style={{
flex: 1,
flexDirection: 'row',
backgroundColor: 'black'
}}
>
<container
style={{
justifyContent: 'center',
}}
>
<label
text="hello"
style={{
color: 'white',
fontSize: 14
}}
/>
</container>
</container>
)
}Below are what components and their props you can use with react-yue. For more details, please check the official document.
props:
BooleanvisibleBooleanenabledBooleanfocusableBooleanmouseDownCanMoveWindow
events:
- onMouseDown
- params
Viewself
- params
- onMouseUp
- params
ViewselfMouseEventevent
- params
- onMouseMove
- params
ViewselfMouseEventevent
- params
- onMouseEnter
- params
ViewselfMouseEventevent
- params
- onMouseLeave
- params
ViewselfMouseEventevent
- params
- onKeyDown
- params
ViewselfKeyEventevent
- params
- onKeyUp
- params
ViewselfKeyEventevent
- params
- onSizeChanged
- params
ViewselfKeyEventevent
- params
- onCaptureLost
- params
ViewselfKeyEventevent
- params
props:
Button::TypetypeBooleandefaultCheckedStringtitleImageimage
events:
- onClick(self)
- params
Buttonself
- params
events:
- onDraw(self, painter, painter)
- params
ContainerselfPainterpainter - The drawing context of the view.RectFdirty - The area in the view to draw on.
- params
props:
Entry::TypetypeStringtext
events:
- onTextChange(self)
- params
Entryself
- params
- onActivate(self)
- params
Entryself
- params
props:
StringtitleViewchildren
props:
Stringtext
props:
NumberpercentBooleanindeterminate
props:
Scroll::PolicyhpolicyScroll::PolicyvpolicyBooleanoverlayScrollbarSizeF sizecontentSizeViewchildren
props:
StringtextScroll::PolicyhpolicyScroll::PolicyvpolicyBooleanoverlayScrollbar
events:
- onTextChange(self)
- params
TextEditself
- params
props:
Vibrant::MaterialmaterialVibrant::BlendingModemode
React will require its modules dynamically so that you can't correctly package your apps when using yackage to package your Node.js project into an executable.
As yackage doesn't support customized code transforming, webpack is recommended to bundle your js correctly. You can take the config of do-space-client as a reference.
npm run test