@wherabouts/react-ui 0.1.0 → 0.3.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/dist/index.d.cts CHANGED
@@ -1,113 +1,165 @@
1
- import { AddressSuggestion, WheraboutsClient } from '@wherabouts/sdk';
2
- import { ClassValue } from 'clsx';
3
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { AddressSuggestion, WheraboutsClient } from '@wherabouts/sdk';
4
3
  import { ReactNode } from 'react';
4
+ import { ClassValue } from 'clsx';
5
5
 
6
6
  interface AddressWithParsed {
7
- id: number;
7
+ country: string;
8
8
  formattedAddress: string;
9
+ id: number;
9
10
  latitude: number;
10
11
  longitude: number;
12
+ postcode: string;
13
+ state: string;
11
14
  streetAddress: string;
12
15
  suburb: string;
13
- state: string;
14
- postcode: string;
15
- country: string;
16
16
  }
17
17
  interface AddressI18nStrings {
18
- noResults: string;
19
18
  enterManually: string;
20
19
  errorRetry: string;
21
20
  geolocationError: string;
21
+ noResults: string;
22
22
  }
23
23
  type AddressValidateFn = (address: AddressWithParsed) => Promise<{
24
24
  message: string;
25
25
  } | null>;
26
26
  type AddressSuggestionInput = AddressSuggestion;
27
27
 
28
- declare function toAddressWithParsed(suggestion: AddressSuggestion): AddressWithParsed;
29
-
30
- declare function cn(...inputs: ClassValue[]): string;
31
-
32
28
  interface AddressAutocompleteProps {
29
+ /** Class applied to the root container. */
33
30
  className?: string;
31
+ /** Required. SDK client created with `createWheraboutsClient`. */
34
32
  client: WheraboutsClient;
33
+ /** Debounce in ms before querying the API. Default 300. */
35
34
  debounceMs?: number;
35
+ /** Disable the input. */
36
36
  disabled?: boolean;
37
+ /** Use the browser's geolocation to bias results by proximity. Default false. */
37
38
  enableGeolocation?: boolean;
39
+ /** External error message to display. */
38
40
  error?: string;
41
+ /** Override built-in UI strings (no results, retry, etc.). */
39
42
  i18nStrings?: Partial<AddressI18nStrings>;
43
+ /** id forwarded to the input element. */
40
44
  id?: string;
45
+ /** Maximum number of suggestions to show. Default 5. */
41
46
  maxSuggestions?: number;
47
+ /** Minimum characters typed before searching. Default 2. */
42
48
  minCharsToSearch?: number;
49
+ /** Called as the input text changes. */
43
50
  onQueryChange?: (query: string) => void;
51
+ /** Called when a suggestion is selected. */
44
52
  onSelect?: (address: AddressWithParsed) => void;
53
+ /** Input placeholder text. */
45
54
  placeholder?: string;
55
+ /** Render a custom empty state. */
46
56
  renderEmpty?: () => ReactNode;
57
+ /** Render a custom error state. */
47
58
  renderError?: (error: Error | null) => ReactNode;
59
+ /** Render a custom loading state. */
48
60
  renderLoading?: () => ReactNode;
61
+ /** Render a custom suggestion row. */
49
62
  renderSuggestion?: (address: AddressWithParsed, isActive: boolean) => ReactNode;
63
+ /** Mark the input as required. */
50
64
  required?: boolean;
65
+ /** Group a run of keystrokes into one billable search (see SDK `newSessionToken()`). */
51
66
  sessionToken?: string;
67
+ /** Explicit latitude for proximity bias (instead of geolocation). */
52
68
  userLat?: number;
69
+ /** Explicit longitude for proximity bias (instead of geolocation). */
53
70
  userLng?: number;
54
71
  }
55
72
  declare function AddressAutocomplete({ client, onQueryChange, onSelect, error: externalError, required, disabled, debounceMs, minCharsToSearch, maxSuggestions, enableGeolocation, userLat, userLng, sessionToken, className, placeholder, renderSuggestion, renderEmpty, renderError, renderLoading, i18nStrings: customI18n, id: customId, }: AddressAutocompleteProps): react_jsx_runtime.JSX.Element;
56
73
 
74
+ interface AddressFieldGroupValue {
75
+ /** Postcode field value. */
76
+ postcode: string;
77
+ /** State field value. */
78
+ state: string;
79
+ /** Street address field value. */
80
+ street: string;
81
+ /** Suburb field value. */
82
+ suburb: string;
83
+ }
84
+ interface AddressFieldGroupProps {
85
+ /** Class applied to the root container. */
86
+ className?: string;
87
+ /** Required. SDK client created with `createWheraboutsClient`. */
88
+ client: WheraboutsClient;
89
+ /** Disable all fields. */
90
+ disabled?: boolean;
91
+ /** Required. Change handler, called with the updated value on any field edit. */
92
+ onChange: (value: AddressFieldGroupValue) => void;
93
+ /** Override the postcode field label. */
94
+ postcodeLabel?: string;
95
+ /** Override the state field label. */
96
+ stateLabel?: string;
97
+ /** Override the street address field label. */
98
+ streetLabel?: string;
99
+ /** Override the suburb field label. */
100
+ suburbLabel?: string;
101
+ /** Required. Controlled value for the field group. */
102
+ value: AddressFieldGroupValue;
103
+ }
104
+ declare function AddressFieldGroup({ client, value, onChange, className, disabled, streetLabel, suburbLabel, stateLabel, postcodeLabel, }: AddressFieldGroupProps): ReactNode;
105
+
57
106
  interface AddressFormFieldProps extends AddressAutocompleteProps {
107
+ /** Class applied to the error text element. */
108
+ errorClassName?: string;
109
+ /** Required. Field label rendered above the input. */
58
110
  label: string;
111
+ /** Class applied to the label element. */
59
112
  labelClassName?: string;
60
- errorClassName?: string;
61
113
  }
62
114
  declare function AddressFormField({ label, labelClassName, errorClassName, error, required, disabled, id: customId, className, ...autocompleteProps }: AddressFormFieldProps): ReactNode;
63
115
 
64
- interface ReverseGeocodeInputProps {
65
- client: WheraboutsClient;
66
- latitude: number | null;
67
- longitude: number | null;
68
- onResult?: (result: {
69
- address: string | null;
70
- distance: number | null;
71
- }) => void;
116
+ interface ForwardGeocodeInputProps {
117
+ /** Class applied to the input element. */
72
118
  className?: string;
119
+ /** Required. SDK client created with `createWheraboutsClient`. */
120
+ client: WheraboutsClient;
121
+ /** Disable the input. */
73
122
  disabled?: boolean;
74
- placeholder?: string;
123
+ /** id forwarded to the input element. */
75
124
  id?: string;
76
- }
77
- declare function ReverseGeocodeInput({ client, latitude, longitude, onResult, className, disabled, placeholder, id, }: ReverseGeocodeInputProps): ReactNode;
78
-
79
- interface ForwardGeocodeInputProps {
80
- client: WheraboutsClient;
81
- query: string | null;
125
+ /** Geocode result callback, called whenever the resolved result changes. */
82
126
  onResult?: (result: {
83
127
  latitude: number | null;
84
128
  longitude: number | null;
85
129
  formattedAddress: string | null;
86
130
  }) => void;
87
- className?: string;
88
- disabled?: boolean;
131
+ /** Input placeholder text. */
89
132
  placeholder?: string;
90
- id?: string;
133
+ /** Address text to geocode. */
134
+ query: string | null;
91
135
  }
92
136
  declare function ForwardGeocodeInput({ client, query, onResult, className, disabled, placeholder, id, }: ForwardGeocodeInputProps): ReactNode;
93
137
 
94
- interface AddressFieldGroupValue {
95
- street: string;
96
- suburb: string;
97
- state: string;
98
- postcode: string;
99
- }
100
- interface AddressFieldGroupProps {
101
- client: WheraboutsClient;
102
- value: AddressFieldGroupValue;
103
- onChange: (value: AddressFieldGroupValue) => void;
138
+ interface ReverseGeocodeInputProps {
139
+ /** Class applied to the input element. */
104
140
  className?: string;
141
+ /** Required. SDK client created with `createWheraboutsClient`. */
142
+ client: WheraboutsClient;
143
+ /** Disable the input. */
105
144
  disabled?: boolean;
106
- streetLabel?: string;
107
- suburbLabel?: string;
108
- stateLabel?: string;
109
- postcodeLabel?: string;
145
+ /** id forwarded to the input element. */
146
+ id?: string;
147
+ /** Latitude to reverse-geocode. */
148
+ latitude: number | null;
149
+ /** Longitude to reverse-geocode. */
150
+ longitude: number | null;
151
+ /** Result callback, called whenever the resolved address changes. */
152
+ onResult?: (result: {
153
+ address: string | null;
154
+ distance: number | null;
155
+ }) => void;
156
+ /** Input placeholder text. */
157
+ placeholder?: string;
110
158
  }
111
- declare function AddressFieldGroup({ client, value, onChange, className, disabled, streetLabel, suburbLabel, stateLabel, postcodeLabel, }: AddressFieldGroupProps): ReactNode;
159
+ declare function ReverseGeocodeInput({ client, latitude, longitude, onResult, className, disabled, placeholder, id, }: ReverseGeocodeInputProps): ReactNode;
160
+
161
+ declare function cn(...inputs: ClassValue[]): string;
162
+
163
+ declare function toAddressWithParsed(suggestion: AddressSuggestion): AddressWithParsed;
112
164
 
113
165
  export { AddressAutocomplete, type AddressAutocompleteProps, AddressFieldGroup, type AddressFieldGroupProps, type AddressFieldGroupValue, AddressFormField, type AddressFormFieldProps, type AddressI18nStrings, type AddressSuggestionInput, type AddressValidateFn, type AddressWithParsed, ForwardGeocodeInput, type ForwardGeocodeInputProps, ReverseGeocodeInput, type ReverseGeocodeInputProps, cn, toAddressWithParsed };
package/dist/index.d.ts CHANGED
@@ -1,113 +1,165 @@
1
- import { AddressSuggestion, WheraboutsClient } from '@wherabouts/sdk';
2
- import { ClassValue } from 'clsx';
3
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { AddressSuggestion, WheraboutsClient } from '@wherabouts/sdk';
4
3
  import { ReactNode } from 'react';
4
+ import { ClassValue } from 'clsx';
5
5
 
6
6
  interface AddressWithParsed {
7
- id: number;
7
+ country: string;
8
8
  formattedAddress: string;
9
+ id: number;
9
10
  latitude: number;
10
11
  longitude: number;
12
+ postcode: string;
13
+ state: string;
11
14
  streetAddress: string;
12
15
  suburb: string;
13
- state: string;
14
- postcode: string;
15
- country: string;
16
16
  }
17
17
  interface AddressI18nStrings {
18
- noResults: string;
19
18
  enterManually: string;
20
19
  errorRetry: string;
21
20
  geolocationError: string;
21
+ noResults: string;
22
22
  }
23
23
  type AddressValidateFn = (address: AddressWithParsed) => Promise<{
24
24
  message: string;
25
25
  } | null>;
26
26
  type AddressSuggestionInput = AddressSuggestion;
27
27
 
28
- declare function toAddressWithParsed(suggestion: AddressSuggestion): AddressWithParsed;
29
-
30
- declare function cn(...inputs: ClassValue[]): string;
31
-
32
28
  interface AddressAutocompleteProps {
29
+ /** Class applied to the root container. */
33
30
  className?: string;
31
+ /** Required. SDK client created with `createWheraboutsClient`. */
34
32
  client: WheraboutsClient;
33
+ /** Debounce in ms before querying the API. Default 300. */
35
34
  debounceMs?: number;
35
+ /** Disable the input. */
36
36
  disabled?: boolean;
37
+ /** Use the browser's geolocation to bias results by proximity. Default false. */
37
38
  enableGeolocation?: boolean;
39
+ /** External error message to display. */
38
40
  error?: string;
41
+ /** Override built-in UI strings (no results, retry, etc.). */
39
42
  i18nStrings?: Partial<AddressI18nStrings>;
43
+ /** id forwarded to the input element. */
40
44
  id?: string;
45
+ /** Maximum number of suggestions to show. Default 5. */
41
46
  maxSuggestions?: number;
47
+ /** Minimum characters typed before searching. Default 2. */
42
48
  minCharsToSearch?: number;
49
+ /** Called as the input text changes. */
43
50
  onQueryChange?: (query: string) => void;
51
+ /** Called when a suggestion is selected. */
44
52
  onSelect?: (address: AddressWithParsed) => void;
53
+ /** Input placeholder text. */
45
54
  placeholder?: string;
55
+ /** Render a custom empty state. */
46
56
  renderEmpty?: () => ReactNode;
57
+ /** Render a custom error state. */
47
58
  renderError?: (error: Error | null) => ReactNode;
59
+ /** Render a custom loading state. */
48
60
  renderLoading?: () => ReactNode;
61
+ /** Render a custom suggestion row. */
49
62
  renderSuggestion?: (address: AddressWithParsed, isActive: boolean) => ReactNode;
63
+ /** Mark the input as required. */
50
64
  required?: boolean;
65
+ /** Group a run of keystrokes into one billable search (see SDK `newSessionToken()`). */
51
66
  sessionToken?: string;
67
+ /** Explicit latitude for proximity bias (instead of geolocation). */
52
68
  userLat?: number;
69
+ /** Explicit longitude for proximity bias (instead of geolocation). */
53
70
  userLng?: number;
54
71
  }
55
72
  declare function AddressAutocomplete({ client, onQueryChange, onSelect, error: externalError, required, disabled, debounceMs, minCharsToSearch, maxSuggestions, enableGeolocation, userLat, userLng, sessionToken, className, placeholder, renderSuggestion, renderEmpty, renderError, renderLoading, i18nStrings: customI18n, id: customId, }: AddressAutocompleteProps): react_jsx_runtime.JSX.Element;
56
73
 
74
+ interface AddressFieldGroupValue {
75
+ /** Postcode field value. */
76
+ postcode: string;
77
+ /** State field value. */
78
+ state: string;
79
+ /** Street address field value. */
80
+ street: string;
81
+ /** Suburb field value. */
82
+ suburb: string;
83
+ }
84
+ interface AddressFieldGroupProps {
85
+ /** Class applied to the root container. */
86
+ className?: string;
87
+ /** Required. SDK client created with `createWheraboutsClient`. */
88
+ client: WheraboutsClient;
89
+ /** Disable all fields. */
90
+ disabled?: boolean;
91
+ /** Required. Change handler, called with the updated value on any field edit. */
92
+ onChange: (value: AddressFieldGroupValue) => void;
93
+ /** Override the postcode field label. */
94
+ postcodeLabel?: string;
95
+ /** Override the state field label. */
96
+ stateLabel?: string;
97
+ /** Override the street address field label. */
98
+ streetLabel?: string;
99
+ /** Override the suburb field label. */
100
+ suburbLabel?: string;
101
+ /** Required. Controlled value for the field group. */
102
+ value: AddressFieldGroupValue;
103
+ }
104
+ declare function AddressFieldGroup({ client, value, onChange, className, disabled, streetLabel, suburbLabel, stateLabel, postcodeLabel, }: AddressFieldGroupProps): ReactNode;
105
+
57
106
  interface AddressFormFieldProps extends AddressAutocompleteProps {
107
+ /** Class applied to the error text element. */
108
+ errorClassName?: string;
109
+ /** Required. Field label rendered above the input. */
58
110
  label: string;
111
+ /** Class applied to the label element. */
59
112
  labelClassName?: string;
60
- errorClassName?: string;
61
113
  }
62
114
  declare function AddressFormField({ label, labelClassName, errorClassName, error, required, disabled, id: customId, className, ...autocompleteProps }: AddressFormFieldProps): ReactNode;
63
115
 
64
- interface ReverseGeocodeInputProps {
65
- client: WheraboutsClient;
66
- latitude: number | null;
67
- longitude: number | null;
68
- onResult?: (result: {
69
- address: string | null;
70
- distance: number | null;
71
- }) => void;
116
+ interface ForwardGeocodeInputProps {
117
+ /** Class applied to the input element. */
72
118
  className?: string;
119
+ /** Required. SDK client created with `createWheraboutsClient`. */
120
+ client: WheraboutsClient;
121
+ /** Disable the input. */
73
122
  disabled?: boolean;
74
- placeholder?: string;
123
+ /** id forwarded to the input element. */
75
124
  id?: string;
76
- }
77
- declare function ReverseGeocodeInput({ client, latitude, longitude, onResult, className, disabled, placeholder, id, }: ReverseGeocodeInputProps): ReactNode;
78
-
79
- interface ForwardGeocodeInputProps {
80
- client: WheraboutsClient;
81
- query: string | null;
125
+ /** Geocode result callback, called whenever the resolved result changes. */
82
126
  onResult?: (result: {
83
127
  latitude: number | null;
84
128
  longitude: number | null;
85
129
  formattedAddress: string | null;
86
130
  }) => void;
87
- className?: string;
88
- disabled?: boolean;
131
+ /** Input placeholder text. */
89
132
  placeholder?: string;
90
- id?: string;
133
+ /** Address text to geocode. */
134
+ query: string | null;
91
135
  }
92
136
  declare function ForwardGeocodeInput({ client, query, onResult, className, disabled, placeholder, id, }: ForwardGeocodeInputProps): ReactNode;
93
137
 
94
- interface AddressFieldGroupValue {
95
- street: string;
96
- suburb: string;
97
- state: string;
98
- postcode: string;
99
- }
100
- interface AddressFieldGroupProps {
101
- client: WheraboutsClient;
102
- value: AddressFieldGroupValue;
103
- onChange: (value: AddressFieldGroupValue) => void;
138
+ interface ReverseGeocodeInputProps {
139
+ /** Class applied to the input element. */
104
140
  className?: string;
141
+ /** Required. SDK client created with `createWheraboutsClient`. */
142
+ client: WheraboutsClient;
143
+ /** Disable the input. */
105
144
  disabled?: boolean;
106
- streetLabel?: string;
107
- suburbLabel?: string;
108
- stateLabel?: string;
109
- postcodeLabel?: string;
145
+ /** id forwarded to the input element. */
146
+ id?: string;
147
+ /** Latitude to reverse-geocode. */
148
+ latitude: number | null;
149
+ /** Longitude to reverse-geocode. */
150
+ longitude: number | null;
151
+ /** Result callback, called whenever the resolved address changes. */
152
+ onResult?: (result: {
153
+ address: string | null;
154
+ distance: number | null;
155
+ }) => void;
156
+ /** Input placeholder text. */
157
+ placeholder?: string;
110
158
  }
111
- declare function AddressFieldGroup({ client, value, onChange, className, disabled, streetLabel, suburbLabel, stateLabel, postcodeLabel, }: AddressFieldGroupProps): ReactNode;
159
+ declare function ReverseGeocodeInput({ client, latitude, longitude, onResult, className, disabled, placeholder, id, }: ReverseGeocodeInputProps): ReactNode;
160
+
161
+ declare function cn(...inputs: ClassValue[]): string;
162
+
163
+ declare function toAddressWithParsed(suggestion: AddressSuggestion): AddressWithParsed;
112
164
 
113
165
  export { AddressAutocomplete, type AddressAutocompleteProps, AddressFieldGroup, type AddressFieldGroupProps, type AddressFieldGroupValue, AddressFormField, type AddressFormFieldProps, type AddressI18nStrings, type AddressSuggestionInput, type AddressValidateFn, type AddressWithParsed, ForwardGeocodeInput, type ForwardGeocodeInputProps, ReverseGeocodeInput, type ReverseGeocodeInputProps, cn, toAddressWithParsed };