@sbc-connect/nuxt-forms 0.6.1 → 0.7.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @sbc-connect/nuxt-forms
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#144](https://github.com/bcgov/connect-nuxt/pull/144) [`3b9fddb`](https://github.com/bcgov/connect-nuxt/commit/3b9fddb1c634fa48c8f4426954cbb2a043f78ff1) Thanks [@eve-git](https://github.com/eve-git)! - Fix issue where postal code was not optional for certain countries.
8
+
9
+ ## 0.6.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#141](https://github.com/bcgov/connect-nuxt/pull/141) [`83c5627`](https://github.com/bcgov/connect-nuxt/commit/83c5627689a50d6fa27f12f2ab7b2ef65e752d0e) Thanks [@deetz99](https://github.com/deetz99)! - ConnectFieldset, ConnectFormFieldWrapper: Move error text to always be under label instead of wrapping. ConnectFieldset: add error border styling to card bodyVariant
14
+
3
15
  ## 0.6.1
4
16
 
5
17
  ### Patch Changes
@@ -4,7 +4,8 @@ import type { FormError } from '@nuxt/ui'
4
4
  const {
5
5
  orientation = 'horizontal',
6
6
  bodyVariant = 'none',
7
- paddingClass = 'x-default'
7
+ paddingClass = 'x-default',
8
+ error
8
9
  } = defineProps<{
9
10
  label?: string
10
11
  description?: string
@@ -19,12 +20,15 @@ const id = useId()
19
20
  const legendId = id + '-legend'
20
21
  const descriptionId = id + '-description'
21
22
 
22
- const bodyClassMap: Record<FieldsetBodyVariant, string> = {
23
- none: '',
24
- card: 'bg-white rounded shadow-xs'
25
- }
23
+ const bodyClassMap = computed<Record<FieldsetBodyVariant, string>>(() => {
24
+ const cardError = error ? 'border-error border-l-3' : 'border-transparent border-l-3'
25
+ return {
26
+ none: '',
27
+ card: 'bg-white rounded shadow-xs ' + cardError
28
+ }
29
+ })
26
30
 
27
- const bodyClass = bodyClassMap[bodyVariant]
31
+ const bodyClass = computed(() => bodyClassMap.value[bodyVariant])
28
32
 
29
33
  const padding = paddingClass === 'x-default'
30
34
  ? 'px-4 sm:px-8'
@@ -52,7 +56,7 @@ const padding = paddingClass === 'x-default'
52
56
  class="text-base text-neutral-highlighted font-bold"
53
57
  >
54
58
  <slot name="label">
55
- <div class="flex flex-wrap gap-4">
59
+ <div class="flex flex-col gap-1">
56
60
  <span>{{ label }}</span>
57
61
  <span
58
62
  v-if="error && typeof error === 'object' && 'message' in error && showErrorMsg"
@@ -7,6 +7,14 @@ defineProps<{
7
7
  required?: boolean
8
8
  }>()
9
9
 
10
+ const isOptionalPostalCodeCountry = (country?: string) => {
11
+ if (!country) {
12
+ return false
13
+ }
14
+
15
+ return isNoPostalCodeCountry(country)
16
+ }
17
+
10
18
  const model = defineModel<string | undefined>({
11
19
  set(value) {
12
20
  if (value) {
@@ -24,10 +32,12 @@ const model = defineModel<string | undefined>({
24
32
  :data-testid="`${parentId}-field-postalCode`"
25
33
  :input-id="`${parentId}-input-postalCode`"
26
34
  :disabled
27
- :required
35
+ :required="required && !isOptionalPostalCodeCountry(country)"
28
36
  :label="country === 'US'
29
37
  ? $t('connect.label.zipCode')
30
- : $t('connect.label.postalCode')
38
+ : isOptionalPostalCodeCountry(country)
39
+ ? $t('connect.label.postalCodeOpt')
40
+ : $t('connect.label.postalCode')
31
41
  "
32
42
  :mask="country === 'CA'
33
43
  ? '*** ***'
@@ -33,7 +33,7 @@ const padding = paddingClass === 'x-default'
33
33
  class="text-base text-neutral-highlighted font-bold"
34
34
  :class="{ 'w-full sm:basis-1/4': orientation === 'horizontal' }"
35
35
  >
36
- <div class="flex gap-2.5" :class="orientation === 'horizontal' ? 'flex-col' : 'flex-wrap'">
36
+ <div class="flex flex-col gap-1">
37
37
  <span>{{ label }}</span>
38
38
  <span
39
39
  v-if="error && typeof error === 'object' && 'message' in error && showErrorMsg"
@@ -2034,3 +2034,15 @@ export const isoCountriesListSortedByName = isoCountriesList.toSorted(
2034
2034
  return 0
2035
2035
  }
2036
2036
  )
2037
+
2038
+ const NO_POSTAL_CODE_COUNTRY_CODES = [
2039
+ 'AO', 'AG', 'AW', 'BS', 'BZ', 'BJ', 'BM', 'BO', 'BQ', 'BW', 'BF', 'BI',
2040
+ 'CM', 'CF', 'TD', 'KM', 'CG', 'CD', 'CK', 'CI', 'CW', 'DJ', 'DM', 'GQ',
2041
+ 'ER', 'FJ', 'TF', 'GA', 'GM', 'GH', 'GD', 'GY', 'HM', 'HK',
2042
+ 'KI', 'KP', 'LY', 'MO', 'MW', 'ML', 'MR', 'NR',
2043
+ 'AN', 'NU', 'QA', 'RW', 'KN', 'ST', 'SC', 'SL', 'SX', 'SB', 'SO', 'SR', 'SY',
2044
+ 'TL', 'TG', 'TK', 'TO', 'TT', 'TV', 'UG', 'AE', 'VU', 'YE', 'ZW'
2045
+ ]
2046
+ export function isNoPostalCodeCountry(countryCode: string): boolean {
2047
+ return NO_POSTAL_CODE_COUNTRY_CODES.indexOf(countryCode) !== -1
2048
+ }
@@ -55,6 +55,7 @@ export function getRequiredAddressSchema() {
55
55
  }
56
56
 
57
57
  const isRequiredRegion = country === 'US' || country === 'CA'
58
+ const isRequiredPostalCode = !!country && !isNoPostalCodeCountry(country)
58
59
 
59
60
  if (isRequiredRegion) {
60
61
  if (!region) {
@@ -64,14 +65,14 @@ export function getRequiredAddressSchema() {
64
65
  path: ['region']
65
66
  })
66
67
  }
68
+ }
67
69
 
68
- if (!postalCode) {
69
- ctx.addIssue({
70
- code: 'custom',
71
- message: t('connect.validation.fieldRequired'),
72
- path: ['postalCode']
73
- })
74
- }
70
+ if (isRequiredPostalCode && !postalCode) {
71
+ ctx.addIssue({
72
+ code: 'custom',
73
+ message: t('connect.validation.fieldRequired'),
74
+ path: ['postalCode']
75
+ })
75
76
  }
76
77
 
77
78
  if (!postalCode) {
@@ -17,6 +17,7 @@ export default {
17
17
  locationDescriptionOpt: 'Location Description (Optional)',
18
18
  mailingAddress: 'Mailing Address',
19
19
  postalCode: 'Postal Code',
20
+ postalCodeOpt: 'Postal Code (Optional)',
20
21
  province: 'Province',
21
22
  region: 'Region',
22
23
  regionOpt: 'Region (Optional)',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sbc-connect/nuxt-forms",
3
3
  "type": "module",
4
- "version": "0.6.1",
4
+ "version": "0.7.0",
5
5
  "repository": "github:bcgov/connect-nuxt",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "./nuxt.config.ts",