frappe-ui 0.1.233 → 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.story.vue +45 -1
- package/src/components/Select/Select.vue +8 -4
- 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";
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { ref } from 'vue'
|
|
3
3
|
import Select from './Select.vue'
|
|
4
4
|
import LucideUser from '~icons/lucide/user'
|
|
5
|
+
import LucideRotate from '~icons/lucide/rotate-ccw'
|
|
6
|
+
import { SelectItemText } from 'reka-ui'
|
|
5
7
|
|
|
6
8
|
const value = ref('')
|
|
7
9
|
const options = [
|
|
@@ -14,7 +16,7 @@ const options = [
|
|
|
14
16
|
]
|
|
15
17
|
</script>
|
|
16
18
|
<template>
|
|
17
|
-
<Story :layout="{ width:
|
|
19
|
+
<Story :layout="{ width: 300, type: 'grid' }">
|
|
18
20
|
<Variant title="Default">
|
|
19
21
|
<div class="p-2">
|
|
20
22
|
<Select :options="options" v-model="value" />
|
|
@@ -30,5 +32,47 @@ const options = [
|
|
|
30
32
|
</Select>
|
|
31
33
|
</div>
|
|
32
34
|
</Variant>
|
|
35
|
+
|
|
36
|
+
<Variant title="Custom footer slot">
|
|
37
|
+
<div class="p-2">
|
|
38
|
+
<Select :options="options" v-model="value">
|
|
39
|
+
<template #footer>
|
|
40
|
+
<div class="grid gap-1">
|
|
41
|
+
<hr />
|
|
42
|
+
<Button variant='ghost'>
|
|
43
|
+
<template #prefix>
|
|
44
|
+
<LucideRotate class="size-4 text-ink-gray-9" />
|
|
45
|
+
</template>
|
|
46
|
+
Reset
|
|
47
|
+
</Button>
|
|
48
|
+
</div>
|
|
49
|
+
</template>
|
|
50
|
+
</Select>
|
|
51
|
+
</div>
|
|
52
|
+
</Variant>
|
|
53
|
+
|
|
54
|
+
<Variant title="Custom option slot">
|
|
55
|
+
<div class="p-2">
|
|
56
|
+
<Select :options="options" v-model="value">
|
|
57
|
+
<template #option="{ option }">
|
|
58
|
+
<div class="inline-flex gap-2 items-center">
|
|
59
|
+
<Avatar
|
|
60
|
+
size="sm"
|
|
61
|
+
image="https://avatars.fastly.steamstatic.com/9ebf36bd3dc6c34f2d79ccf5d63e00eb7866321e_full.jpg"
|
|
62
|
+
/>
|
|
63
|
+
<SelectItemText> {{ option.label }} </SelectItemText>
|
|
64
|
+
</div>
|
|
65
|
+
</template>
|
|
66
|
+
</Select>
|
|
67
|
+
</div>
|
|
68
|
+
</Variant>
|
|
69
|
+
|
|
70
|
+
<Variant title="No suffix">
|
|
71
|
+
<div class="p-2">
|
|
72
|
+
<Select :options="options" v-model="value">
|
|
73
|
+
<template #suffix> {{ ' ' }} </template>
|
|
74
|
+
</Select>
|
|
75
|
+
</div>
|
|
76
|
+
</Variant>
|
|
33
77
|
</Story>
|
|
34
78
|
</template>
|
|
@@ -91,7 +91,9 @@ const selectOptions = computed(() => {
|
|
|
91
91
|
>
|
|
92
92
|
<slot name="prefix" />
|
|
93
93
|
<SelectValue :placeholder="props.placeholder" />
|
|
94
|
-
<
|
|
94
|
+
<slot name="suffix">
|
|
95
|
+
<LucideChevronDown class="size-4 text-ink-gray-4 ml-auto" />
|
|
96
|
+
</slot>
|
|
95
97
|
</SelectTrigger>
|
|
96
98
|
|
|
97
99
|
<SelectPortal>
|
|
@@ -102,17 +104,19 @@ const selectOptions = computed(() => {
|
|
|
102
104
|
>
|
|
103
105
|
<SelectViewport class="p-1 flex flex-col">
|
|
104
106
|
<SelectItem
|
|
105
|
-
v-for="
|
|
107
|
+
v-for="option in selectOptions"
|
|
106
108
|
:disabled="option.disabled"
|
|
107
|
-
:key="
|
|
109
|
+
:key="option.value"
|
|
108
110
|
:value="option.value"
|
|
109
111
|
:class="[sizeClasses, paddingClasses, fontSizeClasses]"
|
|
110
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"
|
|
111
113
|
>
|
|
112
114
|
<SelectItemText>
|
|
113
|
-
{{ option.label }}
|
|
115
|
+
<slot name="option" v-bind="{ option }">{{ option.label }}</slot>
|
|
114
116
|
</SelectItemText>
|
|
115
117
|
</SelectItem>
|
|
118
|
+
|
|
119
|
+
<slot name="footer" />
|
|
116
120
|
</SelectViewport>
|
|
117
121
|
</SelectContent>
|
|
118
122
|
</SelectPortal>
|
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'
|