@@ -6,16 +6,20 @@ import { CustomTooltip } from '@remix-ui/helper'
6
6
7
7
interface IToggleSwitch {
8
8
id : string
9
- onstyle ?: string
10
- offstyle ?: string
9
+ onstyle ?: string // text-ai, text-primary etc
10
+ offstyle ?: string // text-ai, text-secondary etc
11
11
size ?: string // lg,xl,2xl etc
12
- tooltipTextId ?: string
13
- classList ?: string
12
+ tooltipTextId ?: string // formatted message id like "remixApp.mpOp1Tooltip" etc
14
13
disabled ?: boolean
15
14
initiallyOn ?: boolean
16
15
}
17
16
export const ToggleSwitch = ( props : IToggleSwitch ) => {
18
- const { id, onstyle, offstyle, size, tooltipTextId, disabled, initiallyOn} = props
17
+ let { id, onstyle, offstyle, size, tooltipTextId, disabled, initiallyOn} = props
18
+ size = size || 'lg'
19
+ onstyle = onstyle || 'text-primary'
20
+ offstyle = offstyle || 'text-secondary'
21
+ initiallyOn = initiallyOn || true
22
+
19
23
const [ isOn , setIsOn ] = useState ( initiallyOn )
20
24
21
25
@@ -27,14 +31,15 @@ export const ToggleSwitch = (props: IToggleSwitch) => {
27
31
placement = { "auto" }
28
32
tooltipId = "matomoAnonAnalyticsTooltip"
29
33
tooltipClasses = "text-nowrap"
30
- tooltipText = { < FormattedMessage id = "remixApp.mpOp1Tooltip" /> }
34
+ tooltipText = { < FormattedMessage id = { tooltipTextId } /> }
31
35
>
32
36
< button
33
- data-id = "matomoAnonAnalyticsSwitch"
34
- id = 'matomoAnonAnalyticsSwitch'
35
- className = "btn text-ai"
37
+ data-id = { id + "Switch" }
38
+ id = 'matomoAnonAnalyticsSwitch'
39
+ className = { `btn ${ isOn ? onstyle : offstyle } ` }
40
+ disabled = { disabled || false }
36
41
>
37
- < i className = " fas fa-toggle-on fa-2xl" > </ i >
42
+ { isOn ? < i className = { ` fas fa-toggle-on ${ size ? ` fa-${ size } ` : "fa-lg" } ` } > </ i > : < i className = { `fas fa-toggle-off ${ size ? `fa- ${ size } ` : "fa-lg" } ` } > </ i > }
38
43
</ button >
39
44
</ CustomTooltip >
40
45
)
@@ -43,7 +48,7 @@ export const ToggleSwitch = (props: IToggleSwitch) => {
43
48
< button
44
49
data-id = { id + "Switch" }
45
50
id = 'matomoAnonAnalyticsSwitch'
46
- className = " btn text-ai"
51
+ className = { ` btn ${ isOn ? onstyle : offstyle } ` }
47
52
>
48
53
{ isOn ? < i className = { `fas fa-toggle-on ${ size ? `fa-${ size } ` : "fa-lg" } ` } > </ i > : < i className = { `fas fa-toggle-off ${ size ? `fa-${ size } ` : "fa-lg" } ` } > </ i > }
49
54
</ button >
0 commit comments