This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathdefault-address-fields.ts
184 lines (177 loc) · 4.36 KB
/
default-address-fields.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
export interface AddressField {
// The label for the field.
label: string;
// The label for the field if made optional.
optionalLabel: string;
// The HTML autocomplete attribute value. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
autocomplete: string;
// How this field value is capitalized.
autocapitalize?: string;
// Set to true if the field is required.
required: boolean;
// Set to true if the field should not be rendered.
hidden: boolean;
// Fields will be sorted and render in this order, lowest to highest.
index: number;
// The type of input to render. Defaults to text.
type?: string;
}
export interface LocaleSpecificAddressField extends Partial< AddressField > {
priority?: number | undefined;
}
export interface AddressFields {
first_name: AddressField;
last_name: AddressField;
company: AddressField;
address_1: AddressField;
address_2: AddressField;
country: AddressField;
city: AddressField;
state: AddressField;
postcode: AddressField;
phone: AddressField;
}
export type AddressType = 'billing' | 'shipping';
export interface ShippingAddress {
first_name: string;
last_name: string;
company: string;
address_1: string;
address_2: string;
country: string;
city: string;
state: string;
postcode: string;
phone: string;
}
export type KeyedAddressField = AddressField & {
key: keyof AddressFields;
errorMessage?: string;
};
export interface BillingAddress extends ShippingAddress {
email: string;
}
export type CountryAddressFields = Record< string, AddressFields >;
/**
* Default address field properties.
*/
export const defaultAddressFields: AddressFields = {
first_name: {
label: __( 'First name', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'First name (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'given-name',
autocapitalize: 'sentences',
required: true,
hidden: false,
index: 10,
},
last_name: {
label: __( 'Last name', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'Last name (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'family-name',
autocapitalize: 'sentences',
required: true,
hidden: false,
index: 20,
},
company: {
label: __( 'Company', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'Company (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'organization',
autocapitalize: 'sentences',
required: false,
hidden: false,
index: 30,
},
address_1: {
label: __( 'Address', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'Address (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'address-line1',
autocapitalize: 'sentences',
required: true,
hidden: false,
index: 40,
},
address_2: {
label: __( 'Apartment, suite, etc.', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'Apartment, suite, etc. (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'address-line2',
autocapitalize: 'sentences',
required: false,
hidden: false,
index: 50,
},
country: {
label: __( 'Country/Region', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'Country/Region (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'country',
required: true,
hidden: false,
index: 60,
},
city: {
label: __( 'City', 'woo-gutenberg-products-block' ),
optionalLabel: __( 'City (optional)', 'woo-gutenberg-products-block' ),
autocomplete: 'address-level2',
autocapitalize: 'sentences',
required: true,
hidden: false,
index: 70,
},
state: {
label: __( 'State/County', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'State/County (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'address-level1',
autocapitalize: 'sentences',
required: true,
hidden: false,
index: 80,
},
postcode: {
label: __( 'Postal code', 'woo-gutenberg-products-block' ),
optionalLabel: __(
'Postal code (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'postal-code',
autocapitalize: 'characters',
required: true,
hidden: false,
index: 90,
},
phone: {
label: __( 'Phone', 'woo-gutenberg-products-block' ),
optionalLabel: __( 'Phone (optional)', 'woo-gutenberg-products-block' ),
autocomplete: 'tel',
type: 'tel',
required: true,
hidden: false,
index: 100,
},
};
export default defaultAddressFields;