-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement dropdown menu with checkboxes
- Loading branch information
1 parent
fb44e16
commit c9b507a
Showing
12 changed files
with
387 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/checkbox/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import './styles.scss'; |
7 changes: 7 additions & 0 deletions
7
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/checkbox/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/*! | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
@import '../tokens/index'; | ||
|
||
.checkbox { | ||
} |
46 changes: 46 additions & 0 deletions
46
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/dropdown/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import './styles.scss'; | ||
|
||
function onToggleDropdown(event: PointerEvent): void { | ||
const target = event.target as HTMLButtonElement; | ||
target.classList.toggle('button_dropdown_active'); | ||
target.parentNode?.querySelector('.dropdown--list')?.classList.toggle('dropdown--list_expanded'); | ||
} | ||
|
||
function onToggleOption(event: PointerEvent): void { | ||
const target = event.target as HTMLButtonElement; | ||
console.log('onToggleOption', target); | ||
target.classList.toggle('dropdown--option_active'); | ||
target.querySelector('.dropdown--checkbox')?.toggleAttribute('checked'); | ||
} | ||
|
||
function doParentsHaveClass(element: HTMLElement, className: string): boolean { | ||
if (element && element.classList.contains(className)) { | ||
return true; | ||
} | ||
if (element.parentElement) { | ||
return doParentsHaveClass(element.parentElement as HTMLElement, className); | ||
} | ||
return false; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
document.addEventListener('click', (event) => { | ||
const target = event.target as HTMLElement; | ||
if (!doParentsHaveClass(target, 'dropdown')) { | ||
const dropdowns = document.querySelectorAll('.button_dropdown'); | ||
dropdowns.forEach((dropdown) => { | ||
dropdown.classList.remove('button_dropdown_active'); | ||
dropdown.parentNode?.querySelector('.dropdown--list')?.classList.remove('dropdown--list_expanded'); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).onToggleDropdown = onToggleDropdown; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).onToggleOption = onToggleOption; |
70 changes: 70 additions & 0 deletions
70
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/dropdown/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*! | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
@import '../tokens/index'; | ||
|
||
.dropdown { | ||
position: relative; | ||
|
||
&--list { | ||
position: absolute; | ||
top: 44px; | ||
|
||
right: 0; | ||
|
||
display: none; | ||
|
||
min-width: 272px; | ||
max-width: 360px; | ||
max-height: 400px; | ||
padding: 0; | ||
|
||
border: 1px solid lighten(rgb(50, 50, 55), 15%); // color-background-nav-dt | ||
|
||
box-shadow: 0 2px 8px 0 #00000040; | ||
|
||
&_expanded { | ||
display: block; | ||
} | ||
} | ||
|
||
&--option { | ||
position: relative; | ||
|
||
display: block; | ||
|
||
padding: var(--size-s2) 44px; | ||
|
||
list-style-type: none; | ||
|
||
cursor: pointer; | ||
letter-spacing: -0.03em; | ||
|
||
text-transform: capitalize; | ||
|
||
border: none; | ||
background-color: var(--color-background-nav-dt); | ||
|
||
font: var(--font-text-m); | ||
|
||
&:hover { | ||
background-color: lighten(rgb(50, 50, 55), 10%); // color-background-nav-dt | ||
} | ||
|
||
&_active { | ||
background-color: var(--color-key-blue); | ||
|
||
&:hover { | ||
background-color: lighten(rgb(48, 127, 255), 10%); // color-key-blue | ||
} | ||
} | ||
} | ||
|
||
&--checkbox { | ||
position: absolute; | ||
|
||
left: var(--size-s3); | ||
|
||
pointer-events: none; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import './dropdown/styles'; | ||
@import './checkbox/styles'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.