mirror of
https://github.com/picocss/pico.git
synced 2025-04-22 01:26:13 -04:00
feature(issue#52): added a new dropdown component
This commit is contained in:
parent
e7ffe74a05
commit
72a3adb16b
15 changed files with 498 additions and 9 deletions
|
@ -2032,6 +2032,109 @@ progress::-moz-progress-bar {
|
||||||
background-position: -200% 0;
|
background-position: -200% 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
details[role=dropdown] {
|
||||||
|
padding: 0;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary {
|
||||||
|
position: relative;
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary::after {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div {
|
||||||
|
position: relative;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul {
|
||||||
|
z-index: 100;
|
||||||
|
position: absolute;
|
||||||
|
top: auto;
|
||||||
|
right: 0px;
|
||||||
|
left: 0px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-top: none;
|
||||||
|
border-bottom-right-radius: var(--border-radius);
|
||||||
|
border-bottom-left-radius: var(--border-radius);
|
||||||
|
background-color: var(--background-color);
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li::marker {
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=radio],
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox] {
|
||||||
|
display: none;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
-moz-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li label {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li label:hover {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input:checked + label {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox] + label:before {
|
||||||
|
display: inline-block;
|
||||||
|
width: calc(var(--spacing) * 1.2);
|
||||||
|
height: calc(var(--spacing) * 1.2);
|
||||||
|
margin-right: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--primary);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
content: "";
|
||||||
|
vertical-align: text-bottom;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox]:checked + label:before {
|
||||||
|
background-image: var(--icon-checkbox);
|
||||||
|
background-position: center;
|
||||||
|
background-size: calc(var(--spacing) * 0.8) auto;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-color: var(--primary);
|
||||||
|
}
|
||||||
|
details[role=dropdown][disabled] summary, details[role=dropdown].disabled summary {
|
||||||
|
color: var(--muted-color);
|
||||||
|
cursor: not-allowed;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary::before {
|
||||||
|
display: block;
|
||||||
|
z-index: 80;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
background: transparent;
|
||||||
|
content: " ";
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary::after {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loading ([aria-busy=true])
|
* Loading ([aria-busy=true])
|
||||||
*/
|
*/
|
||||||
|
|
File diff suppressed because one or more lines are too long
2
css/pico.classless.min.css
vendored
2
css/pico.classless.min.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
103
css/pico.css
103
css/pico.css
|
@ -2310,6 +2310,109 @@ progress::-moz-progress-bar {
|
||||||
background-position: -200% 0;
|
background-position: -200% 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
details[role=dropdown] {
|
||||||
|
padding: 0;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary {
|
||||||
|
position: relative;
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary::after {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div {
|
||||||
|
position: relative;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul {
|
||||||
|
z-index: 100;
|
||||||
|
position: absolute;
|
||||||
|
top: auto;
|
||||||
|
right: 0px;
|
||||||
|
left: 0px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-top: none;
|
||||||
|
border-bottom-right-radius: var(--border-radius);
|
||||||
|
border-bottom-left-radius: var(--border-radius);
|
||||||
|
background-color: var(--background-color);
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li::marker {
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=radio],
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox] {
|
||||||
|
display: none;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
-moz-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li label {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li label:hover {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input:checked + label {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox] + label:before {
|
||||||
|
display: inline-block;
|
||||||
|
width: calc(var(--spacing) * 1.2);
|
||||||
|
height: calc(var(--spacing) * 1.2);
|
||||||
|
margin-right: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--primary);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
content: "";
|
||||||
|
vertical-align: text-bottom;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox]:checked + label:before {
|
||||||
|
background-image: var(--icon-checkbox);
|
||||||
|
background-position: center;
|
||||||
|
background-size: calc(var(--spacing) * 0.8) auto;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-color: var(--primary);
|
||||||
|
}
|
||||||
|
details[role=dropdown][disabled] summary, details[role=dropdown].disabled summary {
|
||||||
|
color: var(--muted-color);
|
||||||
|
cursor: not-allowed;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary::before {
|
||||||
|
display: block;
|
||||||
|
z-index: 80;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
background: transparent;
|
||||||
|
content: " ";
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary::after {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loading ([aria-busy=true])
|
* Loading ([aria-busy=true])
|
||||||
*/
|
*/
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2002,6 +2002,109 @@ progress::-moz-progress-bar {
|
||||||
background-position: -200% 0;
|
background-position: -200% 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
details[role=dropdown] {
|
||||||
|
padding: 0;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary {
|
||||||
|
position: relative;
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary::after {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div {
|
||||||
|
position: relative;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul {
|
||||||
|
z-index: 100;
|
||||||
|
position: absolute;
|
||||||
|
top: auto;
|
||||||
|
right: 0px;
|
||||||
|
left: 0px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-top: none;
|
||||||
|
border-bottom-right-radius: var(--border-radius);
|
||||||
|
border-bottom-left-radius: var(--border-radius);
|
||||||
|
background-color: var(--background-color);
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li::marker {
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=radio],
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox] {
|
||||||
|
display: none;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
-moz-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li label {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li label:hover {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input:checked + label {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox] + label:before {
|
||||||
|
display: inline-block;
|
||||||
|
width: calc(var(--spacing) * 1.2);
|
||||||
|
height: calc(var(--spacing) * 1.2);
|
||||||
|
margin-right: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--primary);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
content: "";
|
||||||
|
vertical-align: text-bottom;
|
||||||
|
}
|
||||||
|
details[role=dropdown] summary + div ul li input[type=checkbox]:checked + label:before {
|
||||||
|
background-image: var(--icon-checkbox);
|
||||||
|
background-position: center;
|
||||||
|
background-size: calc(var(--spacing) * 0.8) auto;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-color: var(--primary);
|
||||||
|
}
|
||||||
|
details[role=dropdown][disabled] summary, details[role=dropdown].disabled summary {
|
||||||
|
color: var(--muted-color);
|
||||||
|
cursor: not-allowed;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary::before {
|
||||||
|
display: block;
|
||||||
|
z-index: 80;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
background: transparent;
|
||||||
|
content: " ";
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
details[role=dropdown][open] summary::after {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loading ([aria-busy=true])
|
* Loading ([aria-busy=true])
|
||||||
*/
|
*/
|
||||||
|
|
File diff suppressed because one or more lines are too long
2
css/pico.fluid.classless.min.css
vendored
2
css/pico.fluid.classless.min.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
css/pico.min.css
vendored
2
css/pico.min.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
63
docs/dropdowns.html
Normal file
63
docs/dropdowns.html
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<html data-theme="light">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<script src="script.js"></script>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css"
|
||||||
|
/>
|
||||||
|
<link rel="stylesheet" href="./styles.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<h1>Dropdown for picocss</h1>
|
||||||
|
<h3>Single select</h3>
|
||||||
|
<p>in order to use dropdown component, use <code>role='dropdown'</code> on details tag.</p>
|
||||||
|
<details role="dropdown">
|
||||||
|
<summary>Single select</summary>
|
||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<input type="radio" id="01" name="option1" />
|
||||||
|
<label for="01">Option 1</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<input type="radio" id="02" name="option1" />
|
||||||
|
<label for="02">Option 2</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
<h3>Multi-select select</h3>
|
||||||
|
<details role="dropdown">
|
||||||
|
<summary>Multi-select</summary>
|
||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<input type="checkbox" id="11" name="option2" />
|
||||||
|
<label for="11">Option 1</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<input type="checkbox" id="12" name="option2" />
|
||||||
|
<label for="12">Option 2</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</d>
|
||||||
|
</details>
|
||||||
|
<h6>Usage notes</h6>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
no need to use javascript to close the dropdown when clicked outside.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
for both single / multi-select case, need javascript to update summary
|
||||||
|
tag text when any option selected.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
in case of single select, remove open attribute on details tag using
|
||||||
|
javascript when an option is selected.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
116
scss/components/_dropdown.scss
Normal file
116
scss/components/_dropdown.scss
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
details[role='dropdown'] {
|
||||||
|
padding: 0;
|
||||||
|
border-bottom: none;
|
||||||
|
|
||||||
|
summary {
|
||||||
|
position: relative;
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& + div {
|
||||||
|
position: relative;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
ul {
|
||||||
|
z-index: 100;
|
||||||
|
position: absolute;
|
||||||
|
top: auto;
|
||||||
|
right: 0px;
|
||||||
|
left: 0px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: var(--border-width) solid var(--form-element-border-color);
|
||||||
|
border-top: none;
|
||||||
|
border-bottom-right-radius: var(--border-radius);
|
||||||
|
border-bottom-left-radius: var(--border-radius);
|
||||||
|
background-color: var(--background-color);
|
||||||
|
list-style: none;
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-bottom: 0;
|
||||||
|
&::marker {
|
||||||
|
content: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='radio'],
|
||||||
|
input[type='checkbox'] {
|
||||||
|
display: none;
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: calc(var(--spacing) * 0.5);
|
||||||
|
line-height: 1;
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + label {
|
||||||
|
background-color: var(--secondary-focus);
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='checkbox'] {
|
||||||
|
& + label:before {
|
||||||
|
display: inline-block;
|
||||||
|
width: calc(var(--spacing) * 1.2);
|
||||||
|
height: calc(var(--spacing) * 1.2);
|
||||||
|
margin-right: calc(var(--spacing) * 0.5);
|
||||||
|
border: var(--border-width) solid var(--primary);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
content: '';
|
||||||
|
vertical-align: text-bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:checked + label:before {
|
||||||
|
background-image: var(--icon-checkbox);
|
||||||
|
background-position: center;
|
||||||
|
background-size: calc(var(--spacing) * 0.8) auto;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-color: var(--primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&[disabled] summary,
|
||||||
|
&.disabled summary {
|
||||||
|
color: var(--muted-color);
|
||||||
|
cursor: not-allowed;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[open] summary {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
&::before {
|
||||||
|
display: block;
|
||||||
|
z-index: 80;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
background: transparent;
|
||||||
|
content: ' ';
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,6 +34,7 @@
|
||||||
@import "components/modal"; // dialog
|
@import "components/modal"; // dialog
|
||||||
@import "components/nav"; // nav
|
@import "components/nav"; // nav
|
||||||
@import "components/progress"; // progress
|
@import "components/progress"; // progress
|
||||||
|
@import "components/dropdown"; // dropdown
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
@import "utilities/loading"; // aria-busy=true
|
@import "utilities/loading"; // aria-busy=true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue