1- import React from 'react' ;
1+ import React , { useEffect } from 'react' ;
22import { Mode , Source , Autorename } from 'postcss-rtlcss/options' ;
33import { useAppContext } from '@components/AppProvider' ;
44import { Switch } from '@components/Switch' ;
55import { SwitchGroup } from '@components/SwitchGroup' ;
66import { stylesheet } from './stylesheet' ;
7+ import { isBoolean } from '@utilities/types' ;
78
89export const Options = ( ) : JSX . Element => {
910
1011 const {
1112 optionsOpen,
12- options,
1313 changeOptionsMode,
1414 changeOptionsSource,
1515 changeOptionsSafeBothPrefix,
@@ -19,7 +19,8 @@ export const Options = (): JSX.Element => {
1919 changeOptionsProcessEnv,
2020 changeOptionsUseCalc,
2121 changeOptionsAutoRename,
22- changeOptionsGreedy
22+ changeOptionsGreedy,
23+ fetchOptions
2324 } = useAppContext ( ) ;
2425
2526 const changeMode = ( value : string ) : void => {
@@ -48,6 +49,41 @@ export const Options = (): JSX.Element => {
4849 }
4950 } ;
5051 const changeGreedy = ( checked : boolean ) : void => changeOptionsGreedy ( checked ) ;
52+
53+ useEffect ( ( ) => {
54+ if ( fetchOptions ) {
55+ if ( fetchOptions . mode ) {
56+ changeMode ( fetchOptions . mode as string ) ;
57+ }
58+ if ( fetchOptions . source ) {
59+ changeSource ( fetchOptions . source === 'rtl' ) ;
60+ }
61+ if ( isBoolean ( fetchOptions . safeBothPrefix ) ) {
62+ changeIgnorePrefixedRules ( fetchOptions . safeBothPrefix as boolean ) ;
63+ }
64+ if ( isBoolean ( fetchOptions . ignorePrefixedRules ) ) {
65+ changeIgnorePrefixedRules ( fetchOptions . ignorePrefixedRules as boolean ) ;
66+ }
67+ if ( isBoolean ( fetchOptions . processUrls ) ) {
68+ changeProcessUrls ( fetchOptions . processUrls as boolean ) ;
69+ }
70+ if ( isBoolean ( fetchOptions . processKeyFrames ) ) {
71+ changeProcessKeyframes ( fetchOptions . processKeyFrames as boolean ) ;
72+ }
73+ if ( isBoolean ( fetchOptions . processEnv ) ) {
74+ changeProcessEnv ( fetchOptions . processEnv as boolean ) ;
75+ }
76+ if ( isBoolean ( fetchOptions . useCalc ) ) {
77+ changeUseCalc ( fetchOptions . useCalc as boolean ) ;
78+ }
79+ if ( fetchOptions . autoRename ) {
80+ changeAutoRename ( fetchOptions . autoRename as string ) ;
81+ }
82+ if ( isBoolean ( fetchOptions . greedy ) ) {
83+ changeGreedy ( fetchOptions . greedy as boolean ) ;
84+ }
85+ }
86+ } , [ fetchOptions ] ) ;
5187
5288 return (
5389 < div css = { stylesheet . wrapper } data-opened = { optionsOpen } >
@@ -62,57 +98,85 @@ export const Options = (): JSX.Element => {
6298 name = "mode"
6399 values = { [ 'combined' , 'override' , 'diff' ] }
64100 onChange = { changeMode }
101+ active = { fetchOptions ?. mode as string || 'combined' }
65102 />
66103 </ div >
67104 { /* Source */ }
68105 < div css = { stylesheet . panel } >
69106 < Switch
70107 labels = { [ 'source: ltr' , 'source: rtl' ] }
71108 onChange = { changeSource }
109+ attributes = { {
110+ checked : fetchOptions ?. source === 'rtl'
111+ } }
72112 />
73113 </ div >
74114 { /* safeBothPrefix */ }
75115 < div css = { stylesheet . panel } >
76116 < Switch
77117 labels = { [ 'safeBothPrefix: false' , 'safeBothPrefix: true' ] }
78118 onChange = { changeSafeBothPrefix }
119+ attributes = { {
120+ checked : ! ! fetchOptions ?. safeBothPrefix
121+ } }
79122 />
80123 </ div >
81124 { /* ignorePrefixedRules */ }
82125 < div css = { stylesheet . panel } >
83126 < Switch
84127 labels = { [ 'ignorePrefixedRules: false' , 'ignorePrefixedRules: true' ] }
85- attributes = { { checked : true } }
86128 onChange = { changeIgnorePrefixedRules }
129+ attributes = { {
130+ checked : ! ! (
131+ isBoolean ( fetchOptions ?. ignorePrefixedRules )
132+ ? fetchOptions . ignorePrefixedRules
133+ : true
134+ )
135+ } }
87136 />
88137 </ div >
89138 { /* processUrls */ }
90139 < div css = { stylesheet . panel } >
91140 < Switch
92141 labels = { [ 'processUrls: false' , 'processUrls: true' ] }
93142 onChange = { changeProcessUrls }
143+ attributes = { {
144+ checked : ! ! fetchOptions ?. processUrls
145+ } }
94146 />
95147 </ div >
96148 { /* processKeyFrames */ }
97149 < div css = { stylesheet . panel } >
98150 < Switch
99151 labels = { [ 'processKeyFrames: false' , 'processKeyFrames: true' ] }
100152 onChange = { changeProcessKeyframes }
153+ attributes = { {
154+ checked : ! ! fetchOptions ?. processKeyFrames
155+ } }
101156 />
102157 </ div >
103158 { /* processEnv */ }
104159 < div css = { stylesheet . panel } >
105160 < Switch
106161 labels = { [ 'processEnv: false' , 'processEnv: true' ] }
107- attributes = { { checked : true } }
108162 onChange = { changeProcessEnv }
163+ attributes = { {
164+ checked : ! ! (
165+ isBoolean ( fetchOptions ?. processEnv )
166+ ? fetchOptions . processEnv
167+ : true
168+ )
169+ } }
109170 />
110171 </ div >
111172 { /* useCalc */ }
112173 < div css = { stylesheet . panel } >
113174 < Switch
114175 labels = { [ 'useCalc: false' , 'useCalc: true' ] }
115176 onChange = { changeUseCalc }
177+ attributes = { {
178+ checked : ! ! fetchOptions ?. useCalc
179+ } }
116180 />
117181 </ div >
118182 { /* autoRename */ }
@@ -122,13 +186,17 @@ export const Options = (): JSX.Element => {
122186 name = "auto-rename"
123187 values = { [ 'disabled' , 'flexible' , 'strict' ] }
124188 onChange = { changeAutoRename }
189+ active = { fetchOptions ?. autoRename as string || 'disabled' }
125190 />
126191 </ div >
127192 { /* greedy */ }
128193 < div css = { stylesheet . panel } >
129194 < Switch
130195 labels = { [ 'greedy: false' , 'greedy: true' ] }
131196 onChange = { changeGreedy }
197+ attributes = { {
198+ checked : ! ! fetchOptions ?. greedy
199+ } }
132200 />
133201 </ div >
134202 </ div >
0 commit comments