Skip to content

Commit

Permalink
Add a new option to set the divider color
Browse files Browse the repository at this point in the history
  • Loading branch information
elchininet committed Oct 20, 2024
1 parent 50c7b8c commit c66d031
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Add a file named `sidebar-config.yaml` or `sidebar-config.json` into your `<conf
| info_color<sup>\*</sup> | String | no | Sets the color of the info texts of the sidebar items |
| info_color_selected<sup>\*</sup> | String | no | Sets the color of the info text of the selected sidebar item |
| notification_color<sup>\*</sup> | String | no | Sets the color of the sidebar notifications |
| divider_color<sup>\*</sup> | String | no | Sets the color of the sidebar dividers |
| styles | String | no | Custom styles that will be added to the styles block of the plugin. Useful to override styles |

>\* These options allow [JavaScript](#javascript-templates) or [Jinja](#jinja-templates) templates.
Expand Down
5 changes: 4 additions & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum SELECTOR {
SIDEBAR_NOTIFICATIONS = '.notifications',
PROFILE = '.profile',
MENU = '.menu',
DIVIDER = '.divider',
HA_ICON_BUTTON = 'ha-icon-button'
}

Expand All @@ -52,6 +53,7 @@ export enum CSS_VARIABLES {
SIDEBAR_BUTTON_COLOR = '--sidebar-icon-color',
SIDEBAR_MENU_BUTTON_BACKGROUND_COLOR = '--sidebar-menu-button-background-color',
PRIMARY_BACKGROUND_COLOR = '--primary-background-color',
DIVIDER_COLOR = '--divider-color',
CUSTOM_SIDEBAR_BACKGROUND = '--custom-sidebar-background',
CUSTOM_SIDEBAR_MENU_BACKGROUND = '--custom-sidebar-menu-background',
CUSTOM_SIDEBAR_TEXT_COLOR = '--custom-sidebar-text-color',
Expand All @@ -62,7 +64,8 @@ export enum CSS_VARIABLES {
CUSTOM_SIDEBAR_INFO_COLOR = '--custom-sidebar-info-color',
CUSTOM_SIDEBAR_SELECTED_INFO_COLOR = '--custom-sidebar-selected-info-color',
CUSTOM_SIDEBAR_NOTIFICATION_COLOR = '--custom-sidebar-notification-color',
CUSTOM_SIDEBAR_SELECTION_OPACITY = '--custom-sidebar-selection-opacity'
CUSTOM_SIDEBAR_SELECTION_OPACITY = '--custom-sidebar-selection-opacity',
CUSTOM_SIDEBAR_DIVIDER_COLOR = '--custom-sidebar-divider-color'
}

export enum CLASS {
Expand Down
8 changes: 7 additions & 1 deletion src/custom-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ class CustomSidebar {
['info_color', CSS_VARIABLES.CUSTOM_SIDEBAR_INFO_COLOR],
['info_color_selected', CSS_VARIABLES.CUSTOM_SIDEBAR_SELECTED_INFO_COLOR],
['notification_color', CSS_VARIABLES.CUSTOM_SIDEBAR_NOTIFICATION_COLOR],
['selection_opacity', CSS_VARIABLES.CUSTOM_SIDEBAR_SELECTION_OPACITY]
['selection_opacity', CSS_VARIABLES.CUSTOM_SIDEBAR_SELECTION_OPACITY],
['divider_color', CSS_VARIABLES.CUSTOM_SIDEBAR_DIVIDER_COLOR]
]
);

Expand Down Expand Up @@ -627,6 +628,7 @@ class CustomSidebar {
background: var(${ CSS_VARIABLES.CUSTOM_SIDEBAR_BACKGROUND }, var(${ CSS_VARIABLES.SIDEBAR_BACKGROUND_COLOR })) !important;
& ${ SELECTOR.MENU } {
background: var(${ CSS_VARIABLES.CUSTOM_SIDEBAR_MENU_BACKGROUND }, var(${ CSS_VARIABLES.CUSTOM_SIDEBAR_BACKGROUND }, var(${ CSS_VARIABLES.SIDEBAR_MENU_BUTTON_BACKGROUND_COLOR }, var(${ CSS_VARIABLES.PRIMARY_BACKGROUND_COLOR }))));
border-bottom: 1px solid var(${ CSS_VARIABLES.CUSTOM_SIDEBAR_DIVIDER_COLOR }, var(${ CSS_VARIABLES.DIVIDER_COLOR }));
}
& ${ SELECTOR.ITEM } {
& > ${ ELEMENT.PAPER_ICON_ITEM } {
Expand Down Expand Up @@ -678,6 +680,9 @@ class CustomSidebar {
background-color: var(${CSS_VARIABLES.CUSTOM_SIDEBAR_NOTIFICATION_COLOR}, var(--accent-color));
}
}
& ${ SELECTOR.DIVIDER }::before {
background-color: var(${ CSS_VARIABLES.CUSTOM_SIDEBAR_DIVIDER_COLOR }, var(${ CSS_VARIABLES.DIVIDER_COLOR }));
}
}
:host([expanded]) {
${ ELEMENT.PAPER_LISTBOX } {
Expand Down Expand Up @@ -706,6 +711,7 @@ class CustomSidebar {
&${ SELECTOR.ITEM_SELECTED } {
& > ${ ELEMENT.PAPER_ICON_ITEM } {
& > ${ SELECTOR.ITEM_TEXT } {
z-index: 1;
&[data-info]::after {
color: var(${ CSS_VARIABLES.CUSTOM_SIDEBAR_SELECTED_INFO_COLOR }, var(${ CSS_VARIABLES.SIDEBAR_SELECTED_TEXT_COLOR }));
}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ interface BaseConfig extends ColorConfig {
sidebar_background?: string;
sidebar_button_color?: string;
menu_background?: string;
divider_color?: string;
styles?: string;
}

Expand Down
3 changes: 2 additions & 1 deletion src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const EXTENDABLE_OPTIONS = [
'info_color',
'info_color_selected',
'notification_color',
'selection_opacity'
'selection_opacity',
'divider_color'
] as const;

type ExtendableConfigOption = typeof EXTENDABLE_OPTIONS[number];
Expand Down
2 changes: 2 additions & 0 deletions src/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const validateExceptionItem = (exception: ConfigException): void => {
'title_color',
'sidebar_button_color',
'menu_background',
'divider_color',
'styles'
],
`${ERROR_PREFIX}, exceptions`
Expand Down Expand Up @@ -198,6 +199,7 @@ export const validateConfig = (config: Config): void => {
'title_color',
'sidebar_button_color',
'menu_background',
'divider_color',
'styles'
],
`${ERROR_PREFIX},`
Expand Down

0 comments on commit c66d031

Please sign in to comment.