mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	client: switch widget: handle the disabled state
This commit is contained in:
		
							parent
							
								
									356c0570f3
								
							
						
					
					
						commit
						d4ef84e0b7
					
				| @ -56,11 +56,11 @@ export default class SharedSwitchWidget extends SwitchWidget { | ||||
|         this.isToggled = isShared; | ||||
| 
 | ||||
|         if (switchDisabled) { | ||||
|             //this.$widget.attr("title", t("shared_switch.inherited"));
 | ||||
|             //this.$switchOff.addClass("switch-disabled");
 | ||||
|             this.disabledTooltip = t("shared_switch.inherited"); | ||||
|             this.canToggle = false; | ||||
|         } else { | ||||
|             //this.$widget.removeAttr("title");
 | ||||
|             //this.$switchOff.removeClass("switch-disabled");
 | ||||
|             this.disabledTooltip = ""; | ||||
|             this.canToggle = true; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -28,7 +28,6 @@ const TPL = ` | ||||
|         border-radius: 24px; | ||||
|         background-color: var(--switch-off-track-background); | ||||
|         transition: background 200ms ease-in; | ||||
|         cursor: pointer; | ||||
|     } | ||||
| 
 | ||||
|     .switch-widget .switch-button.on { | ||||
| @ -61,13 +60,17 @@ const TPL = ` | ||||
|                     background 100ms ease-in; | ||||
|     } | ||||
| 
 | ||||
|     .switch-widget .switch-button > input[type="checkbox"] { | ||||
|     .switch-widget .switch-button input[type="checkbox"] { | ||||
|         position: absolute: | ||||
|         top: 0; | ||||
|         left: 0; | ||||
|         width: 100%; | ||||
|         height: 100%; | ||||
|         opacity: 0; | ||||
|     } | ||||
| 
 | ||||
|     .switch-widget .switch-button:not(.disabled) input[type="checkbox"], | ||||
|     .switch-widget .switch-button:not(.disabled) { | ||||
|         cursor: pointer; | ||||
|     } | ||||
| 
 | ||||
| @ -76,9 +79,8 @@ const TPL = ` | ||||
|         outline-offset: 2px; | ||||
|     } | ||||
| 
 | ||||
|     .switch-widget .switch-disabled { | ||||
|     .switch-widget .switch-button.disabled { | ||||
|         opacity: 70%; | ||||
|         pointer-events: none; | ||||
|     } | ||||
| 
 | ||||
|     .switch-widget .switch-help-button { | ||||
| @ -117,6 +119,8 @@ export default class SwitchWidget extends NoteContextAwareWidget { | ||||
|     switchOffName; | ||||
|     switchOffTooltip; | ||||
| 
 | ||||
|     disabledTooltip; | ||||
| 
 | ||||
|     currentState = false; | ||||
| 
 | ||||
|     doRender() { | ||||
| @ -167,4 +171,19 @@ export default class SwitchWidget extends NoteContextAwareWidget { | ||||
|             this.$switchButton.attr("title", this.switchOnTooltip); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     get canToggle() { | ||||
|         return (!this.$switchButton.hasClass("disabled")); | ||||
|     } | ||||
| 
 | ||||
|     set canToggle(isEnabled) { | ||||
|         this.$switchButton.toggleClass("disabled", !isEnabled); | ||||
|         this.$switchToggle.attr("disabled", !isEnabled); | ||||
| 
 | ||||
|         if (isEnabled) { | ||||
|             this.isToggled = this.currentState; // Reapply the correct tooltip
 | ||||
|         } else { | ||||
|             this.$switchButton.attr("title", this.disabledTooltip); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Adorian Doran
						Adorian Doran