react-yue
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 |
---|
Get Started
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)
}
Style / Layout
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>
)
}
Components
Below are what components and their props you can use with react-yue. For more details, please check the official document.
View (base class)
props:
Boolean
visibleBoolean
enabledBoolean
focusableBoolean
mouseDownCanMoveWindow
events:
- onMouseDown
- params
View
self
- params
- onMouseUp
- params
View
selfMouseEvent
event
- params
- onMouseMove
- params
View
selfMouseEvent
event
- params
- onMouseEnter
- params
View
selfMouseEvent
event
- params
- onMouseLeave
- params
View
selfMouseEvent
event
- params
- onKeyDown
- params
View
selfKeyEvent
event
- params
- onKeyUp
- params
View
selfKeyEvent
event
- params
- onSizeChanged
- params
View
selfKeyEvent
event
- params
- onCaptureLost
- params
View
selfKeyEvent
event
- params
Button
props:
Button::Type
typeBoolean
defaultCheckedString
titleImage
image
events:
- onClick(self)
- params
Button
self
- params
Container
events:
- onDraw(self, painter, painter)
- params
Container
selfPainter
painter - The drawing context of the view.RectF
dirty - The area in the view to draw on.
- params
Entry
props:
Entry::Type
typeString
text
events:
- onTextChange(self)
- params
Entry
self
- params
- onActivate(self)
- params
Entry
self
- params
Group
props:
String
titleView
children
Label
props:
String
text
ProgressBar
props:
Number
percentBoolean
indeterminate
Scroll
props:
Scroll::Policy
hpolicyScroll::Policy
vpolicyBoolean
overlayScrollbarSizeF size
contentSizeView
children
TextEdit
props:
String
textScroll::Policy
hpolicyScroll::Policy
vpolicyBoolean
overlayScrollbar
events:
- onTextChange(self)
- params
TextEdit
self
- params
Vibrant
props:
Vibrant::Material
materialVibrant::BlendingMode
mode
Using with yackage
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.
Run Tests
npm run test