-
Notifications
You must be signed in to change notification settings - Fork 39
feat(docs): refactoring navbar component #276
Merged
pimenovoleg
merged 2 commits into
positive-js:feature/docs
from
Margar1ta:feature/UIM-75-refactoring_navbar_component
Oct 3, 2019
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
61 changes: 61 additions & 0 deletions
61
packages/docs/src/app/components/navbar/navbar-property.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,61 @@ | ||
export interface INavbarProperty { | ||
// name of local storage property | ||
property: string; | ||
|
||
// data array for dropdown | ||
data: any[]; | ||
|
||
// Applies in NavbarProperty.setValue for additional actions (for example: change class on body) | ||
updateTemplate: boolean; | ||
|
||
// Applies in NavbarProperty.setValue for updating selected value | ||
updateSelected: boolean; | ||
} | ||
|
||
export class NavbarProperty { | ||
data: any[]; | ||
currentValue: any; | ||
private readonly property: string; | ||
|
||
constructor(navbarProperty: INavbarProperty) { | ||
this.data = navbarProperty.data; | ||
this.currentValue = this.data[0]; | ||
this.property = navbarProperty.property; | ||
|
||
this.init(); | ||
} | ||
|
||
setValue(i: number) { | ||
this.currentValue = this.data[i]; | ||
localStorage.setItem(this.property, `${i}`); | ||
if (this.updateTemplate) { this.updateTemplate(i); } | ||
if (this.updateSelected) { this.updateSelected(i); } | ||
} | ||
|
||
init() { | ||
const currentValue = +localStorage.getItem(this.property); | ||
|
||
if (currentValue) { | ||
this.setValue(currentValue); | ||
} else { | ||
localStorage.setItem(this.property, '0'); | ||
} | ||
} | ||
|
||
updateTemplate(i: number) { | ||
if (this.currentValue) { | ||
for (const color of this.data) { | ||
document.body.classList.remove(color.className); | ||
} | ||
|
||
document.body.classList.add(this.currentValue.className); | ||
} | ||
} | ||
|
||
updateSelected(i: number) { | ||
this.data.forEach((color) => { | ||
color.selected = false; | ||
}); | ||
this.data[i].selected = true; | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
далее расчет этого св-ва, bold или нет. должен проходить через анализ версии (number)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Готово!