Files
ComponentTest/src/app/components/dropdown/dropdown.scss
T

129 lines
2.8 KiB
SCSS

@use "sass:list";
@use "sass:color";
@use "styles/library" as library;
$border_color: oklch(0 0 0 / 20%);
$border_dark_color: oklch(1 0 0 / 20%);
$hover_bg: oklch(0.9702 0 0); // #F5F5F5
$hover_dark_bg: oklch(0.25 0 0);
$height: 40px;
$border_radius: 8px;
$animation_timing: cubic-bezier(0.4, 0, 0.2, 1);
$default_animation_duration: 0.2s;
:host {
display: inline-block;
position: relative;
--animation-duration: calc(#{$default_animation_duration} * var(--motion-duration-multiplier));
padding: 0; margin: 0;
background-color: light-dark(oklch(1 0 0), oklch(0 0 0));
border-radius: $border_radius;
box-shadow: 0 0 0 1px light-dark($border_color, $border_dark_color) inset;
cursor: pointer;
max-width: 100%;
}
.dropdown-box {
display: flex;
align-items: center;
padding: 0 10px;
height: $height;
box-sizing: border-box;
gap: 8px;
.prefix-icon {
width: 24px; height: 24px;
flex-shrink: 0;
user-select: none;
}
.placeholder {
flex-grow: 1;
font-size: 18px;
height: 24px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
user-select: none;
align-content: center;
}
.chevron {
width: 24px; height: 24px;
flex-shrink: 0;
transition: transform var(--animation-duration) $animation_timing;
user-select: none;
&.open {
transform: rotate(180deg);
}
}
}
.dropdown-list {
position: absolute;
top: calc(100% + 4px);
left: 0;
width: 100%;
padding: 0;
margin: 0;
list-style: none;
background-color: light-dark(oklch(1 0 0), oklch(0 0 0));
border-radius: $border_radius;
z-index: 1000;
max-height: 240px;
overflow-y: auto;
box-shadow: 0 4px 12px oklch(0 0 0 / 10%); // rgba(0, 0, 0, 0.1)
animation: slideIn var(--animation-duration) $animation_timing;
&::after {
content: "";
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
border-radius: $border_radius;
box-shadow: 0 0 0 1px light-dark($border_color, $border_dark_color) inset;
pointer-events: none;
z-index: 1001;
}
@keyframes slideIn {
from {
transform: translateY(-8px);
pointer-events: none;
opacity: 0;
}
to {
transform: translateY(0);
pointer-events: auto;
opacity: 1;
}
}
}
.dropdown-item {
display: flex;
align-items: center;
height: 40px;
padding: 0 16px;
position: relative;
align-content: center;
transition: background-color var(--animation-duration) $animation_timing;
font-size: 16px;
&:hover, &.focused {
background-color: light-dark($hover_bg, $hover_dark_bg);
}
&.selected {
background-color: light-dark(list.nth(library.$brand_palette, 1), list.nth(library.$brand_palette, 11));
color: list.nth(library.$brand_palette, 5);
font-weight: 600;
}
}