Skip to content

Commit 49cdc44

Browse files
committed
component onclick
1 parent 0858d61 commit 49cdc44

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const ManagePreferencesSwitcher = (prop: {
5959
<ToggleSwitch
6060
id = "matomoPerfAnalyticsSwitch"
6161
size = "2xl"
62+
isOn = {matPerfSwitch}
63+
onClick = {() => setMatPerfSwitch(!matPerfSwitch)}
6264
></ToggleSwitch>
6365
</div>
6466
</div>
@@ -81,6 +83,8 @@ const ManagePreferencesSwitcher = (prop: {
8183
<ToggleSwitch
8284
id = "remixAISwitch"
8385
size = "2xl"
86+
isOn = {remixAISwitch}
87+
onClick = {() => setRemixAISwitch(!remixAISwitch)}
8488
></ToggleSwitch>
8589
</div>
8690
</div>

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,15 @@ interface IToggleSwitch {
1111
size?: string // lg,xl,2xl etc
1212
tooltipTextId?: string // formatted message id like "remixApp.mpOp1Tooltip" etc
1313
disabled?: boolean
14-
initiallyOn?: boolean
14+
isOn?: boolean
15+
onClick?: () => void
1516
}
1617
export const ToggleSwitch = (props: IToggleSwitch) => {
17-
let { id, onstyle, offstyle, size, tooltipTextId, disabled, initiallyOn} = props
18+
let { id, onstyle, offstyle, size, tooltipTextId, disabled, isOn, onClick} = props
1819
size = size || 'lg'
1920
onstyle = onstyle || 'text-primary'
2021
offstyle = offstyle || 'text-secondary'
21-
initiallyOn = initiallyOn || true
22-
23-
const [ isOn, setIsOn] = useState(initiallyOn)
24-
25-
26-
const handleClick = (e: any) => {
27-
}
22+
isOn = isOn === false ? isOn : true
2823

2924
const childJSXWithTooltip = (
3025
<CustomTooltip
@@ -37,6 +32,7 @@ export const ToggleSwitch = (props: IToggleSwitch) => {
3732
data-id={ id + "Switch"}
3833
id='matomoAnonAnalyticsSwitch'
3934
className={`btn ${isOn ? onstyle : offstyle}`}
35+
onClick={() => { if(!disabled) onClick()}}
4036
disabled = {disabled || false}
4137
>
4238
{ 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,6 +45,8 @@ export const ToggleSwitch = (props: IToggleSwitch) => {
4945
data-id={ id + "Switch"}
5046
id='matomoAnonAnalyticsSwitch'
5147
className={`btn ${isOn ? onstyle : offstyle}`}
48+
onClick={() => { if(!disabled) onClick()}}
49+
disabled = {disabled || false}
5250
>
5351
{ 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> }
5452
</button>

0 commit comments

Comments
 (0)