@sbc-connect/nuxt-forms 0.1.8 → 0.1.10
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/.env.example +10 -0
- package/CHANGELOG.md +20 -0
- package/app/components/Connect/ButtonControl/Buttons.vue +19 -0
- package/app/components/Connect/ButtonControl/Index.vue +59 -0
- package/app/components/Connect/ButtonControl/Wrapper.vue +10 -0
- package/app/components/Connect/Fieldset.vue +41 -0
- package/app/components/Connect/Form/Address/City.vue +20 -0
- package/app/components/Connect/Form/Address/Country.vue +94 -0
- package/app/components/Connect/Form/Address/DeliveryInstructions.vue +21 -0
- package/app/components/Connect/Form/Address/PostalCode.vue +37 -0
- package/app/components/Connect/Form/Address/Region.vue +107 -0
- package/app/components/Connect/Form/Address/Street.vue +52 -0
- package/app/components/Connect/Form/Address/StreetAdditional.vue +19 -0
- package/app/components/Connect/Form/Address/index.vue +112 -0
- package/app/components/Connect/Form/Input.vue +39 -0
- package/app/components/Connect/Form/Textarea.vue +38 -0
- package/app/components/Connect/Layout/Form.vue +22 -0
- package/app/components/HelloWorld/Forms.vue +2 -2
- package/app/composables/useButtonControl.ts +72 -0
- package/app/interfaces/connect-button-control.ts +17 -0
- package/app/layouts/ConnectForm.vue +5 -0
- package/app/types/forms-page-meta.d.ts +7 -0
- package/app/utils/isoCountriesList.ts +2036 -0
- package/i18n/locales/en-CA.ts +38 -0
- package/i18n/locales/fr-CA.ts +3 -0
- package/modules/form-assets/index.ts +15 -0
- package/modules/form-assets/runtime/assets/connect-form-tw.css +2 -0
- package/nuxt.config.ts +23 -2
- package/package.json +6 -6
- package/app/assets/css/tw-forms.css +0 -2
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{
|
|
3
|
+
name: string
|
|
4
|
+
label: string
|
|
5
|
+
help?: string
|
|
6
|
+
inputId: string
|
|
7
|
+
required?: boolean
|
|
8
|
+
autofocus?: boolean
|
|
9
|
+
disabled?: boolean
|
|
10
|
+
}>()
|
|
11
|
+
|
|
12
|
+
const model = defineModel<string>({ required: true })
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<UFormField
|
|
17
|
+
:name
|
|
18
|
+
:help
|
|
19
|
+
class="grow flex-1"
|
|
20
|
+
>
|
|
21
|
+
<template #default="{ error }">
|
|
22
|
+
<ConnectTextarea
|
|
23
|
+
:id="inputId"
|
|
24
|
+
v-model="model"
|
|
25
|
+
:data-testid="inputId"
|
|
26
|
+
:required
|
|
27
|
+
:invalid="!!error"
|
|
28
|
+
:label
|
|
29
|
+
:autofocus
|
|
30
|
+
:disabled
|
|
31
|
+
/>
|
|
32
|
+
<div
|
|
33
|
+
v-if="!help && !error"
|
|
34
|
+
class="h-4 mt-1"
|
|
35
|
+
/>
|
|
36
|
+
</template>
|
|
37
|
+
</UFormField>
|
|
38
|
+
</template>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ConnectLayout>
|
|
3
|
+
<template #header>
|
|
4
|
+
<!-- Exposes the header slot of the base layout -->
|
|
5
|
+
<slot name="header">
|
|
6
|
+
<ConnectHeader />
|
|
7
|
+
</slot>
|
|
8
|
+
</template>
|
|
9
|
+
<template #body>
|
|
10
|
+
<!-- Exposes the body slot of the base layout -->
|
|
11
|
+
<slot name="body">
|
|
12
|
+
<div class="grow max-w-full overflow-hidden">
|
|
13
|
+
<slot />
|
|
14
|
+
</div>
|
|
15
|
+
</slot>
|
|
16
|
+
</template>
|
|
17
|
+
<template #footer>
|
|
18
|
+
<ConnectButtonControlWrapper />
|
|
19
|
+
<ConnectFooter />
|
|
20
|
+
</template>
|
|
21
|
+
</ConnectLayout>
|
|
22
|
+
</template>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const useButtonControl = () => {
|
|
2
|
+
const route = useRoute()
|
|
3
|
+
|
|
4
|
+
function setButtonControl(buttonControl: ConnectButtonControl) {
|
|
5
|
+
// @ts-expect-error; typescript complains about the object type being too large
|
|
6
|
+
route.meta.buttonControl = buttonControl
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getButtonControl(): ConnectButtonControl {
|
|
10
|
+
return route.meta.buttonControl as ConnectButtonControl
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function handleButtonLoading(reset: boolean, buttonGrp?: 'left' | 'right', buttonIndex?: number) {
|
|
14
|
+
// set button control for loading / disabling buttons on submit or save or reset to default
|
|
15
|
+
const updateButtonGrp = (buttonArray: ConnectButton[], grp: 'left' | 'right') => {
|
|
16
|
+
for (const [index, element] of buttonArray.entries()) {
|
|
17
|
+
if (reset) {
|
|
18
|
+
element.disabled = false
|
|
19
|
+
element.loading = false
|
|
20
|
+
} else {
|
|
21
|
+
element.loading = (grp === buttonGrp) && index === buttonIndex
|
|
22
|
+
element.disabled = !element.loading
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const buttonControl = getButtonControl()
|
|
27
|
+
// update left buttons with loading / disabled as required
|
|
28
|
+
updateButtonGrp(buttonControl.leftGroup.buttons, 'left')
|
|
29
|
+
// update right buttons with loading / disabled as required
|
|
30
|
+
updateButtonGrp(buttonControl.rightGroup.buttons, 'right')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function setAlertText(reset: boolean, grp?: 'left' | 'right', index?: number, text?: string) {
|
|
34
|
+
const resetButtonGrp = (buttonArray: ConnectButton[]) => {
|
|
35
|
+
for (const element of buttonArray) {
|
|
36
|
+
element.alertText = undefined
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// clear existing text
|
|
40
|
+
if (route.meta.buttonControl) {
|
|
41
|
+
route.meta.buttonControl.leftGroup.alertText = undefined
|
|
42
|
+
route.meta.buttonControl.rightGroup.alertText = undefined
|
|
43
|
+
resetButtonGrp(route.meta.buttonControl.leftGroup.buttons)
|
|
44
|
+
resetButtonGrp(route.meta.buttonControl.rightGroup.buttons)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// only continue if not resetting
|
|
48
|
+
if (!reset) {
|
|
49
|
+
// required for dom to clear existing content
|
|
50
|
+
// allows screenreader alert for the same content if set multiple times
|
|
51
|
+
await nextTick()
|
|
52
|
+
// set content
|
|
53
|
+
if (route.meta.buttonControl) {
|
|
54
|
+
if (index === undefined) {
|
|
55
|
+
route.meta.buttonControl.leftGroup.alertText = (grp === 'left') ? text : undefined
|
|
56
|
+
route.meta.buttonControl.rightGroup.alertText = (grp === 'right') ? text : undefined
|
|
57
|
+
} else if (grp === 'left' && route.meta.buttonControl.leftGroup.buttons[index]) {
|
|
58
|
+
route.meta.buttonControl.leftGroup.buttons[index].alertText = text
|
|
59
|
+
} else if (grp === 'right' && route.meta.buttonControl.rightGroup.buttons[index]) {
|
|
60
|
+
route.meta.buttonControl.rightGroup.buttons[index].alertText = text
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
getButtonControl,
|
|
68
|
+
setButtonControl,
|
|
69
|
+
handleButtonLoading,
|
|
70
|
+
setAlertText
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ButtonProps } from '@nuxt/ui'
|
|
2
|
+
|
|
3
|
+
export interface ConnectButton extends ButtonProps {
|
|
4
|
+
alertText?: string
|
|
5
|
+
removeAlertSpacing?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ConnectButtonGroup {
|
|
9
|
+
alertText?: string
|
|
10
|
+
buttons: ConnectButton[]
|
|
11
|
+
stacked?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ConnectButtonControl {
|
|
15
|
+
leftGroup: ConnectButtonGroup
|
|
16
|
+
rightGroup: ConnectButtonGroup
|
|
17
|
+
}
|