@thinkpixellab-public/px-vue 3.0.70 → 3.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -111,10 +111,16 @@ export default {
111
111
  this.resize();
112
112
  });
113
113
  },
114
+ html() {
115
+ this.balance();
116
+ },
114
117
  },
115
118
 
116
119
  methods: {
117
120
  resize() {
121
+ this.balance();
122
+ },
123
+ balance() {
118
124
  if (isServer()) {
119
125
  return;
120
126
  }
@@ -126,11 +132,13 @@ export default {
126
132
 
127
133
  if (this.enabled) {
128
134
  try {
135
+ this.$emit('start');
129
136
  this.balanceFailed = false;
130
137
  if (this.$refs.text && this.$refs.text.offsetWidth > 0) {
131
138
  balanceText(this.$refs.text);
132
139
  }
133
140
  this.balanced = true;
141
+ this.$emit('complete');
134
142
  } catch (error) {
135
143
  console.error('balanceText failed');
136
144
  console.error(error);
@@ -14,60 +14,77 @@
14
14
  <template>
15
15
  <div :class="bem()">
16
16
  <!-- in the component -->
17
- <slot name="default" :state="currentStateValue">
17
+ <slot name="default" :state="currentValue">
18
18
  <!-- fallback -->
19
19
  </slot>
20
20
  </div>
21
21
  </template>
22
22
 
23
23
  <script>
24
- // import { mapState } from 'vuex';
25
- // import Component from '~/components/Component.vue';
26
24
  import { gsap } from 'gsap';
27
25
  import { Flip } from 'gsap/Flip';
28
26
 
29
27
  export default {
30
28
  name: 'px-flip',
31
- // components: { Component },
32
- // mixins: [ Mixin ],
33
29
  props: {
34
30
  states: { type: Array, default: null },
35
31
  current: { type: String, default: null },
32
+ autoSelectFirstState: { type: Boolean, default: true },
36
33
  otherProps: { type: String, default: 'opacity,color,backgroundColor' },
37
34
  selector: { type: String, default: '[data-flip]' },
38
35
  targets: { default: null },
36
+ duration: { type: Number, default: 0.5 },
37
+ ease: { type: String, default: 'circ.out' },
38
+ absolute: { type: Boolean, default: false },
39
39
  },
40
40
  data() {
41
- return { currentStateValue: this.current };
41
+ return { currentValue: this.current };
42
42
  },
43
- // computed: {},
44
43
  watch: {
44
+ currentValue(nv) {
45
+ this.$emit('update:current', nv);
46
+ },
47
+
45
48
  async current(nv) {
46
49
  const targetElements = this.targets || this.$el.querySelectorAll(this.selector);
47
50
 
48
- console.log(targetElements);
49
-
50
51
  // save initial state
51
52
  const state = Flip.getState(targetElements, { props: this.otherProps, absolute: true });
52
53
 
53
54
  // make state changes
54
- this.currentStateValue = nv;
55
+ this.currentValue = nv;
55
56
 
56
57
  await this.$nextTick();
57
58
  // animate from the old state to the new one
58
59
  // animate from the previous state to the current one:
59
60
 
60
61
  Flip.from(state, {
61
- duration: 1,
62
- ease: 'power1.inOut',
63
- absolute: true,
62
+ duration: this.duration,
63
+ ease: this.ease,
64
+ absolute: this.absolute,
64
65
  });
65
66
  },
66
67
  },
67
68
  mounted() {
68
69
  gsap.registerPlugin(Flip);
70
+
71
+ if (!this.currentValue && this.autoSelectFirstState && this.states.length) {
72
+ this.currentValue = this.states[0];
73
+ }
74
+ },
75
+ methods: {
76
+ nextState() {
77
+ if (this.states) {
78
+ const index = this.states.indexOf(this.currentValue);
79
+ if (index >= 0) {
80
+ this.currentValue = this.states[(index + 1) % this.states.length];
81
+ }
82
+ }
83
+ },
84
+ toggle() {
85
+ this.nextState();
86
+ },
69
87
  },
70
- // methods: {},
71
88
  };
72
89
  </script>
73
90
 
@@ -1,18 +1,19 @@
1
+ 'one | two | 50%'
1
2
  <!--
2
3
  Describe this component...
3
4
  -->
4
5
  <template>
5
6
  <div :class="bem()">
6
- <PxFlip :states="['open', 'close']" :current="currentState">
7
+ <PxFlip ref="flip" :states="['one', 'two']" :current="currentState">
7
8
  <template #default="{ state }">
8
9
  {{ state }}
9
10
  <br />
10
11
  <br />
11
- <span :class="bem('container', { state })">
12
- <span data-flip />
13
- <span data-flip />
14
- <span data-flip />
15
- </span>
12
+ <div :class="bem('container', { state })">
13
+ <div :class="bem('red')" data-flip />
14
+ <div :class="bem('gold')" data-flip />
15
+ <div :class="bem('blue')" data-flip />
16
+ </div>
16
17
  </template>
17
18
  </PxFlip>
18
19
  <button @click="toggleState">Toggle</button>
@@ -34,7 +35,7 @@ export default {
34
35
  // props: { a: { type: Boolean, default: false } },
35
36
  data() {
36
37
  return {
37
- currentState: 'open',
38
+ currentState: 'one',
38
39
  };
39
40
  },
40
41
  // computed: {},
@@ -42,10 +43,10 @@ export default {
42
43
  // mounted() {},
43
44
  methods: {
44
45
  toggleState() {
45
- if (this.currentState == 'open') {
46
- this.currentState = 'close';
46
+ if (this.currentState == 'one') {
47
+ this.currentState = 'two';
47
48
  } else {
48
- this.currentState = 'open';
49
+ this.currentState = 'one';
49
50
  }
50
51
  },
51
52
  },
@@ -57,12 +58,18 @@ export default {
57
58
  .demo-px-flip {
58
59
  padding: 5em;
59
60
  &__container {
60
- width: 4em;
61
- height: 4em;
62
- display: flex;
63
- flex-direction: column;
64
- justify-content: space-between;
65
- position: relative;
61
+ width: 200px;
62
+ height: 200px;
63
+ border: 1px solid black;
64
+
65
+ // prettier-ignore
66
+ @include grid-art(
67
+ (
68
+ '50% | 50% | ',
69
+ 'red | gold | 50%',
70
+ 'blue | blue | 50%'
71
+ )
72
+ );
66
73
 
67
74
  span {
68
75
  width: 100%;
@@ -70,18 +77,32 @@ export default {
70
77
  background-color: currentColor;
71
78
  }
72
79
 
73
- &--state-open {
74
- span {
75
- transform: rotate(0deg) scale(1);
76
- }
80
+ &--state-one {
77
81
  }
78
82
 
79
- &--state-close {
80
- span {
81
- transform: scale(0.5);
82
- opacity: 0.5;
83
- }
83
+ &--state-two {
84
+ // prettier-ignore
85
+ @include grid-art(
86
+ (
87
+ '33% | 67% | ',
88
+ 'blue | red | 50%',
89
+ 'gold | gold | 50%'
90
+ )
91
+ );
84
92
  }
85
93
  }
94
+
95
+ &__red {
96
+ background-color: tomato;
97
+ grid-area: red;
98
+ }
99
+ &__gold {
100
+ background-color: gold;
101
+ grid-area: gold;
102
+ }
103
+ &__blue {
104
+ background-color: lightblue;
105
+ grid-area: blue;
106
+ }
86
107
  }
87
108
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.70",
3
+ "version": "3.0.71",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",