-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: nested popover #2649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: nested popover #2649
Changes from 17 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
48247e8
Move popover types to separate file
TatianaFomina 57242bf
tmp
TatianaFomina 2609ac5
open top
TatianaFomina 1c7925d
Fix bug with keyboard navigation
TatianaFomina 86142f9
Fix bug with scroll
TatianaFomina 6be9cf2
Fix mobile
TatianaFomina 44a63ac
Add popover header class
TatianaFomina 77d0dcd
Display nested items on mobile
TatianaFomina 04d2948
Refactor history
TatianaFomina 2f9d0fb
Fix positioning on desktop
TatianaFomina 9821a3f
Fix tests
TatianaFomina 8e65390
Fix child popover indent left
TatianaFomina cef51c7
Fix ts errors in popover files
TatianaFomina 6871c0a
Move files
TatianaFomina de7c00e
Rename cn to bem
TatianaFomina d19665c
Clarify comments and rename method
TatianaFomina 6502e71
Refactor popover css classes
TatianaFomina 6dd5141
Rename cls to css
TatianaFomina 1c2dc42
Split popover desktop and mobile classes
TatianaFomina cf222e8
Add ability to open popover to the left if not enough space to open t…
TatianaFomina b761e4a
Add nested popover test
TatianaFomina f36cb86
Add popover test for mobile screens
TatianaFomina da00f16
Fix tests
TatianaFomina fe4cdf6
Add union type for both popovers
TatianaFomina b056297
Merge branch 'next' into feat/nested-popover
TatianaFomina ce35b59
Add global window resize event
TatianaFomina 75d8476
Multiple fixes
TatianaFomina 7fab576
Move nodes initialization to constructor
TatianaFomina 0bce02c
Rename handleShowingNestedItems to showNestedItems
TatianaFomina b13f8c0
Replace WindowResize with EditorMobileLayoutToggled
TatianaFomina dcdb8fb
New doze of fixes
TatianaFomina c2a7c8f
Review fixes
TatianaFomina acd2710
Fixes
TatianaFomina b5fbccb
Fixes
TatianaFomina 325aeac
Make each nested popover decide itself if it should open top
TatianaFomina 5942b18
Update changelog
TatianaFomina 7611e0a
Update changelog
TatianaFomina 03aa22c
Update changelog
TatianaFomina 2d9d73a
Merge branch 'next' into feat/nested-popover
TatianaFomina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
const ELEMENT_DELIMITER = '__'; | ||
const MODIFIER_DELIMITER = '--'; | ||
|
||
/** | ||
* Utility function that allows to construct class names from block and element names | ||
* | ||
* @param blockName - string with block name | ||
* @param elementName - string with element name | ||
* @param modifier - modifier to be appended | ||
*/ | ||
export function bem(blockName: string) { | ||
return (elementName?: string, modifier?: string) => { | ||
const className = [blockName, elementName] | ||
.filter(x => !!x) | ||
.join(ELEMENT_DELIMITER); | ||
|
||
return [className, modifier] | ||
.filter(x => !!x) | ||
.join(MODIFIER_DELIMITER); | ||
}; | ||
} |
2 changes: 2 additions & 0 deletions
2
src/components/utils/popover/components/popover-header/index.ts
This file contains hidden or 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 @@ | ||
export * from './popover-header'; | ||
export * from './popover-header.typings'; |
15 changes: 15 additions & 0 deletions
15
src/components/utils/popover/components/popover-header/popover-header.const.ts
This file contains hidden or 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,15 @@ | ||
import { bem } from '../../../bem'; | ||
|
||
/** | ||
* Popover header block CSS class constructor | ||
*/ | ||
const popoverHeaderCn = bem('ce-popover-header'); | ||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* CSS class names to be used in popover header class | ||
*/ | ||
export const cls = { | ||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
root: popoverHeaderCn(), | ||
text: popoverHeaderCn('text'), | ||
backButton: popoverHeaderCn('back-button'), | ||
}; |
84 changes: 84 additions & 0 deletions
84
src/components/utils/popover/components/popover-header/popover-header.ts
This file contains hidden or 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,84 @@ | ||
import { PopoverHeaderParams } from './popover-header.typings'; | ||
import Dom from '../../../../dom'; | ||
import { cls } from './popover-header.const'; | ||
import { IconChevronLeft } from '@codexteam/icons'; | ||
import Listeners from '../../../listeners'; | ||
|
||
/** | ||
* Represents popover header ui element | ||
*/ | ||
export class PopoverHeader { | ||
/** | ||
* Listeners util instance | ||
*/ | ||
private listeners = new Listeners(); | ||
|
||
/** | ||
* Header html elements | ||
*/ | ||
private nodes: { | ||
root: null | HTMLElement, | ||
text: null | HTMLElement, | ||
backButton: null | HTMLElement | ||
} = { | ||
root: null, | ||
text: null, | ||
backButton: null, | ||
}; | ||
|
||
/** | ||
* Text displayed inside header | ||
*/ | ||
private readonly text: string; | ||
|
||
/** | ||
* Back button click handler | ||
*/ | ||
private readonly onBackButtonClick: () => void; | ||
|
||
/** | ||
* Constructs the instance | ||
* | ||
* @param params - popover header params | ||
*/ | ||
constructor({ text, onBackButtonClick }: PopoverHeaderParams) { | ||
this.text = text; | ||
this.onBackButtonClick = onBackButtonClick; | ||
this.make(); | ||
} | ||
|
||
/** | ||
* Returns popover header root html element | ||
*/ | ||
public getElement(): HTMLElement | null { | ||
return this.nodes.root; | ||
} | ||
|
||
/** | ||
* Destroys the instance | ||
*/ | ||
public destroy(): void { | ||
this.nodes.root.remove(); | ||
this.nodes.root = null; | ||
this.nodes.backButton = null; | ||
this.nodes.text = null; | ||
this.listeners.removeAll(); | ||
this.listeners.destroy(); | ||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Constructs HTML elements corresponding to popover header params | ||
*/ | ||
private make(): void { | ||
this.nodes.root = Dom.make('div', [ cls.root ]); | ||
|
||
this.nodes.backButton = Dom.make('button', [ cls.backButton ]); | ||
this.nodes.backButton.innerHTML = IconChevronLeft; | ||
this.nodes.root.appendChild(this.nodes.backButton); | ||
this.listeners.on(this.nodes.backButton, 'click', this.onBackButtonClick); | ||
|
||
this.nodes.text = Dom.make('div', [ cls.text ]); | ||
this.nodes.text.innerText = this.text; | ||
this.nodes.root.appendChild(this.nodes.text); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/components/utils/popover/components/popover-header/popover-header.typings.ts
This file contains hidden or 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,14 @@ | ||
/** | ||
* Popover header params | ||
*/ | ||
export interface PopoverHeaderParams { | ||
/** | ||
* Text to be displayed inside header | ||
*/ | ||
text: string; | ||
|
||
/** | ||
* Back button click handler | ||
*/ | ||
onBackButtonClick: () => void; | ||
} |
2 changes: 2 additions & 0 deletions
2
src/components/utils/popover/components/popover-item/index.ts
This file contains hidden or 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 @@ | ||
export * from './popover-item'; | ||
export * from './popover-item.const'; |
26 changes: 26 additions & 0 deletions
26
src/components/utils/popover/components/popover-item/popover-item.const.ts
This file contains hidden or 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,26 @@ | ||
import { bem } from '../../../bem'; | ||
|
||
/** | ||
* Popover item block CSS class constructor | ||
*/ | ||
const className = bem('ce-popover-item'); | ||
|
||
/** | ||
* CSS class names to be used in popover item class | ||
*/ | ||
export const cls = { | ||
container: className(), | ||
active: className(null, 'active'), | ||
disabled: className(null, 'disabled'), | ||
focused: className(null, 'focused'), | ||
hidden: className(null, 'hidden'), | ||
confirmationState: className(null, 'confirmation'), | ||
noHover: className(null, 'no-hover'), | ||
noFocus: className(null, 'no-focus'), | ||
title: className('title'), | ||
secondaryTitle: className('secondary-title'), | ||
icon: className('icon'), | ||
iconTool: className('icon', 'tool'), | ||
iconChevronRight: className('icon', 'chevron-right'), | ||
wobbleAnimation: bem('wobble')(), | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.