omim - init expansion

This commit is contained in:
dntzhang 2019-06-21 15:25:14 +08:00
parent ea48d50698
commit 09e0443487
12 changed files with 718 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script src="bundle.js"></script>
</body>
</html>

View File

@ -0,0 +1,30 @@
import '../../src/expansion/index.tsx'
import { define, render, h, WeElement } from 'omi'
define('my-app', class extends WeElement {
static propTypes = {
expand: Boolean
}
onClick = () => {
this.expand = !this.expand
this.update()
}
expand = true
render(props, data) {
return (
<div>
<button onClick={this.onClick}>Toggle</button>
<m-expansion expand={this.expand}>
<div style="width:100px;height:100px;background:green;">{Math.random()}</div>
</m-expansion>
<div>Bottom</div>
</div>
)
}
})
render(<my-app />, 'body')

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta
name="viewport"
content="width=device-width,initial-scale=1,user-scalable=no"
/>
<meta charset="UTF-8" />
<title>Add Omi in One Minute</title>
</head>
<body>
<script src="https://tencent.github.io/omi/packages/omi/dist/omi.js"></script>
<script src="../../src/expansion/index.js"></script>
<div>
<button id="myBtn">Toggle</button>
<m-expansion >
<div style="width:100px;height:100px;background:green;"></div>
</m-expansion>
<div>Bottom</div>
</div>
<script>
document.querySelector('#myBtn').addEventListener('click',function(){
})
</script>
</body>
</html>

View File

@ -1,2 +1 @@
import '../icon';
import '../input';
export {};

View File

@ -1,2 +1 @@
import '../icon';
import '../input';
export {};

18
packages/omim/src/expansion/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
import { WeElement } from 'omi';
import '../theme.ts';
interface Props {
expand: boolean;
}
interface Data {
}
export default class Expansion extends WeElement<Props, Data> {
static css: any;
static propTypes: {
expand: BooleanConstructor;
};
preHeight: number;
receiveProps(): boolean;
installed(): void;
render(props: any): JSX.Element;
}
export {};

View File

@ -0,0 +1,362 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("omi"));
else if(typeof define === 'function' && define.amd)
define(["omi"], factory);
else if(typeof exports === 'object')
exports["MExpansion"] = factory(require("omi"));
else
root["MExpansion"] = factory(root["Omi"]);
})(window, function(__WEBPACK_EXTERNAL_MODULE_omi__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./src/expansion/index.tsx");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./node_modules/_css-loader@1.0.1@css-loader/index.js!./node_modules/_resolve-url-loader@3.1.0@resolve-url-loader/index.js!./node_modules/_sass-loader@7.1.0@sass-loader/lib/loader.js?!./src/expansion/index.scss":
/*!****************************************************************************************************************************************************************************************************************!*\
!*** ./node_modules/_css-loader@1.0.1@css-loader!./node_modules/_resolve-url-loader@3.1.0@resolve-url-loader!./node_modules/_sass-loader@7.1.0@sass-loader/lib/loader.js??ref--4-3!./src/expansion/index.scss ***!
\****************************************************************************************************************************************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(/*! ../../node_modules/_css-loader@1.0.1@css-loader/lib/css-base.js */ "./node_modules/_css-loader@1.0.1@css-loader/lib/css-base.js")(false);
// imports
// module
exports.push([module.i, ":host {\n display: block;\n transition: height 200ms cubic-bezier(0.4, 0, 0.2, 1);\n overflow: hidden; }\n", ""]);
// exports
/***/ }),
/***/ "./node_modules/_css-loader@1.0.1@css-loader/lib/css-base.js":
/*!*******************************************************************!*\
!*** ./node_modules/_css-loader@1.0.1@css-loader/lib/css-base.js ***!
\*******************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
// css base code, injected by the css-loader
module.exports = function(useSourceMap) {
var list = [];
// return the list of modules as css string
list.toString = function toString() {
return this.map(function (item) {
var content = cssWithMappingToString(item, useSourceMap);
if(item[2]) {
return "@media " + item[2] + "{" + content + "}";
} else {
return content;
}
}).join("");
};
// import a list of modules into the list
list.i = function(modules, mediaQuery) {
if(typeof modules === "string")
modules = [[null, modules, ""]];
var alreadyImportedModules = {};
for(var i = 0; i < this.length; i++) {
var id = this[i][0];
if(typeof id === "number")
alreadyImportedModules[id] = true;
}
for(i = 0; i < modules.length; i++) {
var item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
if(mediaQuery && !item[2]) {
item[2] = mediaQuery;
} else if(mediaQuery) {
item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
}
list.push(item);
}
}
};
return list;
};
function cssWithMappingToString(item, useSourceMap) {
var content = item[1] || '';
var cssMapping = item[3];
if (!cssMapping) {
return content;
}
if (useSourceMap && typeof btoa === 'function') {
var sourceMapping = toComment(cssMapping);
var sourceURLs = cssMapping.sources.map(function (source) {
return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
});
return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
}
return [content].join('\n');
}
// Adapted from convert-source-map (MIT)
function toComment(sourceMap) {
// eslint-disable-next-line no-undef
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
return '/*# ' + data + ' */';
}
/***/ }),
/***/ "./src/expansion/index.scss":
/*!**********************************!*\
!*** ./src/expansion/index.scss ***!
\**********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
var result = __webpack_require__(/*! !../../node_modules/_css-loader@1.0.1@css-loader!../../node_modules/_resolve-url-loader@3.1.0@resolve-url-loader!../../node_modules/_sass-loader@7.1.0@sass-loader/lib/loader.js??ref--4-3!./index.scss */ "./node_modules/_css-loader@1.0.1@css-loader/index.js!./node_modules/_resolve-url-loader@3.1.0@resolve-url-loader/index.js!./node_modules/_sass-loader@7.1.0@sass-loader/lib/loader.js?!./src/expansion/index.scss");
if (typeof result === "string") {
module.exports = result;
} else {
module.exports = result.toString();
}
/***/ }),
/***/ "./src/expansion/index.tsx":
/*!*********************************!*\
!*** ./src/expansion/index.tsx ***!
\*********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var omi_1 = __webpack_require__(/*! omi */ "omi");
var css = __webpack_require__(/*! ./index.scss */ "./src/expansion/index.scss");
//@ts-ignore
__webpack_require__(/*! ../theme.ts */ "./src/theme.ts");
var Expansion = /** @class */ (function (_super) {
__extends(Expansion, _super);
function Expansion() {
return _super !== null && _super.apply(this, arguments) || this;
}
Expansion.prototype.receiveProps = function () {
//@ts-ignore
var rect = this.shadowRoot.querySelector('div').getBoundingClientRect();
if (this.props.expand) {
this.style.height = rect.height + 'px';
}
else {
this.style.height = '0px';
}
return false;
};
Expansion.prototype.installed = function () {
console.log(this.props.expand);
console.log(this.children[0]);
//@ts-ignore
var rect = this.children[0].getBoundingClientRect();
if (!this.props.expand) {
this.style.height = '0px';
}
else {
console.log(this.shadowRoot.firstChild);
console.log(rect.height);
this.style.height = rect.height + 'px';
}
};
Expansion.prototype.render = function (props) {
console.log(123);
return (omi_1.h("div", __assign({}, omi_1.extractClass(props, 'm-expansion')),
omi_1.h("slot", null)));
};
Expansion.css = css;
Expansion.propTypes = {
expand: Boolean
};
Expansion = __decorate([
omi_1.tag('m-expansion')
], Expansion);
return Expansion;
}(omi_1.WeElement));
exports.default = Expansion;
/***/ }),
/***/ "./src/theme.ts":
/*!**********************!*\
!*** ./src/theme.ts ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports) {
theme();
document.addEventListener('DOMContentLoaded', function () {
theme();
});
function theme() {
if (document.body && !document.body.style.getPropertyValue('--mdc-theme-primary')) {
document.body.style.setProperty('--mdc-theme-primary', '#0072d9');
document.body.style.setProperty('--mdc-theme-secondary', '#2170b8');
document.body.style.setProperty('--mdc-theme-error', '#f5222d');
document.body.style.setProperty('--mdc-theme-surface', '#ffffff');
document.body.style.setProperty('--mdc-theme-on-primary', '#ffffff');
document.body.style.setProperty('--mdc-theme-on-secondary', '#ffffff');
document.body.style.setProperty('--mdc-theme-on-error', '#ffffff');
document.body.style.setProperty('--mdc-theme-on-surface', '#000000');
document.body.style.setProperty('--mdc-theme-background', '#ffffff');
document.body.style.setProperty('--mdc-shape-small-component-radius', '4px');
document.body.style.setProperty('--mdc-shape-medium-component-radius', '4px');
document.body.style.setProperty('--mdc-shape-large-component-radius', '0px');
document.body.style.setProperty('--mdc-typography--font-family', 'Roboto, sans-serif');
}
}
/***/ }),
/***/ "omi":
/*!******************************************************************************!*\
!*** external {"commonjs":"omi","commonjs2":"omi","amd":"omi","root":"Omi"} ***!
\******************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_omi__;
/***/ })
/******/ })["default"];
});
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,7 @@
:host {
display: block;
transition: height 200ms cubic-bezier(0.4, 0, 0.2, 1);
overflow: hidden;
}

View File

@ -0,0 +1,54 @@
import { tag, WeElement, h, extractClass, getHost } from 'omi'
import * as css from './index.scss'
//@ts-ignore
import '../theme.ts'
interface Props {
expand: boolean
}
interface Data {}
@tag('m-expansion')
export default class Expansion extends WeElement<Props, Data> {
static css = css
static propTypes = {
expand: Boolean
}
_host: HTMLElement
preHeight: number
receiveProps(){
const rect = this._host.getBoundingClientRect()
if(this.props.expand){
this.style.height = rect.height + 'px'
}else{
this.style.height = '0px'
}
return false
}
installed() {
const rect = this._host.getBoundingClientRect()
if(!this.props.expand){
this.style.height = '0px'
}else{
this.style.height = rect.height +'px'
}
}
render(props) {
return (
<div
{...extractClass(props, 'm-expansion')}
>
<slot />
</div>
)
}
}

View File

@ -0,0 +1,25 @@
{
"name": "@omim/elevation",
"version": "0.0.1",
"description": "Material Design for Omi.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"omi",
"omim",
"material",
"material design",
"material-design"
],
"author": "dntzhang <dntzhang@qq.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Tencent/omi/issues"
},
"homepage": "https://github.com/Tencent/omi",
"typings": "./index.d.ts",
"types": "index.d.ts",
"dependencies": {}
}