项目作者: euler-ui

项目描述 :
Euler UI widgets & utilities, powered by React.
高级语言: JavaScript
项目地址: git://github.com/euler-ui/euler-ui.git
创建时间: 2016-05-31T11:57:44Z
项目社区:https://github.com/euler-ui/euler-ui

开源协议:MIT License

下载


Euler UI widgets & utilities, powered by React.

Build Status
Coverage Status
Dependency Status
devDependency Status
Monthly Downloads

NPM

Introduction

Euler UI is a library including a set of UI widgets & utilities, it aims to speed up front end development.

Topics

Quick start

Node.js

  1. npm install euler-ui

Then:

  1. var euler = require("euler-ui");

or es6

  1. import * as euler from 'euler-ui'
  2. import { request, i18n, Notification, Select } from 'euler-ui'

Features

Request

Aren’t you tired of configuring nginx server to test with different back-end server?
Aren’t you tired of creating an express server to start your app?
With simple configuration, you can count on Request module and be able to test with different back-end server, without configuring nginx server or creating an express server.

  • Start server

    1. create e_conf/req folder at your project root
    2. add conf.json at e_conf/req.

      1. {
      2. "STATIC_FOLDER": ["/", "/src"], // static folders that be used at request server
      3. "WEBPACK_CONF_FILE": "webpack.config.js", // webpack config file path
      4. "BUILD_ENV": "DEV", // build env, default is DEV, options are DEV, SIT, UAT, PROD, it will be mapped with different proxy file.
      5. "INDEX_HTML": "src/public/index.html", // index html that be used at request server
      6. }
    3. run

      1. npm estart
  • Sending a request

    1. create proxy folder at e_conf/req
    2. create differnt request proxy for different environment, e.g., proxy.json or proxy_dev.json, proxy_sit.json, proxy_uat.json, proxy_prod.json

      1. proxy.json
      2. [
      3. "proxy": "http://localhost:8000" // global proxy setting
      4. ]
    3. request

      1. actions/login.js
      2. import { request } from 'euler-ui'
      3. export const loginUser = (userName, pwd) => {
      4. request({
      5. url: "/portal/login",
      6. method: "post",
      7. data: {
      8. userName: userName,
      9. password: pwd
      10. }
      11. }, (err, response) => {
      12. if (err) {
      13. error();
      14. return;
      15. }
      16. successs();
      17. })
      18. }
      1. components/login.js
      2. import {loginUser} from '../actions/login'
      3. ...
      4. login() {
      5. loginUser();
      6. }
      7. ...
    4. request API
      Simply speaking, use below api to send a request, the request will be sent to the proxy server.

      1. request({
      2. url: "/portal/login",
      3. method: 'get', //post or get or put or delete
      4. queryParams: { // query parameters, the request url will be /portal/login?param1=value1¶m2=value2
      5. parma1: 'value1',
      6. parma2: 'value2'
      7. },
      8. restParams: {
      9. productId: "1000"
      10. // if url path is '/issues/product/:productId/groupbystatus', the real path will be
      11. // '/issues/product/1000/groupbystatus'
      12. },
      13. loadingMask: true,// display load mask, default is false
      14. data: { // post data
      15. userName: 'Tom',
      16. age: 28
      17. },
      18. proxy: true, // default is true, if set as false, the url won't get proxied, useful for retrieving local resources
      19. headers: { //header data
      20. 'Context-type': "text"
      21. }
      22. }, (err, response) => { //http://visionmedia.github.io/superagent/#response-properties
      23. if (err) {
      24. error()
      25. return;
      26. }
      27. success();
      28. })

      Moreover, you can specify a request at proxy.json with the same identifier sent by request

      1. proxy.json
      2. [
      3. "proxy": "http://localhost:8000", // global proxy setting
      4. "requests": {
      5. "LOGIN": {
      6. "path": "login", // path will be used to send request by browser
      7. "source": "localhost:8001/login"// real path the request will be sent to
      8. }
      9. }
      10. ]
      1. request({
      2. id: "USER_LOGIN", // key at e_conf/req/proxy/proxy*.json#requests
      3. method: 'get', //post or get or put or delete
      4. queryParams: { // query parameters, the request url will be /portal/login?param1=value1¶m2=value2
      5. parma1: 'value1',
      6. parma2: 'value2'
      7. },
      8. restParams: {
      9. productId: "1000"
      10. // if url path is '/issues/product/:productId/groupbystatus', the real path will be
      11. // '/issues/product/1000/groupbystatus'
      12. }
      13. data: { // post data
      14. userName: 'Tom',
      15. age: 28
      16. },
      17. headers: { //header data
      18. 'Context-type': "text"
      19. }
      20. }, (err, response) => { //http://visionmedia.github.io/superagent/#response-properties
      21. if (err) {
      22. error()
      23. return;
      24. }
      25. success();
      26. })

      Notification

A simple notification creator for you to create information/warning/error/success notificaiton.

  1. // Create a hello world notificaiton as information.
  2. Notification.create({
  3. message: "Hello World!"
  4. })
  5. // you can specify notification type with type configuraiton
  6. Notification.create({
  7. message: "Hello World!",
  8. type: "warning"// default is info, options are info, warning, success, error
  9. })
  10. // By default, the notification will be automatically closed in 3 seconds
  11. // you can use timeout configuration to specify the time before the notificaiton be closed
  12. // if timeout is smaller than or equal 0, the notificaiton will just keep still, and only can be closed manually.
  13. Notification.create({
  14. message: "Hello World!",
  15. timeout: -1 // this notificaiton won't get closed unless manully click its close button.
  16. })

I18N

Module for internationalization and localization purpose. Switch differnt locale at runtime!

  1. create e_conf/i18n folder at your project root.

  2. add conf.json at e_conf/i18n.

    1. {
    2. "default": "zh_cn", // default locale name, you can append url query "locale=xxx" to overwrite this settings
    3. // locale maps will be used to map locale file,
    4. // the key is local name, the value is local file suffix,
    5. // e.g., if locale is zh, locales map is {"zh", "zh_cn"}, i18n/locale_zh_cn.json will be used.
    6. "locales": {
    7. "zh": "zh_cn",
    8. "zh_cn": "zh_cn",
    9. "en": "en_us",
    10. "en_us": "en_us"
    11. }
    12. }
  3. add your locale*.json.

    1. locale_en_us.json
    2. {
    3. "notification": {
    4. "success": "Success",
    5. "error": "Error",
    6. "info": "Information",
    7. "warning": "Warning"
    8. }
    9. }
    1. locale_zh_cn.json
    2. {
    3. "notification": {
    4. "success": "成功",
    5. "error": "错误",
    6. "info": "通知",
    7. "warning": "警告"
    8. }
    9. }
  4. After above steps, you are now free to use our i18n module!

    1. main.js
    2. import { i18n} from 'euler-ui'
    3. console.log(Localization.get("notification.info"));

    Spinner

Widget for show or display loading mask.

  1. ```js
  2. import {Spinner} from 'euler-ui'
  3. var spinner = Spinner.show({
  4. type: 'circle', // spinner type, default is circle, options are dot, ring
  5. at: domElement // specify where to show the spinner, default is document.body
  6. })
  7. Spinner.hide([spinner]); // hide the spinner, if the spinner is not passed in, it will just hide last spinner created by spinner.show.
  8. ```

Select

License

The MIT License (MIT)

Copyright (c) 2016 Shin Xi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.