Skip to content

Commit fe8c9d2

Browse files
committed
feat(@dpc-sdp/ripple-ui-forms): add rplEvents to all field types
1 parent e09a114 commit fe8c9d2

File tree

16 files changed

+220
-31
lines changed

16 files changed

+220
-31
lines changed

packages/ripple-ui-forms/src/components/RplFormAlert/RplFormAlert.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useMediaQuery } from '@vueuse/core'
66
interface Props {
77
status: 'error' | 'success'
88
title: string
9-
fields: {
9+
fields?: {
1010
fieldId: string
1111
text: string
1212
}[]

packages/ripple-ui-forms/src/components/RplFormDate/RplFormDate.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { watch, ref } from 'vue'
99
import { format, isMatch, isValid, parse } from 'date-fns'
1010
import RplFormInput from '../RplFormInput/RplFormInput.vue'
1111
import useFormkitFriendlyEventEmitter from '../../composables/useFormkitFriendlyEventEmitter.js'
12+
import { useRippleEvent } from '@dpc-sdp/ripple-ui-core'
13+
import type { rplEventPayload } from '@dpc-sdp/ripple-ui-core'
1214
1315
type DatePart = 'day' | 'month' | 'year'
1416
interface InternalDate {
@@ -20,6 +22,7 @@ interface InternalDate {
2022
interface Props {
2123
id: string
2224
name: string
25+
label?: string
2326
disabled?: boolean
2427
required: boolean
2528
invalid?: boolean | DatePart[]
@@ -33,11 +36,17 @@ const props = withDefaults(defineProps<Props>(), {
3336
disabled: false,
3437
required: false,
3538
invalid: false,
39+
label: undefined,
3640
variant: 'default',
3741
dateFormat: 'yyyy-MM-dd'
3842
})
3943
40-
const emit = defineEmits<{ (e: 'onChange', value: string[]): void }>()
44+
const emit = defineEmits<{
45+
(e: 'onChange', value: string[]): void
46+
(e: 'update', payload: rplEventPayload & { action: 'exit' }): void
47+
}>()
48+
49+
const { emitRplEvent } = useRippleEvent('rpl-form-input', emit)
4150
4251
const ingestValue = (dateStr: string): InternalDate | null => {
4352
// An empty external value is valid, so we should clear all the inputs
@@ -198,6 +207,20 @@ const isPartInvalid = (part: DatePart) => {
198207
199208
return false
200209
}
210+
211+
const handleUpdate = (event) => {
212+
emitRplEvent(
213+
'update',
214+
{
215+
...event,
216+
id: props.id,
217+
field: 'date',
218+
label: props?.label,
219+
value: `${internalDay.value}-${internalMonth.value}-${internalYear.value}`
220+
},
221+
{ global: true }
222+
)
223+
}
201224
</script>
202225

203226
<template>
@@ -220,6 +243,8 @@ const isPartInvalid = (part: DatePart) => {
220243
:disabled="disabled"
221244
:required="required"
222245
:invalid="isPartInvalid('day')"
246+
:global-events="false"
247+
@update="handleUpdate"
223248
@input="handleChangeDay"
224249
/>
225250
</div>
@@ -240,6 +265,8 @@ const isPartInvalid = (part: DatePart) => {
240265
:disabled="disabled"
241266
:required="required"
242267
:invalid="isPartInvalid('month')"
268+
:global-events="false"
269+
@update="handleUpdate"
243270
@input="handleChangeMonth"
244271
/>
245272
</div>
@@ -260,6 +287,8 @@ const isPartInvalid = (part: DatePart) => {
260287
:disabled="disabled"
261288
:required="required"
262289
:invalid="isPartInvalid('day')"
290+
:global-events="false"
291+
@update="handleUpdate"
263292
@input="handleChangeYear"
264293
/>
265294
</div>

packages/ripple-ui-forms/src/components/RplFormDropdown/RplFormDropdown.vue

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ export default {
66

77
<script setup lang="ts">
88
import { RplIcon } from '@dpc-sdp/ripple-ui-core/vue'
9-
import { computed, ref, watch, nextTick } from 'vue'
9+
import { computed, ref, watch, nextTick, inject } from 'vue'
1010
import { onClickOutside } from '@vueuse/core'
1111
import useFormkitFriendlyEventEmitter from '../../composables/useFormkitFriendlyEventEmitter'
1212
import MultiValueLabel from './MultiValueLabel.vue'
13+
import { useRippleEvent } from '@dpc-sdp/ripple-ui-core'
14+
import type { rplEventPayload } from '@dpc-sdp/ripple-ui-core'
1315
1416
export interface RplFormDropdownProps {
1517
id: string
18+
label?: string
1619
labelId: string
1720
value?: string | string[]
1821
disabled?: boolean
@@ -32,6 +35,7 @@ export interface RplFormDropdownProps {
3235
3336
const props = withDefaults(defineProps<RplFormDropdownProps>(), {
3437
value: undefined,
38+
label: undefined,
3539
disabled: false,
3640
variant: 'default',
3741
placeholder: 'Select',
@@ -43,7 +47,13 @@ const props = withDefaults(defineProps<RplFormDropdownProps>(), {
4347
multiple: false
4448
})
4549
46-
const emit = defineEmits<{ (e: 'onChange', value: string[]): void }>()
50+
const emit = defineEmits<{
51+
(e: 'onChange', value: string[]): void
52+
(e: 'update', payload: rplEventPayload & { action: 'select' }): void
53+
}>()
54+
55+
const form: object = inject('form')
56+
const { emitRplEvent } = useRippleEvent('rpl-form-input', emit)
4757
4858
const containerRef = ref(null)
4959
const inputRef = ref(null)
@@ -138,9 +148,9 @@ const handleArrowDown = () => {
138148
}
139149
140150
const handleSelectOption = (optionValue) => {
141-
if (props.multiple) {
142-
let newValue
151+
let newValue = optionValue
143152
153+
if (props.multiple) {
144154
if (!Array.isArray(props.value)) {
145155
// Value is empty, just create a new array
146156
newValue = [optionValue]
@@ -156,8 +166,22 @@ const handleSelectOption = (optionValue) => {
156166
useFormkitFriendlyEventEmitter(props, emit, 'onChange', newValue)
157167
} else {
158168
handleClose(true)
159-
useFormkitFriendlyEventEmitter(props, emit, 'onChange', optionValue)
169+
useFormkitFriendlyEventEmitter(props, emit, 'onChange', newValue)
160170
}
171+
172+
emitRplEvent(
173+
'update',
174+
{
175+
action: 'select',
176+
field: 'dropdown',
177+
id: props.id,
178+
label: props?.label,
179+
value: newValue,
180+
contextId: form?.id,
181+
contextName: form?.name
182+
},
183+
{ global: true }
184+
)
161185
}
162186
163187
const isOptionSelected = (optionValue) => {

packages/ripple-ui-forms/src/components/RplFormInput/RplFormInput.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import type { rplEventPayload } from '@dpc-sdp/ripple-ui-core'
1414
interface Props {
1515
id: string
1616
disabled?: boolean
17-
className: string
17+
className?: string
1818
value?: string
19-
type: string
19+
type?: string
2020
name: string
21+
label?: string
2122
prefixIcon?: string
2223
suffixIcon?: string
2324
minlength?: number
@@ -29,6 +30,7 @@ interface Props {
2930
invalid?: boolean
3031
required?: boolean
3132
centeredText?: boolean
33+
globalEvents?: boolean
3234
onInput: (payload: Event) => void
3335
onBlur: (payload: Event) => void
3436
}
@@ -37,6 +39,7 @@ const props = withDefaults(defineProps<Props>(), {
3739
type: 'text',
3840
className: 'rpl-form__input',
3941
value: undefined,
42+
label: undefined,
4043
prefixIcon: undefined,
4144
suffixIcon: undefined,
4245
minlength: undefined,
@@ -49,6 +52,7 @@ const props = withDefaults(defineProps<Props>(), {
4952
invalid: false,
5053
variant: 'default',
5154
centeredText: false,
55+
globalEvents: true,
5256
onInput: () => null,
5357
onBlur: () => null
5458
})
@@ -57,9 +61,8 @@ const emit = defineEmits<{
5761
(e: 'update', payload: rplEventPayload & { action: 'exit' }): void
5862
}>()
5963
60-
const { emitRplEvent } = useRippleEvent('rpl-form-input', emit)
61-
6264
const form: object = inject('form')
65+
const { emitRplEvent } = useRippleEvent('rpl-form-input', emit)
6366
6467
const classes = computed(() => {
6568
return {
@@ -81,14 +84,15 @@ const handleChange = () => {
8184
'update',
8285
{
8386
action: 'exit',
87+
field: 'input',
8488
id: props.id,
8589
type: props.type,
86-
label: props.name,
90+
label: props?.label,
8791
value: props.value,
8892
contextId: form?.id,
8993
contextName: form?.name
9094
},
91-
{ global: true }
95+
{ global: props.globalEvents }
9296
)
9397
}
9498
</script>

packages/ripple-ui-forms/src/components/RplFormOptionButtons/RplFormOptionButtons.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<script setup lang="ts">
22
import useFormkitFriendlyEventEmitter from '../../composables/useFormkitFriendlyEventEmitter'
3+
import { inject } from 'vue'
4+
import { useRippleEvent } from '@dpc-sdp/ripple-ui-core'
5+
import type { rplEventPayload } from '@dpc-sdp/ripple-ui-core'
36
47
export interface Props {
58
id: string
69
name: string
710
value: string
11+
label?: string
812
disabled?: boolean
913
perfectSquares?: boolean
1014
onChange: (value: string) => void
@@ -16,6 +20,7 @@ export interface Props {
1620
}
1721
1822
const props = withDefaults(defineProps<Props>(), {
23+
label: undefined,
1924
disabled: false,
2025
variant: 'default',
2126
layout: 'block',
@@ -24,11 +29,30 @@ const props = withDefaults(defineProps<Props>(), {
2429
options: () => []
2530
})
2631
27-
const emit = defineEmits<{ (e: 'onChange', value: string[]): void }>()
32+
const emit = defineEmits<{
33+
(e: 'onChange', value: string[]): void
34+
(e: 'update', payload: rplEventPayload & { action: 'select' }): void
35+
}>()
36+
37+
const form: object = inject('form')
38+
const { emitRplEvent } = useRippleEvent('rpl-form-input', emit)
2839
2940
const handleChange = (selectedId: string) => {
30-
// TODO - Wire up event bus handling here
3141
useFormkitFriendlyEventEmitter(props, emit, 'onChange', selectedId)
42+
43+
emitRplEvent(
44+
'update',
45+
{
46+
action: 'select',
47+
field: 'option-buttons',
48+
id: props.id,
49+
label: props?.label,
50+
value: selectedId,
51+
contextId: form?.id,
52+
contextName: form?.name
53+
},
54+
{ global: true }
55+
)
3256
}
3357
3458
const isChecked = (optionId: string): boolean => {

packages/ripple-ui-forms/src/components/RplFormOptions/RplFormCheckboxGroup.vue

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<script setup lang="ts">
22
import RplFormOption from './RplFormOption.vue'
33
import useFormkitFriendlyEventEmitter from '../../composables/useFormkitFriendlyEventEmitter'
4+
import { inject } from 'vue'
5+
import { useRippleEvent } from '@dpc-sdp/ripple-ui-core'
6+
import type { rplEventPayload } from '@dpc-sdp/ripple-ui-core'
47
58
interface Props {
69
id: string
710
value: string[]
11+
label?: string
812
disabled?: boolean
913
variant?: 'default' | 'reverse'
1014
onChange: (value: string[]) => void
@@ -17,13 +21,20 @@ interface Props {
1721
}
1822
1923
const props = withDefaults(defineProps<Props>(), {
24+
label: undefined,
2025
disabled: false,
2126
variant: 'default',
2227
onChange: () => undefined,
2328
options: () => []
2429
})
2530
26-
const emit = defineEmits<{ (e: 'onChange', value: string[]): void }>()
31+
const emit = defineEmits<{
32+
(e: 'onChange', value: string[]): void
33+
(e: 'update', payload: rplEventPayload & { action: 'select' }): void
34+
}>()
35+
36+
const form: object = inject('form')
37+
const { emitRplEvent } = useRippleEvent('rpl-form-input', emit)
2738
2839
const handleToggle = (selectedValue: string) => {
2940
let newValue
@@ -41,8 +52,21 @@ const handleToggle = (selectedValue: string) => {
4152
newValue = [...props.value, selectedValue]
4253
}
4354
44-
// TODO - Wire up event bus handling here
4555
useFormkitFriendlyEventEmitter(props, emit, 'onChange', newValue)
56+
57+
emitRplEvent(
58+
'update',
59+
{
60+
action: 'select',
61+
id: props.id,
62+
field: 'checkbox-group',
63+
label: props?.label,
64+
value: newValue,
65+
contextId: form?.id,
66+
contextName: form?.name
67+
},
68+
{ global: true }
69+
)
4670
}
4771
4872
const isChecked = (optionValue: string): boolean => {
@@ -63,6 +87,7 @@ const isChecked = (optionValue: string): boolean => {
6387
:label="option.label"
6488
:disabled="disabled || option.disabled"
6589
:checked="isChecked(option.value)"
90+
:global-events="false"
6691
@on-change="handleToggle(option.value)"
6792
/>
6893
</div>

0 commit comments

Comments
 (0)