frappe-ui 0.1.234 → 0.1.235
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.
- package/package.json +1 -1
- package/src/components/MonthPicker/MonthPicker.story.vue +21 -0
- package/src/components/MonthPicker/MonthPicker.vue +116 -0
- package/src/components/MonthPicker/index.ts +1 -0
- package/src/components/MonthPicker/types.ts +3 -0
- package/src/components/Select/Select.vue +5 -7
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import MonthPicker from './MonthPicker.vue'
|
|
4
|
+
const val = ref('')
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<Story :layout="{ type: 'grid', width: 500 }">
|
|
9
|
+
<Variant title="Default">
|
|
10
|
+
<div class="p-2">
|
|
11
|
+
<MonthPicker v-model="val" />
|
|
12
|
+
</div>
|
|
13
|
+
</Variant>
|
|
14
|
+
|
|
15
|
+
<Variant title="Fit width">
|
|
16
|
+
<div class="p-2">
|
|
17
|
+
<MonthPicker v-model="val" class="w-fit" />
|
|
18
|
+
</div>
|
|
19
|
+
</Variant>
|
|
20
|
+
</Story>
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import { MonthPickerProps } from './types'
|
|
4
|
+
|
|
5
|
+
import Popover from '../Popover/Popover.vue'
|
|
6
|
+
import LucideCalender from '~icons/lucide/calendar'
|
|
7
|
+
import LucideChevronLeft from '~icons/lucide/chevron-left'
|
|
8
|
+
import LucideChevronRight from '~icons/lucide/chevron-right'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<MonthPickerProps>(), {
|
|
11
|
+
placeholder: 'Select month',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const viewMode = ref('month')
|
|
15
|
+
const model = defineModel<String>({ default: '' })
|
|
16
|
+
|
|
17
|
+
const months = [
|
|
18
|
+
'January',
|
|
19
|
+
'February',
|
|
20
|
+
'March',
|
|
21
|
+
'April',
|
|
22
|
+
'May',
|
|
23
|
+
'June',
|
|
24
|
+
'July',
|
|
25
|
+
'August',
|
|
26
|
+
'September',
|
|
27
|
+
'October',
|
|
28
|
+
'November',
|
|
29
|
+
'December',
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
const currentYear = ref(new Date().getFullYear())
|
|
33
|
+
|
|
34
|
+
const yearRangeStart = computed(
|
|
35
|
+
() => currentYear.value - (currentYear.value % 12),
|
|
36
|
+
)
|
|
37
|
+
const yearRange = computed(() =>
|
|
38
|
+
Array.from({ length: 12 }, (_, i) => yearRangeStart.value + i),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const pickerList = computed(() =>
|
|
42
|
+
viewMode.value == 'year' ? yearRange.value : months,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const toggleViewMode = () => {
|
|
46
|
+
viewMode.value = viewMode.value == 'year' ? 'month' : 'year'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const handleOnClick = (v: string | number) => {
|
|
50
|
+
let ar = model.value.split(' ')
|
|
51
|
+
const indexToModify = viewMode.value == 'year' ? 1 : 0
|
|
52
|
+
ar[indexToModify] = String(v)
|
|
53
|
+
model.value = ar.join(' ')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const prevClick = () => {
|
|
57
|
+
currentYear.value += viewMode.value == 'year' ? -12 : -1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const nextClick = () => {
|
|
61
|
+
currentYear.value += viewMode.value == 'year' ? 12 : 1
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const formatBtn = (v: string | number) =>
|
|
65
|
+
viewMode.value == 'month' ? (v as String).slice(0, 3) : v
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<Popover
|
|
70
|
+
popover-class="mt-2 shadow-xl rounded-lg border bg-surface-modal p-2"
|
|
71
|
+
>
|
|
72
|
+
<template #target="{ togglePopover }">
|
|
73
|
+
<Button @click="togglePopover" class="w-full justify-between">
|
|
74
|
+
{{ model || props.placeholder }}
|
|
75
|
+
<template #suffix> <LucideCalender class="size-4" /> </template>
|
|
76
|
+
</Button>
|
|
77
|
+
</template>
|
|
78
|
+
|
|
79
|
+
<template #body>
|
|
80
|
+
<div class="flex gap-2 justify-between">
|
|
81
|
+
<Button variant="ghost" @click="prevClick">
|
|
82
|
+
<LucideChevronLeft class="size-4 text-ink-gray-5" />
|
|
83
|
+
</Button>
|
|
84
|
+
|
|
85
|
+
<!-- view toggler -->
|
|
86
|
+
<Button @click="toggleViewMode">
|
|
87
|
+
<template v-if="viewMode == 'month'">
|
|
88
|
+
{{ model.split(' ')[1] ?? currentYear }}
|
|
89
|
+
</template>
|
|
90
|
+
<template v-else>
|
|
91
|
+
{{ yearRangeStart }} - {{ yearRangeStart + 11 }}
|
|
92
|
+
</template>
|
|
93
|
+
</Button>
|
|
94
|
+
|
|
95
|
+
<Button variant="ghost" @click="nextClick">
|
|
96
|
+
<LucideChevronRight class="size-4 text-ink-gray-5" />
|
|
97
|
+
</Button>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<hr class="my-2" />
|
|
101
|
+
|
|
102
|
+
<!-- picker btns -->
|
|
103
|
+
<div class="grid grid-cols-3 gap-3">
|
|
104
|
+
<Button
|
|
105
|
+
v-for="x in pickerList"
|
|
106
|
+
@click="() => handleOnClick(x)"
|
|
107
|
+
:variant="model.includes(String(x)) ? 'solid' : 'ghost'"
|
|
108
|
+
:key="x"
|
|
109
|
+
class="text-sm text-ink-gray-9"
|
|
110
|
+
>
|
|
111
|
+
{{ formatBtn(x) }}
|
|
112
|
+
</Button>
|
|
113
|
+
</div>
|
|
114
|
+
</template>
|
|
115
|
+
</Popover>
|
|
116
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MonthPicker } from "./MonthPicker.vue";
|
|
@@ -104,18 +104,16 @@ const selectOptions = computed(() => {
|
|
|
104
104
|
>
|
|
105
105
|
<SelectViewport class="p-1 flex flex-col">
|
|
106
106
|
<SelectItem
|
|
107
|
-
v-for="
|
|
107
|
+
v-for="option in selectOptions"
|
|
108
108
|
:disabled="option.disabled"
|
|
109
|
-
:key="
|
|
109
|
+
:key="option.value"
|
|
110
110
|
:value="option.value"
|
|
111
111
|
:class="[sizeClasses, paddingClasses, fontSizeClasses]"
|
|
112
112
|
class="text-base text-ink-gray-9 flex items-center relative data-[highlighted]:bg-surface-gray-2 border-0 [data-state=checked]:bg-surface-gray-2 data-[disabled]:text-ink-gray-4"
|
|
113
113
|
>
|
|
114
|
-
<
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
</SelectItemText>
|
|
118
|
-
</slot>
|
|
114
|
+
<SelectItemText>
|
|
115
|
+
<slot name="option" v-bind="{ option }">{{ option.label }}</slot>
|
|
116
|
+
</SelectItemText>
|
|
119
117
|
</SelectItem>
|
|
120
118
|
|
|
121
119
|
<slot name="footer" />
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { default as Card } from './components/Card.vue'
|
|
|
10
10
|
export * from './components/Combobox'
|
|
11
11
|
export * from './components/Checkbox'
|
|
12
12
|
export * from './components/DatePicker'
|
|
13
|
+
export * from './components/MonthPicker'
|
|
13
14
|
export * from './components/Dialog'
|
|
14
15
|
export { default as Dialogs } from './components/Dialogs.vue'
|
|
15
16
|
export * from './components/Divider'
|