@thinkpixellab-public/px-vue 3.0.70 → 3.0.72

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.
@@ -17,14 +17,14 @@ ar
17
17
  <template>
18
18
  <div :class="bem()">
19
19
  <button
20
- v-if="!disabled"
20
+ v-if="!disabled && !arrowsHidden"
21
21
  :class="[bem('button', { start: true, visible: arrowStartVisible }), buttonClass]"
22
22
  @click="scrollPages(-1)"
23
23
  aria-label="Scroll to previous"
24
24
  :disabled="!arrowStartVisible"
25
25
  >
26
26
  <slot name="button" :location="'start'">
27
- <span :class="bem('arrow-icon')">
27
+ <span :class="[bem('arrow-icon'), iconClass]">
28
28
  <px-icon :src="arrowStartSrc" size="0.8em" />
29
29
  </span>
30
30
  </slot>
@@ -35,14 +35,14 @@ ar
35
35
  </div>
36
36
 
37
37
  <button
38
- v-if="!disabled"
38
+ v-if="!disabled && !arrowsHidden"
39
39
  :class="[bem('button', { end: true, visible: arrowEndVisible }), buttonClass]"
40
40
  @click="scrollPages(1)"
41
41
  aria-label="Scroll to next"
42
42
  :disabled="!arrowEndVisible"
43
43
  >
44
44
  <slot name="button" :location="'end'">
45
- <span :class="bem('arrow-icon')">
45
+ <span :class="[bem('arrow-icon'), iconClass]">
46
46
  <px-icon :src="arrowEndSrc" size="0.8em" />
47
47
  </span>
48
48
  </slot>
@@ -65,7 +65,9 @@ export default {
65
65
  arrowStartSrc: { type: String, default: require('../assets/icons/nav-prev.svg') },
66
66
  arrowEndSrc: { type: String, default: require('../assets/icons/nav-next.svg') },
67
67
  buttonClass: { type: String, default: null },
68
+ iconClass: { type: String, default: null },
68
69
  disabled: { type: Boolean, default: false },
70
+ arrowsHidden: { type: Boolean, default: false },
69
71
  },
70
72
  data() {
71
73
  return {
@@ -112,6 +114,20 @@ export default {
112
114
  });
113
115
  }
114
116
  },
117
+
118
+ scrollToElement(el) {
119
+ if (this.$refs.scroller) {
120
+ console.log(`el.offsetLeft: ${el.offsetLeft}`);
121
+
122
+ //const left = el.offsetLeft - this.$refs.scroller.offsetWidth;
123
+ const left = el.offsetLeft - this.$refs.scroller.offsetWidth / 2;
124
+
125
+ this.$refs.scroller.scrollTo({
126
+ left: left,
127
+ behavior: 'smooth',
128
+ });
129
+ }
130
+ },
115
131
  },
116
132
  };
117
133
  </script>
@@ -122,10 +138,13 @@ export default {
122
138
  .px-arrow-scroller {
123
139
  // prettier-ignore
124
140
  @include grid-art((
125
- 'auto | 1fr | auto |',
141
+ 'auto | 1fr | auto |',
126
142
  'arrow-start | scroller | arrow-end | auto'
127
143
  ));
128
144
 
145
+ align-items: center;
146
+ align-content: center;
147
+
129
148
  &__button {
130
149
  position: relative;
131
150
  align-self: center;
@@ -150,13 +169,19 @@ export default {
150
169
  .px-arrow-scroller__arrow-icon {
151
170
  @include button-icon(
152
171
  (
153
- padding: 0.1em 1em 0.25em,
172
+ padding: 0.1em 1em,
154
173
  cursor: pointer,
155
- display: block,
156
- alignItems: center,
157
- min-height: null,
174
+ display: flex,
175
+ align-items: center,
176
+ justify-content: center,
158
177
  )
159
178
  );
179
+
180
+ @include media-until-mobile {
181
+ min-width: 1em;
182
+ padding-left: 0;
183
+ padding-right: 0;
184
+ }
160
185
  }
161
186
  }
162
187
 
@@ -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);
@@ -1,78 +1,20 @@
1
1
  <!--
2
- Use for global mobile awareness in javascript. This doesn't actually handle mobile detection
3
- but provides a consistent interface for communicating between a single component that does
4
- the detection and other components that subscribe to an eventbus and update a property called
5
- isMobile.
6
-
7
- Sample usage using a css variable for detecting mobile (this keeps css and js in sync):
8
-
9
- ### MyLayout.vue (or other global component)
10
-
11
- // add PxBaseMobileAware as a mixin
12
- import PxBaseMobileAware from '@thinkpixellab-public/px-vue/components/PxBaseMobileAware.vue';
13
- mixins: [PxBaseMobileAware],
14
-
15
- // add a resize handler and call setGlobalIsMobile
16
- resize() {
17
- if (this.$el) {
18
- const cssMobile = getComputedStyle(this.$el).getPropertyValue('--is-mobile');
19
- this.setGlobalIsMobile(cssMobile.toLowerCase().trim() == 'true');
20
- }
21
- },
22
-
23
- // add a css variable that changes with the viewport
24
-
25
- .my-layout {
26
- --is-mobile: false;
27
- @include media-until-mobile() {
28
- --is-mobile: true;
29
- }
30
- }
31
-
32
- ### MyComponent.vue
33
-
34
- // use PxBaseMobileAware as a mixin
35
- import PxBaseMobileAware from '@thinkpixellab-public/px-vue/components/PxBaseMobileAware.vue';
36
- mixins: [PxBaseMobileAware]
37
-
38
- // use the isMobile property as needed in a template
39
- <div> This is mobile: {{isMobile ? 'yup' : 'nope' }} </div>
40
-
41
- // or in code
42
- watch: {
43
- isMobile(nv) {
44
- // do something when isMobile changes
45
- }
46
- }
47
-
48
-
2
+ Must be used in conjuction with PxBaseMobileProvide. See notes in that file for details.
49
3
  -->
50
4
 
51
5
  <script>
52
- import utils from '../utils/utils.js';
53
-
54
6
  export default {
55
- data() {
56
- return { isMobile: null };
57
- },
58
- mounted() {
59
- if (utils.getQueryBool('alwaysMobile')) {
60
- this.isMobile = true;
61
- return;
62
- }
63
-
64
- if (this.$globalOn) {
65
- this.$globalOn('mobile-changed', isMobile => {
66
- this.isMobile = isMobile;
67
- });
68
- }
7
+ inject: {
8
+ mediaQuery: {
9
+ default: { isMobile: null, currentBreakpoint: null },
10
+ },
69
11
  },
70
- methods: {
71
- setGlobalIsMobile(isMobile) {
72
- if (this.$globalEmit) {
73
- this.$globalEmit('mobile-changed', isMobile);
74
- this.isMobile = isMobile;
75
- }
12
+ computed: {
13
+ isMobile() {
14
+ return this.mediaQuery.isMobile;
15
+ },
16
+ currentBreakpoint() {
17
+ return this.mediaQuery.currentBreakpoint;
76
18
  },
77
19
  },
78
20
  };
@@ -0,0 +1,50 @@
1
+ <!--
2
+
3
+ Use for global mobile / media query awareness in javascript. Provides values for isMobile and
4
+ currentBreakpoint that can be used in any component.
5
+
6
+ Use this in parent component or layout to provide the values to child components. Use
7
+ PxBaseMobileAware in child components to inject the values.
8
+
9
+ In many cases you can just add this as a mixin but if that component also has a resize method
10
+ then be sure to call this.updateMediaQuery() from the resize method.
11
+
12
+ -->
13
+
14
+ <script>
15
+ import PxBaseResize from './PxBaseResize.vue';
16
+ export default {
17
+ provide() {
18
+ return {
19
+ mediaQuery: this.mediaQuery,
20
+ };
21
+ },
22
+ mixins: [PxBaseResize],
23
+ data() {
24
+ return { mediaQuery: { isMobile: null, currentBreakpoint: null } };
25
+ },
26
+
27
+ methods: {
28
+ updateMediaQuery() {
29
+ this.mediaQuery.isMobile =
30
+ getComputedStyle(document.documentElement).getPropertyValue('--is-mobile').trim() ==
31
+ 'true';
32
+
33
+ this.mediaQuery.currentBreakpoint = getComputedStyle(document.documentElement)
34
+ .getPropertyValue('--breakpoint')
35
+ .trim();
36
+ },
37
+ resize() {
38
+ this.updateMediaQuery();
39
+ },
40
+ },
41
+ };
42
+ </script>
43
+
44
+ <style lang="scss">
45
+ @use '@/px-styles.config.scss' as *;
46
+ @use '@thinkpixellab/px-edge-shared/styles/px-styles-fluent.scss' as fluent;
47
+ @include fluent.fluent() {
48
+ @include media-breakpoint-vars;
49
+ }
50
+ </style>
@@ -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.72",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",