-
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 1184fbf
Showing
25 changed files
with
601 additions
and
44 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/button/assets/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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'; |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
/*! | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
@import '../tokens/index'; | ||
|
||
.checkbox { | ||
position: relative; | ||
|
||
display: inline-block; | ||
|
||
width: 18px; | ||
height: 18px; | ||
|
||
cursor: pointer; | ||
|
||
input[type='checkbox'] { | ||
width: 0; | ||
height: 0; | ||
|
||
opacity: 0; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/dropdown/dropdown.stories.ftl
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,20 @@ | ||
<#macro display> | ||
<div class="dropdown"> | ||
<button class="button button_dropdown" role="combobox" | ||
aria-controls="id-of-listbox" | ||
aria-haspopup="listbox" | ||
aria-expanded="false" | ||
></button> | ||
<ul role="listbox" id="id-of-listbox" class="dropdown--list"> | ||
<li role="option" class="dropdown--option" tabindex="0"> | ||
<input type="checkbox" class="checkbox dropdown--checkbox" id="option-1" tabindex="-1"/> | ||
Option 1 | ||
</li> | ||
<li role="option" class="dropdown--option" tabindex="0"> | ||
<input type="checkbox" class="checkbox dropdown--checkbox" id="option-2" tabindex="-1"/> | ||
Option 2 | ||
</li> | ||
</#list> | ||
</ul> | ||
</div> | ||
</#macro> |
85 changes: 85 additions & 0 deletions
85
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,85 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import './styles.scss'; | ||
import { hasAncestorWithClass } from '../utils'; | ||
|
||
// page objects selectors | ||
const DROPDOWN = '[data-role="dropdown"]'; | ||
const DROPDOWN_TOGGLE = '[data-role="dropdown-toggle"]'; | ||
const DROPDOWN_LIST = '[data-role="dropdown-listbox"]'; | ||
|
||
function initDropdowns(): void { | ||
const dropdowns = document.querySelectorAll(DROPDOWN); | ||
dropdowns.forEach((dropdown: Element) => | ||
dropdown.querySelectorAll(DROPDOWN_TOGGLE)?.forEach((button: Element) => { | ||
button.addEventListener('click', (event) => onToggleDropdown(event, dropdown)); | ||
}) | ||
); | ||
} | ||
|
||
function onToggleDropdown(event: Event, dropdown: Element): void { | ||
const buttons = dropdown.querySelectorAll(DROPDOWN_TOGGLE); | ||
buttons?.forEach(toggleDropdownButton); | ||
const list = dropdown.querySelector(DROPDOWN_LIST); | ||
toggleDropdownList(list); | ||
} | ||
|
||
function toggleDropdownButton(button: Element): void { | ||
if (button.classList.contains('button_dropdown')) { | ||
button.classList.toggle('button_dropdown_active'); | ||
} | ||
} | ||
|
||
function toggleDropdownList(list: Element | null): void { | ||
console.log(list); | ||
list?.classList.toggle('dropdown--list_expanded'); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
initDropdowns(); | ||
|
||
document.addEventListener('click', (event) => { | ||
const target = event.target as HTMLElement; | ||
if (!hasAncestorWithClass(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'); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
// function onToggleDropdown(event: PointerEvent): void { | ||
// const target = event.target as HTMLButtonElement; | ||
// if (target.classList.contains('button_dropdown')) { | ||
// target.classList.toggle('button_dropdown_active'); | ||
// } | ||
// target.parentNode | ||
// ?.querySelector('.dropdown') | ||
// ?.querySelector('.dropdown--list') | ||
// ?.classList.toggle('dropdown--list_expanded'); | ||
// } | ||
|
||
function onToggleOption(event: PointerEvent): void { | ||
const target = event.target as HTMLButtonElement; | ||
target.classList.toggle('dropdown--option_active'); | ||
target.querySelector('.dropdown--checkbox')?.toggleAttribute('checked'); | ||
} | ||
|
||
function onToggleOptionByKey(event: KeyboardEvent): void { | ||
const target = event.target as HTMLButtonElement; | ||
if (event.key === 'Enter' || event.key === ' ') { | ||
target.classList.toggle('dropdown--option_active'); | ||
target.querySelector('.dropdown--checkbox')?.toggleAttribute('checked'); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).onToggleOption = onToggleOption; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).onToggleOptionByKey = onToggleOptionByKey; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).initDropdowns = initDropdowns; |
89 changes: 89 additions & 0 deletions
89
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,89 @@ | ||
/*! | ||
* 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; | ||
z-index: 9; | ||
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; | ||
} | ||
|
||
@media (width < $breakpoint-desktop-min) { | ||
top: 0; | ||
right: -52px; | ||
|
||
width: 100vw; | ||
max-width: unset; | ||
} | ||
} | ||
|
||
&--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 | ||
} | ||
|
||
&:focus-visible { | ||
z-index: 1; | ||
|
||
outline: 4px solid var(--color-key-blue-05); | ||
} | ||
|
||
&_active { | ||
background-color: var(--color-key-blue); | ||
|
||
&:hover { | ||
background-color: lighten(rgb(48, 127, 255), 10%); // color-key-blue | ||
} | ||
} | ||
} | ||
|
||
&--checkbox { | ||
position: absolute; | ||
|
||
top: 50%; | ||
|
||
left: 12px; | ||
|
||
margin-top: -9px; | ||
|
||
pointer-events: none; | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/icon/assets/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
13 changes: 13 additions & 0 deletions
13
dokka-subprojects/plugin-base-frontend/src/main/ui-kit/utils.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,13 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
export function hasAncestorWithClass(element: HTMLElement, className: string): boolean { | ||
if (element && element.classList.contains(className)) { | ||
return true; | ||
} | ||
if (element.parentElement) { | ||
return hasAncestorWithClass(element.parentElement as HTMLElement, className); | ||
} | ||
return false; | ||
} |
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.