Omi

Next Front End Framework

README

English | 简体中文

omi

Omi - Front End Cross-Frameworks Framework


  1. ```tsx
  2. import { tag, WeElement, h, render } from 'omi'

  3. @tag('hello-world')
  4. class HelloWorld extends WeElement {
  5.   static css = 'p { color: red }'
  6.   
  7.   render(props) {
  8.     return (
  9.       <>
  10.         <h1>Omi</h1>
  11.         <p>Hello {props.msg}</p>
  12.       </>
  13.     )
  14.   }
  15. }

  16. render(<hello-world msg='World' />, 'body')
  17. ```



Why Omi?


- Cross frameworks, components of omi are pure custom elements
- Tiny size and High performance
- One framework. Mobile & desktop & mini program
- Compliance with browser trend and API design
- Merge [Web Components](https://developers.google.com/web/fundamentals/web-components/), [JSX/TSX](https://reactjs.org/docs/introducing-jsx.html) into one framework
- JSX/TSX is the best development experience (code intelligent completion and tip) UI Expression with least grammatical noise and it's turing complete(template engine is not, es template string is but grammatical noise is too loud)
- Look at Facebook React vs Web Components,Omicombines their advantages and gives developers the freedom to choose the way they like
- Shadow DOM or Light DOM merges with Virtual DOM, Omi uses both virtual DOM and real Shadow DOM to make view updates more accurate and faster
- Scoped CSS's best solution is [Shadow DOM](https://developers.google.com/web/fundamentals/web-components/shadowdom), the community churning out frameworks and libraries for Scoped CSS (using JS or JSON writing styles such as Radium, jsxstyle, react-style; binding to webpack using generated unique className filename-classname-hash, such as CSS Modules, Vue), are hack technologies; _and Shadow DOM Style is the perfect solution
- Be friendly to custom elements, you can pass false attributes to elements through string '0' or string 'false', you can [pass object attributes to elements through : prefix and Omi.$](https://github.com/Tencent/omi/releases/tag/v6.8.0)
- Enhanced CSS, rpx unit support base on750 screen width


New Project


  1. ``` sh
  2. $ npx omi-cli init my-app     # init project
  3. $ cd my-app          
  4. $ npm start           # develop
  5. $ npm run build       # release
  6. ```

New Component


  1. ``` sh
  2. $ npx omi-cli init-component my-component     # init project
  3. $ cd my-app          
  4. $ npm start           # develop
  5. $ npm run build       # release
  6. ```

Examples



**Project****Description**
------------------------------------------------------------------
[snake![](https://dntzhang.github.io/cax/asset/hot.png)The
|[custom-elements-everywhere](https://custom-elements-everywhere.com/)|
[omi-piano![](https://dntzhang.github.io/cax/asset/hot.png)](https://github.com/Wscats/piano)|Build
[omi-devtools](https://github.com/f/omi-devtools)|
[omi-chart](https://github.com/Tencent/omi/tree/v6/packages/omi-chart)|
[md2site](https://tencent.github.io/omi/assets/md2site/)|
[omi-30-seconds](https://github.com/Tencent/omi/tree/v6/packages/omi-30-seconds)|
[omi-canvas](https://github.com/Tencent/omi/tree/v6/packages/omi-canvas)|
[omi-swiper](https://github.com/loo41/Omi-Swiper)|
[omi-vscode](https://github.com/ZainChen/omi-vscode)|
[omi-ex](https://github.com/Tencent/omi/tree/v6/packages/omi-ex)|
[omi-transform](https://github.com/Tencent/omi/tree/v6/packages/omi-transform)|Omi
[omi-finger](https://github.com/Tencent/omi/tree/v6/packages/omi-finger)|Support
[omi-touch](https://github.com/Tencent/omi/tree/v6/packages/omi-touch)|Smooth
[omi-i18n](https://github.com/i18next/omi-i18n)|
[omie](https://github.com/Wscats/omi-electron)|Build
[omi-cv](https://github.com/Wscats/CV)|Create

Useful Resources


**Title**Other**Related**|
-----------------------------------------------------------|-----------------|
|[Web|||
|[Snake-Eating|||
|[Constructable|||
|[Web|||
|[Web|||
|[Using|||
|[Using|||
|[Styling
|[Developer||
|[Develop||
[60FPS[简体中文](https://github.com/Tencent/omi/blob/master/tutorial/omi-transform.cn.md)
[Shadow[简体中文](https://github.com/Tencent/omi/blob/master/tutorial/shadow-dom-in-depth.cn.md)|
[Part|求翻译|
[Web[简体中文](https://developer.mozilla.org/zh-CN/docs/Web/Web_Components)|
[Web
[Web
[Web
[CSS|[简体中文](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Using_CSS_variables)
[CSS
[Platform
[The|[简体中文](https://github.com/Tencent/omi/blob/master/tutorial/the-power-of-web-components.cn.md)|
|[ShadowRoot](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot)|[简体中文](https://developer.mozilla.org/zh-CN/docs/Web/API/ShadowRoot)||
|[slotted](https://developer.mozilla.org/en-US/docs/Web/CSS/::slotted)|[简体中文](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::slotted)||

<!--

Overview of the Readme


  - Lifecycle
- License -->

Usage with TypeScript


Define cross-frameworks button element with TypeScript:

  1. ```ts
  2. import { tag, WeElement, h, extractClass } from 'omi'
  3. import * as css from './index.scss'

  4. interface Props {
  5.   size?: 'medium' | 'small' | 'mini',
  6.   type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'text'
  7.   plain?: boolean,
  8.   round?: boolean,
  9.   circle?: boolean,
  10.   loading?: boolean,
  11.   disabled?: boolean,
  12.   icon?: string,
  13.   autofocus?: boolean,
  14.   nativeType?: 'button' | 'submit' | 'reset',
  15.   block?: boolean
  16.   text?: string
  17. }

  18. @tag('o-button')
  19. export default class Button extends WeElement<Props>{
  20.   static css = css

  21.   static defaultProps = {
  22.     plain: false,
  23.     round: false,
  24.     circle: false,
  25.     loading: false,
  26.     disabled: false,
  27.     autofocus: false,
  28.     nativeType: 'button',
  29.     block: false
  30.   }

  31.   static propTypes = {
  32.     size: String,
  33.     type: String,
  34.     plain: Boolean,
  35.     round: Boolean,
  36.     circle: Boolean,
  37.     loading: Boolean,
  38.     disabled: Boolean,
  39.     icon: String,
  40.     autofocus: Boolean,
  41.     nativeType: String,
  42.     block: Boolean,
  43.     text: String
  44.   }

  45.   render(props) {
  46.     return <button disabled={props.disabled} {...extractClass(props, 'o-button', {
  47.       ['o-button-' + props.type]: props.type,
  48.       ['o-button-' + props.size]: props.size,
  49.       'is-plain': props.plain,
  50.       'is-round': props.round,
  51.       'is-circle': props.circle,
  52.       'is-disabled': props.disabled,
  53.       'is-block': props.block
  54.     })} type={props.nativeType} >
  55.       {props.loading && <i class='icon-loading'></i>}
  56.       {props.text}
  57.       <slot></slot>
  58.     </button>
  59.   }
  60. }
  61. ```

TypeScript Auto Complete


  1. ``` js
  2. import { h, WeElement, tag, classNames } from 'omi';
  3. import * as styles from './_index.less';

  4. interface ButtonProps {
  5.   href?: string,
  6.   disabled?: boolean,
  7.   type?: 'default' | 'primary' | 'danger',
  8.   htmltype?: 'submit' | 'button' | 'reset',
  9.   onClick?: (e: any) => void
  10. }

  11. const TAG = 'o-button'

  12. declare global {
  13.   namespace JSX {
  14.     interface IntrinsicElements {
  15.       [TAG]: Omi.Props & ButtonProps
  16.     }
  17.   }
  18. }

  19. @tag(TAG)
  20. export default class oButton extends WeElement<ButtonProps> {
  21. ...
  22. ...
  23. ...
  24. ```

omi



Browsers Support



Omi works in the latest two versions of all major browsers: Safari 10+, IE 11+, and the evergreen Chrome, Firefox, and Edge.

→ Browsers Support


  1. ``` html
  2. <script src="https://unpkg.com/@webcomponents/webcomponentsjs@2.0.0/webcomponents-bundle.js"></script>
  3. ```

Contributors



Any form of contribution is welcome. The above contributors have been officially released by Tencent.

We very much welcome developers to contribute to Tencent's open source, and we will also give them incentives to acknowledge and thank them. Here we provide an official description of Tencent's open source contribution. Specific contribution rules for each project are formulated by the project team. Developers can choose the appropriate project and participate according to the corresponding rules. The Tencent Project Management Committee will report regularly to qualified contributors and awards will be issued by the official contact.


Please contact us for any questions.


License


MIT © Tencent