Skip to content

Commit

Permalink
Merge pull request #156 from anhduy1202/edit/acm-select.svelte
Browse files Browse the repository at this point in the history
Modify acm-select.svelte to create a custom select dropdown
  • Loading branch information
anhduy1202 committed Oct 25, 2021
2 parents aa053fc + 87c2fdd commit 1aec8dd
Showing 1 changed file with 67 additions and 21 deletions.
88 changes: 67 additions & 21 deletions src/lib/components/utils/acm-select.svelte
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>

1 comment on commit 1aec8dd

@vercel
Copy link

@vercel vercel bot commented on 1aec8dd Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.