Skip to content

Commit 0858d61

Browse files
committed
use react component
1 parent 1edd2a9 commit 0858d61

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

libs/remix-ui/app/src/lib/remix-app/components/modals/managePreferences.tsx

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,12 @@ const ManagePreferencesSwitcher = (prop: {
3232
<p className='form-check-label text-secondary'><FormattedMessage id="remixApp.mpOp1Details" /></p>
3333
</div>
3434
<div>
35-
<CustomTooltip
36-
placement={"auto"}
37-
tooltipId="matomoAnonAnalyticsTooltip"
38-
tooltipClasses="text-nowrap"
39-
tooltipText={<FormattedMessage id="remixApp.mpOp1Tooltip" />}
40-
>
41-
<button
42-
data-id="matomoAnonAnalyticsSwitch"
43-
id='matomoAnonAnalyticsSwitch'
44-
className="btn text-ai"
45-
disabled
46-
>
47-
<i className="fas fa-toggle-on fa-2xl"></i>
48-
</button>
49-
</CustomTooltip>
35+
<ToggleSwitch
36+
id = "matomoAnonAnalyticsSwitch"
37+
size = "2xl"
38+
tooltipTextId = "remixApp.mpOp1Tooltip"
39+
disabled = {true}
40+
></ToggleSwitch>
5041
</div>
5142
</div>
5243
<div data-id="matomoPerfAnalytics" className='justify-content-between d-flex'>
@@ -87,14 +78,10 @@ const ManagePreferencesSwitcher = (prop: {
8778
/></p>
8879
</div>
8980
<div>
90-
<button
91-
data-id="remixAISwitch"
92-
id='remixAISwitch'
93-
className="btn text-ai"
94-
onClick={() => setRemixAISwitch(!remixAISwitch)}
95-
>
96-
{ remixAISwitch ? <i className="fas fa-toggle-on fa-2xl"></i> : <i className="fas fa-toggle-off fa-2xl"></i> }
97-
</button>
81+
<ToggleSwitch
82+
id = "remixAISwitch"
83+
size = "2xl"
84+
></ToggleSwitch>
9885
</div>
9986
</div>
10087
</>

libs/remix-ui/toggle/src/lib/toggle-switch/toggle-switch.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ import { CustomTooltip } from '@remix-ui/helper'
66

77
interface IToggleSwitch {
88
id: string
9-
onstyle?: string
10-
offstyle?: string
9+
onstyle?: string // text-ai, text-primary etc
10+
offstyle?: string // text-ai, text-secondary etc
1111
size?: string // lg,xl,2xl etc
12-
tooltipTextId?: string
13-
classList?: string
12+
tooltipTextId?: string // formatted message id like "remixApp.mpOp1Tooltip" etc
1413
disabled?: boolean
1514
initiallyOn?: boolean
1615
}
1716
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+
1923
const [ isOn, setIsOn] = useState(initiallyOn)
2024

2125

@@ -27,14 +31,15 @@ export const ToggleSwitch = (props: IToggleSwitch) => {
2731
placement={"auto"}
2832
tooltipId="matomoAnonAnalyticsTooltip"
2933
tooltipClasses="text-nowrap"
30-
tooltipText={<FormattedMessage id="remixApp.mpOp1Tooltip" />}
34+
tooltipText={<FormattedMessage id={tooltipTextId} />}
3135
>
3236
<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}
3641
>
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> }
3843
</button>
3944
</CustomTooltip>
4045
)
@@ -43,7 +48,7 @@ export const ToggleSwitch = (props: IToggleSwitch) => {
4348
<button
4449
data-id={ id + "Switch"}
4550
id='matomoAnonAnalyticsSwitch'
46-
className="btn text-ai"
51+
className={`btn ${isOn ? onstyle : offstyle}`}
4752
>
4853
{ 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> }
4954
</button>

0 commit comments

Comments
 (0)