@antify/ui 3.3.1 → 3.3.3

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.
@@ -1,6 +1,8 @@
1
1
  <script lang="ts" setup>
2
2
  import {
3
- ref, useSlots, watch,
3
+ ref,
4
+ useSlots,
5
+ onMounted,
4
6
  } from 'vue';
5
7
  import {
6
8
  faXmark,
@@ -9,12 +11,10 @@ import AntButton from './AntButton.vue';
9
11
  import AntSkeleton from './AntSkeleton.vue';
10
12
 
11
13
  const emit = defineEmits([
12
- 'update:open',
13
14
  'close',
14
15
  ]);
15
16
  const props = withDefaults(defineProps<{
16
17
  title: string;
17
- open: boolean;
18
18
  fullscreen?: boolean;
19
19
  padding?: boolean;
20
20
  skeleton?: boolean;
@@ -23,31 +23,35 @@ const props = withDefaults(defineProps<{
23
23
  padding: false,
24
24
  skeleton: false,
25
25
  });
26
- const openModal = ref(props.open);
27
- const openBackground = ref(props.open);
28
-
29
- watch(() => props.open, (val) => {
30
- function onKeydown(e: KeyboardEvent) {
31
- if (e.key === 'Escape') {
32
- closeModal();
33
- }
34
- }
26
+ const openModal = ref(false);
27
+ const openBackground = ref(false);
35
28
 
36
- if (val) {
37
- openBackground.value = true;
38
- setTimeout(() => openModal.value = true, props.fullscreen ? 0 : 100);
39
- document.addEventListener('keydown', onKeydown);
40
- } else {
41
- openModal.value = false;
42
- setTimeout(() => openBackground.value = false, props.fullscreen ? 0 : 100);
43
- document.removeEventListener('keydown', onKeydown);
29
+ function onKeydown(e: KeyboardEvent) {
30
+ if (e.key === 'Escape') {
31
+ closeModal();
44
32
  }
45
- });
33
+ }
46
34
 
47
35
  function closeModal() {
48
- emit('update:open', false);
49
- emit('close');
36
+ openModal.value = false;
37
+
38
+ setTimeout(() => openBackground.value = false, props.fullscreen ? 0 : 100);
39
+ document.removeEventListener('keydown', onKeydown);
40
+
41
+ setTimeout(
42
+ () => {
43
+ emit('close');
44
+ },
45
+ // Wait finishing the close animation
46
+ 400,
47
+ );
50
48
  }
49
+
50
+ onMounted(() => {
51
+ openBackground.value = true;
52
+ setTimeout(() => openModal.value = true, props.fullscreen ? 0 : 100);
53
+ document.addEventListener('keydown', onKeydown);
54
+ });
51
55
  </script>
52
56
 
53
57
  <template>
@@ -28,12 +28,7 @@ const Docs = exports.Docs = {
28
28
  AntKeycap: _AntKeycap.default
29
29
  },
30
30
  setup() {
31
- const open = (0, _vue.computed)({
32
- // @ts-ignore
33
- get: () => args.open,
34
- // @ts-ignore
35
- set: val => args.open = val
36
- });
31
+ const open = (0, _vue.ref)(false);
37
32
  return {
38
33
  args,
39
34
  open
@@ -60,7 +55,11 @@ const Docs = exports.Docs = {
60
55
  </div>
61
56
  <AntButton @click="() => open = true" state="primary">Open Modal</AntButton>
62
57
 
63
- <AntModal v-bind="args" v-model:open="open">
58
+ <AntModal
59
+ v-if="open"
60
+ v-bind="args"
61
+ @close="open = false"
62
+ >
64
63
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <br/>
65
64
  sed diam nonumy eirmod tempor invidunt <br/>
66
65
  ut labore et dolore magna aliquyam erat, <br/>
@@ -83,15 +82,13 @@ const Docs = exports.Docs = {
83
82
  `
84
83
  }),
85
84
  args: {
86
- title: "Lorem ipsum dolor",
87
- open: false
85
+ title: "Lorem ipsum dolor"
88
86
  }
89
87
  };
90
88
  const Fullscreen = exports.Fullscreen = {
91
89
  render: Docs.render,
92
90
  args: {
93
91
  ...Docs.args,
94
- open: true,
95
92
  fullscreen: true
96
93
  }
97
94
  };
@@ -1,7 +1,7 @@
1
1
  import AntModal from "../AntModal.vue";
2
2
  import AntButton from "../AntButton.vue";
3
3
  import {
4
- computed
4
+ ref
5
5
  } from "vue";
6
6
  import AntKeycap from "../AntKeycap.vue";
7
7
  const meta = {
@@ -23,12 +23,7 @@ export const Docs = {
23
23
  AntKeycap
24
24
  },
25
25
  setup() {
26
- const open = computed({
27
- // @ts-ignore
28
- get: () => args.open,
29
- // @ts-ignore
30
- set: (val) => args.open = val
31
- });
26
+ const open = ref(false);
32
27
  return {
33
28
  args,
34
29
  open
@@ -55,7 +50,11 @@ export const Docs = {
55
50
  </div>
56
51
  <AntButton @click="() => open = true" state="primary">Open Modal</AntButton>
57
52
 
58
- <AntModal v-bind="args" v-model:open="open">
53
+ <AntModal
54
+ v-if="open"
55
+ v-bind="args"
56
+ @close="open = false"
57
+ >
59
58
  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <br/>
60
59
  sed diam nonumy eirmod tempor invidunt <br/>
61
60
  ut labore et dolore magna aliquyam erat, <br/>
@@ -78,15 +77,13 @@ export const Docs = {
78
77
  `
79
78
  }),
80
79
  args: {
81
- title: "Lorem ipsum dolor",
82
- open: false
80
+ title: "Lorem ipsum dolor"
83
81
  }
84
82
  };
85
83
  export const Fullscreen = {
86
84
  render: Docs.render,
87
85
  args: {
88
86
  ...Docs.args,
89
- open: true,
90
87
  fullscreen: true
91
88
  }
92
89
  };
@@ -24,10 +24,20 @@ const props = withDefaults(defineProps<{
24
24
  showWeekend?: boolean;
25
25
  showTodayButton?: boolean;
26
26
  skeleton?: boolean;
27
+ /**
28
+ * To highlight specific days with a custom color e.g. legal holidays
29
+ * date have the following format: yyyy-mm-dd
30
+ */
31
+ specialDays?: {
32
+ name: string | null;
33
+ date: string;
34
+ color: string;
35
+ }[];
27
36
  }>(), {
28
37
  showWeekend: false,
29
38
  showTodayButton: true,
30
39
  skeleton: false,
40
+ specialDays: () => [],
31
41
  });
32
42
  defineEmits([
33
43
  'select',
@@ -68,6 +78,8 @@ const matrix = computed(() => {
68
78
  isCurrentMonth,
69
79
  isWeekend: weekdayIndex === 5 || weekdayIndex === 6,
70
80
  isToday: date === format(Date.now(), 'yyyy-MM-dd') && isCurrentMonth,
81
+ isSpecialDay: !!props.specialDays.find(specialDay => specialDay.date === date),
82
+ specialDayColor: props.specialDays.find(specialDay => specialDay.date === date)?.color,
71
83
  };
72
84
 
73
85
  currentDate = addDays(currentDate, 1);
@@ -102,6 +114,12 @@ const weekDays = computed(() => {
102
114
  ];
103
115
  });
104
116
 
117
+ const getColorNumber = (color: string) => {
118
+ const match = color.match(/(\d+)/);
119
+
120
+ return match ? parseInt(match[0], 10) : null;
121
+ };
122
+
105
123
  watch(() => props.modelValue, (val) => {
106
124
  const date = new Date(val);
107
125
  currentMonthIndex.value = date.getMonth();
@@ -156,7 +174,15 @@ watch(() => props.modelValue, (val) => {
156
174
  'text-for-white-bg-font': day.isCurrentMonth,
157
175
  'outline outline-primary-500': day.isToday,
158
176
  'hover:bg-base-200 hover:text-base-200-font': day.date !== format(modelValue, 'yyyy-MM-dd'),
159
- 'bg-primary-500 text-primary-500-font hover:bg-primary-300 hover:text-primary-300-font': day.date === format(modelValue, 'yyyy-MM-dd'),
177
+ '!bg-primary-500 !text-primary-500-font hover:bg-primary-300 hover:text-primary-300-font': day.date === format(modelValue, 'yyyy-MM-dd'),
178
+ }"
179
+ :style="{
180
+ backgroundColor: day.isSpecialDay ? `var(--color-${day.specialDayColor})` : 'none',
181
+ color: day.isSpecialDay
182
+ ? getColorNumber(day.specialDayColor) < 500
183
+ ? 'var(--color-for-white-bg-font)'
184
+ : '#fff'
185
+ : 'none'
160
186
  }"
161
187
  @click="() => $emit('update:modelValue', new Date(day.date).getTime())"
162
188
  >
@@ -7,6 +7,7 @@ module.exports = exports.Docs = void 0;
7
7
  var _AntDatePicker = _interopRequireDefault(require("../AntDatePicker.vue"));
8
8
  var _AntDateSwitcher = _interopRequireDefault(require("../AntDateSwitcher.vue"));
9
9
  var _vue = require("vue");
10
+ var _dateFns = require("date-fns");
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
12
  const meta = {
12
13
  title: "Components/Date Picker",
@@ -53,5 +54,11 @@ const Docs = exports.Docs = {
53
54
  </div>
54
55
  </div>`
55
56
  }),
56
- args: {}
57
+ args: {
58
+ specialDays: [{
59
+ name: "Special Day",
60
+ date: (0, _dateFns.format)((0, _dateFns.addDays)(/* @__PURE__ */new Date(), 1), "yyyy-MM-dd"),
61
+ color: "success-300"
62
+ }]
63
+ }
57
64
  };
@@ -3,6 +3,10 @@ import AntDateSwitcher from "../AntDateSwitcher.vue";
3
3
  import {
4
4
  ref
5
5
  } from "vue";
6
+ import {
7
+ addDays,
8
+ format
9
+ } from "date-fns";
6
10
  const meta = {
7
11
  title: "Components/Date Picker",
8
12
  component: AntCalendar,
@@ -48,5 +52,13 @@ export const Docs = {
48
52
  </div>
49
53
  </div>`
50
54
  }),
51
- args: {}
55
+ args: {
56
+ specialDays: [
57
+ {
58
+ name: "Special Day",
59
+ date: format(addDays(/* @__PURE__ */ new Date(), 1), "yyyy-MM-dd"),
60
+ color: "success-300"
61
+ }
62
+ ]
63
+ }
52
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antify/ui",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {