28d04b86a782fed158c6d3efe0b62ffb9634d489
[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     
95     childContainer : false,
96
97     layoutCls : function()
98     {
99         var cls = '';
100         var t = this;
101         
102         ['', 'top', 'bottom', 'left', 'right', 'x', 'y' ].forEach(function(v) {
103             // in theory these can do margin_top : ml-xs-3 ??? but we don't support that yet
104             
105             if (t['margin' + (v.length ? '_' : '') + v].length) {
106                 cls += ' m' +  (v.length ? v[0]  : '') + '-' +  t['margin' + (v.length ? '_' : '') + v];
107             }
108             if (t['padding' + (v.length ? '_' : '') + v].length) {
109                 cls += ' p' +  (v.length ? v[0]  : '') + '-' +  t['padding' + (v.length ? '_' : '') + v];
110             }
111         });
112         
113         ['', 'xs', 'sm', 'lg', 'xl',   ].forEach(function(v) {
114             if (t['display' + (v.length ? '_' : '') + v].length) {
115                 cls += ' d' +  (v.length ? '-' : '') + v + '-' + t['margin' + (v.length ? '_' : '') + v].length
116             }
117         });
118         
119         // more generic support?
120         if (this.hidden) {
121             cls += ' d-none';
122         }
123         
124         return cls;
125     },
126  
127        // Roo.log("Call onRender: " + this.xtype);
128         /*  We are looking at something like this.
129 <div class="card">
130     <img src="..." class="card-img-top" alt="...">
131     <div class="card-body">
132         <h5 class="card-title">Card title</h5>
133          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
134
135         >> this bit is really the body...
136         <div> << we will ad dthis in hopefully it will not break shit.
137         
138             <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>
139         
140         </div> <<
141           <a href="#" class="card-link">Card link</a>
142           
143     </div>
144     <div class="card-footer">
145         <small class="text-muted">Last updated 3 mins ago</small>
146     </div>
147 </div>
148          */
149     getAutoCreate : function(){
150         
151         var cfg = {
152             tag : 'div',
153             cls : 'card',
154             cn : [ ]
155         };
156         
157         if (this.weight.length && this.weight != 'light') {
158             cfg.cls += ' text-white'
159         }
160         if (this.weight.length) {
161             cfg.cls += ' bg-' + this.weight;
162         }
163         
164         cfg.cls += this.layoutCls(); 
165         
166         if (this.header.length) {
167             cfg.cn.push({
168                 tag : this.header_size > 0 ? 'h' + this.header_size : 'div',
169                 cls : 'card-header',
170                 html : this.header // escape?
171             });
172         }
173         if (this.header_image.length) {
174             cfg.cn.push({
175                 tag : 'img',
176                 cls : 'card-img-top',
177                 src: this.header_image // escape?
178             });
179         }
180         
181         var body = {
182             tag : 'div',
183             cls : 'card-body',
184             cn : []
185         };
186         cfg.push(body);
187         
188         if (this.title.length) {
189             body.cn.push({
190                 tag : 'div',
191                 cls : 'card-title',
192                 src: this.title // escape?
193             });
194         }
195         
196         if (this.subtitle.length) {
197             body.cn.push({
198                 tag : 'div',
199                 cls : 'card-title',
200                 src: this.subtitle // escape?
201             });
202         }
203         
204         body.cn.push({
205             tag : 'div',
206             cls : 'roo-card-body-ctr'
207         });
208         
209         // fixme ? handle objects?
210         if (this.footer.length) {
211             body.cn.push({
212                 tag : 'div',
213                 cls : 'card-footer',
214                 html: this.footer // escape?
215             });
216         }
217         // footer...
218         
219         return cfg;
220     },
221     
222     
223     getChildContainer : function()
224     {
225         
226         if(!this.el){
227             return false;
228         }
229         return this.el.select('.roo-card-body-ctr',true).first();    
230     }
231     
232 }