summaryrefslogtreecommitdiffstats
path: root/afb-client/bower_components/foundation-apps/scss/components/_motion.scss
blob: 88bd3a006e4b5bad8ab4b25f76c14e56a4abc1b9 (plain)
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
// FOUNDATION MOTION UI
// Table of Contents
//
// 0. Variables
// 1. Base Transitions
//      a. Slide
//      b. Fade
//      c. Hinge
//      d. Scale
//      e. Spin
// 2. Base Animations
//      a. Shake
//      b. Spinners
//      c. Wiggle
// 3. HTML Attributes

// 0. Variables
// - - - - - - - - - - - - - - - - - - - - - - - - -

/// @Foundation.settings
// Motion UI
// Classes to use when triggering in/out animations
$motion-class: (
  in: "ng-enter",
  out: "ng-leave",
) !default;
$motion-class-active: (
  in: "ng-enter-active",
  out: "ng-leave-active",
) !default;
$motion-class-stagger: (
  in: "ng-enter-stagger",
  out: "ng-leave-stagger",
) !default;
$motion-class-showhide: (
  in: "ng-hide-remove",
  out: "ng-hide-add",
);
$motion-class-showhide-active: (
  in: "ng-hide-remove-active",
  out: "ng-hide-add-active",
);

// Set if movement-based transitions should also fade the element in and out
$motion-slide-and-fade: false !default;
$motion-hinge-and-fade: true !default;
$motion-scale-and-fade: true !default;
$motion-spin-and-fade: true !default;

// Default speed for transitions and animations
$motion-duration-default: 500ms !default;

// Slow and fast modifiders
$motion-duration-slow: 750ms !default;
$motion-duration-fast: 250ms !default;
$motion-stagger-duration-default: 150ms !default;
$motion-stagger-duration-short: 50ms !default;
$motion-stagger-duration-long: 300ms !default;

// Default timing function for transitions and animations
$motion-timing-default: ease !default;

// Built-in and custom easing functions
// Every item in this map becomes a CSS class
$motion-timings: (
  linear: linear,
  ease: ease,
  easeIn: ease-in,
  easeOut: ease-out,
  easeInOut: ease-in-out,
  bounceIn: cubic-bezier(0.485, 0.155, 0.240, 1.245),
  bounceOut: cubic-bezier(0.485, 0.155, 0.515, 0.845),
  bounceInOut: cubic-bezier(0.760, -0.245, 0.240, 1.245),
) !default;

// Default delay for all transitions and animations
$motion-delay-default: 0 !default;
// Short and long delay modifiers
$motion-delay-short: 300ms !default;
$motion-delay-long: 700ms !default;
///

// Looks for a timing function in the list of presets
// If none are found, returns the value as-is.
@function get-timing($timing) {
  @if map-has-key($motion-timings, $timing) {
    @return map-get($motion-timings, $timing);
  }
  @else {
    @return $timing;
  }
}

// Applies transition settings common to all mixins
@mixin transition-basics(
  $duration: $motion-duration-default,
  $timing: $motion-timing-default,
  $delay: $motion-delay-default
) {
  transition-duration: $duration;
  transition-timing-function: get-timing($timing);
  transition-delay: $delay;
}

// Wraps content in an enter/leave class, chained to the parent selector
// Define the initial state of a transition here
@mixin transition-start($dir) {
  $sel1: map-get($motion-class, $dir);
  $sel2: map-get($motion-class-showhide, $dir);

  &.#{$sel1},
  &.#{$sel2} {
    @content;
  }
}

// Wraps content in an enter/leave active class, chained to the matching
// enter/leave class, chained to the parent selector
// Define the end state of a transition here
@mixin transition-end($dir) {
  $sel1:  map-get($motion-class, $dir);
  $sel1A: map-get($motion-class-active, $dir);

  $sel2:  map-get($motion-class-showhide, $dir);
  $sel2A: map-get($motion-class-showhide-active, $dir);

  &.#{$sel1}.#{$sel1A},
  &.#{$sel2}.#{$sel2A} {
    @content;
  }
}

@mixin stagger($delay-amount) {
  transition-delay: $delay-amount;
  // this is to avoid accidental CSS inheritance
  transition-duration:0;
}


// 1. Base Transitions
// - - - - - - - - - - - - - - - - - - - - - - - - -

// SLIDE
@mixin slide (
  $dir: in,
  $from: left,
  $fade: $motion-slide-and-fade,
  $duration: $motion-duration-default,
  $timing: $motion-timing-default,
  $delay: $motion-delay-default
) {
  $slideDirections: (
    top:    translateY(-100%),
    right:  translateX(100%),
    bottom: translateY(100%),
    left:   translateX(-100%),
  );
  $start: '';
  $end: '';

  @if $dir == in {
    $start: map-get($slideDirections, $from);
    $end: translateX(0) translateY(0);
  }
  @else {
    $start: translateX(0) translateY(0);
    $end: map-get($slideDirections, $from);
  }

  // CSS Output
  @include transition-start($dir) {
    @include transition-basics($duration, $timing, $delay);
    transition-property: transform, opacity;
    backface-visibility: hidden;
    transform: $start;

    @if $fade { opacity: if($dir == in, 0, 1); }
  }
  @include transition-end($dir) {
    transform: $end;

    @if $fade { opacity: if($dir == in, 1, 0); }
  }
}

// FADE
@mixin fade(
  $dir: in,
  $from: 0,
  $to: 1,
  $duration: $motion-duration-default,
  $timing: $motion-timing-default,
  $delay: $motion-delay-default
) {
  @include transition-start($dir) {
    @include transition-basics($duration, $timing, $delay);
    transition-property: opacity;
    opacity: $from;
  }
  @include transition-end($dir) {
    opacity: $to;
  }
}

// HINGE
@mixin hinge (
  $dir: in,
  $from: left,
  $axis: edge,
  $perspective: 2000px,
  $turn-origin: from-back,
  $fade: $motion-hinge-and-fade,
  $duration: $motion-duration-default,
  $timing: $motion-timing-default,
  $delay: $motion-delay-default
) {

  // Rotation directions when hinging from back vs. front
  $rotationAmount: 90deg;
  $rotationsBack: (
    top: rotateX($rotationAmount * -1),
    right: rotateY($rotationAmount * -1),
    bottom: rotateX($rotationAmount),
    left: rotateY($rotationAmount),
  );
  $rotationsFrom: (
    top: rotateX($rotationAmount),
    right: rotateY($rotationAmount),
    bottom: rotateX($rotationAmount * -1),
    left: rotateY($rotationAmount * -1),
  );

  // Rotation origin
  $rotation: '';
  @if $turn-origin == from-front {
    $rotation: map-get($rotationsFrom, $from);
  }
  @else if $turn-origin == from-back {
    $rotation: map-get($rotationsBack, $from);
  }
  @else {
    @warn "`$turn-origin` must be either `from-back` or `from-front`";
  }

  // Start and end state
  $start: '';
  $end: '';
  @if $dir == in {
    $start: perspective($perspective) $rotation;
    $end: rotate(0deg);
  }
  @else {
    $start: rotate(0deg);
    $end: perspective($perspective) $rotation;
  }

  // Turn axis
  $origin: '';
  @if $axis == edge {
    $origin: $from;
  }
  @else {
    $origin: center;
  }

  @include transition-start($dir) {
    @include transition-basics($duration, $timing, $delay);
    transition-property: transform, opacity;
    transform: $start;
    transform-origin: $origin;
    @if $fade { opacity: if($dir == in, 0, 1); }
  }
  @include transition-end($dir) {
    transform: $end;
    @if $fade { opacity: if($dir == in, 1, 0); }
  }
}

// SCALE
@mixin scale(
  $dir: in,
  $from: 1.5,
  $to: 1,
  $fade: $motion-scale-and-fade,
  $duration: $motion-duration-default,
  $timing: $motion-timing-default,
  $delay: $motion-delay-default
) {
  @include transition-start($dir) {
    @include transition-basics($duration, $timing, $delay);
    transition-property: transform, property;
    transform: scale($from);
    @if $fade { opacity: if($dir == in, 0, 1) }
  }
  @include transition-end($dir) {
    transform: scale($to);
    @if $fade { opacity: if($dir == in, 1, 0) }
  }
}

// SPIN
@mixin spin(
  $dir: in,
  $amount: 0.75turn,
  $ccw: false,
  $fade: $motion-spin-and-fade,
  $duration: $motion-duration-default,
  $timing: $motion-timing-default,
  $delay: $motion-delay-default
) {
  $amount: turn-to-deg($amount);
  $start: 0;
  $end: 0;

  @if $dir == in {
    $start: if($ccw, $amount, $amount * -1);
    $end: 0;
  }
  @else {
    $start: 0;
    $end: if($ccw, $amount * -1, $amount);
  }

  @include transition-start($dir) {
    transition-property: transform, opacity;
    transform: rotate($start);
    @if $fade { opacity: if($dir == in, 0, 1); }
  }
  @include transition-end($dir) {
    transform: rotate($end);
    @if $fade { opacity: if($dir == in, 1, 0); }
  }
}


// 2. Base Animations
// - - - - - - - - - - - - - - - - - - - - - - - - -

// SHAKE
@keyframes shake {
  0%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90% {
    transform: translateX(7%);
  }
  5%, 15%, 25%, 35%, 45%, 55%, 65%, 75%, 85%, 95% {
    transform: translateX(-7%);
  }
  100% { transform: translateX(0); }
}

// SPINNERS
@keyframes spin-cw {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes spin-ccw {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}

// WIGGLE
@keyframes wiggle {
  40%, 50%, 60% {
    transform: rotate(7deg);
  }
  35%, 45%, 55%, 65% {
    transform: rotate(-7deg);
  }
  0%, 30%, 70%, 100% { transform: rotate(0); }
}

@mixin animation(
  $animation,
  $duration: $motion-duration-default,
  $timing: $motion-timing-default,
  $delay: $motion-delay-default,
  $iterations: null
) {
  
  animation-name: $animation;
  animation-duration: $duration;
  animation-timing-function: $timing;

  backface-visibility: hidden;
  transform: translate3d(0,0,0);

  @if $delay != null {
    animation-delay: $delay;
  }
  @if $iterations != null {
    animation-iteration-count: $iterations;
  }

  @if $animation == null {
    @warn "Please include an animation name";
  }
}

// 3. HTML Exports
// - - - - - - - - - - - - - - - - - - - - - - - - -

@include exports(motion) {
  /*
    Transitions
  */

  // Slide
  .slideInDown    { @include slide($from: top); }
  .slideInLeft    { @include slide($from: right); }
  .slideInUp      { @include slide($from: bottom); }
  .slideInRight   { @include slide($from: left); }
  .slideOutBottom { @include slide($dir: out, $from: bottom); }
  .slideOutRight  { @include slide($dir: out, $from: right); }
  .slideOutUp     { @include slide($dir: out, $from: top); }
  .slideOutLeft   { @include slide($dir: out, $from: left); }

  // Fade
  .fadeIn  { @include fade(in, 0, 1); }
  .fadeOut { @include fade(out, 1, 0); }

  // Hinge
  .hingeInFromTop      { @include hinge($dir: in, $from: top); }
  .hingeInFromRight    { @include hinge($dir: in, $from: right); }
  .hingeInFromBottom   { @include hinge($dir: in, $from: bottom); }
  .hingeInFromLeft     { @include hinge($dir: in, $from: left); }
  .hingeInFromMiddleX  { @include hinge($dir: in, $from: top,   $axis: center); }
  .hingeInFromMiddleY  { @include hinge($dir: in, $from: right, $axis: center); }
  .hingeOutFromTop     { @include hinge($dir: out, $from: top); }
  .hingeOutFromRight   { @include hinge($dir: out, $from: right); }
  .hingeOutFromBottom  { @include hinge($dir: out, $from: bottom); }
  .hingeOutFromLeft    { @include hinge($dir: out, $from: left); }
  .hingeOutFromMiddleX { @include hinge($dir: out, $from: top,   $axis: center); }
  .hingeOutFromMiddleY { @include hinge($dir: out, $from: right, $axis: center); }

  // Scale
  .zoomIn  { @include scale(in,  1.5, 1); }
  .zoomOut { @include scale(out, 0.5, 1); }

  // Spin
  .spinIn     { @include spin(in, 0.75turn); }
  .spinOut    { @include spin(out, 0.75turn); }
  .spinInCCW  { @include spin(in, 0.75turn, true); }
  .spinOutCCW { @include spin(out, 0.75turn, true); }

  /*
    Transition modifiers
  */

  // Duration
  .slow { transition-duration: $motion-duration-slow !important; }
  .fast { transition-duration: $motion-duration-fast !important; }

  // Easing
  @each $easing in map-keys($motion-timings) {
    .#{$easing} {
      transition-timing-function: map-get($motion-timings, $easing) !important;
    }
  }

  // Delay
  .delay       { transition-delay: $motion-delay-short !important; }
  .long-delay  { transition-delay: $motion-delay-long !important; }

  /*
    Animations
  */

  .shake    { @include animation(shake); }
  .spin-cw  { @include animation(spin-cw); }
  .spin-ccw { @include animation(spin-ccw); }
  .wiggle   { @include animation(wiggle); }

  /*
    Animation modifiers
  */

  .shake,
  .spin-cw,
  .spin-ccw,
  .wiggle {
    // Repeat
    &.infinite { animation-iteration-count: infinite; }

    // Easing
    @each $timing in map-keys($motion-timings) {
      &.#{$timing} {
        animation-timing-function: map-get($motion-timings, $timing) !important;
      }
    }

    // Duration
    &.slow { animation-duration: $motion-duration-slow !important; }
    &.fast { animation-duration: $motion-duration-fast !important; }

    // Delay
    &.delay       { animation-delay: $motion-delay-short !important; }
    &.long-delay  { animation-delay: $motion-delay-long !important; }
  }
  .stagger { @include stagger($motion-stagger-duration-default); }
  .stort-stagger { @include stagger($motion-stagger-duration-default); }
  .long-stagger { @include stagger($motion-stagger-duration-default); }
}

// View animation classes
// - - - - - - - - - - - - - - - - - - - -

// Applied to the immediate parent of the animating views
.position-absolute {
  overflow: hidden;
  position: relative;
}

// Applied to the animating views
.ui-animation {
  &.ng-enter-active, &.ng-leave-active {
    position: absolute !important;
    backface-visibility: hidden;
    -webkit-transform-style: preserve-3d;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
}