-
Notifications
You must be signed in to change notification settings - Fork 16
/
_formtastic_base.sass
628 lines (618 loc) · 16.2 KB
/
_formtastic_base.sass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
//
// FORMTASTIC SASS
// Flexible styling for formtastic forms
// http://www.github.com/activestylus/formtastic-sass
//
//--------------------------------------------------------
// STACKED FORMS
// Labels fill up the full width of the form
// Inputs are on new lines
//--------------------------------------------------------
//
// Arguments:
//
// +stack-form(full-width, input-width, submit-button-align)
//
// Example:
//
// form.formtastic
// +stack-form(300px,"full","right")
//
// Default Settings:
//
!stacked_fieldset=100%
// Full width of the fieldset
//
!stacked_input="auto"
// "auto" = automatic widths
// "full" = same width as form
// "960px" = custom width
//
!stacked_padding=0
// Left padding on all labels and inputs
//
!stacked_button_align="buttons-left"
// "buttons-left" = float submit button left
// "buttons-right" = float submit button right
// "buttons-center" = no float, auto width
// "buttons-full" = submit button matches input width
//
!stacked_select_width = "select-auto"
// "select-auto" = default width
// "select-full" = same as specified input width
//
//--------------------------------------------------------
// FLOATED FORMS
// Column layout with labels left of the inputs
// Comes in 2 flavors for text alignment of the labels
//--------------------------------------------------------
//
// Arguments:
//
// +float-form-left(total-width, label-width, input-width, label-padding-x, submit-align)
//
// Examples:
//
// form.lefty
// +float-form-left(800px,500px,200px,6px,"buttons-left")
//
// form.righty
// +float-form-right(800px,500px,200px,6px,"buttons-left")
//
//--------------------------------------------------------
// Default Settings:
// (do not mix units because calculations are made)
//
!floated_total_width = 100%
// Total Width of form
//
!floated_input_width = 70%
// Width of inputs
//
!floated_label_width = 20%
// Width of Label
//
!floated_label_padding_x = 0
// How far labels are spaced from inputs
//
!floated_button_align = "buttons-left"
// "buttons-left" = float submit button left
// "buttons-right" = float submit button right
// "buttons-center" = no float, auto width
// "buttons-full" = submit button matches input width
//
!floated_label_text_align = "left"
// "left"
// "right"
// "center"
//
!floated_select_width = "select-auto"
// "select-auto" = default width
// "select-full" = same as specified input width
//
//========================================================
// FORMTASTIC STYLING
// Note: Be careful when modifying widths and
// horizontal padding/margins as you can break layouts
//========================================================
=formtastic_clearfix
*display: inline-block
&:after
content: " "
display: block
height: 0
clear: both
visibility: hidden
//
//
//
//--------------------------------------------------------
//========================================================
// Base stuff (do not edit unless you are smarter than me :p)
//========================================================
//--------------------------------------------------------
//
//
//
//--------------------------------------------------------
// Generic Mixins
//--------------------------------------------------------
=float-labels(!width,!padding=0,!direction="left")
:width = !width - !padding
:text-align = !direction
:display inline
:float left
:clear none
@if !padding == 0
:padding 0
@else
:padding-#{!direction} = !padding
=block(!block_float="clear")
:display block
@if !block_float=="clear"
:clear both
:float none
@else
:float = !block_float
=inline(!float="none",!clear="none")
:display inline
:float = !float
:clear = !clear
=reset-form
// Reset elements
ul, ol, legend, p
:margin 0
:padding 0
li
:margin-left 0px
:margin-right 0px
:padding-left 0px
:padding-right 0px
// Clearfix fieldsets
fieldset
:display block
+formtastic_clearfix
// * fields
abbr, acronym
:border 0
:font-variant normal
:font-weight normal
// Reset list styles
ol, ul
:list-style none
// Clearfix label
label
:display block
+formtastic_clearfix
// Align Inputs
input, textarea
:vertical-align middle
// Make Labels Clickable
.check_boxes, .radio
input
:margin 0
label
:cursor pointer
// Hide hidden fields
.hidden
:display none
// Date Time Selects shown inline
.date, .time, .datetime
li
:float left
:width auto
:clear none
label
:display none
:width auto
input
:display inline
:margin 0
:padding 0
// Error lists for each input
.errors
:list-style square
li
:padding 0
:border none
:display list-item
:float none
:clear both
.inputs
:z-index 99
// Float Submit Buttons
.buttons li
:float left
// Reset Nested Fieldset & Legends
li
+formtastic_clearfix
:display block
fieldset
:border none
:position relative
:margin-top 0px
legend
:display block
:margin-bottom 0
.label
:display block
:clear both
:background transparent
// Reset lists for checkboxes and radio buttons
ol
:float left
:margin 0
li
:padding 0
:border 0
:display inline
//
//--------------------------------------------------------
// Form Stack
//--------------------------------------------------------
//
=stack-form(!stacked_fieldset, !stacked_input, !stacked_padding, !stacked_button_align, !stacked_select_width)
+reset-form
fieldset
:width = !stacked_fieldset
ol
:padding-left = !stacked_padding
input
:clear both
:float none
li
+block
:width = !stacked_fieldset
ol
:padding 0
li
:clear none
:width auto
fieldset
legend, legend .label
:display block
:clear both
.label
:position relative
label, input
:width auto
.date, .time, .datetime
ol
:width = !stacked_fieldset
li
:display inline
:clear none
:float left
:padding-right = !stacked_padding / 2
.checkbox, .radio
li
:display block
input
:border none
label
+block
:width = !stacked_input
input, textarea
@if !stacked_input=="full"
:width = !stacked_fieldset - !stacked_padding
@else
:width = !stacked_input
select
@if !stacked_select_width == "select-auto"
:width auto
@else
:width = !stacked_input
.errors li
:display list-item
.buttons
ol
:padding-left = !stacked_padding
:padding-right = !stacked_padding
li
@if !stacked_button_align == "buttons-left"
:float left
@if !stacked_button_align == "buttons-right"
:float right
@if !stacked_button_align == "buttons-center"
:float none
:width auto
:clear none
:display inline
input
@if !stacked_button_align == "buttons-full"
:width = !stacked_fieldset
@else
:width auto
#errorExplanation
:width = !stacked_fieldset - !stacked_padding
.label
// Legend Left Margin Hack for IE
:#left -0.5em
:#position relative
//
//--------------------------------------------------------
// Float Form Core
//--------------------------------------------------------
//
=float-form(!floated_total_width,!floated_label_width,!floated_input_width,!floated_label_padding_x, !floated_button_align, !floated_label_text_align, !floated_select_width )
+reset-form
fieldset
:width = !floated_total_width
label
:float left
:width = !floated_label_width - !floated_label_padding_x
:text-align = !floated_label_text_align
:padding-#{!floated_label_text_align} = !floated_label_padding_x
li
ol
:padding = 0 ( !floated_total_width - (!floated_input_width + !floated_label_width)) 0 !floated_label_width
fieldset
legend, legend .label
:display block
legend
+float-labels(!floated_label_width,!floated_label_padding_x,!floated_label_text_align)
:width = !floated_total_width - !floated_label_padding_x
.label
:position absolute
:width = !floated_label_width - !floated_label_padding_x
:top 0px
@if !floated_label_text_align=="right"
:left 0
@else
:left = !floated_label_padding_x
label
:padding-left 0
label, input
:width auto
:display inline
:clear none
:text-align left
select
:padding 0
:clear both
:display block
.inline-hints, .inline-errors, .errors
:margin = 0 0 0 !floated_label_width
input, textarea
:width = !floated_input_width
select
@if !floated_select_width=="select-auto"
:width auto
@else
:width = !floated_input_width
.checkbox, .radio
li
:display block
:clear both
input
:border none
.buttons
:padding-left = !floated_label_width
:width = !floated_total_width - !floated_label_width
input
:width auto
ol
@if !floated_button_align == "buttons-right"
:padding-right = !floated_label_padding_x
li
:width auto
@if !floated_button_align == "buttons-right"
:float right
@else
:float left
@if !floated_button_align == "full-buttons"
input
:width = !floated_input_width
@else
:display inline
#errorExplanation
:margin-left = !floated_label_width
:width = !floated_input_width
//
//--------------------------------------------------------
// Float Form Left/Right
//--------------------------------------------------------
//
=float-form-left(!floated_total_width,!floated_label_width,!floated_input_width,!floated_label_padding_x, !floated_button_align)
+float-form(!floated_total_width,!floated_label_width,!floated_input_width,!floated_label_padding_x, !floated_button_align,"left")
=float-form-right(!floated_total_width,!floated_label_width,!floated_input_width,!floated_label_padding_x, !floated_button_align)
+float-form(!floated_total_width,!floated_label_width,!floated_input_width,!floated_label_padding_x, !floated_button_align,"right")
//
//--------------------------------------------------------
// Float Inputs
//--------------------------------------------------------
//
=float-inputs(!margin_right=10px,!line_height=150%)
.radio, .check_boxes
ol
+inline("left")
li
:width auto
+inline("left","none")
input
:float none
:display inline
label
:display block
:clear none
:width auto
:padding-left 0
:line-height = !line_height
:margin-right = !margin_right
//
=float-inputs-for(!dom_target,!margin_right=10px,!line_height=150%)
#{!dom_target}
+float-inputs-core(!margin_right,!line_height)
//
//--------------------------------------------------------
// Grid Inputs
//--------------------------------------------------------
//
=grid-inputs(!width=100px,!line_height=150%)
.radio, .check_boxes
ol
+inline("left")
li
+inline("left","none")
:width = !width
label
+inline("left","none")
:width auto
:line-height = !line_height
=grid-inputs-for(!dom_target,!width=100px,!line_height=150%)
#{!dom_target}
+grid-inputs-core(!width,!line_height)
//--------------------------------------------------------
// Labels
//--------------------------------------------------------
=bold-labels(!select="all")
li
@if !select == "all"
label, legend span.label
:font-weight bold
li
label
:font-weight normal
@if !select == "required"
&.required
label, .label
:font-weight bold
li
label
:font-weight normal
//---------------------------------------------------
// Original Mixin (deprecated!)
//
!form_layout="float"
// Set the general layout of the form
// "float" will use two column layout with labels on the left
// "clear" will have labels above the inputs
//
!total_width=100%
// Set width of entire fieldset
//
// Set label widths and hint/error left margins
!label_width=24%
//
!input_width=70%
// Set width of inputs, textareas and selects
//
!label_pad=2%
// Set horizontal padding for labels
//
!label_float="left"
// Set alignment of labels
// "clear" puts labels above inputs
// "left" floats labels left and aligns text left
// "right" floats labels left and aligns text right
//
// Set widths of all inputs, textareas and selects (all aligned)
// False will preserve auto width
!full_width_inputs=true
//
// Set float direction of form buttons ("right" or "left")
!button_float="left"
// Installation ------------------------------------------
//
//$ sudo gem install haml
//$ cd rails app
//$ haml --rails (or merb/sinatra/etc)
//
// Set up master Sass file and include it in your html
// Save this file as _base.sass and include it in master sass like so:
//
// @import base.sass
//
// Usage -------------------------------------------------
//
// form.formtastic
// +formtastic-float
//
// This will provide forms of columns with label floated left
// For label on top of inputs you can use
//
// form.formtastic
// +formtastic-block
//
// Customize ---------------------------------------------
//
// form.formtastic
// +formtastic(410px,100px,300px,12px,"right",true)
//
// Note: When using pixel values be sure to pad total width by 10px
// Still looking for a way to make this cleaner
//--------------------------------------------------------
=formtastic(!total_width,!label_width,!input_width,!label_pad,!label_float,!button_float,!full_width_inputs)
fieldset
:width = !total_width
ol li
label
@if !label_float=="clear"
:display block
:clear both
:float none
@else
:float left
:width = !label_width - !label_pad
@if !label_float=="left"
:padding-left = !label_pad
:text-align left
@else
:text-align right
fieldset
legend
@if !label_float=="clear"
:display block
:clear both
:float none
span.label
:display block
:clear both
:float none
@else
:width = !label_width - !label_pad
@if !label_float=="left"
:padding-left = !label_pad
@else
:padding-right = !label_pad
:text-align right
span.label
:position absolute
:width = !label_width - !label_pad
ol
@if !label_float=="clear"
:padding 0
@else
:padding = 0 ( !total_width - (!input_width + !label_width)) 0 !label_width
@if !label_float == "clear"
&.string input, &.password input, &.numeric input, &.text textarea, select
:width = !input_width
@else
p.inline-hints, p.inline-errors, ul.errors
:margin = 0 0 0 !label_width
@if !full_width_inputs
&.string input, &.password input, &.numeric input, &.text textarea, select
:width = !input_width
&.boolean label
:padding-left = !label_width
fieldset
&.buttons
@if !label_float == "clear"
:width = !total_width
@else
:padding-left = !label_width
:width = !input_width
@if !button_float == "left"
ol
li
:display inline
:width auto
:float left
@if !button_float == "right"
ol
:padding-left 0
@if !label_float == "clear"
:width = !input_width
li
:float right
:width auto
@if !label_float != "clear"
:padding-left = !label_pad
//--------------------------------------------------------
// Formtastic Errors on top (aligned with label)
//
// Create formtastic.rb in config/initializers and add this:
// Formtastic::SemanticFormBuilder.inline_order = [:errors, :input, :hints]
// Best used with right-aligned labels
// +formtastic(100%,20%,70%,4%,"right")
//--------------------------------------------------------
=formtastic-errors-on-top(!label_vertical_margin=21px)
ol li.error
p.inline-errors
:margin-top 0px
label, span.label
:margin-top = "-#{!label_vertical_margin}"
:padding-bottom 18px
fieldset label
:margin-top 0
:padding-bottom 0