fds-vue-core 7.2.7 → 8.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fds-vue-core",
3
- "version": "7.2.7",
3
+ "version": "8.0.0",
4
4
  "description": "FDS Vue Core Component Library",
5
5
  "type": "module",
6
6
  "main": "./dist/fds-vue-core.cjs.js",
@@ -15,7 +15,6 @@ const meta: Meta<typeof FdsPhonenumber> = {
15
15
  invalidMessage: { control: 'text' },
16
16
  defaultCountry: { control: 'text' },
17
17
  locale: { control: 'text' },
18
- numberType: { control: 'select', options: ['mobile', 'any'] },
19
18
  },
20
19
  args: {
21
20
  label: 'Telefonnummer',
@@ -80,37 +79,6 @@ export const InvalidNumber: Story = {
80
79
  }),
81
80
  }
82
81
 
83
- export const AllowAnyNumberType: Story = {
84
- args: {
85
- numberType: 'any',
86
- meta: 'Mobil och fast telefon accepteras (t.ex. Stockholm 08 + 6–7 siffror)',
87
- },
88
- render: (args) => ({
89
- components: { FdsPhonenumber },
90
- setup() {
91
- // Stockholm: 08 + 7 siffror
92
- const number = ref('081234567')
93
- const country = ref('SE')
94
- const phoneValid = ref<boolean | null>(null)
95
- const e164 = ref('')
96
- return { args, number, country, phoneValid, e164 }
97
- },
98
- template: `
99
- <div>
100
- <FdsPhonenumber
101
- v-bind="args"
102
- v-model="number"
103
- v-model:country="country"
104
- @valid="phoneValid = $event"
105
- @update:e164="e164 = $event"
106
- />
107
- <p class="mt-4 text-sm">valid: {{ phoneValid }}</p>
108
- <p class="text-sm">E.164: {{ e164 || '—' }}</p>
109
- </div>
110
- `,
111
- }),
112
- }
113
-
114
82
  export const EnglishLocale: Story = {
115
83
  args: {
116
84
  locale: 'en',
@@ -34,7 +34,6 @@ const props = withDefaults(defineProps<FdsPhonenumberProps>(), {
34
34
  defaultCountry: 'SE',
35
35
  countries: undefined,
36
36
  locale: undefined,
37
- numberType: 'mobile',
38
37
  disabled: false,
39
38
  dataTestid: undefined,
40
39
  selectClass: undefined,
@@ -78,8 +77,6 @@ const countryItems = computed(() => {
78
77
  )
79
78
  })
80
79
 
81
- const phoneValidationOptions = computed(() => ({ numberType: props.numberType }))
82
-
83
80
  /** Set after the phone number field has blurred; validation does not run on input. */
84
81
  const committedValid = ref<boolean | null>(null)
85
82
 
@@ -104,19 +101,15 @@ const showInvalidMessage = computed(
104
101
  const noCountryResults = ref(false)
105
102
 
106
103
  function runValidation() {
107
- const validationState = getPhoneValidationState(
108
- nationalNumber.value ?? '',
109
- country.value ?? 'SE',
110
- phoneValidationOptions.value,
111
- )
104
+ const validationState = getPhoneValidationState(nationalNumber.value ?? '', country.value ?? 'SE')
112
105
  committedValid.value = validationState
113
106
  emit('valid', validationState)
114
107
 
115
- const result = validatePhoneNumber(nationalNumber.value ?? '', country.value ?? 'SE', phoneValidationOptions.value)
108
+ const result = validatePhoneNumber(nationalNumber.value ?? '', country.value ?? 'SE')
116
109
  emit('update:e164', result.isValid && result.phoneNumber ? result.phoneNumber : '')
117
110
  }
118
111
 
119
- watch([country, () => props.numberType], () => {
112
+ watch(country, () => {
120
113
  if (committedValid.value === null) {
121
114
  return
122
115
  }
@@ -1,4 +1,4 @@
1
- import { getCountries, getCountryCallingCode } from 'libphonenumber-js/max'
1
+ import { getCountries, getCountryCallingCode } from 'libphonenumber-js/mobile'
2
2
 
3
3
  export interface CountryPhoneOption {
4
4
  value: string
@@ -1,12 +1,6 @@
1
1
  import type { FdsInputProps } from '../FdsInput/types'
2
2
  import type { CountryPhoneOption } from './countries'
3
3
 
4
- /**
5
- * `mobile` – mobile numbers only (Google libphonenumber metadata).
6
- * `any` – mobile and fixed-line numbers.
7
- */
8
- export type FdsPhonenumberNumberType = 'mobile' | 'any'
9
-
10
4
  type FdsPhonenumberInputPassthroughProps = Pick<
11
5
  FdsInputProps,
12
6
  | 'id'
@@ -37,8 +31,6 @@ export interface FdsPhonenumberProps extends FdsPhonenumberInputPassthroughProps
37
31
  countries?: CountryPhoneOption[]
38
32
  /** BCP 47 locale for country names in the list, e.g. `sv-SE` or `en`. Falls back to FDS i18n locale. */
39
33
  locale?: string
40
- /** Which number types are accepted when validating with libphonenumber-js. */
41
- numberType?: FdsPhonenumberNumberType
42
34
  disabled?: boolean
43
35
  dataTestid?: string
44
36
  selectClass?: string
@@ -1,9 +1,4 @@
1
- import parsePhoneNumberFromString, { type CountryCode, type NumberType } from 'libphonenumber-js/max'
2
- import type { FdsPhonenumberNumberType } from './types'
3
-
4
- interface ValidatePhoneOptions {
5
- numberType?: FdsPhonenumberNumberType
6
- }
1
+ import parsePhoneNumberFromString, { type CountryCode, type NumberType } from 'libphonenumber-js/mobile'
7
2
 
8
3
  /** Result shape kept stable for consumers (same fields as previous `phone` package integration). */
9
4
  export interface PhoneValidationResult {
@@ -23,16 +18,9 @@ const INVALID_RESULT: PhoneValidationResult = {
23
18
  }
24
19
 
25
20
  const MOBILE_NUMBER_TYPES = new Set<NumberType>(['MOBILE', 'FIXED_LINE_OR_MOBILE'])
26
- const ANY_NUMBER_TYPES = new Set<NumberType>(['MOBILE', 'FIXED_LINE', 'FIXED_LINE_OR_MOBILE'])
27
21
 
28
- function matchesNumberType(type: NumberType | undefined, numberType: FdsPhonenumberNumberType): boolean {
29
- if (!type) {
30
- return numberType === 'any'
31
- }
32
- if (numberType === 'mobile') {
33
- return MOBILE_NUMBER_TYPES.has(type)
34
- }
35
- return ANY_NUMBER_TYPES.has(type)
22
+ function isMobileNumberType(type: NumberType | undefined): boolean {
23
+ return type !== undefined && MOBILE_NUMBER_TYPES.has(type)
36
24
  }
37
25
 
38
26
  function buildCandidates(value: string): string[] {
@@ -60,11 +48,7 @@ function toValidationResult(parsed: NonNullable<ReturnType<typeof parsePhoneNumb
60
48
  }
61
49
  }
62
50
 
63
- function runPhoneValidation(
64
- value: string,
65
- countryIso2: string,
66
- numberType: FdsPhonenumberNumberType,
67
- ): PhoneValidationResult {
51
+ function runPhoneValidation(value: string, countryIso2: string): PhoneValidationResult {
68
52
  const country = countryIso2 as CountryCode
69
53
 
70
54
  for (const candidate of buildCandidates(value)) {
@@ -72,7 +56,7 @@ function runPhoneValidation(
72
56
  if (!parsed?.isValid()) {
73
57
  continue
74
58
  }
75
- if (matchesNumberType(parsed.getType(), numberType)) {
59
+ if (isMobileNumberType(parsed.getType())) {
76
60
  return toValidationResult(parsed)
77
61
  }
78
62
  }
@@ -80,27 +64,19 @@ function runPhoneValidation(
80
64
  return INVALID_RESULT
81
65
  }
82
66
 
83
- export function validatePhoneNumber(
84
- nationalNumber: string,
85
- countryIso2: string,
86
- options: ValidatePhoneOptions = {},
87
- ): PhoneValidationResult {
67
+ export function validatePhoneNumber(nationalNumber: string, countryIso2: string): PhoneValidationResult {
88
68
  const trimmed = nationalNumber.trim()
89
69
  if (!trimmed) {
90
70
  return INVALID_RESULT
91
71
  }
92
72
 
93
- return runPhoneValidation(trimmed, countryIso2, options.numberType ?? 'mobile')
73
+ return runPhoneValidation(trimmed, countryIso2)
94
74
  }
95
75
 
96
76
  /** `null` when empty, otherwise whether the number is valid for the selected country. */
97
- export function getPhoneValidationState(
98
- nationalNumber: string,
99
- countryIso2: string,
100
- options: ValidatePhoneOptions = {},
101
- ): boolean | null {
77
+ export function getPhoneValidationState(nationalNumber: string, countryIso2: string): boolean | null {
102
78
  if (!nationalNumber.trim()) {
103
79
  return null
104
80
  }
105
- return validatePhoneNumber(nationalNumber, countryIso2, options).isValid
81
+ return validatePhoneNumber(nationalNumber, countryIso2).isValid
106
82
  }
package/src/index.ts CHANGED
@@ -263,11 +263,7 @@ export {
263
263
  type PhoneValidationResult,
264
264
  } from './components/Form/FdsPhonenumber/validatePhone'
265
265
 
266
- export type {
267
- FdsPhonenumberEmits,
268
- FdsPhonenumberNumberType,
269
- FdsPhonenumberProps,
270
- } from './components/Form/FdsPhonenumber/types'
266
+ export type { FdsPhonenumberEmits, FdsPhonenumberProps } from './components/Form/FdsPhonenumber/types'
271
267
 
272
268
  // Table component types
273
269
  export type { FdsTableProps } from './components/Table/FdsTable/types'