Skip to content

Commit e442a80

Browse files
committed
add new encoding toggle switch component
1 parent 92148a7 commit e442a80

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
@use "@/libs/theme/styles/variables" as *;
2+
3+
.container {
4+
display: flex;
5+
align-items: center;
6+
gap: .5rem;
7+
}
8+
9+
.label {
10+
display: flex;
11+
flex-direction: column;
12+
text-transform: uppercase;
13+
font-size: .75rem;
14+
line-height: 1.25rem;
15+
color: var(--color_fg_default);
16+
letter-spacing: .1px;
17+
}
18+
19+
.fullLabel {
20+
display: none;
21+
font-size: .8125rem;
22+
font-weight: 500;
23+
@media #{$breakpoint-dimension-sm} {
24+
display: unset;
25+
}
26+
}
27+
28+
.input {
29+
opacity: 0;
30+
width: 0;
31+
height: 0;
32+
}
33+
34+
.switch__container {
35+
position: relative;
36+
display: inline-block;
37+
width: 40px;
38+
height: 24px;
39+
transition: all .25s cubic-bezier(.17,.67,.83,.67);
40+
}
41+
42+
.picker__round {
43+
border-radius: 24px;
44+
&::before {
45+
border-radius: 50%;
46+
}
47+
}
48+
49+
.picker__slider {
50+
position: absolute;
51+
cursor: pointer;
52+
top: 0;
53+
left: 0;
54+
right: 0;
55+
bottom: 0;
56+
background-color: var(--color_bg_layer_bold);
57+
border: 1px solid var(--color_border_default);
58+
box-shadow: 0 0 1px rgba(0,0,0,.06),0 0 1px rgba(0,0,0,.06),inset 0 1px 1px .5px rgba(0,0,0,.04);
59+
transition: background-color .25s cubic-bezier(.17,.67,.83,.67),border .25s ease;
60+
&::before {
61+
position: absolute;
62+
content: "";
63+
height: 16px;
64+
width: 16px;
65+
top: 3px;
66+
left: 3px;
67+
background: linear-gradient(180deg,transparent,rgba(0,0,0,.08)),#fff;
68+
box-shadow: 0 2px 2px -1px rgba(0,0,0,.2),0 2px 4px -2px rgba(0,0,0,.2),inset 0 .5px .5px hsla(0,0%,100%,.12);
69+
transition: transform .25s cubic-bezier(.34,1.56,.64,1),background-color .2s ease;
70+
will-change: transform;
71+
}
72+
}
73+
74+
input:checked+.picker__slider {
75+
background-color: var(--color_fg_bold);
76+
border: 1px solid var(--color_fg_bold);
77+
&::before {
78+
transform: translateX(16px);
79+
background-color: var(--color_fg_on_state_success);
80+
}
81+
}
82+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { ChangeEvent, useEffect, useState } from "react";
2+
import styles from "./encoding-format-toggle-switch.module.scss";
3+
import { EncodingValues } from "@/features/common/values/encoding.values";
4+
import { useDecoderStore } from "@/features/decoder/services/decoder.store";
5+
import { getPickersUiDictionary } from "@/features/localization/services/ui-language-dictionary.service";
6+
import { Switch } from "react-aria-components";
7+
import clsx from "clsx";
8+
9+
interface EncodingFormatToggleSwitchComponentProps {
10+
languageCode: string;
11+
}
12+
13+
export const EncodingFormatToggleSwitchComponent: React.FC<
14+
EncodingFormatToggleSwitchComponentProps
15+
> = ({ languageCode }) => {
16+
const dictionary = getPickersUiDictionary(languageCode);
17+
18+
const handleSymmetricSecretKeyEncodingChange = useDecoderStore(
19+
(state) => state.handleSymmetricSecretKeyEncodingChange
20+
);
21+
22+
const onSecretEncodingFormatChange = (event: ChangeEvent<HTMLInputElement>) => {
23+
handleSymmetricSecretKeyEncodingChange(event.target.checked ? EncodingValues.BASE64URL : EncodingValues.UTF8);
24+
};
25+
26+
return (
27+
<div className={styles.container}>
28+
<div className={styles.label}>
29+
<span className={styles.fullLabel}>Base64URL Encoded?</span>
30+
</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>
40+
</div>
41+
);
42+
};

0 commit comments

Comments
 (0)