@citizenplane/pimp 9.7.3 → 9.7.5

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": "@citizenplane/pimp",
3
- "version": "9.7.3",
3
+ "version": "9.7.5",
4
4
  "scripts": {
5
5
  "dev": "storybook dev -p 8080",
6
6
  "build-storybook": "storybook build --output-dir ./docs",
@@ -16,7 +16,9 @@
16
16
  placeholder="Enter your phone number"
17
17
  valid-characters-only
18
18
  @close="focusOnInput"
19
+ @country-changed="handleCountryChanged"
19
20
  @open="handleDropdownOpen"
21
+ @validate="handleOnValidate"
20
22
  >
21
23
  <template #arrow-icon>
22
24
  <cp-icon class="cpTelInput__arrow" size="20" type="chevron-down" />
@@ -73,6 +75,22 @@ const props = withDefaults(defineProps<Props>(), {
73
75
  size: Sizes.MD,
74
76
  })
75
77
 
78
+ const emit = defineEmits<Emits>()
79
+
80
+ type PhoneObject = {
81
+ country: string
82
+ countryCode: string
83
+ formatted: string
84
+ nationalNumber: string
85
+ possible: boolean
86
+ valid: boolean
87
+ }
88
+
89
+ interface Emits {
90
+ (e: 'countryChanged', countryCode: string): void
91
+ (e: 'validate', phoneObject: PhoneObject): void
92
+ }
93
+
76
94
  const inputModel = defineModel<string>()
77
95
  const telInputRef = ref<HTMLInputElement | null>(null)
78
96
 
@@ -128,6 +146,14 @@ const handleDropdownOpen = async () => {
128
146
 
129
147
  setTimeout(() => searchBox.focus(), 1)
130
148
  }
149
+
150
+ const handleCountryChanged = (country: { iso2: string }) => {
151
+ emit('countryChanged', country?.iso2 || '')
152
+ }
153
+
154
+ const handleOnValidate = (phoneObject: PhoneObject) => {
155
+ emit('validate', phoneObject)
156
+ }
131
157
  </script>
132
158
 
133
159
  <style lang="scss">