Skip to content

Commit 92148a7

Browse files
authored
Merge pull request #883 from jsonwebtoken/update-algorithm-picker
Update algorithm picker
2 parents 83bea5a + 2993e82 commit 92148a7

File tree

10 files changed

+231
-192
lines changed

10 files changed

+231
-192
lines changed

src/features/common/components/debugger-picker/debugger-picker.component.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { DebuggerPickerOptionModel } from "@/features/common/models/debugger-pic
55
import { LibraryFilterLabel } from "@/features/libraries/models/library-filters.model";
66
import { isGroupedOptionsType } from "./utils";
77

8-
98
interface PickerLabelProps {
109
label: string | null;
1110
}
@@ -17,12 +16,12 @@ const getGroupLabel = (
1716
>,
1817
selected: DebuggerPickerOptionModel
1918
): LibraryFilterLabel | undefined => {
20-
if(!isGroupedOptionsType(options)) return undefined
19+
if (!isGroupedOptionsType(options)) return undefined;
2120

2221
const group = (options as GroupBase<DebuggerPickerOptionModel>[]).find(
2322
(group) => group.options.some((opt) => opt.value === selected.value)
2423
);
25-
return group ? group.label as LibraryFilterLabel : undefined;
24+
return group ? (group.label as LibraryFilterLabel) : undefined;
2625
};
2726

2827
const PickerLabel: React.FC<PickerLabelProps> = ({ label }) => {
@@ -56,15 +55,12 @@ export const DebuggerPickerComponent: React.FC<
5655
label,
5756
options,
5857
handleSelection,
59-
selectedOptionCode,
6058
placeholder,
6159
minWidth,
6260
}) => {
6361
const [isClient, setIsClient] = useState(false);
6462

65-
const handleChange = (
66-
selection: SingleValue<DebuggerPickerOptionModel>
67-
) => {
63+
const handleChange = (selection: SingleValue<DebuggerPickerOptionModel>) => {
6864
if (!selection) {
6965
return;
7066
}
@@ -78,21 +74,20 @@ export const DebuggerPickerComponent: React.FC<
7874

7975
if (!isClient) {
8076
return (
81-
<div className={styles.picker} data-has-label={label !== null}>
77+
<>
8278
<PickerLabel label={label} />
8379
<div className="react-select-placeholder"></div>
84-
</div>
80+
</>
8581
);
8682
}
8783

8884
return (
89-
<div className={styles.picker} data-has-label={label !== null}>
85+
<>
9086
{label && <PickerLabel label={label} />}
9187
<Select
9288
aria-label={"Debugger picker"}
9389
className="react-select-container"
9490
onChange={handleChange}
95-
value={selectedOptionCode}
9691
options={options}
9792
menuPortalTarget={document.body}
9893
classNamePrefix={"react-select"}
@@ -101,8 +96,22 @@ export const DebuggerPickerComponent: React.FC<
10196
styles={{
10297
control: (base) => ({
10398
...base,
104-
minHeight: "1.75rem",
105-
height: "1.75rem",
99+
alignItems: 'center',
100+
cursor: 'pointer',
101+
display: 'flex',
102+
flexWrap: 'wrap',
103+
justifyContent: 'space-between',
104+
minHeight: '2.5rem',
105+
position: 'relative',
106+
transition: '0.2s ease-out',
107+
borderRadius: '1rem',
108+
boxShadow: 'rgba(0, 0, 0, 0.04) 0px 1px 1px -0.5px, rgba(0, 0, 0, 0.04) 0px 3px 3px -1.5px, rgba(0, 0, 0, 0.04) 0px 0px 0px 1px inset',
109+
boxSizing: 'border-box',
110+
height: '2.5rem',
111+
width: '100%',
112+
padding: '0px 0.25rem',
113+
minWidth: '240px',
114+
outline: '0px !important',
106115
...(minWidth ? { minWidth: minWidth } : {}),
107116
}),
108117

@@ -125,6 +134,6 @@ export const DebuggerPickerComponent: React.FC<
125134
}),
126135
}}
127136
></Select>
128-
</div>
137+
</>
129138
);
130139
};

src/features/common/components/debugger-picker/debugger-picker.module.scss

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ $picker-list-width-lg: 7rem;
1414
$picker-list-offset-lg: calc(($picker-list-width-lg - $picker-width-lg) / 2);
1515

1616
.picker {
17-
position: relative;
18-
display: flex;
19-
justify-content: space-between;
20-
align-items: center;
21-
background: transparent;
22-
border: none;
23-
color: var(--color_fg_bold);
24-
cursor: pointer;
25-
gap: 0.75rem;
17+
position: relative;
18+
display: flex;
19+
justify-content: space-between;
20+
align-items: center;
21+
background: transparent;
22+
color: var(--color_fg_bold);
23+
gap: .75rem;
24+
width: 100vh;
2625

2726
//width: $picker-width-sm;
2827

@@ -56,4 +55,4 @@ $picker-list-offset-lg: calc(($picker-list-width-lg - $picker-width-lg) / 2);
5655

5756
.picker__fullName {
5857
display: flex;
59-
}
58+
}

src/features/common/components/widget/widget/widget.component.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { ReactNode, useId } from "react";
22
import styles from "./widget.module.scss";
33
import { BoxComponent } from "@/features/common/components/box/box.component";
4-
import { WidgetAlgPickerComponent } from "@/features/debugger/components/debugger-alg-picker/debugger-alg-picker.component";
54
import { DebuggerWidgetValues } from "@/features/common/values/debugger-widget.values";
65
import { clsx } from "clsx";
76
import { getLocalizedSecondaryFont } from "@/libs/theme/fonts";
@@ -23,12 +22,9 @@ interface WidgetComponentProps {
2322

2423
export const WidgetComponent: React.FC<WidgetComponentProps> = ({
2524
id,
26-
widget,
2725
languageCode,
2826
headlineConfig,
2927
title,
30-
description,
31-
exampleGenerator,
3228
contentInput,
3329
contentOutput,
3430
}) => {
@@ -42,6 +38,7 @@ export const WidgetComponent: React.FC<WidgetComponentProps> = ({
4238
contentClassName={styles.content}
4339
aria-labelledby={headlineConfig.isVisible ? widgetId : undefined}
4440
>
41+
4542
{headlineConfig.isVisible && (
4643
<h2
4744
id={widgetId}
@@ -54,14 +51,7 @@ export const WidgetComponent: React.FC<WidgetComponentProps> = ({
5451
{headlineConfig.actions}
5552
</h2>
5653
)}
57-
<div className={styles.input__description}>
58-
<span>{description}</span>
59-
<WidgetAlgPickerComponent
60-
label={exampleGenerator.label}
61-
languageCode={languageCode}
62-
widget={widget}
63-
/>
64-
</div>
54+
6555
<div heap-ignore="true" className={styles.content__input}>
6656
{contentInput}
6757
</div>

src/features/common/components/widget/widget/widget.module.scss

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,3 @@
4242
line-height: 2.25rem;
4343
}
4444
}
45-
46-
.input__description {
47-
grid-column: span 6;
48-
width: 100%;
49-
color: var(--color_fg_default);
50-
display: flex;
51-
flex-direction: column;
52-
margin-bottom: 2rem;
53-
54-
gap: 0.625rem;
55-
row-gap: 0.25rem;
56-
57-
font-size: 0.875rem;
58-
line-height: 1.375rem;
59-
60-
& strong {
61-
font-weight: 500;
62-
}
63-
64-
@media #{$breakpoint-dimension-sm} {
65-
grid-column: span 12;
66-
flex-direction: row;
67-
align-items: center;
68-
justify-content: space-between;
69-
}
70-
}

src/features/debugger/components/debugger-alg-picker/debugger-alg-picker.component.tsx

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import {
1515
algDictionary,
1616
jwsExampleAlgHeaderParameterValuesDictionary,
1717
} from "@/features/common/values/jws-alg-header-parameter-values.dictionary";
18-
import { useButton } from "@react-aria/button";
19-
import { clsx } from "clsx";
20-
import { PrimaryFont } from "@/libs/theme/fonts";
18+
import { useButton } from "@react-aria/button"
2119
import { DebuggerPickerOptionModel } from "@/features/common/models/debugger-picker-option.model";
2220

2321
enum PickerStates {
@@ -60,11 +58,11 @@ export const WidgetAlgPickerComponent: React.FC<
6058
elementType: "span",
6159
preventFocusOnPress: true,
6260
},
63-
buttonRef,
61+
buttonRef
6462
);
6563

6664
const [pickerState, setPickerState] = useState<PickerStates>(
67-
PickerStates.IDLE,
65+
PickerStates.IDLE
6866
);
6967
const [canUseEs512, setCanUseEs512] = useState(false);
7068
const [canUseEd25519, setCanUseEd25519] = useState(false);
@@ -73,11 +71,11 @@ export const WidgetAlgPickerComponent: React.FC<
7371
const dictionary = getPickersUiDictionary(languageCode);
7472

7573
const selectEncoderAlg$ = useEncoderStore(
76-
(state) => state.selectEncodingExample,
74+
(state) => state.selectEncodingExample
7775
);
7876

7977
const selectDecoderAlg$ = useDecoderStore(
80-
(state) => state.selectDecodingExample,
78+
(state) => state.selectDecodingExample
8179
);
8280

8381
const selectExample = (value: string) => {
@@ -94,13 +92,6 @@ export const WidgetAlgPickerComponent: React.FC<
9492
setPickerState(PickerStates.IDLE);
9593
};
9694

97-
const openPicker = () => {
98-
setPickerState(PickerStates.PICKING);
99-
};
100-
101-
const closePicker = () => {
102-
setPickerState(PickerStates.IDLE);
103-
};
10495

10596
useEffect(() => {
10697
(async function runEs512Check() {
@@ -116,9 +107,9 @@ export const WidgetAlgPickerComponent: React.FC<
116107
})();
117108
}, []);
118109

119-
const noneAlgOptions: DebuggerPickerOptionModel[] = useMemo(() => {
110+
/* const noneAlgOptions: DebuggerPickerOptionModel[] = useMemo(() => {
120111
return Object.entries(
121-
jwsExampleAlgHeaderParameterValuesDictionary.unsecured,
112+
jwsExampleAlgHeaderParameterValuesDictionary.unsecured
122113
).map((entry) => {
123114
const [key, value] = entry;
124115
@@ -127,7 +118,7 @@ export const WidgetAlgPickerComponent: React.FC<
127118
label: value.name,
128119
};
129120
});
130-
}, []);
121+
}, []); */
131122

132123
const symmetricAlgOptions: DebuggerPickerOptionModel[] = useMemo(() => {
133124
return Object.entries(jwsExampleAlgHeaderParameterValuesDictionary.mac).map(
@@ -138,13 +129,13 @@ export const WidgetAlgPickerComponent: React.FC<
138129
value: key,
139130
label: value.name,
140131
};
141-
},
132+
}
142133
);
143134
}, []);
144135

145136
const asymmetricAlgOptions: DebuggerPickerOptionModel[] = useMemo(() => {
146137
const digitalSignatureEntries = Object.entries(
147-
jwsExampleAlgHeaderParameterValuesDictionary.digitalSignature,
138+
jwsExampleAlgHeaderParameterValuesDictionary.digitalSignature
148139
);
149140

150141
const asymmetricAlgOptions: DebuggerPickerOptionModel[] = [];
@@ -194,41 +185,30 @@ export const WidgetAlgPickerComponent: React.FC<
194185
}, [canUseEd25519, canUseEd448, canUseEs512]);
195186

196187
const algOptions = useMemo(() => {
197-
return [...noneAlgOptions, ...symmetricAlgOptions, ...asymmetricAlgOptions];
198-
}, [asymmetricAlgOptions, noneAlgOptions, symmetricAlgOptions]);
188+
return [...symmetricAlgOptions, ...asymmetricAlgOptions];
189+
}, [asymmetricAlgOptions, symmetricAlgOptions]);
199190

200191
return (
201-
<div role="region" aria-label={label} className={styles.picker}>
202-
{pickerState === PickerStates.IDLE && (
203-
<button
204-
role="button"
205-
className={clsx(styles.button, PrimaryFont.className)}
206-
onClick={openPicker}
207-
>
208-
{dictionary.exampleAlgPicker.label}
209-
</button>
210-
)}
211-
{pickerState === PickerStates.PICKING && (
212-
<>
192+
<div role="region" aria-label={label} className={styles.alg_picker}>
193+
<div className={styles.container}>
194+
<div className={styles.picker}>
195+
<div className={styles.picker__label}>
196+
<label className={styles.picker__fullName}>
197+
{dictionary.exampleAlgPicker.label}
198+
</label>
199+
</div>
213200
<DebuggerPickerComponent
214201
label={null}
202+
data-has-label={label !== null}
215203
languageCode={languageCode}
216204
handleSelection={selectExample}
217205
selectedOptionCode={null}
218206
options={algOptions}
219207
placeholder={dictionary.exampleAlgPicker.defaultValue}
220208
minWidth={null}
221209
/>
222-
<button
223-
{...buttonProps}
224-
aria-label={dictionary.exampleAlgPicker.closeButton.label}
225-
className={styles.closeButton}
226-
onClick={closePicker}
227-
>
228-
<span>+</span>
229-
</button>
230-
</>
231-
)}
210+
</div>
211+
</div>
232212
</div>
233213
);
234214
};

0 commit comments

Comments
 (0)