UNPKG

1.76 kBJavaScriptView Raw
1/**
2 * Vue BarajaJS
3 * A plugin for spreading items in a card-like fashion.
4 *
5 * Copyright 2021-2023, Marc S. Brooks (https://mbrooks.info)
6 * Licensed under the MIT license:
7 * http://www.opensource.org/licenses/mit-license.php
8 */
9
10'use strict';
11
12import {ref} from 'vue';
13import Baraja from 'baraja-js';
14import 'baraja-js/dist/baraja.min.css';
15
16/**
17 * Provides Vue Component wrapper.
18 */
19export default {
20 setup() {
21 const elRef = ref(null);
22
23 return {elRef};
24 },
25
26 mounted() {
27 this.baraja = new Baraja(
28 this.$el,
29 this.options
30 );
31 },
32
33 data() {
34 return {
35 baraja: null
36 };
37 },
38
39 watch: {
40 fan(newVal, oldVal) {
41 if (!Object.is(newVal, oldVal)) {
42 this.baraja.fan(newVal);
43 }
44 },
45 add(newVal, oldVal) {
46 if (newVal !== oldVal) {
47 this.baraja.add(newVal);
48 }
49 },
50 close(newVal, oldVal) {
51 if (newVal !== oldVal) {
52 this.baraja.close();
53 }
54 },
55 last(newVal, oldVal) {
56 if (newVal !== oldVal) {
57 this.baraja.last();
58 }
59 },
60 next(newVal, oldVal) {
61 if (newVal !== oldVal) {
62 this.baraja.next();
63 }
64 }
65 },
66
67 props: {
68 id: {
69 default: 'baraja-js',
70 type: String
71 },
72 options: {
73 default: () => ({}),
74 type: Object
75 },
76 fan: {
77 default: () => ({}),
78 type: Object
79 },
80 add: {
81 default: '',
82 type: String
83 },
84 close: {
85 default: false,
86 type: Boolean
87 },
88 last: {
89 default: false,
90 type: Boolean
91 },
92 next: {
93 default: false,
94 type: Boolean
95 }
96 },
97
98 template: `
99 <ul v-bind:id="id" class="baraja-container" ref="wrapper">
100 <slot :child="this.$slots.default" />
101 </ul>
102 `
103};