PluginProbe
The Innovative Form Builder – IvyForms / 0.8.2
The Innovative Form Builder – IvyForms v0.8.2
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / constants / choicePresets.ts

choicePresets.ts in The Innovative Form Builder – IvyForms 0.8.2, at frontend/src/constants/choicePresets.ts

224 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { countryList } from '@/constants/countries'
2
3 export type ChoicePresetId =
4 | 'countries'
5 | 'states'
6 | 'stateAbbreviations'
7 | 'continents'
8 | 'gender'
9 | 'ageRanges'
10 | 'weekdays'
11 | 'rating'
12
13 export interface ChoicePresetOption {
14 id: string
15 label: string
16 }
17
18 export interface ChoicePreset {
19 id: ChoicePresetId
20 labelKey: string
21 options: ChoicePresetOption[]
22 }
23
24 const normalizeLabel = (label: string) => label.trim()
25
26 const makePresetOptions = (options: string[]) =>
27 options.map((label) => {
28 const normalized = normalizeLabel(label)
29 const value = normalized
30 .toLowerCase()
31 .replace(/[^a-z0-9]+/g, '-')
32 .replace(/(^-|-$)/g, '')
33 return {
34 id: value || normalized,
35 label: normalized,
36 }
37 })
38
39 const usStates = [
40 'Alabama',
41 'Alaska',
42 'Arizona',
43 'Arkansas',
44 'California',
45 'Colorado',
46 'Connecticut',
47 'Delaware',
48 'District of Columbia',
49 'Florida',
50 'Georgia',
51 'Hawaii',
52 'Idaho',
53 'Illinois',
54 'Indiana',
55 'Iowa',
56 'Kansas',
57 'Kentucky',
58 'Louisiana',
59 'Maine',
60 'Maryland',
61 'Massachusetts',
62 'Michigan',
63 'Minnesota',
64 'Mississippi',
65 'Missouri',
66 'Montana',
67 'Nebraska',
68 'Nevada',
69 'New Hampshire',
70 'New Jersey',
71 'New Mexico',
72 'New York',
73 'North Carolina',
74 'North Dakota',
75 'Ohio',
76 'Oklahoma',
77 'Oregon',
78 'Pennsylvania',
79 'Rhode Island',
80 'South Carolina',
81 'South Dakota',
82 'Tennessee',
83 'Texas',
84 'Utah',
85 'Vermont',
86 'Virginia',
87 'Washington',
88 'West Virginia',
89 'Wisconsin',
90 'Wyoming',
91 ]
92
93 const usStateAbbreviations = [
94 'AL',
95 'AK',
96 'AZ',
97 'AR',
98 'CA',
99 'CO',
100 'CT',
101 'DE',
102 'DC',
103 'FL',
104 'GA',
105 'HI',
106 'ID',
107 'IL',
108 'IN',
109 'IA',
110 'KS',
111 'KY',
112 'LA',
113 'ME',
114 'MD',
115 'MA',
116 'MI',
117 'MN',
118 'MS',
119 'MO',
120 'MT',
121 'NE',
122 'NV',
123 'NH',
124 'NJ',
125 'NM',
126 'NY',
127 'NC',
128 'ND',
129 'OH',
130 'OK',
131 'OR',
132 'PA',
133 'RI',
134 'SC',
135 'SD',
136 'TN',
137 'TX',
138 'UT',
139 'VT',
140 'VA',
141 'WA',
142 'WV',
143 'WI',
144 'WY',
145 ]
146
147 const continents = [
148 'Africa',
149 'Antarctica',
150 'Asia',
151 'Europe',
152 'North America',
153 'Oceania',
154 'South America',
155 ]
156
157 const genderOptions = ['Female', 'Male', 'Non-binary', 'Prefer not to say']
158
159 const ageRangeOptions = [
160 'Under 18',
161 '18-24',
162 '25-34',
163 '35-44',
164 '45-54',
165 '55-64',
166 '65 or Above',
167 'Prefer Not to Answer',
168 ]
169
170 const weekdayOptions = [
171 'Monday',
172 'Tuesday',
173 'Wednesday',
174 'Thursday',
175 'Friday',
176 'Saturday',
177 'Sunday',
178 ]
179
180 const ratingOptions = ['1', '2', '3', '4', '5']
181
182 export const choicePresets: ChoicePreset[] = [
183 {
184 id: 'countries',
185 labelKey: 'bulk_edit_preset_countries',
186 options: makePresetOptions(countryList.map((country) => country.name)),
187 },
188 {
189 id: 'states',
190 labelKey: 'bulk_edit_preset_states',
191 options: makePresetOptions(usStates),
192 },
193 {
194 id: 'stateAbbreviations',
195 labelKey: 'bulk_edit_preset_state_abr',
196 options: makePresetOptions(usStateAbbreviations),
197 },
198 {
199 id: 'continents',
200 labelKey: 'bulk_edit_preset_continents',
201 options: makePresetOptions(continents),
202 },
203 {
204 id: 'gender',
205 labelKey: 'bulk_edit_preset_gender',
206 options: makePresetOptions(genderOptions),
207 },
208 {
209 id: 'ageRanges',
210 labelKey: 'bulk_edit_preset_age',
211 options: makePresetOptions(ageRangeOptions),
212 },
213 {
214 id: 'weekdays',
215 labelKey: 'bulk_edit_preset_days',
216 options: makePresetOptions(weekdayOptions),
217 },
218 {
219 id: 'rating',
220 labelKey: 'bulk_edit_preset_rating',
221 options: ratingOptions.map((num) => ({ id: num, label: num })),
222 },
223 ]
224