Roo/bootstrap/Card.js
[roojs1] / Roo / bootstrap / Card.js
1 /*
2  * This is BS4's Card element.. - similar to our containers probably..
3  * 
4  */
5 /**
6  * @class Roo.bootstrap.Card
7  * @extends Roo.bootstrap.Component
8  * Bootstrap Card class
9  *
10  *
11  * possible... may not be implemented..
12  * @cfg {String} header_image  
13  * @cfg {String|Object} header
14  * @cfg {String|Object} header_size (0|1|2|3|4|5) H1 or H2 etc.. 0 indicates default
15  * 
16  * @cfg {String|Object} title
17  * @cfg {String|Object} subtitle
18  * @cfg {String} html -- html contents - or just use children..
19  * @cfg {String|Object} footer
20  * @cfg {Array} - links
21  *
22  * @cfg {String} weight (primary|warning|info|danger|secondary|success|light|dark)
23  * 
24  * @cfg {String} margin (0|1|2|3|4|5|auto)
25  * @cfg {String} margin_top (0|1|2|3|4|5|auto)
26  * @cfg {String} margin_bottom (0|1|2|3|4|5|auto)
27  * @cfg {String} margin_left (0|1|2|3|4|5|auto)
28  * @cfg {String} margin_right (0|1|2|3|4|5|auto)
29  * @cfg {String} margin_x (0|1|2|3|4|5|auto)
30  * @cfg {String} margin_y (0|1|2|3|4|5|auto)
31  *
32  * @cfg {String} padding (0|1|2|3|4|5)
33  * @cfg {String} padding_top (0|1|2|3|4|5)
34  * @cfg {String} padding_bottom (0|1|2|3|4|5)
35  * @cfg {String} padding_left (0|1|2|3|4|5)
36  * @cfg {String} padding_right (0|1|2|3|4|5)
37  * @cfg {String} padding_x (0|1|2|3|4|5)
38  * @cfg {String} padding_y (0|1|2|3|4|5)
39  *
40  * @cfg {String} display (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
41  * @cfg {String} display_xs (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
42  * @cfg {String} display_sm (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
43  * @cfg {String} display_lg (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
44  * @cfg {String} display_xl (none|inline|inline-block|block|table|table-cell|table-row|flex|inline-flex)
45  
46  * @constructor
47  * Create a new Container
48  * @param {Object} config The config object
49  */
50
51 Roo.bootstrap.Card = function(config){
52     Roo.bootstrap.Card.superclass.constructor.call(this, config);
53     
54     this.addEvents({
55         
56     });
57 };
58
59
60 Roo.extend(Roo.bootstrap.Card, Roo.bootstrap.Component,  {
61     
62     
63     weight : '',
64     
65     margin: '', /// may be better in component?
66     margin_top: '', 
67     margin_bottom: '', 
68     margin_left: '',
69     margin_right: '',
70     margin_x: '',
71     margin_y: '',
72     
73     padding : '',
74     padding_top: '', 
75     padding_bottom: '', 
76     padding_left: '',
77     padding_right: '',
78     padding_x: '',
79     padding_y: '',
80     
81     display: '', 
82     display_xs: '', 
83     display_sm: '', 
84     display_lg: '',
85     display_xl: '',
86  
87     header_image  : '',
88     header : '',
89     header_size : 0,
90     title : '',
91     subtitle : '',
92     html : '',
93
94     layoutCls : function()
95     {
96         var cls = '';
97         var t = this;
98         
99         ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
100             // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
101             
102             if (t['margin' + (v.length ? '_' : '') + v].length) {
103                 cls += ' m' +  (v.length ? v[0]  : '') + '-' +  t['margin' + (v.length ? '_' : '') + v];
104             }
105             if (t['padding' + (v.length ? '_' : '') + v].length) {
106                 cls += ' p' +  (v.length ? v[0]  : '') + '-' +  t['padding' + (v.length ? '_' : '') + v];
107             }
108         });
109         
110         ['', 'xs', 'sm', 'lg', 'xl',   ].forEach(function(v) {
111             if (t['display' + (v.length ? '_' : '') + v].length) {
112                 cls += ' d' +  (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v].length
113             }
114         });
115         
116         // more generic support?
117         if (this.hidden) {
118             cls += ' d-none';
119         }
120         
121         return cls;
122     },
123  
124        // Roo.log("Call onRender: " + this.xtype);
125         /*  We are looking at something like this.
126 <div class="card">
127     <img src="..." class="card-img-top" alt="...">
128     <div class="card-body">
129         <h5 class="card-title">Card title</h5>
130          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
131
132         >> this bit is really the body...
133         <div> << we will ad dthis in hopefully it will not break shit.
134         
135             <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
136         
137         </div> <<
138           <a href="#" class="card-link">Card link</a>
139           
140     </div>
141     <div class="card-footer">
142         <small class="text-muted">Last updated 3 mins ago</small>
143     </div>
144 </div>
145          */
146     getAutoCreate : function(){
147         
148         var cfg = {
149             tag : 'div',
150             cls : 'card',
151             cn : [ ]
152         };
153         
154         if (this.weight.length && this.weight != 'light') {
155             cfg.cls += ' text-white'
156         }
157         if (this.weight.length) {
158             cfg.cls += ' bg-' + this.weight;
159         }
160         
161         cfg.cls += this.layoutCls(); 
162         
163         if (this.header.length) {
164             cfg.cn.push({
165                 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
166                 cls : 'card-header',
167                 html : this.header // escape?
168             });
169         }
170         if (this.header_image.length) {
171             cfg.cn.push({
172                 tag : 'img',
173                 cls : 'card-img-top',
174                 src: this.header_image // escape?
175             });
176         }
177         
178         var body = {
179             tag : 'div',
180             cls : 'card-body',
181             cn : []
182         };
183         cfg.push(body);
184         
185         if (this.title.length) {
186             body.cn.push({
187                 tag : 'div',
188                 cls : 'card-title',
189                 src: this.title // escape?
190             });
191         }
192         
193         if (this.subtitle.length) {
194             body.cn.push({
195                 tag : 'div',
196                 cls : 'card-title',
197                 src: this.subtitle // escape?
198             });
199         }
200         
201           
202         
203         return cfg;
204     },
205 }