1616 * You should have received a copy of the GNU Affero General Public License
1717 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1818 */
19- import UIComponentWindow from './UIComponentWindow.js' ;
20- import Button from './Components/Button.js' ;
21- import Flexer from './Components/Flexer.js' ;
22- import Slider from './Components/Slider.js' ;
19+ import UIWindow from './UIWindow.js' ;
2320
2421const UIWindowThemeDialog = async function UIWindowThemeDialog ( options ) {
2522 options = options ?? { } ;
@@ -28,70 +25,33 @@ const UIWindowThemeDialog = async function UIWindowThemeDialog (options) {
2825
2926 let state = { } ;
3027
31- const slider_ch = ( e ) => {
32- state [ e . meta . name ] = e . target . value ;
33- if ( e . meta . name === 'lig' ) {
34- state . light_text = e . target . value < 60 ? true : false ;
35- }
36- svc_theme . apply ( state ) ;
37- } ;
38-
39- const hue_slider = new Slider ( {
40- label : i18n ( 'hue' ) ,
41- name : 'hue' , min : 0 , max : 360 ,
42- value : svc_theme . get ( 'hue' ) ,
43- on_change : slider_ch ,
44- } ) ;
45- const sat_slider = new Slider ( {
46- label : i18n ( 'saturation' ) ,
47- name : 'sat' , min : 0 , max : 100 ,
48- value : svc_theme . get ( 'sat' ) ,
49- on_change : slider_ch ,
50- } ) ;
51- const lig_slider = new Slider ( {
52- label : i18n ( 'lightness' ) ,
53- name : 'lig' , min : 0 , max : 100 ,
54- value : svc_theme . get ( 'lig' ) ,
55- on_change : slider_ch ,
56- } ) ;
57- const alpha_slider = new Slider ( {
58- label : i18n ( 'transparency' ) ,
59- name : 'alpha' , min : 0 , max : 1 , step : 0.01 ,
60- value : svc_theme . get ( 'alpha' ) ,
61- on_change : slider_ch ,
62- } ) ;
28+ let h = '' ;
29+ h += '<div class="theme-dialog-content" style="display: flex; flex-direction: column; gap: 10pt;">' ;
30+ h += `<button class="button button-secondary reset-colors-btn">${ i18n ( 'reset_colors' ) } </button>` ;
31+ h += `<div class="slider-container" style="display: flex; flex-direction: column; gap: 5px;">` ;
32+ h += `<label style="font-weight: 500; color: #5f626d;">${ i18n ( 'hue' ) } </label>` ;
33+ h += `<input type="range" class="theme-slider" id="hue-slider" name="hue" min="0" max="360" value="${ svc_theme . get ( 'hue' ) } " style="width: 100%;">` ;
34+ h += `</div>` ;
35+ h += `<div class="slider-container" style="display: flex; flex-direction: column; gap: 5px;">` ;
36+ h += `<label style="font-weight: 500; color: #5f626d;">${ i18n ( 'saturation' ) } </label>` ;
37+ h += `<input type="range" class="theme-slider" id="sat-slider" name="sat" min="0" max="100" value="${ svc_theme . get ( 'sat' ) } " style="width: 100%;">` ;
38+ h += `</div>` ;
39+ h += `<div class="slider-container" style="display: flex; flex-direction: column; gap: 5px;">` ;
40+ h += `<label style="font-weight: 500; color: #5f626d;">${ i18n ( 'lightness' ) } </label>` ;
41+ h += `<input type="range" class="theme-slider" id="lig-slider" name="lig" min="0" max="100" value="${ svc_theme . get ( 'lig' ) } " style="width: 100%;">` ;
42+ h += `</div>` ;
43+ h += `<div class="slider-container" style="display: flex; flex-direction: column; gap: 5px;">` ;
44+ h += `<label style="font-weight: 500; color: #5f626d;">${ i18n ( 'transparency' ) } </label>` ;
45+ h += `<input type="range" class="theme-slider" id="alpha-slider" name="alpha" min="0" max="1" step="0.01" value="${ svc_theme . get ( 'alpha' ) } " style="width: 100%;">` ;
46+ h += `</div>` ;
47+ h += '</div>' ;
6348
64- const component = new Flexer ( {
65- children : [
66- new Button ( {
67- label : i18n ( 'reset_colors' ) ,
68- style : 'secondary' ,
69- on_click : ( ) => {
70- svc_theme . reset ( ) ;
71- state = { } ;
72- hue_slider . set ( 'value' , svc_theme . get ( 'hue' ) ) ;
73- sat_slider . set ( 'value' , svc_theme . get ( 'sat' ) ) ;
74- lig_slider . set ( 'value' , svc_theme . get ( 'lig' ) ) ;
75- alpha_slider . set ( 'value' , svc_theme . get ( 'alpha' ) ) ;
76- } ,
77- } ) ,
78- hue_slider ,
79- sat_slider ,
80- lig_slider ,
81- alpha_slider ,
82- ] ,
83- gap : '10pt' ,
84- } ) ;
85-
86- const w = await UIComponentWindow ( {
49+ const el_window = await UIWindow ( {
8750 title : i18n ( 'ui_colors' ) ,
88- component,
8951 icon : null ,
9052 uid : null ,
9153 is_dir : false ,
92- message : 'message' ,
93- // body_icon: options.body_icon,
94- // backdrop: options.backdrop ?? false,
54+ body_content : h ,
9555 is_resizable : false ,
9656 is_droppable : false ,
9757 has_head : true ,
@@ -102,31 +62,43 @@ const UIWindowThemeDialog = async function UIWindowThemeDialog (options) {
10262 show_in_taskbar : false ,
10363 window_class : 'window-alert' ,
10464 dominant : true ,
105- body_content : '' ,
10665 width : 350 ,
107- // parent_uuid: options.parent_uuid,
108- // ...options.window_options,
10966 window_css :{
11067 height : 'initial' ,
11168 } ,
11269 body_css : {
11370 width : 'initial' ,
11471 padding : '20px' ,
115- // 'background-color': `hsla(
116- // var(--primary-hue),
117- // calc(max(var(--primary-saturation) - 15%, 0%)),
118- // calc(min(100%,var(--primary-lightness) + 20%)), .91)`,
11972 'background-color' : `hsla(
12073 var(--primary-hue),
12174 var(--primary-saturation),
12275 var(--primary-lightness),
12376 var(--primary-alpha))` ,
12477 'backdrop-filter' : 'blur(3px)' ,
125-
12678 } ,
12779 ...options . window_options ,
12880 } ) ;
12981
82+ // Event handlers
83+ $ ( el_window ) . find ( '.theme-slider' ) . on ( 'input' , function ( e ) {
84+ const name = $ ( this ) . attr ( 'name' ) ;
85+ const value = parseFloat ( $ ( this ) . val ( ) ) ;
86+ state [ name ] = value ;
87+ if ( name === 'lig' ) {
88+ state . light_text = value < 60 ? true : false ;
89+ }
90+ svc_theme . apply ( state ) ;
91+ } ) ;
92+
93+ $ ( el_window ) . find ( '.reset-colors-btn' ) . on ( 'click' , function ( ) {
94+ svc_theme . reset ( ) ;
95+ state = { } ;
96+ $ ( el_window ) . find ( '#hue-slider' ) . val ( svc_theme . get ( 'hue' ) ) ;
97+ $ ( el_window ) . find ( '#sat-slider' ) . val ( svc_theme . get ( 'sat' ) ) ;
98+ $ ( el_window ) . find ( '#lig-slider' ) . val ( svc_theme . get ( 'lig' ) ) ;
99+ $ ( el_window ) . find ( '#alpha-slider' ) . val ( svc_theme . get ( 'alpha' ) ) ;
100+ } ) ;
101+
130102 return { } ;
131103}
132104
0 commit comments