Skip to content

Commit c2ff54f

Browse files
committed
Additional fixes to PR #919
1 parent 712ab9f commit c2ff54f

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

Diff for: packages/cyberstorm/src/components/MultiSelectSearch/MultiSelectSearch.module.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@
7979
--border-color: var(--color-cyber-green--80);
8080
}
8181

82-
.removeAllButton {
82+
.clearSearch {
8383
width: 3rem;
8484
height: 100%;
8585
color: #c6c3ff;
8686
background: transparent;
8787
opacity: 0.5;
8888
}
8989

90-
.openMenuButton {
90+
.showMenuButton {
9191
width: 3rem;
9292
height: 100%;
9393
color: #9c9cc4;

Diff for: packages/cyberstorm/src/components/MultiSelectSearch/MultiSelectSearch.tsx

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"use client";
22
import React from "react";
33
import styles from "./MultiSelectSearch.module.css";
4-
import { Icon } from "../Icon/Icon";
54
import { classnames } from "../../utils/utils";
6-
import { Button } from "../../index";
5+
import { Button, Icon } from "../../index";
76
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
87
import {
98
faCaretDown,
@@ -12,19 +11,17 @@ import {
1211
} from "@fortawesome/pro-solid-svg-icons";
1312
import { isNode } from "../../utils/type_guards";
1413

15-
type Option = {
14+
export type MultiSelectSearchOption = {
1615
label: string;
1716
value: string;
1817
};
1918
type Props = {
20-
options: Option[];
21-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22-
value: Option[];
23-
onChange: (v: Option[]) => void;
19+
options: MultiSelectSearchOption[];
20+
value: MultiSelectSearchOption[];
21+
onChange: (v: MultiSelectSearchOption[]) => void;
2422
onBlur: () => void;
2523
// TODO: Implement disabled state
2624
disabled?: boolean;
27-
name: string;
2825
placeholder?: string;
2926
color?: "red" | "green";
3027
};
@@ -35,22 +32,21 @@ type Props = {
3532
*/
3633
export const MultiSelectSearch = React.forwardRef<HTMLInputElement, Props>(
3734
function MultiSelectSearch(props, ref) {
38-
const { name, options, value, onChange, onBlur, placeholder, color } =
39-
props;
35+
const { options, value, onChange, onBlur, placeholder, color } = props;
4036
const menuRef = React.useRef<HTMLDivElement | null>(null);
4137
const inputRef = React.useRef<HTMLInputElement | null>(null);
4238

4339
const [isVisible, setIsVisible] = React.useState(false);
4440
const [search, setSearch] = React.useState("");
4541
const [filteredOptions, setFilteredOptions] = React.useState(options);
4642

47-
function add(incomingOption: Option) {
43+
function add(incomingOption: MultiSelectSearchOption) {
4844
if (!value.some((option) => option.value === incomingOption.value)) {
4945
onChange([...value, incomingOption]);
5046
}
5147
}
5248

53-
function remove(incomingOption: Option) {
49+
function remove(incomingOption: MultiSelectSearchOption) {
5450
onChange(value.filter((option) => option.value !== incomingOption.value));
5551
}
5652

@@ -89,7 +85,7 @@ export const MultiSelectSearch = React.forwardRef<HTMLInputElement, Props>(
8985

9086
return (
9187
<div className={styles.root} ref={ref}>
92-
<div className={styles.value}>
88+
<div className={styles.selected}>
9389
{value.map((option) => {
9490
return (
9591
<Button.Root
@@ -109,16 +105,15 @@ export const MultiSelectSearch = React.forwardRef<HTMLInputElement, Props>(
109105
<div
110106
className={styles.search}
111107
onFocus={(e) => {
112-
e.stopPropagation();
113108
inputRef.current && inputRef.current.focus();
109+
e.stopPropagation();
114110
}}
115111
role="button"
116112
tabIndex={0}
117113
ref={menuRef}
118114
>
119115
<div className={styles.inputContainer} data-color={color}>
120116
<input
121-
name={name}
122117
className={styles.input}
123118
value={search}
124119
data-color={color}
@@ -129,10 +124,10 @@ export const MultiSelectSearch = React.forwardRef<HTMLInputElement, Props>(
129124
/>
130125
<button
131126
onClick={(e) => {
132-
e.stopPropagation();
133127
setSearch("");
128+
e.stopPropagation();
134129
}}
135-
className={styles.removeAllButton}
130+
className={styles.clearSearch}
136131
>
137132
<Icon inline>
138133
<FontAwesomeIcon icon={faCircleXmark} />
@@ -141,10 +136,10 @@ export const MultiSelectSearch = React.forwardRef<HTMLInputElement, Props>(
141136
<div className={styles.inputButtonDivider}></div>
142137
<button
143138
onClick={(e) => {
144-
e.stopPropagation();
145139
setIsVisible(!isVisible);
140+
e.stopPropagation();
146141
}}
147-
className={styles.openMenuButton}
142+
className={styles.showMenuButton}
148143
>
149144
<Icon inline>
150145
<FontAwesomeIcon icon={faCaretDown} />
@@ -162,8 +157,8 @@ export const MultiSelectSearch = React.forwardRef<HTMLInputElement, Props>(
162157
<MultiSelectItem
163158
key={option.value}
164159
onClick={(e) => {
165-
e.stopPropagation();
166160
add(option);
161+
e.stopPropagation();
167162
}}
168163
option={option}
169164
/>
@@ -180,7 +175,7 @@ MultiSelectSearch.displayName = "MultiSelectSearch";
180175

181176
const MultiSelectItem = (props: {
182177
onClick: (e: React.MouseEvent | React.KeyboardEvent) => void;
183-
option: Option;
178+
option: MultiSelectSearchOption;
184179
}) => {
185180
return (
186181
<div

0 commit comments

Comments
 (0)