@citizenplane/pimp 6.4.0 → 7.0.4

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 (70) hide show
  1. package/.eslintrc.js +3 -6
  2. package/.lintstagedrc.json +4 -0
  3. package/dist/favicon.ico +0 -0
  4. package/dist/pimp.es.js +10617 -0
  5. package/dist/pimp.umd.js +9 -35597
  6. package/dist/style.css +1 -0
  7. package/jest.config.js +11 -11
  8. package/package-lock.json +7966 -13664
  9. package/package.json +37 -41
  10. package/src/App.vue +12 -17
  11. package/src/assets/styles/base/_base.scss +3 -16
  12. package/src/assets/styles/helpers/_keyframes.scss +26 -29
  13. package/src/components/buttons/CpButton.vue +10 -6
  14. package/src/components/core/BaseInputLabel/index.vue +2 -2
  15. package/src/components/core/playground-sections/SectionAtomicElements.vue +1 -1
  16. package/src/components/core/playground-sections/SectionButtons.vue +14 -11
  17. package/src/components/core/playground-sections/SectionDatePickers.vue +31 -17
  18. package/src/components/core/playground-sections/SectionFeedbackIndicators.vue +1 -1
  19. package/src/components/core/playground-sections/SectionInputs.vue +3 -3
  20. package/src/components/core/playground-sections/SectionListsAndTables.vue +2 -2
  21. package/src/components/core/playground-sections/SectionSelectMenus.vue +13 -13
  22. package/src/components/core/playground-sections/SectionSelects.vue +1 -1
  23. package/src/components/core/playground-sections/SectionSimpleInputs.vue +20 -18
  24. package/src/components/core/playground-sections/SectionToasters.vue +1 -1
  25. package/src/components/core/playground-sections/SectionToggles.vue +23 -36
  26. package/src/components/core/playground-sections/SectionTypography.vue +1 -1
  27. package/src/components/date-pickers/CpCalendar.vue +60 -14
  28. package/src/components/date-pickers/CpDate.vue +11 -13
  29. package/src/components/date-pickers/CpDatepicker.vue +55 -8
  30. package/src/components/feedback-indicators/CpAlert.vue +5 -15
  31. package/src/components/feedback-indicators/CpToaster.vue +299 -86
  32. package/src/components/helpers-utilities/TransitionExpand.vue +52 -58
  33. package/src/components/index.js +38 -73
  34. package/src/components/inputs/CpInput.vue +20 -55
  35. package/src/components/inputs/CpTextarea.vue +8 -9
  36. package/src/components/lists-and-table/CpTable/CpTableEmptyState/index.vue +1 -6
  37. package/src/components/lists-and-table/CpTable/index.scss +16 -9
  38. package/src/components/lists-and-table/CpTable/index.vue +6 -5
  39. package/src/components/selects/CpSelect.vue +10 -11
  40. package/src/components/selects/CpSelectMenu/index.vue +13 -23
  41. package/src/components/toggles/CpCheckbox/index.scss +8 -5
  42. package/src/components/toggles/CpCheckbox/index.vue +3 -7
  43. package/src/components/toggles/CpRadio/index.scss +14 -11
  44. package/src/components/toggles/CpRadio/index.vue +34 -47
  45. package/src/components/toggles/CpSwitch/index.vue +18 -17
  46. package/src/components/typography/CpHeading/index.vue +2 -2
  47. package/src/components/visual/CpIcon.vue +156 -0
  48. package/src/directives/ClickOutside.js +13 -0
  49. package/src/directives/ResizeSelect.js +1 -1
  50. package/src/libs/CoreDatepicker.vue +127 -133
  51. package/src/main.js +16 -10
  52. package/src/plugins/toaster.js +69 -0
  53. package/src/utils/constants/src/Intent.js +4 -4
  54. package/vite.config.js +45 -0
  55. package/dist/demo.html +0 -10
  56. package/dist/img/chevron-down-icon.dd31db33.svg +0 -3
  57. package/dist/pimp.common.js +0 -35587
  58. package/dist/pimp.common.js.map +0 -1
  59. package/dist/pimp.css +0 -1
  60. package/dist/pimp.umd.js.map +0 -1
  61. package/dist/pimp.umd.min.js +0 -2
  62. package/dist/pimp.umd.min.js.map +0 -1
  63. package/public/index.html +0 -17
  64. package/src/components/core/playground-sections/SectionMultiSelects.vue +0 -57
  65. package/src/components/selects/CpMultiselect.vue +0 -211
  66. package/src/helpers/multiselectMixin.js +0 -765
  67. package/src/helpers/pointerMixin.js +0 -135
  68. package/src/libs/CoreMultiSelect.vue +0 -618
  69. package/src/libs/CoreToaster.vue +0 -269
  70. package/vue.config.js +0 -20
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <transition name="asd__fade">
2
+ <transition :name="transitionName">
3
3
  <div
4
4
  v-show="showDatepicker"
5
5
  :id="wrapperId"
@@ -7,6 +7,7 @@
7
7
  class="asd__wrapper"
8
8
  :class="wrapperClasses"
9
9
  :style="showFullscreen ? undefined : wrapperStyles"
10
+ @keydown.esc="closeDatepicker"
10
11
  >
11
12
  <div v-if="showFullscreen" class="asd__mobile-header asd__mobile-only">
12
13
  <button class="asd__mobile-close" type="button" @click="closeDatepicker">
@@ -16,12 +17,20 @@
16
17
  <h3>{{ mobileHeader || mobileHeaderFallback }}</h3>
17
18
  </div>
18
19
  <div class="asd__datepicker-header">
19
- <div class="asd__change-month-button asd__change-month-button--previous">
20
- <chevron-left-icon @click="previousMonth"></chevron-left-icon>
21
- </div>
22
- <div class="asd__change-month-button asd__change-month-button--next">
23
- <chevron-right-icon @click="nextMonth"></chevron-right-icon>
24
- </div>
20
+ <button
21
+ class="asd__change-month-button asd__change-month-button--previous"
22
+ aria-label="previous month"
23
+ @click="previousMonth"
24
+ >
25
+ <cp-icon type="chevron-left" />
26
+ </button>
27
+ <button
28
+ class="asd__change-month-button asd__change-month-button--next"
29
+ aria-label="next month"
30
+ @click="nextMonth"
31
+ >
32
+ <cp-icon type="chevron-right" />
33
+ </button>
25
34
  <div
26
35
  v-for="(month, index) in showMonths"
27
36
  :key="month"
@@ -89,13 +98,8 @@
89
98
  :ref="`date-${dayDate}`"
90
99
  class="asd__day"
91
100
  :data-date="dayDate"
92
- :tabindex="isDateVisible(dayDate) && isSameDate(focusedDate, dayDate) ? 0 : -1"
93
- :class="getDayClasses(dayDate)"
94
- @mouseover="
95
- () => {
96
- setHoverDate(dayDate)
97
- }
98
- "
101
+ :class="getDayClasses(dayNumber, dayDate)"
102
+ @mouseover="setHoverDate(dayDate)"
99
103
  >
100
104
  <button
101
105
  v-if="dayNumber"
@@ -121,23 +125,19 @@
121
125
  </template>
122
126
 
123
127
  <script>
124
- import vClickOutside from 'v-click-outside'
125
- import { ChevronLeftIcon, ChevronRightIcon } from 'vue-feather-icons'
126
128
  import { DateTime, Info } from 'luxon'
127
129
 
128
130
  import { randomString } from '@/helpers'
129
131
  import ResizeSelect from '@/directives/ResizeSelect'
130
132
 
131
- const MOBILE_SIZE = 768
133
+ import CpIcon from '@/components/visual/CpIcon.vue'
132
134
 
133
135
  export default {
134
136
  name: 'CoreDatepicker',
135
137
  components: {
136
- ChevronRightIcon,
137
- ChevronLeftIcon,
138
+ CpIcon,
138
139
  },
139
140
  directives: {
140
- clickOutside: vClickOutside.directive,
141
141
  resizeSelect: ResizeSelect,
142
142
  },
143
143
  props: {
@@ -241,6 +241,17 @@ export default {
241
241
  default: () => process.env.NODE_ENV === 'test',
242
242
  },
243
243
  },
244
+ emits: [
245
+ 'date-one-selected',
246
+ 'date-two-selected',
247
+ 'is-inline',
248
+ 'previous-month',
249
+ 'next-month',
250
+ 'opened',
251
+ 'cancelled',
252
+ 'closed',
253
+ 'apply',
254
+ ],
244
255
  data() {
245
256
  return {
246
257
  wrapperId: 'datepicker-wrapper-' + randomString(5),
@@ -281,22 +292,27 @@ export default {
281
292
  viewportWidth: undefined,
282
293
  isMobile: undefined,
283
294
  triggerElement: undefined,
284
- isInline: this.inline || false,
285
295
  }
286
296
  },
287
297
  computed: {
298
+ transitionName() {
299
+ return this.inline ? '' : 'asd__fade'
300
+ },
288
301
  wrapperClasses() {
289
- return {
290
- 'asd__wrapper--datepicker-open': this.showDatepicker,
291
- 'asd__wrapper--full-screen': this.showFullscreen,
292
- 'asd__wrapper--isInline': this.isInline,
293
- 'asd__wrapper--showOneMonth': this.monthsToShow === 1,
294
- }
302
+ return [
303
+ this.$attrs.class,
304
+ {
305
+ 'asd__wrapper--datepicker-open': this.showDatepicker,
306
+ 'asd__wrapper--full-screen': this.showFullscreen,
307
+ 'asd__wrapper--isInline': this.inline,
308
+ 'asd__wrapper--showOneMonth': this.monthsToShow === 1,
309
+ },
310
+ ]
295
311
  },
296
312
  wrapperStyles() {
297
313
  return {
298
314
  width: this.width * this.showMonths + 'px',
299
- zIndex: this.isInline ? '' : '100',
315
+ zIndex: this.inline ? '' : '100',
300
316
  }
301
317
  },
302
318
  innerStyles() {
@@ -362,7 +378,6 @@ export default {
362
378
  },
363
379
  selectedDate2(newValue) {
364
380
  const newDate = !newValue || newValue === '' ? '' : newValue
365
- if (newValue && this.selectedDate1 && !this.isDateVisible(newDate)) this.nextMonth()
366
381
  this.$emit('date-two-selected', newDate)
367
382
  },
368
383
  mode() {
@@ -415,13 +430,13 @@ export default {
415
430
  this.generateMonths()
416
431
  this.generateYears()
417
432
 
418
- if (this.startOpen || this.isInline) {
433
+ if (this.startOpen || this.inline) {
419
434
  this.openDatepicker()
420
435
  }
421
436
 
422
437
  this.triggerElement.addEventListener('click', this._handleWindowClickEvent)
423
438
  },
424
- destroyed() {
439
+ unmounted() {
425
440
  window.removeEventListener('resize', this._handleWindowResizeEvent)
426
441
  window.removeEventListener('click', this._handleWindowClickEvent)
427
442
  this.triggerElement.removeEventListener('click', this._handleWindowClickEvent)
@@ -429,17 +444,10 @@ export default {
429
444
  methods: {
430
445
  handleDatepickerSizing() {
431
446
  this.viewportWidth = window.innerWidth + 'px'
432
- this._isWindowLessThan = (width) => {
433
- return window.innerWidth <= width || screen.width <= width
434
- }
435
-
436
- this.isInline = this.inline || this._isWindowLessThan(MOBILE_SIZE)
437
- this.$emit('is-inline', this.isInline)
438
447
 
439
448
  this._handleWindowResizeEvent = this.debounce(() => {
440
- this.isInline = this.inline || this._isWindowLessThan(MOBILE_SIZE)
441
- this.isInline ? this.openDatepicker() : this.closeDatepicker()
442
- this.$emit('is-inline', this.isInline)
449
+ this.inline ? this.openDatepicker() : this.closeDatepicker()
450
+ this.$emit('is-inline', this.inline)
443
451
  this.positionDatepicker()
444
452
  this.setStartDates()
445
453
  }, 200)
@@ -453,11 +461,11 @@ export default {
453
461
  }
454
462
  window.addEventListener('resize', this._handleWindowResizeEvent)
455
463
  },
456
- getDayClasses(dayDate) {
464
+ getDayClasses(dayNumber, dayDate) {
457
465
  return [
458
466
  {
459
- 'asd__day--enabled': this.dayNumber !== 0,
460
- 'asd__day--empty': this.dayNumber === 0,
467
+ 'asd__day--enabled': dayNumber !== 0,
468
+ 'asd__day--empty': dayNumber === 0,
461
469
  'asd__day--disabled': this.isDisabled(dayDate),
462
470
  'asd__day--selected':
463
471
  dayDate && (this.selectedDate1 === dayDate || this.selectedDate2 === dayDate) && !this.isRecurrent,
@@ -518,7 +526,7 @@ export default {
518
526
  return null
519
527
  },
520
528
  handleClickOutside(event) {
521
- if (event.target.id === this.triggerElementId || !this.showDatepicker || this.isInline || this.isRecurrent) {
529
+ if (event.target.id === this.triggerElementId || !this.showDatepicker || this.inline || this.isRecurrent) {
522
530
  return
523
531
  }
524
532
  this.closeDatepicker()
@@ -586,6 +594,12 @@ export default {
586
594
  }
587
595
  },
588
596
  setStartDates() {
597
+ // Set dates if initialized
598
+ if (this.mode === 'range') {
599
+ if (this.dateOne) this.selectDate(this.dateOne)
600
+ if (this.dateTwo) this.selectDate(this.dateTwo)
601
+ }
602
+
589
603
  let startDate = this.dateOne ? DateTime.fromISO(this.dateOne) : DateTime.local()
590
604
  const minDate = DateTime.fromISO(this.minDate)
591
605
 
@@ -722,20 +736,12 @@ export default {
722
736
  const targetMonth = DateTime.fromISO(this.visibleMonths[visibleMonthIdx])
723
737
  const monthIdx = targetMonth.month
724
738
  const year = targetMonth.year
725
- this.focusedDate = DateTime.fromISO(this.focusedDate).set({ month: monthIdx }).set({ year }).toISODate()
739
+ this.focusedDate = DateTime.fromISO(this.focusedDate).set({ month: monthIdx, year }).toISODate()
726
740
  }
727
741
  },
728
742
  isToday(date) {
729
743
  return DateTime.local().toISODate() === date
730
744
  },
731
- isSameDate(date1, date2) {
732
- if (!date1) {
733
- return false
734
- }
735
- const dtDate1 = typeof date1 === 'object' ? DateTime.fromJSDate(date1) : DateTime.fromISO(date1)
736
-
737
- return dtDate1.toISODate() === date2
738
- },
739
745
  isSelected(date) {
740
746
  if (!date) {
741
747
  return
@@ -909,7 +915,7 @@ export default {
909
915
  this.initialDate2 = this.dateTwo
910
916
  this.$emit('opened')
911
917
  this.$nextTick(() => {
912
- if (!this.isInline) this.setFocusedDate(this.focusedDate)
918
+ if (!this.inline) this.setFocusedDate(this.focusedDate)
913
919
  })
914
920
  },
915
921
  closeDatepickerCancel() {
@@ -921,7 +927,7 @@ export default {
921
927
  }
922
928
  },
923
929
  closeDatepicker() {
924
- if (this.isInline) {
930
+ if (this.inline) {
925
931
  return
926
932
  }
927
933
  this.showDatepicker = false
@@ -944,6 +950,7 @@ export default {
944
950
 
945
951
  const viewportWidth = document.documentElement.clientWidth || window.innerWidth
946
952
  this.viewportWidth = viewportWidth + 'px'
953
+
947
954
  this.isMobile = viewportWidth < 768
948
955
 
949
956
  if (this.isMobile) {
@@ -970,8 +977,11 @@ export default {
970
977
  },
971
978
  }
972
979
  </script>
980
+ <style lang="scss">
981
+ @include popover-desktop('asd__fade');
982
+ </style>
973
983
 
974
- <style lang="stylus" scoped>
984
+ <style lang="stylus">
975
985
  $tablet = 768px
976
986
 
977
987
  $background-grey-color = #f7f7f7
@@ -986,16 +996,8 @@ degrade()
986
996
  position absolute
987
997
  z-index -1
988
998
 
989
- // fade in
990
- .asd__fade-enter-active,
991
- .asd__fade-leave-active
992
- transition all 0.2s ease
993
-
994
- .asd__fade-enter,
995
- .asd__fade-leave-active
996
- opacity 0
997
999
  // datepicker
998
- .asd__list-complete-enter,
1000
+ .asd__list-complete-enter-from,
999
1001
  .asd__list-complete-leave-to
1000
1002
  opacity 0
1001
1003
  transform translateY(30px)
@@ -1006,8 +1008,6 @@ degrade()
1006
1008
 
1007
1009
  .asd
1008
1010
  &__wrapper
1009
- left: 50%;
1010
- transform: translateX(-50%);
1011
1011
  border-radius 10px
1012
1012
  white-space nowrap
1013
1013
  text-align center
@@ -1015,25 +1015,13 @@ degrade()
1015
1015
  overflow hidden
1016
1016
 
1017
1017
  &:not(&--isInline) {
1018
- box-shadow 0 24px 38px 3px rgba(0,0,0,0.14), 0 9px 46px 8px rgba(0,0,0,0.12), 0 11px 15px -7px rgba(0,0,0,0.2)
1019
- }
1020
-
1021
- @media (min-width: $tablet) {
1022
- position absolute
1023
- margin-top 10px
1018
+ box-shadow 0 9px 24px rgba(62, 62, 91, 20%), 0 4px 4px rgba(62, 62, 91, 10%);
1024
1019
  }
1025
1020
 
1026
1021
  &--isInline {
1027
- position relative
1028
- margin-top 16px
1022
+ position relative !important
1029
1023
  }
1030
1024
 
1031
- @media (max-width: $tablet) {
1032
- position relative
1033
- margin-top 16px
1034
- }
1035
-
1036
-
1037
1025
  &:before
1038
1026
  // Line between the two months
1039
1027
  @media (min-width: $tablet)
@@ -1045,7 +1033,7 @@ degrade()
1045
1033
  bottom 0
1046
1034
  margin auto
1047
1035
  width 1px
1048
- background $neutral-dark-5
1036
+ background $neutral-dark-4
1049
1037
  z-index -1
1050
1038
 
1051
1039
  &--showOneMonth {
@@ -1073,41 +1061,58 @@ degrade()
1073
1061
  &__change-month-button
1074
1062
  position absolute
1075
1063
  z-index 10
1064
+ top 16px
1065
+ border-radius: 100%;
1066
+
1067
+ &:focus-visible {
1068
+ outline: 2px solid $secondary-color;
1069
+ outline-offset: 2px;
1070
+ }
1071
+
1072
+ i
1073
+ color $neutral-dark
1076
1074
 
1077
1075
  svg
1078
1076
  cursor pointer
1079
1077
  stroke-width 1.2px
1080
- stroke black
1081
1078
 
1082
1079
  @media (min-width: $tablet)
1083
1080
  top 22px
1084
1081
 
1085
- &--previous
1086
- left 0
1082
+ &--previous {
1083
+ left 16px
1087
1084
 
1088
- @media (min-width: $tablet)
1089
- padding-left 24px
1085
+ @media (min-width: $tablet) {
1086
+ left 24px
1087
+ }
1088
+ }
1090
1089
 
1091
- &--next
1092
- right 0
1090
+ &--next {
1091
+ right 16px
1093
1092
 
1094
- @media (min-width: $tablet)
1095
- padding-right 24px
1093
+ @media (min-width: $tablet) {
1094
+ right 24px
1095
+ }
1096
+ }
1096
1097
 
1097
- &__days-legend
1098
+ &__days-legend {
1098
1099
  position absolute
1099
1100
  font-size 12px
1100
1101
  line-height 15px
1101
1102
  user-select none
1102
1103
 
1103
- @media (min-width: $tablet)
1104
- top 60px
1104
+ @media (min-width: $tablet) {
1105
1105
  padding 0 24px
1106
+ top 60px
1107
+ }
1106
1108
 
1107
- @media (max-width: $tablet)
1108
- top 36px
1109
+ @media (max-width: $tablet - 1px) {
1110
+ top 56px
1111
+ padding: 0 16px;
1112
+ }
1113
+ }
1109
1114
 
1110
- &__day-title
1115
+ &__day-title {
1111
1116
  display inline-block
1112
1117
  width percentage(1 / 7)
1113
1118
  text-align center
@@ -1115,23 +1120,38 @@ degrade()
1115
1120
  font-size 14px
1116
1121
  line-height 18px
1117
1122
  margin-left -1px
1123
+ }
1118
1124
 
1119
- &__month-table
1125
+ &__month-table {
1120
1126
  border-spacing 0 6px
1121
1127
  width 100%
1122
1128
  max-width 100%
1129
+ }
1130
+
1131
+ &__wrapper:not(&__wrapper--isInline) &__month {
1132
+ padding-left: 16px;
1133
+ padding-right: 16px;
1134
+
1135
+ @media (min-width: $tablet) {
1136
+ padding-left: 24px;
1137
+ padding-right: 24px;
1138
+ }
1139
+ }
1123
1140
 
1124
- &__month
1141
+ &__month {
1125
1142
  transition all $transition-time ease
1126
1143
  display inline-block
1144
+ padding 16px 16px 8px
1127
1145
 
1128
- @media (min-width: $tablet)
1129
- padding 24px
1130
- padding-bottom 12px
1146
+ @media (min-width: $tablet) {
1147
+ padding 24px 24px 12px;
1148
+ }
1131
1149
 
1132
- &--hidden
1150
+ &--hidden {
1133
1151
  height 275px
1134
1152
  visibility hidden
1153
+ }
1154
+ }
1135
1155
 
1136
1156
  &__month-name
1137
1157
  font-size 16px
@@ -1188,8 +1208,8 @@ degrade()
1188
1208
 
1189
1209
  &--hovered
1190
1210
  .asd__day--end-week
1191
- border-top-right-radius 5px
1192
- border-bottom-right-radius 5px
1211
+ border-top-right-radius 5px
1212
+ border-bottom-right-radius 5px
1193
1213
 
1194
1214
  .asd__day--start-week
1195
1215
  border-top-left-radius 5px
@@ -1266,8 +1286,8 @@ degrade()
1266
1286
  &--empty .asd__day-number
1267
1287
  color $neutral-dark-3 !important
1268
1288
 
1269
- button
1270
- cursor default
1289
+ &--disabled *
1290
+ cursor not-allowed !important
1271
1291
 
1272
1292
  &--today .asd__day-button .asd__day-number
1273
1293
  color $primary-color
@@ -1306,7 +1326,6 @@ degrade()
1306
1326
  width 35px
1307
1327
  height 35px
1308
1328
  border none
1309
- cursor pointer
1310
1329
  user-select none
1311
1330
  font-size 14px
1312
1331
 
@@ -1315,31 +1334,6 @@ degrade()
1315
1334
  position relative
1316
1335
  color $neutral-dark
1317
1336
 
1318
- &__action-buttons
1319
- min-height 50px
1320
- padding-top 10px
1321
- margin-bottom 12px
1322
-
1323
- button
1324
- display block
1325
- position relative
1326
- background transparent
1327
- border none
1328
- font-weight bold
1329
- font-size 15px
1330
- cursor pointer
1331
-
1332
- &:hover
1333
- text-decoration underline
1334
-
1335
- &:nth-child(1)
1336
- float left
1337
- left 15px
1338
-
1339
- &:nth-child(2)
1340
- float right
1341
- right 15px
1342
-
1343
1337
  &__mobile-header
1344
1338
  border-bottom $border-normal
1345
1339
  position relative
package/src/main.js CHANGED
@@ -1,15 +1,21 @@
1
- import Vue from 'vue'
2
- import PortalVue from 'portal-vue'
3
- import Pimp from './components'
1
+ import { createApp } from 'vue'
4
2
 
5
3
  import App from './App.vue'
6
- import './components'
4
+ const app = createApp(App)
5
+
6
+ // Plugins
7
+ import Pimp from './components'
8
+ app.use(Pimp)
9
+
10
+ import Toaster from './plugins/toaster'
11
+ app.use(Toaster)
7
12
 
8
- Vue.use(PortalVue)
9
- Vue.use(Pimp)
13
+ import Maska from 'maska'
14
+ app.use(Maska)
10
15
 
11
- Vue.config.productionTip = false
16
+ // Directives
17
+ import ClickOutside from './directives/ClickOutside'
18
+ app.directive('click-outside', ClickOutside)
12
19
 
13
- new Vue({
14
- render: (h) => h(App),
15
- }).$mount('#app')
20
+ // Mount
21
+ app.mount('#app')
@@ -0,0 +1,69 @@
1
+ import CpToaster from '@/components/feedback-indicators/CpToaster.vue'
2
+ import { Intent } from '@/utils/constants'
3
+
4
+ import { h, render } from 'vue'
5
+
6
+ const createElement = () => typeof document !== 'undefined' && document.createElement('div')
7
+
8
+ const mount = (component, { props, children, element, app } = {}) => {
9
+ let el = element ? element : createElement()
10
+
11
+ let vNode = h(component, props, children)
12
+ if (app && app._context) {
13
+ vNode.appContext = app._context
14
+ }
15
+
16
+ render(vNode, el)
17
+
18
+ const destroy = () => {
19
+ if (el) {
20
+ render(null, el)
21
+ }
22
+ el = null
23
+ vNode = null
24
+ }
25
+
26
+ return { vNode, destroy, el }
27
+ }
28
+
29
+ const createToaster = (globalOptions = {}) => {
30
+ return {
31
+ show(options = {}) {
32
+ let localOptions = { ...options }
33
+
34
+ mount(CpToaster, {
35
+ props: { ...globalOptions, ...localOptions },
36
+ })
37
+ },
38
+ unique(options = {}) {
39
+ options.isUnique = true
40
+ return this.show(options)
41
+ },
42
+ success(options = {}) {
43
+ options.type = Intent.SUCCESS.value
44
+ return this.show(options)
45
+ },
46
+ critical(options = {}) {
47
+ options.type = Intent.CRITICAL.value
48
+ return this.show(options)
49
+ },
50
+ info(options = {}) {
51
+ options.type = Intent.INFO.value
52
+ return this.show(options)
53
+ },
54
+ warning(options = {}) {
55
+ options.type = Intent.WARNING.value
56
+ return this.show(options)
57
+ },
58
+ }
59
+ }
60
+
61
+ export default {
62
+ install(app, options) {
63
+ app.component('CpToaster', CpToaster)
64
+
65
+ let methods = createToaster(options)
66
+ app.$toaster = methods
67
+ app.config.globalProperties.$toaster = methods
68
+ },
69
+ }
@@ -1,18 +1,18 @@
1
1
  export default {
2
2
  SUCCESS: {
3
3
  value: 'success',
4
- icon: 'CheckCircleIcon',
4
+ icon: 'check-circle',
5
5
  },
6
6
  CRITICAL: {
7
7
  value: 'critical',
8
- icon: 'AlertOctagonIcon',
8
+ icon: 'alert-octagon',
9
9
  },
10
10
  WARNING: {
11
11
  value: 'warning',
12
- icon: 'AlertTriangleIcon',
12
+ icon: 'alert-triangle',
13
13
  },
14
14
  INFO: {
15
15
  value: 'info',
16
- icon: 'InfoIcon',
16
+ icon: 'info',
17
17
  },
18
18
  }
package/vite.config.js ADDED
@@ -0,0 +1,45 @@
1
+ import path from 'path'
2
+ import { defineConfig } from 'vite'
3
+ import vue from '@vitejs/plugin-vue'
4
+
5
+ // https://vitejs.dev/config/
6
+ export default defineConfig({
7
+ plugins: [vue()],
8
+ resolve: {
9
+ alias: {
10
+ '@': path.resolve(__dirname, '/src'),
11
+ },
12
+ },
13
+ server: {
14
+ port: 8080,
15
+ },
16
+ css: {
17
+ preprocessorOptions: {
18
+ scss: {
19
+ additionalData: `@import "@/assets/styles/main.scss";`,
20
+ },
21
+ stylus: {
22
+ imports: [path.resolve(__dirname, `src/assets/styl/colors.styl`)],
23
+ },
24
+ },
25
+ },
26
+ build: {
27
+ lib: {
28
+ entry: path.resolve(__dirname, 'src/components/index.js'),
29
+ name: 'Pimp',
30
+ fileName: (format) => `pimp.${format}.js`,
31
+ },
32
+ rollupOptions: {
33
+ // make sure to externalize deps that shouldn't be bundled
34
+ // into your library
35
+ external: ['vue'],
36
+ output: {
37
+ // Provide global variables to use in the UMD build
38
+ // for externalized deps
39
+ globals: {
40
+ vue: 'Vue',
41
+ },
42
+ },
43
+ },
44
+ },
45
+ })
package/dist/demo.html DELETED
@@ -1,10 +0,0 @@
1
- <meta charset="utf-8">
2
- <title>pimp demo</title>
3
- <script src="./pimp.umd.js"></script>
4
-
5
- <link rel="stylesheet" href="./pimp.css">
6
-
7
-
8
- <script>
9
- console.log(pimp)
10
- </script>
@@ -1,3 +0,0 @@
1
- <svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M6 9.68298L12 15.683L18 9.68298" stroke="#3E3E5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
3
- </svg>