• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    JavaScript
  • Created almost 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Render the views of Yue with React.

react-yue

npm-version build-badge

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 color
  • backgroundColor: hex|rgb|rgba|hsl|hsla| name of a color
  • fontSize: number representing a pixel value
  • fontWeight: supports 100-900 and all values in https://libyue.com/docs/latest/js/api/font_weight.html
  • fontFamily: name of a font to use
  • fontStyle: normal|italic
  • textAlign: left|center|right
  • verticalAlign: 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 visible
  • Boolean enabled
  • Boolean focusable
  • Boolean mouseDownCanMoveWindow

events:

  • onMouseDown
    • params
      • View self
  • onMouseUp
    • params
      • View self
      • MouseEvent event
  • onMouseMove
    • params
      • View self
      • MouseEvent event
  • onMouseEnter
    • params
      • View self
      • MouseEvent event
  • onMouseLeave
    • params
      • View self
      • MouseEvent event
  • onKeyDown
    • params
      • View self
      • KeyEvent event
  • onKeyUp
    • params
      • View self
      • KeyEvent event
  • onSizeChanged
    • params
      • View self
      • KeyEvent event
  • onCaptureLost
    • params
      • View self
      • KeyEvent event

Button

props:

  • Button::Type type
  • Boolean defaultChecked
  • String title
  • Image image

events:

  • onClick(self)
    • params
      • Button self

Container

events:

  • onDraw(self, painter, painter)
    • params
      • Container self
      • Painter painter - The drawing context of the view.
      • RectF dirty - The area in the view to draw on.

Entry

props:

  • Entry::Type type
  • String text

events:

  • onTextChange(self)
    • params
      • Entry self
  • onActivate(self)
    • params
      • Entry self

Group

props:

  • String title
  • View children

Label

props:

  • String text

ProgressBar

props:

  • Number percent
  • Boolean indeterminate

Scroll

props:

  • Scroll::Policy hpolicy
  • Scroll::Policy vpolicy
  • Boolean overlayScrollbar
  • SizeF size contentSize
  • View children

TextEdit

props:

  • String text
  • Scroll::Policy hpolicy
  • Scroll::Policy vpolicy
  • Boolean overlayScrollbar

events:

  • onTextChange(self)
    • params
      • TextEdit self

Vibrant

props:

  • Vibrant::Material material
  • Vibrant::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

More Repositories

1

http-proxy-to-socks

hpts(http-proxy-to-socks) is a nodejs client to convert socks proxy into http proxy
JavaScript
535
star
2

youdao-collins-chrome-extension

A chrome extension to help you search english words in collins dict.
JavaScript
147
star
3

encryptsocks

Encrypt your socks transmission.
JavaScript
141
star
4

cheerio-without-node-native

Cheerio build that excludes node native modules so that you can use it in platforms like React Native and chrome extensions.
JavaScript
130
star
5

typescript-handbook-zh

TypeScriptζ‰‹ε†ŒδΈ­ζ–‡η‰ˆγ€‚
HTML
94
star
6

nysocks

Nysocks binds kcp and libuv to provide an aggressive tcp tunnel in nodejs.
C++
81
star
7

wasm-opencc

OpenCC compiled by Emscripten so that you can run it on browsers or nodejs without compiling.
C++
53
star
8

frozen_east_text_detection.pb

27
star
9

htmlparser2-without-node-native

htmlparser2 build that excludes node native modules so that you can use it in platforms like React Native.
JavaScript
24
star
10

kcp-node

WIP
JavaScript
9
star
11

react-native-leetcode-reader

LeetCode iOS app built with React Native.
JavaScript
7
star
12

oyyd-blog

A blog for oyyd.net.
JavaScript
6
star
13

redux-proptypes-pack

Use React.PropTypes in your redux apps.
JavaScript
4
star
14

rs-object

Node.js bindings to Rust [object](https://github.com/gimli-rs/object).
Rust
3
star
15

do-space-client

A desktop client of Digital Ocean Space by the lib of Yue.
JavaScript
3
star
16

hoppscotch-tauri

Hoppscotch and a rust proxy server bundled with tauri.
Rust
3
star
17

eslint-plugin-graphql-schema

GraphQL schema specific linting rules for ESLint
JavaScript
3
star
18

os-proxy-socks

WIP
JavaScript
1
star
19

redux-thunk-dispatch

Record redux thunk actions and dispatch them when your server side code restarts.
JavaScript
1
star
20

addon_abort_example

C++
1
star
21

redux-thunk-dispatch-todosmvc

An example of redux-thunk-dispatch with react-hot-loader
JavaScript
1
star
22

switch-proxy

switch-proxy(sp) simplifies switching proxies of your git, docker, npm, etc.
JavaScript
1
star