Roo/bootstrap/Card.js
[roojs1] / Roo / bootstrap / Card.js
index fe7af10..bd6467c 100644 (file)
@@ -9,13 +9,40 @@
  *
  *
  * possible... may not be implemented..
- * @cfg {String} header content of header (for panel)
- * @cfg {String|Object} - title
- * @cfg {String|Object} - subtitle
- * @cfg {String|Object} - body
- * @cfg {String|Object} - footer
+ * @cfg {String} header_image  
+ * @cfg {String|Object} header
+ * @cfg {String|Object} header_size (0|1|2|3|4|5) H1 or H2 etc.. 0 indicates default
+ * 
+ * @cfg {String|Object} title
+ * @cfg {String|Object} subtitle
+ * @cfg {String} html -- html contents - or just use children..
+ * @cfg {String|Object} footer
  * @cfg {Array} - links
- *     
+ *
+ * @cfg {String} weight (primary|warning|info|danger|secondary|success|light|dark)
+ * 
+ * @cfg {String} margin (0|1|2|3|4|5|auto)
+ * @cfg {String} margin_top (0|1|2|3|4|5|auto)
+ * @cfg {String} margin_bottom (0|1|2|3|4|5|auto)
+ * @cfg {String} margin_left (0|1|2|3|4|5|auto)
+ * @cfg {String} margin_right (0|1|2|3|4|5|auto)
+ * @cfg {String} margin_x (0|1|2|3|4|5|auto)
+ * @cfg {String} margin_y (0|1|2|3|4|5|auto)
+ *
+ * @cfg {String} padding (0|1|2|3|4|5)
+ * @cfg {String} padding_top (0|1|2|3|4|5)
+ * @cfg {String} padding_bottom (0|1|2|3|4|5)
+ * @cfg {String} padding_left (0|1|2|3|4|5)
+ * @cfg {String} padding_right (0|1|2|3|4|5)
+ * @cfg {String} padding_x (0|1|2|3|4|5)
+ * @cfg {String} padding_y (0|1|2|3|4|5)
+ *
+ * @cfg {String} display (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
+ * @cfg {String} display_xs (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
+ * @cfg {String} display_sm (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
+ * @cfg {String} display_lg (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
+ * @cfg {String} display_xl (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
  * @constructor
  * Create a new Container
  * @param {Object} config The config object
@@ -32,8 +59,68 @@ Roo.bootstrap.Card = function(config){
 
 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component,  {
     
-   
-   
+    
+    weight : '',
+    
+    margin: '', /// may be better in component?
+    margin_top: '', 
+    margin_bottom: '', 
+    margin_left: '',
+    margin_right: '',
+    margin_x: '',
+    margin_y: '',
+    
+    padding : '',
+    padding_top: '', 
+    padding_bottom: '', 
+    padding_left: '',
+    padding_right: '',
+    padding_x: '',
+    padding_y: '',
+    
+    display: '', 
+    display_xs: '', 
+    display_sm: '', 
+    display_lg: '',
+    display_xl: '',
+    header_image  : '',
+    header : '',
+    header_size : 0,
+    title : '',
+    subtitle : '',
+    html : '',
+
+    layoutCls : function()
+    {
+        var cls = '';
+        var t = this;
+        
+        ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
+            // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
+            
+            if (t['margin' + (v.length ? '_' : '') + v].length) {
+                cls += ' m' +  (v.length ? v[0]  : '') + '-' +  t['margin' + (v.length ? '_' : '') + v];
+            }
+            if (t['padding' + (v.length ? '_' : '') + v].length) {
+                cls += ' p' +  (v.length ? v[0]  : '') + '-' +  t['padding' + (v.length ? '_' : '') + v];
+            }
+        });
+        
+        ['', 'xs', 'sm', 'lg', 'xl',   ].forEach(function(v) {
+            if (t['display' + (v.length ? '_' : '') + v].length) {
+                cls += ' d' +  (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v].length
+            }
+        });
+        
+        // more generic support?
+        if (this.hidden) {
+            cls += ' d-none';
+        }
+        
+        return cls;
+    },
        // Roo.log("Call onRender: " + this.xtype);
         /*  We are looking at something like this.
 <div class="card">
@@ -59,128 +146,60 @@ Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component,  {
     getAutoCreate : function(){
         
         var cfg = {
-            tag : this.tag || 'div',
-            html : '',
-            cls : ''
+            tag : 'div',
+            cls : 'card',
+            cn : [ ]
         };
-        if (this.jumbotron) {
-            cfg.cls = 'jumbotron';
-        }
-        
         
-        
-        // - this is applied by the parent..
-        //if (this.cls) {
-        //    cfg.cls = this.cls + '';
-        //}
-        
-        if (this.sticky.length) {
-            
-            var bd = Roo.get(document.body);
-            if (!bd.hasClass('bootstrap-sticky')) {
-                bd.addClass('bootstrap-sticky');
-                Roo.select('html',true).setStyle('height', '100%');
-            }
-             
-            cfg.cls += 'bootstrap-sticky-' + this.sticky;
+        if (this.weight.length && this.weight != 'light') {
+            cfg.cls += ' text-white'
         }
-       
-       
-        if (this.well.length) {
-            switch (this.well) {
-                case 'lg':
-                case 'sm':
-                    cfg.cls +=' well well-' +this.well;
-                    break;
-                default:
-                    cfg.cls +=' well';
-                    break;
-            }
+        if (this.weight.length) {
+            cfg.cls += ' bg-' + this.weight;
         }
         
-        if (this.hidden) {
-            cfg.cls += ' hidden';
-        }
+        cfg.cls += this.layoutCls(); 
         
-        
-        if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
-            cfg.cls +=' alert alert-' + this.alert;
+        if (this.header.length) {
+            cfg.cn.push({
+                tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
+                cls : 'card-header',
+                html : this.header // escape?
+            });
         }
-        
-        var body = cfg;
-        
-        if (this.panel.length) {
-            cfg.cls += ' panel panel-' + this.panel;
-            cfg.cn = [];
-            if (this.header.length) {
-                
-                var h = [];
-                
-                if(this.expandable){
-                    
-                    cfg.cls = cfg.cls + ' expandable';
-                    
-                    h.push({
-                        tag: 'i',
-                        cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus') 
-                    });
-                    
-                }
-                
-                h.push(
-                    {
-                        tag: 'span',
-                        cls : 'panel-title',
-                        html : (this.expandable ? '&nbsp;' : '') + this.header
-                    },
-                    {
-                        tag: 'span',
-                        cls: 'panel-header-right',
-                        html: this.rheader
-                    }
-                );
-                
-                cfg.cn.push({
-                    cls : 'panel-heading',
-                    style : this.expandable ? 'cursor: pointer' : '',
-                    cn : h
-                });
-                
-            }
-            
-            body = false;
+        if (this.header_image.length) {
             cfg.cn.push({
-                cls : 'panel-body' + (this.expanded ? '' : ' hide'),
-                html : this.html
+                tag : 'img',
+                cls : 'card-img-top',
+                src: this.header_image // escape?
             });
-            
-            
-            if (this.footer.length) {
-                cfg.cn.push({
-                    cls : 'panel-footer',
-                    html : this.footer
-                    
-                });
-            }
-            
         }
         
-        if (body) {
-            body.html = this.html || cfg.html;
-            // prefix with the icons..
-            if (this.fa) {
-                body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
-            }
-            if (this.icon) {
-                body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
-            }
-            
-            
+        var body = {
+            tag : 'div',
+            cls : 'card-body',
+            cn : []
+        };
+        cfg.push(body);
+        
+        if (this.title.length) {
+            body.cn.push({
+                tag : 'div',
+                cls : 'card-title',
+                src: this.title // escape?
+            });
         }
-        if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
-            cfg.cls =  'container';
+        
+        if (this.subtitle.length) {
+            body.cn.push({
+                tag : 'div',
+                cls : 'card-title',
+                src: this.subtitle // escape?
+            });
         }
         
+          
+        
         return cfg;
     },
 }
\ No newline at end of file