Skip to content

Commit

Permalink
Handle switching theme, store selecte theme in cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Volmarg committed Apr 10, 2021
1 parent 08be8da commit 81cf002
Show file tree
Hide file tree
Showing 17 changed files with 583 additions and 8 deletions.
202 changes: 202 additions & 0 deletions public/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -95728,6 +95728,179 @@ button.color-picker {
color: white;
}

.settings {
display: none;
direction: ltr;
}

@media (min-width: 1200px) {
.settings {
display: block;
}
}
.settings-icons {
background: #fff;
color: #000;
position: fixed;
top: 50%;
right: 0;
width: 50px;
padding: 0.5rem;
border-top-left-radius: 0.2rem;
border-bottom-left-radius: 0.2rem;
box-shadow: -5px 0 10px 0 rgba(0, 0, 0, 0.1);
transition: all 0.1s ease-in-out;
cursor: pointer;
}

.settings-icons .settings-icon {
text-align: center;
padding: 0.5rem;
border-radius: 0.2rem;
background: #f2f4f6;
color: #000;
display: block;
}

.settings-icons .settings-icon:hover {
background: #e9ecef;
color: #000;
}

.settings-icons .settings-icon:first-child {
color: #2264c3;
}

.settings-icons .settings-icon svg {
stroke-width: 2;
}

.settings-panel {
background: #fff;
border-left: 0 solid transparent;
display: block;
max-height: 160px;
position: fixed;
width: 175px;
z-index: 800;
top: 40%;
bottom: 0;
right: -175px;
border-radius: 5px;
transition: 0.5s ease-in-out;
}

.settings-panel-shown {
right: -5px;
transition: 0.5s ease-in-out;
}

.settings.open .settings-panel:before {
content: "";
background: rgba(0, 0, 0, 0.325);
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 100%;
z-index: -1;
pointer-events: none;
}

.settings.open .settings-panel {
right: 0;
}

.settings-content {
height: 100%;
overflow: auto;
position: relative;
background: #fff;
}

.settings-title {
padding: 0.6rem 1.5rem;
font-size: 0.875rem;
background: #121923;
height: 55px;
}

.settings-options {
padding: 1rem 1.5rem;
}

.js-settings-close {
color: white;
font-size: 21px;
}
.js-settings-close:hover {
opacity: 0.5;
}

.theme-color, .theme-color-light, .theme-color-dark {
width: 30px !important;
height: 30px !important;
border: 1px solid rgba(0, 0, 0, 0.4) !important;
}

.theme-color-dark {
background: black !important;
}

.theme-color-light {
background: white !important;
}
.theme-color-light:after {
border-color: black !important;
}

input[type=radio].square-checkbox {
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: 0;
background: lightgray;
height: 16px;
width: 16px;
border: 1px solid white;
}

input[type=radio].square-checkbox:checked {
background: #aaaaaa;
}

input[type=checkbox].square-checkbox:hover {
filter: brightness(90%);
}

input[type=checkbox].square-checkbox:disabled {
background: #e6e6e6;
opacity: 0.6;
pointer-events: none;
}

input[type=radio].square-checkbox:after {
content: "";
position: relative;
left: 40%;
top: 20%;
width: 15%;
height: 40%;
border: solid #fff;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
display: none;
}

input[type=radio].square-checkbox:checked:after {
display: block;
}

input[type=radio].square-checkbox:disabled:after {
border-color: #7b7b7b;
}

.form-type-date-time-picker {
background-color: white !important;
}
Expand Down Expand Up @@ -97146,6 +97319,10 @@ form legend {
height: 28px;
}

.header.navbar {
box-shadow: 0 0 2rem 0 rgba(33, 37, 41, 0.1);
}

/* latin-ext */
@font-face {
font-family: "Courgette";
Expand Down Expand Up @@ -97211,6 +97388,31 @@ form legend {
.st-theme-github > .nav .nav-link.active {
border-top-color: #5dacbd !important;
}

[data-theme=dark] .sidebar {
background-color: #121923;
}
[data-theme=dark] .sidebar .sidebar-link {
color: rgba(255, 255, 255, 0.6);
}
[data-theme=dark] .sidebar .menu-node-todo-icon {
color: #CC3EE2 !important;
}
[data-theme=dark] .sidebar li.nav-item.open .sidebar-link, [data-theme=dark] .sidebar li.nav-item .sidebar-link.active {
color: white;
}
[data-theme=dark] .sidebar .menu-node-my-schedules-icon {
color: rgba(20, 120, 220, 0.75) !important;
}
[data-theme=dark] .sidebar hr {
border-color: rgba(255, 255, 255, 0.15);
}
[data-theme=dark] .sidebar .sidebar-logo {
border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
[data-theme=dark] .bgc-grey-100, [data-theme=dark] .bgcH-grey-100:hover {
background-color: #f7f7fc !important;
}
/*!
* Bootstrap-select v1.13.18 (https://developer.snapappointments.com/bootstrap-select)
*
Expand Down
6 changes: 3 additions & 3 deletions public/assets/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/service-worker.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/assets/scripts/Initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import FineUploaderService from "./libs/fine-uploader/FineUploaderServi
import AjaxEvents from "./core/ajax/AjaxEvents";
import TuiCalendarService from "./libs/tui-calendar/TuiCalendarService";
import SmartTab from "./libs/smarttab/SmartTab";
import JsSettingsTooltip from "./core/ui/JsSettingsTooltip";

import EditViaModalPrefilledWithEntityDataAction from "./core/ui/Actions/EditViaModalPrefilledWithEntityDataAction";
/**
Expand Down Expand Up @@ -171,8 +172,12 @@ export default class Initializer {

let windowEvents = new WindowEvents();
let documentEvents = new DocumentEvents();
let jsSettings = new JsSettingsTooltip();

jsSettings.setThemeFromCookie();

// new
jsSettings.init();
SearchBar.init();
BootstrapDatepicker.init();
Scrollbar.init();
Expand Down
86 changes: 86 additions & 0 deletions src/assets/scripts/core/ui/JsSettingsTooltip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* @description handles the logic of tooltip visible on the right side of the interface
*/
import JsCookie from "../../libs/js-cookie/JsCookie";

export default class JsSettingsTooltip {

private static readonly SETTINGS_COG_SELECTOR = ".js-settings-toggle";
private static readonly SETTINGS_PANEL_SELECTOR = ".settings-panel";
private static readonly SETTINGS_CLOSE_PANEL_SELECTOR = ".js-settings-close";

private static readonly SETTINGS_THEME_COLOR_INPUT_SELECTOR = "input.theme-color";
private static readonly BODY_DATA_ATTRIBUTE_THEME = "data-theme";

/**
* @description will initialize the main logic
*/
public init(): void
{
this.attachShowingTooltipToCogsIcon();
this.handleClosingSettingsPanel();
this.handleThemeSelect();
}

/**
* @description will set the theme from cookie saved value
*/
public setThemeFromCookie(): void
{
if( JsCookie.isJsSettingsSelectedTheme() ){
this.setTheme(JsCookie.getJsSettingsSelectedTheme());
}
}

/**
* @description will attach the events/logic for showing the panel upon clicking on the cogs icon
*/
private attachShowingTooltipToCogsIcon(): void
{
$(JsSettingsTooltip.SETTINGS_COG_SELECTOR).on('click', () => {
$(JsSettingsTooltip.SETTINGS_PANEL_SELECTOR).addClass('settings-panel-shown');
})
}

/**
* @description attaches the logic responsible to hiding back the js settings panel
*/
private handleClosingSettingsPanel(): void
{
$(JsSettingsTooltip.SETTINGS_CLOSE_PANEL_SELECTOR).on('click', () => {
$(JsSettingsTooltip.SETTINGS_PANEL_SELECTOR).removeClass('settings-panel-shown');
})
}

/**
* @description will handle selecting theme
* - based on user click,
* - based on what's already stored in cookies,
*/
private handleThemeSelect(): void
{
$(JsSettingsTooltip.SETTINGS_THEME_COLOR_INPUT_SELECTOR).on('click', (event) => {
//@ts-ignore
let selectedTheme = event.target.value;
this.setTheme(selectedTheme);
})
}

/**
* @description will set given theme
*/
private setTheme(themeName: string): void
{
$(JsSettingsTooltip.SETTINGS_THEME_COLOR_INPUT_SELECTOR).removeAttr('checked');
$(JsSettingsTooltip.SETTINGS_THEME_COLOR_INPUT_SELECTOR).prop("checked", false);

$("body").attr(JsSettingsTooltip.BODY_DATA_ATTRIBUTE_THEME, themeName);
JsCookie.setJsSettingsSelectedTheme(themeName);

$(`${JsSettingsTooltip.SETTINGS_THEME_COLOR_INPUT_SELECTOR}[value="${themeName}"]`)
.attr("checked", "checked")
.prop("checked", true);
}


}
34 changes: 34 additions & 0 deletions src/assets/scripts/libs/js-cookie/JsCookie.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as Cookies from 'js-cookie';
import StringUtils from "../../core/utils/StringUtils";

/**
* @description handles the predefined cookies
*/
export default class JsCookie {

static readonly COOKIE_KEY_HIDE_FIRST_LOGIN_INFORMATION = "HIDE_FIRST_LOGIN_INFORMATION"
static readonly COOKIE_KEY_JS_SETTINGS_SELECTED_THEME = "JS_SETTINGS_SELECTED_THEME";

/**
* @description Sets the `COOKIE_KEY_HIDE_FIRST_LOGIN_INFORMATION` cookie
Expand All @@ -26,4 +30,34 @@ export default class JsCookie {
return !StringUtils.isEmptyString(cookieValue);
}

/**
* @description save the selected theme
*/
public static setJsSettingsSelectedTheme(themName: string): void
{
Cookies.set(JsCookie.COOKIE_KEY_JS_SETTINGS_SELECTED_THEME, themName);
}

/**
* @description get the selected theme
*
* @return boolean
*/
public static getJsSettingsSelectedTheme(): string
{
let cookieValue = Cookies.get(JsCookie.COOKIE_KEY_JS_SETTINGS_SELECTED_THEME);
return cookieValue;
}

/**
* @description checks if the theme is selected already
*
* @return boolean
*/
public static isJsSettingsSelectedTheme(): boolean
{
let cookieValue = Cookies.get(JsCookie.COOKIE_KEY_JS_SETTINGS_SELECTED_THEME);
return !StringUtils.isEmptyString(cookieValue);
}

}
2 changes: 2 additions & 0 deletions src/assets/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
@import "ui/components/forms.scss";
@import "ui/components/sidebar.scss";
@import "ui/components/widgets.scss";
@import "ui/components/right-tooltip.scss";
@import "ui/components/square-checkbox.scss";

@import "ui/page-elements/form-types.scss";
@import "ui/page-elements/user-settings.scss";
Expand Down
Loading

0 comments on commit 81cf002

Please sign in to comment.