@farm-investimentos/front-mfe-components 11.1.0 → 11.2.0

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.
Files changed (48) hide show
  1. package/dist/front-mfe-components.common.js +790 -695
  2. package/dist/front-mfe-components.common.js.map +1 -1
  3. package/dist/front-mfe-components.css +2 -2
  4. package/dist/front-mfe-components.umd.js +790 -695
  5. package/dist/front-mfe-components.umd.js.map +1 -1
  6. package/dist/front-mfe-components.umd.min.js +1 -1
  7. package/dist/front-mfe-components.umd.min.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/components/Buttons/ExportButton/ExportButton.stories.js +11 -4
  10. package/src/components/Buttons/ExportButton/ExportButton.vue +29 -70
  11. package/src/components/Card/Card.scss +2 -2
  12. package/src/components/Card/Card.stories.js +0 -1
  13. package/src/components/Card/Card.vue +4 -1
  14. package/src/components/Card/CardComposition.stories.ts +1 -2
  15. package/src/components/Card/CardContent/CardContent.stories.js +13 -2
  16. package/src/components/Card/CardContent/CardContent.vue +6 -3
  17. package/src/components/Checkbox/Checkbox.scss +10 -0
  18. package/src/components/Checkbox/Checkbox.stories.js +15 -1
  19. package/src/components/Checkbox/Checkbox.vue +9 -1
  20. package/src/components/ContextMenu/ContextMenu.vue +18 -8
  21. package/src/components/DataTableHeader/DataTableHeader.scss +9 -1
  22. package/src/components/DataTableHeader/DataTableHeader.stories.js +48 -24
  23. package/src/components/DataTableHeader/DataTableHeader.vue +7 -11
  24. package/src/components/DataTablePaginator/DataTablePaginator.scss +24 -7
  25. package/src/components/DataTablePaginator/DataTablePaginator.vue +45 -11
  26. package/src/components/DatePicker/DatePicker.vue +6 -0
  27. package/src/components/DialogHeader/DialogHeader.stories.js +11 -0
  28. package/src/components/DialogHeader/DialogHeader.vue +8 -9
  29. package/src/components/Form/Form.stories.js +52 -0
  30. package/src/components/Form/Form.vue +2 -0
  31. package/src/components/IconBox/IconBox.scss +8 -0
  32. package/src/components/IconBox/IconBox.vue +1 -1
  33. package/src/components/IdCaption/IdCaption.stories.js +18 -0
  34. package/src/components/IdCaption/IdCaption.vue +21 -2
  35. package/src/components/Loader/Loader.stories.ts +1 -1
  36. package/src/components/Loader/Loader.vue +50 -58
  37. package/src/components/Modal/Modal.scss +0 -1
  38. package/src/components/Modal/Modal.vue +13 -4
  39. package/src/components/RangeDatePicker/RangeDatePicker.vue +6 -0
  40. package/src/components/Switcher/Switcher.scss +6 -0
  41. package/src/components/Switcher/Switcher.stories.js +28 -0
  42. package/src/components/Switcher/Switcher.vue +27 -2
  43. package/src/components/TableContextMenu/TableContextMenu.stories.js +15 -0
  44. package/src/components/Typography/Typography.scss +2 -1
  45. package/src/helpers/calculateMainZindex.js +10 -0
  46. package/src/helpers/date.js +3 -0
  47. package/src/helpers/index.js +1 -0
  48. package/src/components/Switcher/Switcher.api.stories.js +0 -20
@@ -16,10 +16,20 @@
16
16
  ></v-select>
17
17
  </div>
18
18
 
19
- <ul :class="{ 'farm-paginator': true, 'farm-paginator--disabled': disabled || totalPages == null }">
19
+ <ul
20
+ :class="{
21
+ 'farm-paginator': true,
22
+ 'farm-paginator--disabled': disabled || totalPages == null,
23
+ }"
24
+ >
20
25
  <li>
21
- <button :disabled="currentPage === 1 || disabled || totalPages == null" @click="previousPage">
22
- <farm-icon color="gray" size="sm">chevron-left</farm-icon>
26
+ <button :disabled="canGoBack" @click="firstPage">
27
+ <farm-icon size="sm">chevron-double-left</farm-icon>
28
+ </button>
29
+ </li>
30
+ <li>
31
+ <button :disabled="canGoBack" @click="previousPage">
32
+ <farm-icon size="sm">chevron-left</farm-icon>
23
33
  </button>
24
34
  </li>
25
35
 
@@ -32,13 +42,18 @@
32
42
  :disabled="currentPage === item || item === '...' || disabled"
33
43
  @click="currentPage = item"
34
44
  >
35
- {{ item }}
45
+ <farm-bodytext :type="2" variation="regular">{{ item }}</farm-bodytext>
36
46
  </button>
37
47
  </li>
38
48
 
39
49
  <li>
40
- <button :disabled="currentPage === totalPages || disabled || totalPages == null || totalPages === 0" @click="nextPage">
41
- <farm-icon color="gray" size="sm">chevron-right</farm-icon>
50
+ <button :disabled="canGoForward" @click="nextPage">
51
+ <farm-icon size="sm">chevron-right</farm-icon>
52
+ </button>
53
+ </li>
54
+ <li>
55
+ <button :disabled="canGoForward" @click="lastPage">
56
+ <farm-icon size="sm">chevron-double-right</farm-icon>
42
57
  </button>
43
58
  </li>
44
59
  </ul>
@@ -47,7 +62,6 @@
47
62
  <script lang="ts">
48
63
  import Vue from 'vue';
49
64
  import { VSelect } from 'vuetify/lib/components/VSelect';
50
- import Icon from '../Icon';
51
65
 
52
66
  /**
53
67
  * Componente de paginação usado em tabelas e listas
@@ -55,6 +69,9 @@ import Icon from '../Icon';
55
69
  */
56
70
  export default Vue.extend({
57
71
  name: 'farm-datatable-paginator',
72
+ components: {
73
+ VSelect,
74
+ },
58
75
  props: {
59
76
  /**
60
77
  * Lista de opções para o controle de registros por página
@@ -118,6 +135,12 @@ export default Vue.extend({
118
135
  nextPage() {
119
136
  this.currentPage++;
120
137
  },
138
+ firstPage() {
139
+ this.currentPage = 1;
140
+ },
141
+ lastPage() {
142
+ this.currentPage = this.totalPages;
143
+ },
121
144
  },
122
145
  data() {
123
146
  return {
@@ -161,6 +184,20 @@ export default Vue.extend({
161
184
  return [...this.range(1, left), '...', ...this.range(right, this.totalPages)];
162
185
  }
163
186
  },
187
+ canGoBack: function () {
188
+ const goBack = this.currentPage === 1 || this.disabled || this.totalPages == null;
189
+
190
+ return goBack;
191
+ },
192
+ canGoForward: function () {
193
+ const goNext =
194
+ this.currentPage === this.totalPages ||
195
+ this.disabled ||
196
+ this.totalPages == null ||
197
+ this.totalPages === 0;
198
+
199
+ return goNext;
200
+ },
164
201
  },
165
202
  watch: {
166
203
  selectedLimit(newValue) {
@@ -176,10 +213,7 @@ export default Vue.extend({
176
213
  this.selectedLimit = newValue;
177
214
  },
178
215
  },
179
- components: {
180
- VSelect,
181
- 'farm-icon': Icon,
182
- },
216
+
183
217
  });
184
218
  </script>
185
219
 
@@ -143,6 +143,12 @@ export default Vue.extend({
143
143
  this.dateField = newValue;
144
144
  this.fieldRange = this.formatDateRange(newValue);
145
145
  },
146
+ fieldRange(newValue) {
147
+ if (!newValue) {
148
+ this.dateField = '';
149
+ this.save();
150
+ }
151
+ },
146
152
  },
147
153
  methods: {
148
154
  formatDateRange(date) {
@@ -3,6 +3,17 @@ import DialogHeader from './DialogHeader.vue';
3
3
  export default {
4
4
  title: 'Display/Dialog/DialogHeader',
5
5
  component: DialogHeader,
6
+ parameters: {
7
+ docs: {
8
+ description: {
9
+ component: `Dialog Header<br />
10
+ selector: <em>farm-dialog-header</em><br />
11
+ <span style="color: var(--farm-primary-base);">ready for use</span>
12
+ `,
13
+ },
14
+ },
15
+ viewMode: 'docs',
16
+ },
6
17
  };
7
18
 
8
19
  export const Primary = () => ({
@@ -7,16 +7,15 @@
7
7
 
8
8
  <slot></slot>
9
9
 
10
- <farm-icon
10
+ <farm-btn
11
11
  v-if="hasCloseIcon"
12
- role="button"
13
- title="Fechar"
12
+ icon
14
13
  class="farm-dialog-header__close"
15
- color="secondary"
14
+ title="Fechar"
16
15
  @click="onClose"
17
16
  >
18
- close-thick
19
- </farm-icon>
17
+ <farm-icon role="button"> close-thick </farm-icon>
18
+ </farm-btn>
20
19
  </header>
21
20
  </template>
22
21
  <script lang="ts">
@@ -28,21 +27,21 @@ export default Vue.extend({
28
27
  name: 'farm-dialog-header',
29
28
  props: {
30
29
  /**
31
- * Título
30
+ * Title
32
31
  */
33
32
  title: {
34
33
  type: String,
35
34
  default: '',
36
35
  },
37
36
  /**
38
- * Ícone - usa os do material icons
37
+ * Icon
39
38
  */
40
39
  iconTitle: {
41
40
  type: String,
42
41
  default: null,
43
42
  },
44
43
  /**
45
- * Ícone - se possui o ícone de fechar
44
+ * Has close icon?
46
45
  */
47
46
  hasCloseIcon: {
48
47
  type: Boolean,
@@ -33,6 +33,7 @@ export const Primary = () => ({
33
33
  document: 'Document',
34
34
  name: 'Name',
35
35
  checkbox: true,
36
+ birthDate: new Date('1980/09/20').toISOString()
36
37
  },
37
38
  validForm: false,
38
39
  rules: {
@@ -53,6 +54,17 @@ export const Primary = () => ({
53
54
 
54
55
  <farm-label :required="true">True/false</farm-label>
55
56
  <farm-checkbox v-model="form.checkbox" :rules="[rules.checked]" />
57
+
58
+ <farm-label :required="true">Birthdate:</farm-label>
59
+ <DatePicker
60
+ ref="birthDate"
61
+ inputId="form-pf-birthDate"
62
+ class="mt-4"
63
+ v-model="form.birthDate"
64
+ :readonly="true"
65
+ :required="true"
66
+ />
67
+
56
68
 
57
69
  <div class="footer" :style="[styles.footer]">
58
70
  <farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
@@ -169,3 +181,43 @@ export const RadioGroupReset = () => ({
169
181
  </farm-form>
170
182
  `,
171
183
  });
184
+
185
+ export const DatePickers = () => ({
186
+ data() {
187
+ return {
188
+ birthDate: '',
189
+ rangeDate: [],
190
+ validForm: false,
191
+ styles,
192
+ };
193
+ },
194
+ template: `
195
+ <farm-form v-model="validForm" :style="[styles.vForm]" ref="form">
196
+
197
+ <farm-label :required="true">Birthdate: {{ birthDate }}</farm-label>
198
+ <DatePicker
199
+ ref="birthDate"
200
+ inputId="form-pf-birthDate"
201
+ class="mt-4"
202
+ v-model="birthDate"
203
+ :readonly="true"
204
+ :required="true"
205
+ />
206
+
207
+ <farm-label :required="true">Range: {{ rangeDate }}</farm-label>
208
+ <RangeDatePicker
209
+ ref="rangeDate"
210
+ inputId="form-pf-rangeDate"
211
+ class="mt-4"
212
+ v-model="rangeDate"
213
+ :readonly="true"
214
+ :required="true"
215
+ />
216
+
217
+ <div class="footer" :style="[styles.footer]">
218
+ <farm-btn color="secondary" outlined @click="$refs.form.reset()" class="mr-3">Reset</farm-btn>
219
+ <farm-btn color="secondary" :disabled="!validForm">Salvar</farm-btn>
220
+ </div>
221
+ </farm-form>
222
+ `,
223
+ });
@@ -48,6 +48,8 @@ export default Vue.extend({
48
48
  validationFields.push($leaf.$children[0]);
49
49
  } else if ($leaf.validatable) {
50
50
  validationFields.push($leaf);
51
+ } else {
52
+ recursiveFormField($leaf);
51
53
  }
52
54
  });
53
55
  };
@@ -14,6 +14,10 @@
14
14
  background: var(--farm-#{$color}-lighten);
15
15
  }
16
16
  }
17
+
18
+ &--neutral .farm-icon.farm-icon {
19
+ color: var(--farm-neutral-darken);
20
+ }
17
21
  }
18
22
 
19
23
  .farm-icon-box--inverted.farm-icon-box {
@@ -27,4 +31,8 @@
27
31
  color: white;
28
32
  }
29
33
 
34
+ &--neutral .farm-icon.farm-icon--white {
35
+ color: var(--farm-neutral-darken);
36
+ }
37
+
30
38
  }
@@ -48,7 +48,7 @@ export default Vue.extend({
48
48
  default: 'md',
49
49
  },
50
50
  /**
51
- * INverted
51
+ * Inverted
52
52
  */
53
53
  inverted: {
54
54
  type: Boolean,
@@ -114,3 +114,21 @@ export const NoTextToClip = () => ({
114
114
  </farm-idcaption>
115
115
  `,
116
116
  });
117
+
118
+ export const IconBoxCustomColor = () => ({
119
+ template: `
120
+ <farm-idcaption
121
+ icon="account-box-outline"
122
+ copyText="texto a copiar"
123
+ iconBoxColor="error"
124
+ :link="true"
125
+ >
126
+ <template v-slot:title>
127
+ Upper Line Text
128
+ </template>
129
+ <template v-slot:subtitle>
130
+ Lower: Line Text Line Text Line Text
131
+ </template>
132
+ </farm-idcaption>
133
+ `,
134
+ });
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="idcaption">
3
- <farm-icon-box v-if="icon" :icon="icon" size="md" />
3
+ <farm-icon-box v-if="icon" :icon="icon" :color="iconBoxColor" size="md" />
4
4
  <div
5
5
  :class="{ idcaption__body: true, 'idcaption__body--single': !hasTitle || !hasSubtitle }"
6
6
  >
@@ -24,7 +24,7 @@
24
24
  </template>
25
25
 
26
26
  <script lang="ts">
27
- import Vue, { computed } from 'vue';
27
+ import Vue, { computed, PropType } from 'vue';
28
28
  export default Vue.extend({
29
29
  name: 'farm-idcaption',
30
30
  props: {
@@ -34,6 +34,25 @@ export default Vue.extend({
34
34
  icon: {
35
35
  type: String,
36
36
  },
37
+ /**
38
+ * IconBox Color
39
+ */
40
+ iconBoxColor: {
41
+ type: String as PropType<
42
+ | 'primary'
43
+ | 'secondary'
44
+ | 'neutral'
45
+ | 'info'
46
+ | 'success'
47
+ | 'error'
48
+ | 'warning'
49
+ | 'success'
50
+ | 'extra-1'
51
+ | 'extra-2'
52
+ | 'gray'
53
+ >,
54
+ default: 'primary',
55
+ },
37
56
  /**
38
57
  * copy to clipboard
39
58
  */
@@ -43,7 +43,7 @@ export const Overlay = () => ({
43
43
  this.show = true;
44
44
  setTimeout(() => {
45
45
  this.show = false;
46
- }, 2000);
46
+ }, 5000);
47
47
  },
48
48
  },
49
49
  });
@@ -1,60 +1,58 @@
1
1
  <template>
2
- <div>
3
- <div class="farm-loader__overlay" v-if="mode === 'overlay'" :style="styleObject">
4
- <div
5
- role="progressbar"
6
- aria-valuemin="0"
7
- aria-valuemax="100"
8
- class="farm-loader farm-loader--big farm-loader--visible farm-loader--indeterminate"
2
+ <div class="farm-loader__overlay" v-if="mode === 'overlay'" :style="styleObject">
3
+ <div
4
+ role="progressbar"
5
+ aria-valuemin="0"
6
+ aria-valuemax="100"
7
+ class="farm-loader farm-loader--big farm-loader--visible farm-loader--indeterminate"
8
+ >
9
+ <svg
10
+ xmlns="http://www.w3.org/2000/svg"
11
+ viewBox="22.857142857142858 22.857142857142858 45.714285714285715 45.714285714285715"
12
+ style="transform: rotate(0deg)"
9
13
  >
10
- <svg
11
- xmlns="http://www.w3.org/2000/svg"
12
- viewBox="22.857142857142858 22.857142857142858 45.714285714285715 45.714285714285715"
13
- style="transform: rotate(0deg)"
14
- >
15
- <circle
16
- fill="transparent"
17
- cx="45.714285714285715"
18
- cy="45.714285714285715"
19
- r="20"
20
- stroke-dasharray="125.664"
21
- stroke-dashoffset="125.66370614359172px"
22
- class="farm-loader__overlay"
23
- ></circle>
24
- </svg>
25
- <div class="farm-loader__info"></div>
26
- </div>
27
- </div>
28
- <div v-else>
29
- <div
30
- role="progressbar"
31
- aria-valuemin="0"
32
- aria-valuemax="100"
33
- class="farm-loader farm-loader--visible farm-loader--indeterminate"
34
- :class="calculateSize"
35
- >
36
- <svg
37
- xmlns="http://www.w3.org/2000/svg"
38
- viewBox="22.857142857142858 22.857142857142858 45.714285714285715 45.714285714285715"
39
- style="transform: rotate(0deg)"
40
- >
41
- <circle
42
- fill="transparent"
43
- cx="45.714285714285715"
44
- cy="45.714285714285715"
45
- r="20"
46
- stroke-dasharray="125.664"
47
- stroke-dashoffset="125.66370614359172px"
48
- class="farm-loader__overlay"
49
- ></circle>
50
- </svg>
51
- <div class="farm-loader__info"></div>
52
- </div>
14
+ <circle
15
+ fill="transparent"
16
+ cx="45.714285714285715"
17
+ cy="45.714285714285715"
18
+ r="20"
19
+ stroke-dasharray="125.664"
20
+ stroke-dashoffset="125.66370614359172px"
21
+ class="farm-loader__overlay"
22
+ ></circle>
23
+ </svg>
24
+ <div class="farm-loader__info"></div>
53
25
  </div>
54
26
  </div>
27
+ <div
28
+ v-else
29
+ role="progressbar"
30
+ aria-valuemin="0"
31
+ aria-valuemax="100"
32
+ class="farm-loader farm-loader--visible farm-loader--indeterminate"
33
+ :class="calculateSize"
34
+ >
35
+ <svg
36
+ xmlns="http://www.w3.org/2000/svg"
37
+ viewBox="22.857142857142858 22.857142857142858 45.714285714285715 45.714285714285715"
38
+ style="transform: rotate(0deg)"
39
+ >
40
+ <circle
41
+ fill="transparent"
42
+ cx="45.714285714285715"
43
+ cy="45.714285714285715"
44
+ r="20"
45
+ stroke-dasharray="125.664"
46
+ stroke-dashoffset="125.66370614359172px"
47
+ class="farm-loader__overlay"
48
+ ></circle>
49
+ </svg>
50
+ <div class="farm-loader__info"></div>
51
+ </div>
55
52
  </template>
56
53
  <script lang="ts">
57
54
  import Vue from 'vue';
55
+ import { calculateMainZindex } from '../../helpers';
58
56
 
59
57
  export default Vue.extend({
60
58
  name: 'farm-loader',
@@ -69,15 +67,9 @@ export default Vue.extend({
69
67
  },
70
68
  },
71
69
  data() {
72
- const zIndex = Math.max(
73
- ...Array.from(document.querySelectorAll('body *'), el =>
74
- parseFloat(window.getComputedStyle(el).zIndex)
75
- ).filter(zIndex => !Number.isNaN(zIndex)),
76
- 0
77
- );
78
70
  return {
79
71
  styleObject: {
80
- zIndex,
72
+ zIndex: calculateMainZindex(),
81
73
  },
82
74
  };
83
75
  },
@@ -90,5 +82,5 @@ export default Vue.extend({
90
82
  });
91
83
  </script>
92
84
  <style lang="scss" scoped>
93
- @import 'Loader.scss';
85
+ @import 'Loader';
94
86
  </style>
@@ -6,7 +6,6 @@
6
6
  left: 0;
7
7
  width: 100vw;
8
8
  height: 100vh;
9
- z-index: 100;
10
9
  align-items: center;
11
10
  display: flex;
12
11
  justify-content: center;
@@ -1,7 +1,11 @@
1
1
  <template>
2
2
  <transition name="fade">
3
- <div :class="{ 'farm-modal': true, ['farm-modal--size-' + size]: true }" v-if="inputValue">
4
- <div class="farm-modal--container">
3
+ <div
4
+ v-if="inputValue"
5
+ :class="{ 'farm-modal': true, ['farm-modal--size-' + size]: true }"
6
+ :style="styleObject"
7
+ >
8
+ <div class="farm-modal--container teste">
5
9
  <div class="farm-modal--header">
6
10
  <!-- @slot header -->
7
11
  <slot name="header"></slot>
@@ -21,8 +25,10 @@
21
25
  </div>
22
26
  </transition>
23
27
  </template>
28
+
24
29
  <script lang="ts">
25
- import Vue, { PropType, ref, toRefs, watch } from 'vue';
30
+ import Vue, { PropType, reactive, ref, toRefs, watch } from 'vue';
31
+ import { calculateMainZindex } from '../../helpers';
26
32
 
27
33
  export default Vue.extend({
28
34
  name: 'farm-modal',
@@ -57,6 +63,7 @@ export default Vue.extend({
57
63
  setup(props, { emit }) {
58
64
  const { offsetTop, offsetBottom, persistent, size } = toRefs(props);
59
65
  const inputValue = ref(props.value);
66
+ const styleObject = reactive({ zIndex: 1 });
60
67
  const styles = {
61
68
  marginTop: offsetTop.value + 'px',
62
69
  marginBottom: offsetBottom.value + 'px',
@@ -77,7 +84,8 @@ export default Vue.extend({
77
84
  newValue => {
78
85
  inputValue.value = newValue;
79
86
  if (newValue) {
80
- window.addEventListener('keyup', escHandler);
87
+ (styleObject.zIndex = calculateMainZindex()),
88
+ window.addEventListener('keyup', escHandler);
81
89
  }
82
90
  }
83
91
  );
@@ -91,6 +99,7 @@ export default Vue.extend({
91
99
  return {
92
100
  inputValue,
93
101
  styles,
102
+ styleObject,
94
103
  size,
95
104
  close,
96
105
  };
@@ -116,6 +116,12 @@ export default Vue.extend({
116
116
  this.dateField = newValue;
117
117
  this.fieldRange = this.formatDateRange(newValue);
118
118
  },
119
+ fieldRange(newValue) {
120
+ if (!newValue) {
121
+ this.dateField = [];
122
+ this.save();
123
+ }
124
+ },
119
125
  },
120
126
  methods: {
121
127
  formatDateRange(date) {
@@ -17,9 +17,15 @@
17
17
  &:focus {
18
18
  outline: 0;
19
19
  }
20
+
20
21
  &[block] {
21
22
  display: block;
22
23
  }
24
+
25
+ &--disabled {
26
+ opacity: 0.6;
27
+ cursor: default;
28
+ }
23
29
  }
24
30
 
25
31
  .farm-switch__background {
@@ -0,0 +1,28 @@
1
+ import Switch from './Switcher';
2
+
3
+ export default {
4
+ title: 'Form/Switcher',
5
+ component: Switch,
6
+ };
7
+
8
+ export const Primary = () => ({
9
+ data() {
10
+ return {
11
+ selectedValue: false,
12
+ };
13
+ },
14
+ template: `<div>
15
+ <farm-switcher v-model="selectedValue" block />
16
+ </div>`,
17
+ });
18
+
19
+ export const Disabled = () => ({
20
+ data() {
21
+ return {
22
+ selectedValue: false,
23
+ };
24
+ },
25
+ template: `<div>
26
+ <farm-switcher v-model="selectedValue" block :disabled="true" />
27
+ </div>`,
28
+ });
@@ -1,5 +1,10 @@
1
1
  <template>
2
- <div class="farm-switch" role="checkbox" @click="toggle" @keydown.space.prevent="toggle">
2
+ <div
3
+ :class="{ 'farm-switch': true, 'farm-switch--disabled': isDisabled }"
4
+ role="checkbox"
5
+ @click="toggle"
6
+ @keydown.space.prevent="toggle"
7
+ >
3
8
  <span class="farm-switch__background" :class="backgroundStyles" />
4
9
  <span class="farm-switch__indicator" :style="indicatorStyles" />
5
10
  </div>
@@ -10,10 +15,22 @@ import Vue from 'vue';
10
15
  export default Vue.extend({
11
16
  name: 'farm-switcher',
12
17
  props: {
18
+ /**
19
+ * v-model binding
20
+ */
13
21
  value: {
14
22
  type: Boolean,
15
23
  required: true,
16
24
  },
25
+ /**
26
+ * Is disabled?
27
+ */
28
+ disabled: { type: Boolean, default: false },
29
+ },
30
+ data() {
31
+ return {
32
+ isDisabled: this.disabled,
33
+ };
17
34
  },
18
35
  computed: {
19
36
  backgroundStyles() {
@@ -26,13 +43,21 @@ export default Vue.extend({
26
43
  return { transform: this.value ? 'translateX(16px)' : 'translateX(0)' };
27
44
  },
28
45
  },
46
+ watch: {
47
+ disabled(newValue: boolean) {
48
+ this.isDisabled = newValue;
49
+ },
50
+ },
29
51
  methods: {
30
52
  toggle() {
53
+ if (this.isDisabled) {
54
+ return false;
55
+ }
31
56
  this.$emit('input', !this.value);
32
57
  },
33
58
  },
34
59
  });
35
60
  </script>
36
61
  <style lang="scss" scoped>
37
- @import 'Switcher.scss';
62
+ @import 'Switcher';
38
63
  </style>