Skip to content

Commit 6419845

Browse files
authored
Merge pull request #7 from MathisBurger/dev
merge v1.0.2
2 parents 4d7b6b1 + c1a0a9c commit 6419845

File tree

9 files changed

+275
-0
lines changed

9 files changed

+275
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ Check out the easy to use documentation and play arround with it.
7171
- <a href="documentation/navbar.md">Navbar</a>
7272
- <a href="documentation/sidebar.md">Sidebar</a>
7373
- <a href="documentation/cards.md">Cards</a>
74+
- <a href="documentation/dropdown.md">Dropdown</a>
7475
- <a href="documentation/scripts.md">Scripts</a>

documentation/dropdown.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Dropdown documentation
2+
3+
This part of the documentation will show you how to use the<br>
4+
included dropdown menus of ChocolateCSS.
5+
6+
# Basic usage
7+
8+
Using single page dropdown menus with ChocolateCSS is very easy.
9+
10+
```html
11+
<div class="dropdown dropdown-dark active">
12+
<div class="dropdown-menu">
13+
<div class="dropdown-menu-item">Item 1</div>
14+
<div class="dropdown-menu-item">Item 2</div>
15+
</div>
16+
</div>
17+
```
18+
19+
The other `div` tag contains three classes. The `dropdown` class defines the general structure of the dropdown.<br>
20+
The `dropdown-dark` class defines the theme of the dropdown.
21+
There are three different themes available.
22+
23+
- `dropdown-light`
24+
- `dropdown-grey`
25+
- `dropdown-dark`
26+
27+
The `active` class sets the visibility of the dropdown. `active` means, that the dropdown fades in from the top.
28+
29+
Into the other `div` you will have to put a div with the class `dropdown-menu`. Into this you can put your menu elements.<br>
30+
To define a menu element, you need to put a div into your menu `div` and add another `div` with the class `dropdown-menu-item`.
31+
32+
# Multiple menus
33+
34+
Multiple menus in one dropdown menu are also possible.
35+
36+
```html
37+
<div class="dropdown dropdown-dark active">
38+
<div class="dropdown-menu" id="main-menu">
39+
<div class="dropdown-menu-item" onclick="DropdownForwardMenu('main-menu', 'sec-menu');">Item 1</div>
40+
<div class="dropdown-menu-item">Item 2</div>
41+
</div>
42+
<div class="dropdown-submenu" id="sec-menu">
43+
<div class="dropdown-menu-item" onclick="DropdownBackwardMenu('sec-menu', 'main-menu');">Item 3</div>
44+
<div class="dropdown-menu-item">Item 4</div>
45+
</div>
46+
</div>
47+
```
48+
49+
To get multiple menus in one dropdown to work, you will have to add the `dropdown-toggler.js` script to your html body.
50+
51+
```html
52+
<script src="js/dropdown-toggler.js"></script>
53+
```
54+
55+
After that you can go on with adding a submenu.<br>
56+
The structure of the submenu is equal to the structure of
57+
default dropdown menu. Just change the class to `dropdown-submenu`.
58+
59+
```html
60+
<div class="dropdown-submenu">
61+
<div class="dropdown-menu-item">Item 3</div>
62+
<div class="dropdown-menu-item">Item 4</div>
63+
</div>
64+
```
65+
66+
Your submenu is hidden now.<br>
67+
To make them callable, you will need to add an id to every menu (Look main example).
68+
69+
Check out the <a href="./scripts.md">script documentation</a> to learn how to toggle between the different menus of the dropdown.

documentation/scripts.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,30 @@ Just add this to the bottom of your HTML body.
2323
<script src="<pathToJsFolder>/sidebar-toggler.js"></script>
2424
```
2525

26+
# Dropdown script
2627

28+
Use the `dropdown-toggler.js` script if you want to switch between different menus in your dropdown.
29+
30+
```html
31+
<script src="<pathToJsFolder>/dropdown-toggler.js"></script>
32+
```
33+
34+
Now you can use the script to switch between the menus.
35+
36+
There are two different functions you can use.
37+
38+
`DropdownForwardMenu`
39+
You can use this function to switch to a new sub menu.
40+
Its syntax is quite easy.
41+
```js
42+
DropdownForwardMenu('from', 'to');
43+
```
44+
Just call the function and replace the string parameters with the ids of the menus, you want to switch.
45+
46+
Same with the `DropdownBackwardMenu` function.
47+
48+
```js
49+
DropdownBackwardMenu('from', 'to');
50+
```
51+
52+
Its usage is the same as the usage of the `DropdownForwardMenu` function.

dropdown/animations.scss

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
@import "./dropdown.scss";
2+
3+
.dropdown.active {
4+
display: flex;
5+
animation-name: showDropdown;
6+
animation-fill-mode: forwards;
7+
animation-duration: 1s;
8+
}
9+
10+
@keyframes showDropdown {
11+
from {
12+
top: -100%;
13+
opacity: 0.5;
14+
}
15+
to {
16+
top: 2.5%;
17+
opacity: 1;
18+
}
19+
}
20+
21+
.old-out {
22+
animation-name: oldOut;
23+
animation-duration: .3s;
24+
animation-fill-mode: forwards;
25+
}
26+
27+
@keyframes oldOut {
28+
from {
29+
left: 0;
30+
}
31+
to {
32+
left: -100%;
33+
}
34+
}
35+
36+
.old-in {
37+
animation-name: oldIn;
38+
animation-duration: .3s;
39+
animation-fill-mode: backwards;
40+
}
41+
42+
@keyframes oldIn {
43+
from {
44+
left: 0;
45+
}
46+
to {
47+
left: -100%;
48+
}
49+
}
50+
51+
.new-out {
52+
animation-name: newOut;
53+
animation-duration: .3s;
54+
animation-fill-mode: forwards;
55+
}
56+
57+
@keyframes newOut {
58+
from {
59+
right: -10px;
60+
}
61+
to {
62+
right: -100%;
63+
}
64+
}
65+
66+
.new-in {
67+
animation-name: newIn;
68+
animation-duration: .3s;
69+
animation-fill-mode: forwards;
70+
}
71+
72+
@keyframes newIn {
73+
from {
74+
right: -100%;
75+
}
76+
to {
77+
right: -10px;
78+
}
79+
}

dropdown/dropdown.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.dropdown {
2+
width: fit-content;
3+
height: fit-content;
4+
border-radius: 12px;
5+
padding: 10px 10px 10px 10px;
6+
display: none;
7+
position: absolute;
8+
top: -100%;
9+
overflow: hidden;
10+
}

dropdown/menu.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.dropdown-menu {
2+
display: flex;
3+
flex-direction: column;
4+
width: 100%;
5+
height: 100%;
6+
}
7+
8+
.dropdown-submenu {
9+
@extend .dropdown-menu;
10+
position: absolute;
11+
right: -100%;
12+
}
13+
14+
.dropdown-menu-item {
15+
width: 200px;
16+
height: 50px;
17+
display: flex;
18+
flex-direction: row;
19+
justify-content: center;
20+
align-items: center;
21+
border-radius: 7px;
22+
transition: .3s;
23+
}
24+
25+
.dropdown-menu-item:hover {
26+
filter: brightness(2);
27+
}

dropdown/theme.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@import "./dropdown.scss";
2+
@import "./menu.scss";
3+
4+
@mixin dropdownTheme($class-name, $bg-color, $text-color) {
5+
6+
.dropdown.#{$class-name} {
7+
background: $bg-color;
8+
box-shadow: 1px 1px 1px rgba(0,0,0,0.2);
9+
}
10+
11+
.#{$class-name} .dropdown-menu-item {
12+
color: $text-color;
13+
font-family: "Roboto", sans-serif;
14+
font-size: 1.2em;
15+
background: $bg-color;
16+
}
17+
}

js/dropdown-toggler.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
3+
function DropdownForwardMenu(from, to) {
4+
5+
let fromElement = document.getElementById(from);
6+
removeUnusedClasses(fromElement);
7+
8+
let toElement = document.getElementById(to);
9+
removeUnusedClasses(toElement);
10+
11+
fromElement.classList.add('old-out');
12+
toElement.classList.add('new-in');
13+
14+
}
15+
16+
function DropdownBackwardMenu(from, to) {
17+
18+
let fromElement = document.getElementById(from);
19+
removeUnusedClasses(fromElement);
20+
21+
let toElement = document.getElementById(to);
22+
removeUnusedClasses(toElement);
23+
24+
fromElement.classList.add('new-out');
25+
toElement.classList.add('old-in');
26+
}
27+
28+
function removeUnusedClasses(element) {
29+
30+
element.classList.contains('old-out') ? element.classList.remove('old-out') : null;
31+
element.classList.contains('old-in') ? element.classList.remove('old-in') : null;
32+
element.classList.contains('new-out') ? element.classList.remove('new-out') : null;
33+
element.classList.contains('new-in') ? element.classList.remove('new-in') : null;
34+
}

main.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
@import "./cards/responsive.scss";
2828

2929

30+
// Dropdown
31+
@import "./dropdown/dropdown.scss";
32+
@import "./dropdown/menu.scss";
33+
@import "./dropdown/theme.scss";
34+
@import "./dropdown/animations.scss";
35+
36+
3037

3138
// Buttons
3239
@include buttonBase(btn-blue, #1d3bae, #264BD9, #fff);
@@ -62,3 +69,8 @@
6269
@include cardTheme(card-light, #fff, rgba(0,0,0,0.4), #000);
6370
@include cardTheme(card-grey, #303030, rgba(0,0,0,0.6), #fff);
6471
@include cardTheme(card-dark, #161616, rgba(0,0,0,0.6), #fff);
72+
73+
// Dropdown
74+
@include dropdownTheme(dropdown-light, rgb(221, 221, 221), #000);
75+
@include dropdownTheme(dropdown-grey, rgb(153, 153, 153), #fff);
76+
@include dropdownTheme(dropdown-dark, #232323, #fff);

0 commit comments

Comments
 (0)