-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from anhduy1202/edit/acm-select.svelte
Modify acm-select.svelte to create a custom select dropdown
- Loading branch information
Showing
1 changed file
with
67 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,83 @@ | ||
<script lang="ts"> | ||
export let defaultValue: string = ''; | ||
export let options: string[] = []; | ||
let currentValue: string = defaultValue; | ||
let active: boolean = false; | ||
const toggleDropdown = () => { | ||
active = !active; | ||
}; | ||
const handleOption = (term) => { | ||
currentValue = term; | ||
defaultValue = currentValue; | ||
active = false; | ||
}; | ||
</script> | ||
|
||
<select name="school-year" bind:value={defaultValue}> | ||
{#each options as optionValue (optionValue)} | ||
<option value={optionValue}>{optionValue}</option> | ||
{/each} | ||
</select> | ||
<div class="term" name="school-year"> | ||
<div class="option-box" class:active> | ||
<div class="selected" on:click={toggleDropdown}>{currentValue}</div> | ||
<div class="option"> | ||
{#each options as optionValue (optionValue)} | ||
<div class="option-choice" on:click={() => handleOption(optionValue)}> | ||
{optionValue} | ||
</div> | ||
{/each} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<style> | ||
select { | ||
text-align: center; | ||
font-size: 18px; | ||
<style lang="scss"> | ||
.term { | ||
font-weight: 600; | ||
padding: 8px 20px; | ||
border: none; | ||
border-radius: 8px; | ||
background-color: var(--acm-dark); | ||
.option-box { | ||
flex-direction: column; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
} | ||
.option-choice, | ||
.selected { | ||
color: var(--acm-light); | ||
outline: none; | ||
appearance: none; | ||
transition: background-color 0.25s ease-in-out; | ||
} | ||
.selected { | ||
background-color: var(--acm-dark); | ||
padding: 8px 24px; | ||
cursor: pointer; | ||
border-radius: 6px; | ||
&:hover { | ||
color: var(--acm-blue); | ||
} | ||
} | ||
.active > .selected { | ||
border-radius: 6px 6px 0 0; | ||
} | ||
select:hover { | ||
.option { | ||
cursor: pointer; | ||
background-color: var(--acm-blue); | ||
visibility: hidden; | ||
margin-bottom: 0.5rem; | ||
transition: all 300ms; | ||
.option-choice { | ||
cursor: pointer; | ||
&:hover { | ||
color: var(--acm-light); | ||
} | ||
} | ||
} | ||
option { | ||
.active > .option { | ||
visibility: visible; | ||
background-color: var(--acm-dark); | ||
color: var(--acm-light); | ||
font-weight: 500; | ||
padding: 8px 24px; | ||
margin-top: 0.2rem; | ||
border-radius: 0 0 6px 6px; | ||
transition: all 200ms; | ||
.option-choice:hover { | ||
color: var(--acm-blue); | ||
} | ||
} | ||
</style> |
1aec8dd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: