Code Monkey home page Code Monkey logo

scriptable-jsx's Introduction

scriptable-jsx

This project helps you to write Scriptable widgets with JSX syntax. And add some useful tools by the way.

you can check demos in demo folder

简体中文

Install

npm i scriptable-jsx

Requirements

  1. webpack (or other bundler)
  2. babel
  3. @babel/plugin-transform-react-jsx

Usage

  1. We can create a jsx file like this:
import { render } from "scriptable-jsx";

const widget = new ListWidget();

render(
  <stack>
    <text>Hello World</text>
  </stack>,
  widget
);

widget.presentMedium();
  1. Set babel:
{
  ...,
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "runtime": "automatic",
        // use scriptable-jsx to parse jsx
        "importSource": "scriptable-jsx"
      }
    ]
  ]
}

Supported Tags

We have supported these native tags now:

  • stack
  • image
  • spacer
  • text
  • date

Remember, just like react, all the native tags are lowercase. The custom tags should start with uppercase.

All the props are the same as native basically. For example:

<date date={new Date()} applyTimeStyle></date>
<stack
  size={new Size(100, 50)}
  backgroundColor={new Color("#ff0000")}
>
  <text>Test</text>
</stack>

External Features

FlexibleSize

import { FlexibleSize } from "scriptable-jsx";

<stack size={new FlexibleSize(50, 50)}></stack>;

The native Size means the pt unit. It's accurate but not flexible. Users need to adapt to different models. But, FlexibleSize helps you to write the relative value to the widget size. The number you supply means the percent of the full size of width/height of the widget.

We have registered common sizes (check this in device-data.ts). You can add custom sizes too.

Warning: Size for macOS is not provided currently. Actually, the runtime size should be provided by the Scriptable app.

TODO

  • add unit tests
  • remove any type

scriptable-jsx's People

Contributors

maoqxxmm avatar

Stargazers

bobsam avatar @553719 avatar  avatar nakahira avatar Kyuuseiryuu avatar xream avatar saimax avatar  avatar

Watchers

 avatar

Forkers

kyuuseiryuu

scriptable-jsx's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.