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