Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify acm-select.svelte to create a custom select dropdown #156

Merged
merged 4 commits into from
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>