@carbon/vue 1.0.0 → 1.1.1

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 (59) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/README.md +9 -156
  3. package/dist/carbon-data-viz-vue.common.js +6 -6
  4. package/dist/carbon-data-viz-vue.common.js.map +1 -1
  5. package/dist/carbon-data-viz-vue.css +1 -1
  6. package/dist/carbon-data-viz-vue.umd.js +6 -6
  7. package/dist/carbon-data-viz-vue.umd.js.map +1 -1
  8. package/dist/carbon-data-viz-vue.umd.min.js.map +1 -1
  9. package/dist/carbon-vue.common.js +8807 -4866
  10. package/dist/carbon-vue.common.js.map +1 -1
  11. package/dist/carbon-vue.umd.js +8807 -4866
  12. package/dist/carbon-vue.umd.js.map +1 -1
  13. package/dist/carbon-vue.umd.min.js +4 -4
  14. package/dist/carbon-vue.umd.min.js.map +1 -1
  15. package/dist/demo.html +2 -2
  16. package/package.json +21 -8
  17. package/src/_internal/_feature-flags.js +42 -0
  18. package/src/components/cv-accordion/_cv-accordion-item-skeleton.vue +10 -0
  19. package/src/components/cv-accordion/cv-accordion-item.vue +6 -0
  20. package/src/components/cv-button/cv-button.vue +32 -3
  21. package/src/components/cv-checkbox/_cv-checkbox-inner-form-item.vue +1 -1
  22. package/src/components/cv-checkbox/_cv-checkbox-inner.vue +1 -0
  23. package/src/components/cv-checkbox/cv-checkbox-skeleton.vue +13 -0
  24. package/src/components/cv-code-snippet/_cv-code-snippet-multiline.vue +10 -0
  25. package/src/components/cv-code-snippet/_cv-code-snippet-oneline.vue +10 -0
  26. package/src/components/cv-code-snippet/cv-code-snippet-skeleton.vue +29 -0
  27. package/src/components/cv-code-snippet/cv-code-snippet.vue +1 -1
  28. package/src/components/cv-content-switcher/cv-content-switcher-button.vue +28 -1
  29. package/src/components/cv-content-switcher/cv-content-switcher.vue +1 -1
  30. package/src/components/cv-data-table/cv-data-table.vue +54 -18
  31. package/src/components/cv-date-picker/_cv-date-picker-inner-c10.vue +220 -0
  32. package/src/components/cv-date-picker/_cv-date-picker-inner.vue +231 -0
  33. package/src/components/cv-date-picker/cv-date-picker.vue +17 -216
  34. package/src/components/cv-dropdown/_cv-dropdown-inner-c10.vue +201 -0
  35. package/src/components/cv-dropdown/_cv-dropdown-inner-form-item.vue +22 -0
  36. package/src/components/cv-dropdown/_cv-dropdown-inner.vue +213 -0
  37. package/src/components/cv-dropdown/cv-dropdown-item.vue +4 -0
  38. package/src/components/cv-dropdown/cv-dropdown-skeleton.vue +18 -0
  39. package/src/components/cv-dropdown/cv-dropdown.vue +20 -167
  40. package/src/components/cv-file-uploader/cv-file-uploader-skeleton.vue +22 -0
  41. package/src/components/cv-file-uploader/cv-file-uploader.vue +48 -8
  42. package/src/components/cv-inline-loader/cv-inline-loader.vue +42 -0
  43. package/src/components/cv-inline-notification/cv-inline-notification.vue +25 -7
  44. package/src/components/cv-loading/cv-loading.vue +18 -1
  45. package/src/components/cv-modal/cv-modal.vue +17 -6
  46. package/src/components/cv-number-input/cv-number-input.vue +9 -2
  47. package/src/components/cv-overflow-menu/cv-overflow-menu.vue +17 -15
  48. package/src/components/cv-pagination/cv-pagination.vue +2 -2
  49. package/src/components/cv-radio-button/cv-radio-button.vue +1 -0
  50. package/src/components/cv-slider/cv-slider.vue +6 -6
  51. package/src/components/cv-structured-list/_cv-structured-list-item-selectable.vue +1 -0
  52. package/src/components/cv-tabs/cv-tabs.vue +22 -11
  53. package/src/components/cv-text-input/cv-text-input.vue +70 -0
  54. package/src/components/cv-toast-notification/cv-toast-notification.vue +35 -0
  55. package/src/components/cv-tooltip/cv-interactive-tooltip.vue +4 -4
  56. package/src/data-viz/cv-bar-graph/cv-bar-graph.vue +7 -4
  57. package/src/data-viz/cv-gauge/cv-gauge.vue +1 -1
  58. package/src/data-viz/cv-pie-chart/cv-pie-chart.vue +8 -7
  59. package/src/components/cv-data-table/_cv-data-table-temp.vue +0 -669
@@ -0,0 +1,220 @@
1
+ <template>
2
+ <div class="cv-date-picker bx--form-item">
3
+ <div
4
+ :data-date-picker="['single', 'range'].includes(kind)"
5
+ :data-date-picker-type="kind"
6
+ class="bx--date-picker"
7
+ :class="[kindClasses, { 'bx--date-picker--light': theme === 'light' }]"
8
+ ref="date-picker"
9
+ >
10
+ <div
11
+ :class="{
12
+ 'bx--date-picker-container': ['single', 'range'].includes(kind),
13
+ }"
14
+ @change="onSimpleChange"
15
+ >
16
+ <label :for="`${uid}-input-1`" class="bx--label">{{
17
+ getDateLabel
18
+ }}</label>
19
+ <div class="bx--date-picker-input__wrapper">
20
+ <input
21
+ :data-invalid="isInvalid"
22
+ type="text"
23
+ :id="`${uid}-input-1`"
24
+ class="bx--date-picker__input"
25
+ :pattern="pattern"
26
+ :placeholder="placeholder"
27
+ data-date-picker-input
28
+ :data-date-picker-input-from="kind === 'range'"
29
+ ref="date"
30
+ />
31
+ <Calendar16
32
+ v-if="['single', 'range'].includes(kind)"
33
+ class="bx--date-picker__icon"
34
+ data-date-picker-icon
35
+ @click="cal.open()"
36
+ />
37
+ </div>
38
+ <div class="bx--form-requirement" v-if="isInvalid">
39
+ <slot name="invalid-message">{{
40
+ invalidMessage || invalidDateMessage
41
+ }}</slot>
42
+ </div>
43
+ </div>
44
+ <div
45
+ :class="{ 'bx--date-picker-container': kind === 'range' }"
46
+ v-if="kind === 'range'"
47
+ >
48
+ <label :for="`${uid}-input-2`" class="bx--label">{{
49
+ getDateEndLabel
50
+ }}</label>
51
+ <div class="bx--date-picker-input__wrapper">
52
+ <input
53
+ type="text"
54
+ :id="`${uid}-input-2`"
55
+ class="bx--date-picker__input"
56
+ :pattern="pattern"
57
+ :placeholder="placeholder"
58
+ data-date-picker-input
59
+ :data-date-picker-input-to="kind === 'range'"
60
+ ref="todate"
61
+ />
62
+ <Calendar16
63
+ class="bx--date-picker__icon"
64
+ data-date-picker-icon
65
+ @click="cal.open()"
66
+ />
67
+ </div>
68
+ </div>
69
+ </div>
70
+ </div>
71
+ </template>
72
+
73
+ <script>
74
+ import Flatpickr from 'flatpickr';
75
+ import l10n from 'flatpickr/dist/l10n/index';
76
+ import RangePlugin from 'flatpickr/dist/plugins/rangePlugin';
77
+ import uidMixin from '../../mixins/uid-mixin';
78
+ import themeMixin from '../../mixins/theme-mixin';
79
+ import Calendar16 from '@carbon/icons-vue/lib/calendar/16';
80
+
81
+ // Weekdays shorthand for english locale
82
+ l10n.en.weekdays.shorthand.forEach((day, index) => {
83
+ const currentDay = l10n.en.weekdays.shorthand;
84
+ if (currentDay[index] === 'Thu' || currentDay[index] === 'Th') {
85
+ currentDay[index] = 'Th';
86
+ } else {
87
+ currentDay[index] = currentDay[index].charAt(0);
88
+ }
89
+ });
90
+
91
+ export default {
92
+ name: 'CvDatePickerInnerC10',
93
+ mixins: [uidMixin, themeMixin],
94
+ components: { Calendar16 },
95
+ props: {
96
+ dateLabel: String,
97
+ dateEndLabel: String,
98
+ kind: {
99
+ type: String,
100
+ default: 'simple',
101
+ validator: val => ['short', 'simple', 'single', 'range'].includes(val),
102
+ },
103
+ calOptions: {
104
+ type: Object,
105
+ default: () => {
106
+ return {
107
+ dateFormat: 'm/d/Y',
108
+ };
109
+ },
110
+ },
111
+ pattern: { type: String, default: '\\d{1,2}/\\d{1,2}/\\d{4}' },
112
+ placeholder: { type: String, default: 'mm/dd/yyyy' },
113
+ invalid: /* deprecate */ {
114
+ type: Boolean,
115
+ default: undefined,
116
+ validator(val) {
117
+ if (val !== undefined) {
118
+ console.warn(
119
+ 'CvDatePicker: invalid prop deprecated in favour of invalidMessage'
120
+ );
121
+ }
122
+ return true;
123
+ },
124
+ },
125
+ invalidDateMessage: /* deprecate */ {
126
+ type: String,
127
+ default: null,
128
+ validator(val) {
129
+ if (val !== null) {
130
+ console.warn(
131
+ 'CvDatePicker: invalidDateMessage deprecated in favour of invalidMessage'
132
+ );
133
+ }
134
+ return true;
135
+ },
136
+ },
137
+ invalidMessage: { type: String, default: null },
138
+ },
139
+ computed: {
140
+ kindClasses() {
141
+ if (this.kind === 'short') {
142
+ return 'bx--date-picker--short bx--date-picker--simple';
143
+ }
144
+ return `bx--date-picker--${this.kind}`;
145
+ },
146
+ getDateLabel() {
147
+ if (this.dateLabel && this.dateLabel.length) {
148
+ return this.dateLabel;
149
+ } else {
150
+ if (this.kind === 'range') {
151
+ return 'Start date';
152
+ } else {
153
+ return 'Date';
154
+ }
155
+ }
156
+ },
157
+ getDateEndLabel() {
158
+ if (this.dateEndLabel && this.dateEndLabel.length) {
159
+ return this.dateEndLabel;
160
+ } else {
161
+ if (this.kind === 'range') {
162
+ return 'End date';
163
+ } else {
164
+ return '';
165
+ }
166
+ }
167
+ },
168
+ getOptions() {
169
+ const _options = { ...this.calOptions };
170
+
171
+ // add events update based on parameters
172
+ _options.onChange = this.onChange;
173
+ // _options.onValueUpdate = this.onChange;
174
+
175
+ if (this.kind === 'range') {
176
+ _options.plugins = [new RangePlugin({ input: this.$refs.todate })];
177
+ }
178
+
179
+ return _options;
180
+ },
181
+ isInvalid() {
182
+ return (
183
+ this.$slots['invalid-message'] ||
184
+ (this.invalidMessage && this.invalidMessage.length) ||
185
+ (this.invalidDateMessage && this.invalidDateMessage.length)
186
+ );
187
+ },
188
+ },
189
+ methods: {
190
+ onChange() {
191
+ // this.$emit('change', ev); // this is a property time
192
+ if (this.kind === 'range') {
193
+ this.$emit('change', {
194
+ startDate: this.$refs.date.value,
195
+ endDate: this.$refs.todate.value,
196
+ });
197
+ } else {
198
+ this.$emit('change', this.$refs.date.value);
199
+ }
200
+ },
201
+ onSimpleChange(ev) {
202
+ if (!['single', 'range'].includes(this.kind)) {
203
+ this.$emit('simpleChange', ev.target.value);
204
+ }
205
+ },
206
+ },
207
+ mounted() {
208
+ if (['single', 'range'].includes(this.kind)) {
209
+ this.cal = new Flatpickr(this.$refs.date, this.getOptions);
210
+ }
211
+ },
212
+ beforeDestroy() {
213
+ if (this.cal) {
214
+ this.cal.destroy();
215
+ }
216
+ },
217
+ };
218
+ </script>
219
+
220
+ <style lang="scss"></style>
@@ -0,0 +1,231 @@
1
+ <template>
2
+ <div class="cv-date-picker bx--form-item">
3
+ <div
4
+ :data-date-picker="['single', 'range'].includes(kind)"
5
+ :data-date-picker-type="kind"
6
+ class="bx--date-picker"
7
+ :class="[kindClasses, { 'bx--date-picker--light': theme === 'light' }]"
8
+ ref="date-picker"
9
+ >
10
+ <div
11
+ :class="{
12
+ 'bx--date-picker-container': ['single', 'range'].includes(kind),
13
+ }"
14
+ @change="onSimpleChange"
15
+ >
16
+ <svg
17
+ v-if="kind === 'single'"
18
+ data-date-picker-icon
19
+ class="bx--date-picker__icon"
20
+ width="14"
21
+ height="16"
22
+ viewBox="0 0 14 16"
23
+ @click="cal.open()"
24
+ >
25
+ <path
26
+ d="M0 5h14v1H0V5zm3-5h1v4H3V0zm7 0h1v4h-1V0zM0 2.5A1.5 1.5 0 0 1 1.5 1h11A1.5 1.5 0 0 1 14 2.5v12a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 0 14.5v-12zm1 0v12a.5.5 0 0 0 .5.5h11a.5.5 0 0 0 .5-.5v-12a.5.5 0 0 0-.5-.5h-11a.5.5 0 0 0-.5.5z"
27
+ fill-rule="nonzero"
28
+ ></path>
29
+ </svg>
30
+ <label :for="`${uid}-input-1`" class="bx--label">{{
31
+ getDateLabel
32
+ }}</label>
33
+ <input
34
+ :data-invalid="isInvalid"
35
+ type="text"
36
+ :id="`${uid}-input-1`"
37
+ class="bx--date-picker__input"
38
+ :pattern="pattern"
39
+ :placeholder="placeholder"
40
+ data-date-picker-input
41
+ :data-date-picker-input-from="kind === 'range'"
42
+ ref="date"
43
+ />
44
+ <div class="bx--form-requirement" v-if="isInvalid">
45
+ <slot name="invalid-message">{{
46
+ invalidMessage || invalidDateMessage
47
+ }}</slot>
48
+ </div>
49
+ </div>
50
+ <div
51
+ :class="{ 'bx--date-picker-container': kind === 'range' }"
52
+ v-if="kind === 'range'"
53
+ >
54
+ <label :for="`${uid}-input-2`" class="bx--label">{{
55
+ getDateEndLabel
56
+ }}</label>
57
+ <input
58
+ type="text"
59
+ :id="`${uid}-input-2`"
60
+ class="bx--date-picker__input"
61
+ :pattern="pattern"
62
+ :placeholder="placeholder"
63
+ data-date-picker-input
64
+ :data-date-picker-input-to="kind === 'range'"
65
+ ref="todate"
66
+ />
67
+ </div>
68
+ <svg
69
+ v-if="kind === 'range'"
70
+ data-date-picker-icon
71
+ class="bx--date-picker__icon"
72
+ width="14"
73
+ height="16"
74
+ viewBox="0 0 14 16"
75
+ @click="cal.open()"
76
+ >
77
+ <path
78
+ d="M0 5h14v1H0V5zm3-5h1v4H3V0zm7 0h1v4h-1V0zM0 2.5A1.5 1.5 0 0 1 1.5 1h11A1.5 1.5 0 0 1 14 2.5v12a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 0 14.5v-12zm1 0v12a.5.5 0 0 0 .5.5h11a.5.5 0 0 0 .5-.5v-12a.5.5 0 0 0-.5-.5h-11a.5.5 0 0 0-.5.5z"
79
+ fill-rule="nonzero"
80
+ ></path>
81
+ </svg>
82
+ </div>
83
+ </div>
84
+ </template>
85
+
86
+ <script>
87
+ import Flatpickr from 'flatpickr';
88
+ import l10n from 'flatpickr/dist/l10n/index';
89
+ import RangePlugin from 'flatpickr/dist/plugins/rangePlugin';
90
+ import uidMixin from '../../mixins/uid-mixin';
91
+ import themeMixin from '../../mixins/theme-mixin';
92
+
93
+ // Weekdays shorthand for english locale
94
+ l10n.en.weekdays.shorthand.forEach((day, index) => {
95
+ const currentDay = l10n.en.weekdays.shorthand;
96
+ if (currentDay[index] === 'Thu' || currentDay[index] === 'Th') {
97
+ currentDay[index] = 'Th';
98
+ } else {
99
+ currentDay[index] = currentDay[index].charAt(0);
100
+ }
101
+ });
102
+
103
+ export default {
104
+ name: 'CvDatePickerInner',
105
+ mixins: [uidMixin, themeMixin],
106
+ props: {
107
+ dateLabel: String,
108
+ dateEndLabel: String,
109
+ kind: {
110
+ type: String,
111
+ default: 'simple',
112
+ validator: val => ['short', 'simple', 'single', 'range'].includes(val),
113
+ },
114
+ calOptions: {
115
+ type: Object,
116
+ default: () => {
117
+ return {
118
+ dateFormat: 'm/d/Y',
119
+ };
120
+ },
121
+ },
122
+ pattern: { type: String, default: '\\d{1,2}/\\d{1,2}/\\d{4}' },
123
+ placeholder: { type: String, default: 'mm/dd/yyyy' },
124
+ invalid: /* deprecate */ {
125
+ type: Boolean,
126
+ default: undefined,
127
+ validator(val) {
128
+ if (val !== undefined) {
129
+ console.warn(
130
+ 'CvDatePicker: invalid prop deprecated in favour of invalidMessage'
131
+ );
132
+ }
133
+ return true;
134
+ },
135
+ },
136
+ invalidDateMessage: /* deprecate */ {
137
+ type: String,
138
+ default: null,
139
+ validator(val) {
140
+ if (val !== null) {
141
+ console.warn(
142
+ 'CvDatePicker: invalidDateMessage deprecated in favour of invalidMessage'
143
+ );
144
+ }
145
+ return true;
146
+ },
147
+ },
148
+ invalidMessage: { type: String, default: null },
149
+ },
150
+ computed: {
151
+ kindClasses() {
152
+ if (this.kind === 'short') {
153
+ return 'bx--date-picker--short bx--date-picker--simple';
154
+ }
155
+ return `bx--date-picker--${this.kind}`;
156
+ },
157
+ getDateLabel() {
158
+ if (this.dateLabel && this.dateLabel.length) {
159
+ return this.dateLabel;
160
+ } else {
161
+ if (this.kind === 'range') {
162
+ return 'Start date';
163
+ } else {
164
+ return 'Date';
165
+ }
166
+ }
167
+ },
168
+ getDateEndLabel() {
169
+ if (this.dateEndLabel && this.dateEndLabel.length) {
170
+ return this.dateEndLabel;
171
+ } else {
172
+ if (this.kind === 'range') {
173
+ return 'End date';
174
+ } else {
175
+ return '';
176
+ }
177
+ }
178
+ },
179
+ getOptions() {
180
+ const _options = { ...this.calOptions };
181
+
182
+ // add events update based on parameters
183
+ _options.onChange = this.onChange;
184
+ // _options.onValueUpdate = this.onChange;
185
+
186
+ if (this.kind === 'range') {
187
+ _options.plugins = [new RangePlugin({ input: this.$refs.todate })];
188
+ }
189
+
190
+ return _options;
191
+ },
192
+ isInvalid() {
193
+ return (
194
+ this.$slots['invalid-message'] ||
195
+ (this.invalidMessage && this.invalidMessage.length) ||
196
+ (this.invalidDateMessage && this.invalidDateMessage.length)
197
+ );
198
+ },
199
+ },
200
+ methods: {
201
+ onChange() {
202
+ // this.$emit('change', ev); // this is a property time
203
+ if (this.kind === 'range') {
204
+ this.$emit('change', {
205
+ startDate: this.$refs.date.value,
206
+ endDate: this.$refs.todate.value,
207
+ });
208
+ } else {
209
+ this.$emit('change', this.$refs.date.value);
210
+ }
211
+ },
212
+ onSimpleChange(ev) {
213
+ if (!['single', 'range'].includes(this.kind)) {
214
+ this.$emit('simpleChange', ev.target.value);
215
+ }
216
+ },
217
+ },
218
+ mounted() {
219
+ if (['single', 'range'].includes(this.kind)) {
220
+ this.cal = new Flatpickr(this.$refs.date, this.getOptions);
221
+ }
222
+ },
223
+ beforeDestroy() {
224
+ if (this.cal) {
225
+ this.cal.destroy();
226
+ }
227
+ },
228
+ };
229
+ </script>
230
+
231
+ <style lang="scss"></style>
@@ -1,229 +1,30 @@
1
1
  <template>
2
- <div class="cv-date-picker bx--form-item">
3
- <div
4
- :data-date-picker="['single', 'range'].includes(kind)"
5
- :data-date-picker-type="kind"
6
- class="bx--date-picker"
7
- :class="[kindClasses, { 'bx--date-picker--light': theme === 'light' }]"
8
- ref="date-picker"
9
- >
10
- <div
11
- :class="{
12
- 'bx--date-picker-container': ['single', 'range'].includes(kind),
13
- }"
14
- @change="onSimpleChange"
15
- >
16
- <svg
17
- v-if="kind === 'single'"
18
- data-date-picker-icon
19
- class="bx--date-picker__icon"
20
- width="14"
21
- height="16"
22
- viewBox="0 0 14 16"
23
- @click="cal.open()"
24
- >
25
- <path
26
- d="M0 5h14v1H0V5zm3-5h1v4H3V0zm7 0h1v4h-1V0zM0 2.5A1.5 1.5 0 0 1 1.5 1h11A1.5 1.5 0 0 1 14 2.5v12a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 0 14.5v-12zm1 0v12a.5.5 0 0 0 .5.5h11a.5.5 0 0 0 .5-.5v-12a.5.5 0 0 0-.5-.5h-11a.5.5 0 0 0-.5.5z"
27
- fill-rule="nonzero"
28
- ></path>
29
- </svg>
30
- <label :for="`${uid}-input-1`" class="bx--label">
31
- {{ getDateLabel }}
32
- </label>
33
- <input
34
- :data-invalid="isInvalid"
35
- type="text"
36
- :id="`${uid}-input-1`"
37
- class="bx--date-picker__input"
38
- :pattern="pattern"
39
- :placeholder="placeholder"
40
- data-date-picker-input
41
- :data-date-picker-input-from="kind === 'range'"
42
- ref="date"
43
- />
44
- <div class="bx--form-requirement" v-if="isInvalid">
45
- <slot name="invalid-message">
46
- {{ invalidMessage || invalidDateMessage }}
47
- </slot>
48
- </div>
49
- </div>
50
- <div
51
- :class="{ 'bx--date-picker-container': kind === 'range' }"
52
- v-if="kind === 'range'"
53
- >
54
- <label :for="`${uid}-input-2`" class="bx--label">
55
- {{ getDateEndLabel }}
56
- </label>
57
- <input
58
- type="text"
59
- :id="`${uid}-input-2`"
60
- class="bx--date-picker__input"
61
- :pattern="pattern"
62
- :placeholder="placeholder"
63
- data-date-picker-input
64
- :data-date-picker-input-to="kind === 'range'"
65
- ref="todate"
66
- />
67
- </div>
68
- <svg
69
- v-if="kind === 'range'"
70
- data-date-picker-icon
71
- class="bx--date-picker__icon"
72
- width="14"
73
- height="16"
74
- viewBox="0 0 14 16"
75
- @click="cal.open()"
76
- >
77
- <path
78
- d="M0 5h14v1H0V5zm3-5h1v4H3V0zm7 0h1v4h-1V0zM0 2.5A1.5 1.5 0 0 1 1.5 1h11A1.5 1.5 0 0 1 14 2.5v12a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 0 14.5v-12zm1 0v12a.5.5 0 0 0 .5.5h11a.5.5 0 0 0 .5-.5v-12a.5.5 0 0 0-.5-.5h-11a.5.5 0 0 0-.5.5z"
79
- fill-rule="nonzero"
80
- ></path>
81
- </svg>
82
- </div>
83
- </div>
2
+ <component
3
+ :is="tagType"
4
+ v-bind="$attrs"
5
+ v-on="$listeners"
6
+ class="cv-data-picker"
7
+ >
8
+ <slot></slot>
9
+ </component>
84
10
  </template>
85
11
 
86
12
  <script>
87
- import Flatpickr from 'flatpickr';
88
- import l10n from 'flatpickr/dist/l10n/index';
89
- import RangePlugin from 'flatpickr/dist/plugins/rangePlugin';
90
- import uidMixin from '../../mixins/uid-mixin';
91
- import themeMixin from '../../mixins/theme-mixin';
92
-
93
- // Weekdays shorthand for english locale
94
- l10n.en.weekdays.shorthand.forEach((day, index) => {
95
- const currentDay = l10n.en.weekdays.shorthand;
96
- if (currentDay[index] === 'Thu' || currentDay[index] === 'Th') {
97
- currentDay[index] = 'Th';
98
- } else {
99
- currentDay[index] = currentDay[index].charAt(0);
100
- }
101
- });
13
+ import CvDatePickerInnerC10 from './_cv-date-picker-inner-c10';
14
+ import CvDatePickerInner from './_cv-date-picker-inner';
15
+ import { componentsX } from '../../_internal/_feature-flags';
102
16
 
103
17
  export default {
104
- name: 'CvDatePicker',
105
- mixins: [uidMixin, themeMixin],
18
+ name: 'CvdataPicker',
19
+ components: { CvDatePickerInnerC10, CvDatePickerInner },
20
+ inheritAttrs: false,
106
21
  props: {
107
- dateLabel: String,
108
- dateEndLabel: String,
109
- kind: {
110
- type: String,
111
- default: 'simple',
112
- validator: val => ['short', 'simple', 'single', 'range'].includes(val),
113
- },
114
- calOptions: {
115
- type: Object,
116
- default: () => {
117
- return {
118
- dateFormat: 'm/d/Y',
119
- };
120
- },
121
- },
122
- pattern: { type: String, default: '\\d{1,2}/\\d{1,2}/\\d{4}' },
123
- placeholder: { type: String, default: 'mm/dd/yyyy' },
124
- invalid: /* deprecate */ {
125
- type: Boolean,
126
- default: undefined,
127
- validator(val) {
128
- if (val !== undefined) {
129
- console.warn(
130
- 'CvDatePicker: invalid prop deprecated in favour of invalidMessage'
131
- );
132
- }
133
- return true;
134
- },
135
- },
136
- invalidDateMessage: /* deprecate */ {
137
- type: String,
138
- default: null,
139
- validator(val) {
140
- if (val !== null) {
141
- console.warn(
142
- 'CvDatePicker: invalidDateMessage deprecated in favour of invalidMessage'
143
- );
144
- }
145
- return true;
146
- },
147
- },
148
- invalidMessage: { type: String, default: null },
22
+ formItem: { type: Boolean, default: true },
149
23
  },
150
24
  computed: {
151
- kindClasses() {
152
- if (this.kind === 'short') {
153
- return 'bx--date-picker--short bx--date-picker--simple';
154
- }
155
- return `bx--date-picker--${this.kind}`;
25
+ tagType() {
26
+ return componentsX ? 'cv-date-picker-inner-c10' : 'cv-date-picker-inner';
156
27
  },
157
- getDateLabel() {
158
- if (this.dateLabel && this.dateLabel.length) {
159
- return this.dateLabel;
160
- } else {
161
- if (this.kind === 'range') {
162
- return 'Start date';
163
- } else {
164
- return 'Date';
165
- }
166
- }
167
- },
168
- getDateEndLabel() {
169
- if (this.dateEndLabel && this.dateEndLabel.length) {
170
- return this.dateEndLabel;
171
- } else {
172
- if (this.kind === 'range') {
173
- return 'End date';
174
- } else {
175
- return '';
176
- }
177
- }
178
- },
179
- getOptions() {
180
- const _options = { ...this.calOptions };
181
-
182
- // add events update based on parameters
183
- _options.onChange = this.onChange;
184
- _options.onValueUpdate = this.onChange;
185
-
186
- if (this.kind === 'range') {
187
- _options.plugins = [new RangePlugin({ input: this.$refs.todate })];
188
- }
189
-
190
- return _options;
191
- },
192
- isInvalid() {
193
- return (
194
- this.$slots['invalid-message'] ||
195
- (this.invalidMessage && this.invalidMessage.length) ||
196
- (this.invalidDateMessage && this.invalidDateMessage.length)
197
- );
198
- },
199
- },
200
- methods: {
201
- onChange() {
202
- // this.$emit('change', ev); // this is a property time
203
- if (this.kind === 'range') {
204
- this.$emit('change', {
205
- startDate: this.$refs.date.value,
206
- endDate: this.$refs.todate.value,
207
- });
208
- } else {
209
- this.$emit('change', this.$refs.date.value);
210
- }
211
- },
212
- onSimpleChange(ev) {
213
- if (!['single', 'range'].includes(this.kind)) {
214
- this.$emit('simpleChange', ev.target.value);
215
- }
216
- },
217
- },
218
- mounted() {
219
- if (['single', 'range'].includes(this.kind)) {
220
- this.cal = new Flatpickr(this.$refs.date, this.getOptions);
221
- }
222
- },
223
- beforeDestroy() {
224
- if (this.cal) {
225
- this.cal.destroy();
226
- }
227
28
  },
228
29
  };
229
30
  </script>