Skip to content

Commit 1edd2a9

Browse files
committed
toggle component
1 parent e9d65fa commit 1edd2a9

File tree

5 files changed

+64
-8
lines changed

5 files changed

+64
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useContext, useEffect, useRef, useState } from 'react'
22
import { FormattedMessage } from 'react-intl'
33
import { useDialogDispatchers } from '../../context/provider'
44
import { CustomTooltip } from "@remix-ui/helper"
5+
import { ToggleSwitch } from '@remix-ui/toggle'
56
import { AppContext } from '../../context/context'
67
declare global {
78
interface Window {
@@ -64,14 +65,10 @@ const ManagePreferencesSwitcher = (prop: {
6465
/></p>
6566
</div>
6667
<div>
67-
<button
68-
data-id="matomoPerfAnalyticsSwitch"
69-
id='matomoPerfAnalyticsSwitch'
70-
className="btn text-ai mt-1"
71-
onClick={() => setMatPerfSwitch(!matPerfSwitch)}
72-
>
73-
{ matPerfSwitch ? <i className="fas fa-toggle-on fa-2xl"></i> : <i className="fas fa-toggle-off fa-2xl"></i> }
74-
</button>
68+
<ToggleSwitch
69+
id = "matomoPerfAnalyticsSwitch"
70+
size = "2xl"
71+
></ToggleSwitch>
7572
</div>
7673
</div>
7774
<div data-id="remixAI" className='justify-content-between d-flex'>

libs/remix-ui/toggle/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/toggle-switch/toggle-switch'

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

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React, { useState } from 'react'
2+
import { FormattedMessage } from 'react-intl'
3+
4+
import './toggle-switch.css'
5+
import { CustomTooltip } from '@remix-ui/helper'
6+
7+
interface IToggleSwitch {
8+
id: string
9+
onstyle?: string
10+
offstyle?: string
11+
size?: string // lg,xl,2xl etc
12+
tooltipTextId?: string
13+
classList?: string
14+
disabled?: boolean
15+
initiallyOn?: boolean
16+
}
17+
export const ToggleSwitch = (props: IToggleSwitch) => {
18+
const { id, onstyle, offstyle, size, tooltipTextId, disabled, initiallyOn} = props
19+
const [ isOn, setIsOn] = useState(initiallyOn)
20+
21+
22+
const handleClick = (e: any) => {
23+
}
24+
25+
const childJSXWithTooltip = (
26+
<CustomTooltip
27+
placement={"auto"}
28+
tooltipId="matomoAnonAnalyticsTooltip"
29+
tooltipClasses="text-nowrap"
30+
tooltipText={<FormattedMessage id="remixApp.mpOp1Tooltip" />}
31+
>
32+
<button
33+
data-id="matomoAnonAnalyticsSwitch"
34+
id='matomoAnonAnalyticsSwitch'
35+
className="btn text-ai"
36+
>
37+
<i className="fas fa-toggle-on fa-2xl"></i>
38+
</button>
39+
</CustomTooltip>
40+
)
41+
42+
const childJSXWithoutTooltip = (
43+
<button
44+
data-id={ id + "Switch"}
45+
id='matomoAnonAnalyticsSwitch'
46+
className="btn text-ai"
47+
>
48+
{ 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+
</button>
50+
)
51+
52+
return tooltipTextId ? childJSXWithTooltip : childJSXWithoutTooltip
53+
}
54+
55+
export default ToggleSwitch

tsconfig.paths.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
"@remix-ui/toaster": [
134134
"libs/remix-ui/toaster/src/index.ts"
135135
],
136+
"@remix-ui/toggle": [
137+
"libs/remix-ui/toggle/src/index.ts"
138+
],
136139
"@remix-ui/tooltip-popup": [
137140
"libs/remix-ui/tooltip-popup/src/index.ts"
138141
],

0 commit comments

Comments
 (0)