lu2
Version:
Simple and flexible UI component library based on native HTML and JavaScript
464 lines (416 loc) • 12.3 kB
CSS
/**
*
* @Select.css
* @author zhangxinxu(.com)
* @create 15-06-18
* @edited 19-08-27
*
**/
:root {
--ui-select-icon-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cpath fill='%232a80eb' d='M145.659 68.949a12.874 12.874 0 0 0-18.473 0L99.479 97.233 71.772 68.949a12.874 12.874 0 0 0-18.473 0c-5.099 5.208-5.099 13.648 0 18.857l46.18 47.14 46.181-47.14c5.099-5.208 5.099-13.649-.001-18.857z'/%3E%3C/svg%3E");
--ui-select-height: 40px;
--ui-select-line-height: var(--ui-line-height, 20px);
--ui-select-padding-block: 10px;
}
[is="ui-select"] {
height: var(--ui-select-height);
line-height: var(--ui-select-line-height);
margin: 0;
border: 1px solid var(--ui-border, #d0d0d5);
font-size: var(--ui-font, 14px);
color: var(--ui-dark, #4c5161);
border-radius: var(--ui-radius, 4px);
background-color: var(--ui-white, #fff);
transition: border-color var(--ui-animate-time, .2s), background-color var(--ui-animate-time, .2s);
font-family: system-ui;
font-feature-settings: "tnum";
vertical-align: middle;
--ui-select-padding-block: calc((var(--ui-select-height) - var(--ui-select-line-height)) / 2);
cursor: pointer;
}
[is="ui-select"][width="100%"] {
width: 100%;
}
[is="ui-select"][width] {
width: attr(width type(*));
}
[is="ui-select"]:is([width$="0"], [width$="1"], [width$="2"], [width$="3"], [width$="4"], [width$="5"], [width$="6"], [width$="7"], [width$="8"], [width$="9"]) {
width: attr(width px);
}
@supports not (appearance: base-select) {
[is="ui-select"] {
appearance: none;
padding: calc(var(--ui-select-padding-block) - 1px) 27px calc(var(--ui-select-padding-block) - 1px) 12px;
background-image: var(--ui-select-icon-arrow);
background-repeat: no-repeat;
background-position: right 7px center;
background-size: var(--ui-select-line-height) auto;
}
[is="ui-select"]:has( + div.ui-select) {
opacity: 0;
pointer-events: none;
}
}
[is="ui-select"][placeholder] {
&:has(option[value=""]:checked),
& + .ui-select .ui-select-button[data-value=""] {
color: var(--ui-gray, #a2a9b6);
}
option[value=""],
& + .ui-select .ui-select-datalist-li[data-value=""] {
display: none;
}
}
[is="ui-select"][multiple] {
visibility: visible;
pointer-events: auto;
height: auto;
vertical-align: top;
cursor: pointer;
padding: 0;
}
[is="ui-select"][multiple] option {
padding-right: 20px;
}
[is="ui-select"][multiple]::picker-icon {
display: none;
}
@supports not (appearance: base-select) {
[is="ui-select"][multiple] {
font-size: 31px;
letter-spacing: calc(-1 * (31px - var(--ui-font, 14px)));
border-right-width: 13px;
border-left: 13px solid;
}
[is="ui-select"][multiple] > option {
min-height: 38px;
height: 38px;
padding: 0 1px;
font-size: inherit;
}
}
select[multiple] > option:disabled {
cursor: default;
}
.ui-select {
display: inline-block;
height: var(--ui-select-height);
line-height: var(--ui-line-height, 20px);
max-width: 100%;
vertical-align: middle;
font-size: var(--ui-font, 14px);
transition: opacity var(--ui-animate-time, .2s);
text-align: start;
font-family: system-ui;
font-feature-settings: "tnum";
position: relative;
--ui-select-padding-block: calc((var(--ui-select-height) - var(--ui-select-line-height)) / 2);
}
@supports (appearance: base-select) {
[is="ui-select"] {
appearance: base-select;
padding: calc(var(--ui-select-padding-block) - 1px) 6px calc(var(--ui-select-padding-block) - 1px) 12px;
&:disabled {
opacity: var(--ui-opacity, .4);
}
&:where(:enabled:not(:open)):hover {
border-color: var(--ui-dark-border, #ababaf);
}
}
}
[disabled] + .ui-select {
pointer-events: none;
}
select[hidden],
select[hidden] + .ui-select {
display: none;
}
[is="ui-select"][multiple] + .ui-select {
vertical-align: top;
}
.ui-select.active {
z-index: 3;
}
.ui-select-button {
display: block;
width: -webkit-fill-available;
width: -moz-available;
width: stretch;
height: calc(var(--ui-select-line-height));
padding: calc(var(--ui-select-padding-block) - 1px) 27px calc(var(--ui-select-padding-block) - 1px) 12px;
color: var(--ui-dark, #4c5161);
border: 1px solid var(--ui-border, #d0d0d5);
border-radius: var(--ui-radius, 4px);
background-color: var(--ui-white, #fff);
text-decoration: none;
transition: border-color var(--ui-animate-time, .2s), background-color var(--ui-animate-time, .2s);
box-sizing: content-box;
cursor: pointer;
font-size: 100%;
}
.ui-select-button:hover {
color: var(--ui-dark, #4c5161);
border-color: var(--ui-dark-border, #ababaf);
}
:not(:disabled) + .ui-select > .ui-select-button:active {
background-color: var(--ui-light, #f7f9fa);
}
.active > button.ui-select-button {
border-color: var(--ui-blue, #2a80eb);
}
.ui-select-text {
display: block;
width: 100%;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-align: start;
}
.ui-select-icon,
.ui-select-text:only-child::after,
.ui-select-button:empty::after {
position: absolute;
width: var(--ui-select-line-height);
height: var(--ui-select-line-height);
background: var(--ui-select-icon-arrow) no-repeat center;
background-size: 100% 100%;
right: 7px;
top: var(--ui-select-padding-block);
}
.ui-select-text:only-child::after,
.ui-select-button:empty::after {
content: "";
}
@supports (appearance: base-select) {
[is="ui-select"]::picker-icon {
-webkit-text-fill-color: transparent;
content: "";
display: block;
width: var(--ui-select-line-height);
height: var(--ui-select-line-height);
background: var(--ui-select-icon-arrow) no-repeat center;
background-size: 100% 100%;
}
[is="ui-select"]:open {
border-color: var(--ui-blue, #2a80eb);
}
}
.ui-select-datalist {
display: none;
box-sizing: border-box;
max-height: 306px;
padding: 0;
border: 1px solid var(--ui-blue, #2a80eb);
border-radius: var(--ui-radius, 4px);
background-color: var(--ui-white, #fff);
font-size: var(--ui-font, 14px);
overflow: auto;
overscroll-behavior: none;
-ms-scroll-chaining: none;
scrollbar-width: thin;
text-align: left;
margin: 0;
}
@supports not (position-try-fallbacks: flip-block) {
.ui-select-datalist {
position: absolute;
left: 0;
right: 0;
top: calc(var(--ui-select-height) - 1px);
}
}
[multiple] ~ .ui-select > .ui-select-datalist {
position: static;
display: block;
width: -webkit-fill-available;
width: -moz-available;
width: stretch;
max-height: none;
height: inherit;
border-color: #d0d0d5;
border-radius: var(--ui-radius, 4px);
box-sizing: border-box;
}
[multiple]:hover ~ .ui-select > .ui-select-datalist {
border-color: var(--ui-dark-border, #ababaf);
}
[multiple]:focus ~ .ui-select > .ui-select-datalist {
border-color: var(--ui-blue, #2a80eb);
}
[data-custom-scroll="true"]::-webkit-scrollbar {
width: 8px;
height: 8px;
}
[data-custom-scroll="true"]::-webkit-scrollbar-thumb {
background-color: #bbb;
border-radius: calc(var(--ui-radius, 4px) + 4px);
}
[data-custom-scroll="true"]::-webkit-scrollbar-thumb:hover {
background-color: #aaa;
}
[data-custom-scroll="true"]::-webkit-scrollbar-track-piece {
background-color: #ddd;
}
.active > .ui-select-datalist,
.ui-select-datalist.active {
display: block;
}
.reverse > .ui-select-datalist {
top: auto;
bottom: calc(var(--ui-select-height) - 1px);
}
body > .ui-select-datalist {
font-family: system-ui;
}
@supports (position-try-fallbacks: flip-block) {
.ui-select-datalist {
position-area: bottom;
position-visibility: anchors-visible;
position-try-fallbacks: flip-block;
width: anchor-size(width);
}
}
.ui-select-intent {
text-indent: 1em;
}
.ui-select-datalist-li,
[is="ui-select"] option {
display: block;
line-height: var(--ui-select-line-height);
padding: calc(var(--ui-select-padding-block) - 1px) 12px;
color: var(--ui-dark, #4c5161);
background-color: var(--ui-white, #fff);
text-decoration: none;
text-overflow: ellipsis;
white-space: nowrap;
transition: background-color var(--ui-animate-time, .2s);
box-sizing: border-box;
overflow: hidden;
}
h6.ui-select-datalist-li,
.ui-select-datalist-li[role="heading"] {
font-weight: 700;
margin: 0;
padding-bottom: 6px;
}
.ui-select-datalist-li[href] {
cursor: pointer;
}
.ui-select-datalist-li:not(:only-child):empty {
display: none;
}
.ui-select-datalist-hr:not(:first-child),
[is="ui-select"] hr:not(:first-child) {
border: 0;
height: 1px;
padding: 7px 12px;
background-color: var(--ui-white, #fff);
margin: 0;
}
.ui-select-datalist-hr:not(:first-child)::before,
[is="ui-select"] hr:not(:first-child)::before {
content: '';
display: block;
border-top: 1px solid var(--ui-border, #d0d0d5);
opacity: var(--ui-opacity, .4);
}
/* reset default a:hover */
.ui-select-datalist-li:hover {
color: var(--ui-dark, #4c5161);
}
.ui-select-datalist > .disabled {
color: var(--ui-gray, #a2a9b6);
cursor: default;
}
.ui-select-datalist > .selected {
background-color: var(--ui-list-selected, #e0f0ff);
}
.ui-select-datalist-li[href]:hover,
[multiple] ~ .ui-select .ui-select-datalist-li[href] {
color: var(--ui-dark, #4c5161);
background-color: var(--ui-list-hover, #f0f7ff);
}
@supports (appearance: base-select) {
[is="ui-select"]::picker(select) {
appearance: base-select;
border: 1px solid var(--ui-blue, #2a80eb);
border-radius: var(--ui-radius, 4px);
max-height: 306px;
overflow: auto;
overscroll-behavior: none;
scrollbar-width: thin;
text-align: left;
top: calc(anchor(bottom) - 1px);
position-try-fallbacks: flip-block;
}
[is="ui-select"].reverse::picker(select) {
top: auto;
bottom: calc(anchor(top) - 1px);
}
[is="ui-select"] option:checked {
background-color: var(--ui-list-selected, #e0f0ff);
}
[is="ui-select"]:enabled option:enabled:hover {
background-color: var(--ui-list-hover, #f0f7ff);
}
[is="ui-select"] option:disabled,
[is="ui-select"]:disabled option {
color: var(--ui-gray, #a2a9b6);
background-color: var(--ui-white, #fff);
cursor: default;
}
[is="ui-select"] optgroup {
padding-top: 6px;
font-weight: 700;
color: var(--ui-dark, #4c5161);
line-height: var(--ui-select-line-height);
}
[is="ui-select"] optgroup:not([label]):not(:first-child)::before {
content: '';
display: block;
padding: 6px 12px 0;
border-top: 1px solid var(--ui-border, #d0d0d5);
opacity: var(--ui-opacity, .4);
margin-inline: 12px;
}
[is="ui-select"] option::checkmark {
display: none;
}
[is="ui-select"]::picker(select) {
opacity: 0;
transition: .2s allow-discrete;
}
[is="ui-select"]::picker(select):popover-open {
opacity: 1;
}
@starting-style {
[is="ui-select"]::picker(select):popover-open {
opacity: 0;
}
}
}
/* disabled */
select:disabled {
cursor: default;
}
select:disabled + .ui-select {
opacity: var(--ui-opacity, .4);
}
select:disabled + .ui-select .ui-select-button,
select:disabled + .ui-select .ui-select-datalist {
cursor: default;
border-color: var(--ui-dark-border, #ababaf);
}
/* error */
[is-error] .ui-select-button,
[is-error][multiple] ~ .ui-select .ui-select-datalist,
select[is-error] {
border-color: var(--ui-red, #eb4646);
}
@media (prefers-reduced-motion: reduce) {
.ui-select-button,
.ui-select,
.ui-select-datalist-li {
transition: none;
}
}