Skip to content

Commit 34a2e9a

Browse files
committed
feat: dropdown value saved in local data
1 parent d9930e4 commit 34a2e9a

File tree

1 file changed

+67
-25
lines changed

1 file changed

+67
-25
lines changed

components/signup-card.vue

+67-25
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,75 @@
2424
<input
2525
class="first-name form-field"
2626
type="text"
27-
:placeholder="firstName.placeholder"
27+
:placeholder="firstNameField.placeholder"
2828
required="true" />
2929
<input
3030
class="last-name form-field"
3131
type="text"
32-
:placeholder="lastName.placeholder"
32+
:placeholder="lastNameField.placeholder"
3333
required="true" />
3434
</div>
3535

3636
<input
3737
class="email form-field"
3838
type="email"
39-
:placeholder="email.placeholder"
39+
:placeholder="emailField.placeholder"
4040
required="true" />
4141

4242
<input
4343
class="org form-field"
44-
:placeholder="org.placeholder"
44+
:placeholder="orgField.placeholder"
4545
type="text"
4646
required="true" />
4747

4848
<ZeroDropdown class="country form-field" :display-selected="true">
49-
<template #toggle-button="{ togglePanel }">
49+
<template #toggle-button="{ togglePanel, selected }">
5050
<div class="toggle-button" @click="togglePanel">
51-
<p class="toggle-button-label">
52-
Country
51+
<p v-if="selected" class="toggle-button-label">
52+
{{ selected.label }}
53+
</p>
54+
<p v-else class="toggle-button-label">
55+
Select an option
5356
</p>
5457
</div>
5558
</template>
56-
<template #dropdown-panel>
59+
<template #dropdown-panel="{ setSelected, closePanel }">
5760
<div class="dropdown-panel">
5861
<div
59-
v-for="option in country.options"
62+
v-for="option in countryField.options"
6063
:key="option.code"
61-
class="country-option">
62-
<p class="country-label" v-html="option.label" />
64+
class="options">
65+
<p
66+
class="option-label"
67+
@click="selectOption(setSelected, closePanel, option, 'country')"
68+
v-html="option.label" />
6369
</div>
6470
</div>
6571
</template>
6672
</ZeroDropdown>
6773

6874
<ZeroDropdown class="familiarity" :display-selected="true">
69-
<template #toggle-button="{ togglePanel }">
70-
<h3 class="dropdown-label" v-html="familiarity.label" />
75+
<template #toggle-button="{ togglePanel, selected }">
76+
<h3 class="dropdown-label" v-html="familiarityField.label" />
7177
<div class="toggle-button form-field" @click="togglePanel">
72-
<p class="toggle-button-label">
78+
<p v-if="selected" class="toggle-button-label">
79+
{{ selected }}
80+
</p>
81+
<p v-else class="toggle-button-label">
7382
Select an option
7483
</p>
7584
</div>
7685
</template>
77-
<template #dropdown-panel>
86+
<template #dropdown-panel="{ setSelected, closePanel }">
7887
<div class="dropdown-panel">
7988
<div
80-
v-for="(option, index) in familiarity.options"
89+
v-for="(option, index) in familiarityField.options"
8190
:key="index"
82-
class="country-option">
83-
<p class="country-label" v-html="option" />
91+
class="options">
92+
<p
93+
class="option-label"
94+
@click="selectOption(setSelected, closePanel, option, 'familiarity')"
95+
v-html="option" />
8496
</div>
8597
</div>
8698
</template>
@@ -102,6 +114,15 @@ const props = defineProps({
102114
}
103115
})
104116
117+
// ======================================================================== Data
118+
const firstName = ref(false)
119+
const lastName = ref(false)
120+
const email = ref(false)
121+
const org = ref(false)
122+
const country = ref(false)
123+
const filecoinFamiliarity = ref(false)
124+
125+
105126
// ==================================================================== Computed
106127
const title = computed(() => { return props.signupCard.title })
107128
@@ -114,19 +135,36 @@ const cardStyles = computed(() => {
114135
return null
115136
})
116137
117-
const firstName = computed(() => { return props.signupCard.signup_form.first_name })
138+
const firstNameField = computed(() => { return props.signupCard.signup_form.first_name })
118139
119-
const lastName = computed(() => { return props.signupCard.signup_form.last_name })
140+
const lastNameField = computed(() => { return props.signupCard.signup_form.last_name })
120141
121-
const email = computed(() => { return props.signupCard.signup_form.email })
142+
const emailField = computed(() => { return props.signupCard.signup_form.email })
122143
123-
const org = computed(() => { return props.signupCard.signup_form.org })
144+
const orgField = computed(() => { return props.signupCard.signup_form.org })
124145
125-
const country = computed(() => { return props.signupCard.signup_form.country })
126-
127-
const familiarity = computed(() => { return props.signupCard.signup_form.filecoin_familiarity })
146+
const countryField = computed(() => { return props.signupCard.signup_form.country })
128147
148+
const familiarityField = computed(() => { return props.signupCard.signup_form.filecoin_familiarity })
129149
150+
// ===================================================================== Methdos
151+
/**
152+
* @method selectOption
153+
*/
154+
const selectOption = (setSelected, closePanel, option, field) => {
155+
if (option) {
156+
setSelected(option)
157+
closePanel()
158+
switch(field) {
159+
case 'country':
160+
country.value = option
161+
break
162+
case 'familiarity':
163+
filecoinFamiliarity.value = option
164+
break
165+
}
166+
}
167+
}
130168
</script>
131169

132170
<style lang="scss" scoped>
@@ -165,4 +203,8 @@ const familiarity = computed(() => { return props.signupCard.signup_form.filecoi
165203
}
166204
}
167205
206+
.option-label {
207+
cursor: pointer;
208+
}
209+
168210
</style>

0 commit comments

Comments
 (0)