Skip to content

Commit 21ba061

Browse files
committed
update toggle switch logic and styles
1 parent a054985 commit 21ba061

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

src/features/decoder/components/encoding-format-toggle-swith/encoding-format-toggle-switch.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@use "@/libs/theme/styles/variables" as *;
22

3+
.encoder_switch {
4+
display: flex;
5+
width: 100%;
6+
justify-content: flex-end;
7+
}
8+
39
.container {
410
display: flex;
511
align-items: center;

src/features/decoder/components/encoding-format-toggle-swith/encoding-format-toggle-switch.tsx

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,58 @@ import { useDecoderStore } from "@/features/decoder/services/decoder.store";
55
import { getPickersUiDictionary } from "@/features/localization/services/ui-language-dictionary.service";
66
import { Switch } from "react-aria-components";
77
import clsx from "clsx";
8+
import { useEncoderStore } from "@/features/encoder/services/encoder.store";
89

910
interface EncodingFormatToggleSwitchComponentProps {
1011
languageCode: string;
12+
isEncoding?: boolean;
1113
}
1214

1315
export const EncodingFormatToggleSwitchComponent: React.FC<
1416
EncodingFormatToggleSwitchComponentProps
15-
> = ({ languageCode }) => {
17+
> = ({ languageCode, isEncoding = false }) => {
1618
const dictionary = getPickersUiDictionary(languageCode);
1719

18-
const handleSymmetricSecretKeyEncodingChange = useDecoderStore(
20+
const handleSymmetricSecretKeyEncodingChangeDe = useDecoderStore(
1921
(state) => state.handleSymmetricSecretKeyEncodingChange
2022
);
2123

22-
const onSecretEncodingFormatChange = (event: ChangeEvent<HTMLInputElement>) => {
23-
handleSymmetricSecretKeyEncodingChange(event.target.checked ? EncodingValues.BASE64URL : EncodingValues.UTF8);
24+
const handleSymmetricSecretKeyEncodingChangeEn = useEncoderStore(
25+
(state) => state.handleSymmetricSecretKeyEncodingChange
26+
);
27+
28+
const onSecretEncodingFormatChange = (
29+
event: ChangeEvent<HTMLInputElement>
30+
) => {
31+
if (isEncoding) {
32+
handleSymmetricSecretKeyEncodingChangeEn(
33+
event.target.checked ? EncodingValues.BASE64URL : EncodingValues.UTF8
34+
);
35+
return;
36+
}
37+
handleSymmetricSecretKeyEncodingChangeDe(
38+
event.target.checked ? EncodingValues.BASE64URL : EncodingValues.UTF8
39+
);
2440
};
2541

2642
return (
27-
<div className={styles.container}>
28-
<div className={styles.label}>
29-
<span className={styles.fullLabel}>Base64URL Encoded?</span>
43+
<div className={styles.encoder_switch}>
44+
<div className={styles.container}>
45+
<div className={styles.label}>
46+
<span className={styles.fullLabel}>Base64URL Encoded?</span>
47+
</div>
48+
<label className={styles.switch__container}>
49+
<input
50+
type="checkbox"
51+
role="switch"
52+
className={styles.input}
53+
onChange={onSecretEncodingFormatChange}
54+
/>
55+
<span
56+
className={clsx(styles.picker__round, styles.picker__slider)}
57+
></span>
58+
</label>
3059
</div>
31-
<label className={styles.switch__container}>
32-
<input type="checkbox" role="switch" className={styles.input} onChange={onSecretEncodingFormatChange}/>
33-
<span
34-
className={clsx(
35-
styles.picker__round,
36-
styles.picker__slider
37-
)}
38-
></span>
39-
</label>
4060
</div>
4161
);
4262
};

0 commit comments

Comments
 (0)