frappe-ui 0.1.14 → 0.1.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frappe-ui",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "A set of components and utilities for rapid UI development",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -52,9 +52,11 @@ module.exports = {
52
52
  }
53
53
  ```
54
54
 
55
+ Now, you can import needed components and start using it:
56
+
55
57
  ```html
56
58
  <template>
57
- <button>Click me</button>
59
+ <Button>Click me</Button>
58
60
  </template>
59
61
  <script>
60
62
  import { Button } from 'frappe-ui'
@@ -149,7 +149,7 @@
149
149
  </template>
150
150
 
151
151
  <script>
152
- import { computed } from 'vue'
152
+ import { computed, ref } from 'vue'
153
153
  import {
154
154
  Dialog as HDialog,
155
155
  DialogPanel,
@@ -194,34 +194,27 @@ export default {
194
194
  handler(actions) {
195
195
  if (!actions) return
196
196
  this.dialogActions = actions.map((action) => {
197
- let _action = {
197
+ let loading = ref(false)
198
+ return {
198
199
  ...action,
199
- loading: action.loading || false,
200
- _onClick: action.onClick,
201
- onClick: () => this.handleAction(_action),
200
+ loading,
201
+ onClick: !action.onClick
202
+ ? this.close
203
+ : async () => {
204
+ loading.value = true
205
+ try {
206
+ await action.onClick()
207
+ } finally {
208
+ loading.value = false
209
+ }
210
+ },
202
211
  }
203
- return _action
204
212
  })
205
213
  },
206
214
  immediate: true,
207
215
  },
208
216
  },
209
217
  methods: {
210
- handleAction(action) {
211
- if (action._onClick && typeof action._onClick === 'function') {
212
- action.loading = true
213
- let result = action._onClick({ close: this.close })
214
- if (result && result.then) {
215
- result
216
- .then(() => (action.loading = false))
217
- .catch(() => (action.loading = false))
218
- } else {
219
- action.loading = false
220
- }
221
- } else {
222
- this.close()
223
- }
224
- },
225
218
  close() {
226
219
  this.open = false
227
220
  },
@@ -0,0 +1,21 @@
1
+ ## Props
2
+
3
+ ### Tabs
4
+
5
+ It is an array of objects which contains the following attributes:
6
+
7
+ 1. `label` is the name of the tab, it is required.
8
+ 2. `icon` is the icon to be shown in the tab, it accept component and it is
9
+ optional.
10
+ 3. You can add more attributes which can be used for custom rendering in the tab
11
+ header or content.
12
+
13
+ ### Options
14
+
15
+ Currently, it has only one option `indicatorLeft` which is used to set the left
16
+ position of the indicator in case of custom rendering. It is optional and
17
+ default value is `20`.
18
+
19
+ ## v-model
20
+
21
+ It is used to set the active tab or change the active tab. It is required.
@@ -28,7 +28,8 @@
28
28
  <div
29
29
  ref="indicator"
30
30
  class="absolute -bottom-px h-px bg-gray-900"
31
- :style="{ left: `${indicatorLeftValue}px` }"
31
+ :class="transitionClass"
32
+ :style="{ left: `${indicatorLeft}px` }"
32
33
  />
33
34
  </TabList>
34
35
  <TabPanels class="flex flex-1 overflow-hidden">
@@ -45,7 +46,6 @@
45
46
 
46
47
  <script setup>
47
48
  import { TabGroup, TabList, Tab, TabPanels, TabPanel } from '@headlessui/vue'
48
- import { TransitionPresets, useTransition } from '@vueuse/core'
49
49
  import { ref, watch, computed, onMounted, nextTick } from 'vue'
50
50
 
51
51
  const props = defineProps({
@@ -57,6 +57,12 @@ const props = defineProps({
57
57
  type: Number,
58
58
  default: 0,
59
59
  },
60
+ options: {
61
+ type: Object,
62
+ default: () => ({
63
+ indicatorLeft: 20,
64
+ }),
65
+ },
60
66
  })
61
67
 
62
68
  const emit = defineEmits(['update:modelValue'])
@@ -70,12 +76,8 @@ const tabRef = ref([])
70
76
  const indicator = ref(null)
71
77
  const tabsLength = ref(props.tabs?.length)
72
78
 
73
- let indicatorLeft = ref(0)
74
-
75
- const indicatorLeftValue = useTransition(indicatorLeft, {
76
- duration: 250,
77
- ease: TransitionPresets.easeOutCubic,
78
- })
79
+ const indicatorLeft = ref(props.options?.indicatorLeft)
80
+ const transitionClass = ref('')
79
81
 
80
82
  function moveIndicator(index) {
81
83
  if (index >= tabsLength.value) {
@@ -93,5 +95,10 @@ watch(changedIndex, (index) => {
93
95
  nextTick(() => moveIndicator(index))
94
96
  })
95
97
 
96
- onMounted(() => moveIndicator(changedIndex.value))
98
+ onMounted(() => {
99
+ moveIndicator(changedIndex.value)
100
+ nextTick(() => {
101
+ transitionClass.value = 'transition-all duration-300 ease-in-out'
102
+ })
103
+ })
97
104
  </script>
@@ -28,6 +28,8 @@ export function createDocumentResource(options, vm) {
28
28
  getConfig('defaultDocUpdateUrl') || 'frappe.client.set_value'
29
29
  let defaultDocDeleteUrl =
30
30
  getConfig('defaultDocDeleteUrl') || 'frappe.client.delete'
31
+ let defaultRunDocMethodUrl =
32
+ getConfig('defaultRunDocMethodUrl') || 'run_doc_method'
31
33
 
32
34
  let setValueOptions = {
33
35
  url: defaultDocUpdateUrl,
@@ -153,7 +155,7 @@ export function createDocumentResource(options, vm) {
153
155
  let { method, onSuccess, ...otherOptions } = methodOptions
154
156
  out[methodKey] = createResource(
155
157
  {
156
- url: 'run_doc_method',
158
+ url: defaultRunDocMethodUrl,
157
159
  makeParams(values) {
158
160
  return {
159
161
  dt: out.doctype,
@@ -30,6 +30,8 @@ export function createListResource(options, vm) {
30
30
  getConfig('defaultDocUpdateUrl') || 'frappe.client.set_value'
31
31
  let defaultDocDeleteUrl =
32
32
  getConfig('defaultDocDeleteUrl') || 'frappe.client.delete'
33
+ let defaultRunDocMethodUrl =
34
+ getConfig('defaultRunDocMethodUrl') || 'run_doc_method'
33
35
 
34
36
  let out = reactive({
35
37
  doctype: options.doctype,
@@ -165,7 +167,7 @@ export function createListResource(options, vm) {
165
167
  ),
166
168
  runDocMethod: createResource(
167
169
  {
168
- url: 'run_doc_method',
170
+ url: defaultRunDocMethodUrl,
169
171
  makeParams({ method, name, ...values }) {
170
172
  return {
171
173
  dt: out.doctype,
@@ -109,12 +109,16 @@ class FileUploadHandler {
109
109
  form_data.append('file_url', options.file_url)
110
110
  }
111
111
 
112
- if (options.doctype && options.docname) {
112
+ if (options.doctype) {
113
113
  form_data.append('doctype', options.doctype)
114
+ }
115
+
116
+ if (options.docname) {
114
117
  form_data.append('docname', options.docname)
115
- if (options.fieldname) {
116
- form_data.append('fieldname', options.fieldname)
117
- }
118
+ }
119
+
120
+ if (options.fieldname) {
121
+ form_data.append('fieldname', options.fieldname)
118
122
  }
119
123
 
120
124
  if (options.method) {