-
Notifications
You must be signed in to change notification settings - Fork 354
Expand file tree
/
Copy pathencoding-format-toggle-switch.tsx
More file actions
61 lines (55 loc) · 2.08 KB
/
encoding-format-toggle-switch.tsx
File metadata and controls
61 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { ChangeEvent, useEffect, useState } from "react";
import styles from "./encoding-format-toggle-switch.module.scss";
import { EncodingValues } from "@/features/common/values/encoding.values";
import { useDecoderStore } from "@/features/decoder/services/decoder.store";
import { getPickersUiDictionary } from "@/features/localization/services/ui-language-dictionary.service";
import clsx from "clsx";
import { useEncoderStore } from "@/features/encoder/services/encoder.store";
interface EncodingFormatToggleSwitchComponentProps {
languageCode: string;
isEncoding?: boolean;
}
export const EncodingFormatToggleSwitchComponent: React.FC<
EncodingFormatToggleSwitchComponentProps
> = ({ languageCode, isEncoding = false }) => {
const dictionary = getPickersUiDictionary(languageCode);
const handleSymmetricSecretKeyEncodingChangeDe = useDecoderStore(
(state) => state.handleSymmetricSecretKeyEncodingChange
);
const handleSymmetricSecretKeyEncodingChangeEn = useEncoderStore(
(state) => state.handleSymmetricSecretKeyEncodingChange
);
const onSecretEncodingFormatChange = (
event: ChangeEvent<HTMLInputElement>
) => {
if (isEncoding) {
handleSymmetricSecretKeyEncodingChangeEn(
event.target.checked ? EncodingValues.BASE64URL : EncodingValues.UTF8
);
return;
}
handleSymmetricSecretKeyEncodingChangeDe(
event.target.checked ? EncodingValues.BASE64URL : EncodingValues.UTF8
);
};
return (
<div className={clsx(styles.base_switch, isEncoding && styles.encoder)}>
<div className={styles.container}>
<div className={styles.label}>
<span className={styles.fullLabel}>{dictionary.base64checkbox.label}</span>
</div>
<label className={styles.switch__container}>
<input
type="checkbox"
role="switch"
className={styles.input}
onChange={onSecretEncodingFormatChange}
/>
<span
className={clsx(styles.picker__round, styles.picker__slider)}
></span>
</label>
</div>
</div>
);
};