Skip to content

Commit 20c6926

Browse files
authored
Merge pull request #429 from fahad-aot/bugfix/fwf-4280-style-multiselect-opion
bugfix/fwf-4280:Added styles for multiselect
2 parents ae0d085 + e543fa7 commit 20c6926

File tree

3 files changed

+161
-16
lines changed

3 files changed

+161
-16
lines changed
Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import React from "react";
1+
import React, { useState,useRef,useEffect } from "react";
22
import Multiselect from 'multiselect-react-dropdown';
3+
import { CloseIcon } from "../SvgIcons/index";
4+
import { StyleServices } from "@formsflow/service";
35

46

57
interface MultiSelectInterface {
@@ -9,6 +11,11 @@ interface MultiSelectInterface {
911
onRemove?: (removed: any) => void;
1012
displayValue?: string;
1113
avoidHighlightFirstOption?: boolean;
14+
hidePlaceholder?:boolean;
15+
className?:string;
16+
disabled?:boolean;
17+
placeholder?:string;
18+
label?:string;
1219
}
1320

1421
export const MultipleSelect: React.FC<MultiSelectInterface> = ({
@@ -17,15 +24,57 @@ export const MultipleSelect: React.FC<MultiSelectInterface> = ({
1724
onSelect = ()=> {},
1825
onRemove = ()=> {},
1926
displayValue= "",
20-
avoidHighlightFirstOption = true
27+
avoidHighlightFirstOption = true,
28+
hidePlaceholder=true,
29+
className,
30+
disabled,
31+
placeholder="",
32+
label
2133

2234
})=>{
23-
return <Multiselect
24-
options={options}
25-
selectedValues={selectedValues}
26-
onSelect={onSelect}
27-
onRemove={onRemove}
28-
displayValue={displayValue}
29-
avoidHighlightFirstOption={avoidHighlightFirstOption}
30-
/>
35+
const primaryColor = StyleServices.getCSSVariable('--ff-primary');
36+
const dropdownRef = useRef<HTMLDivElement | null>(null);
37+
const [isOpen,setIsOpen] = useState(false);
38+
// Toggle dropdown open/close when clicked
39+
const handleClick = (e: MouseEvent) => {
40+
if (dropdownRef.current?.contains(e.target as Node) && !disabled) {
41+
setIsOpen(true);
42+
} else {
43+
setIsOpen(false);
44+
}
45+
};
46+
47+
useEffect(() => {
48+
document.addEventListener("mousedown", handleClick);
49+
50+
return () => {
51+
document.removeEventListener("mousedown", handleClick);
52+
};
53+
}, []);
54+
55+
return (
56+
<div className={`multiselect-container ${className}`} ref={dropdownRef}>
57+
{label && <label className="multiple-select-label">{label}</label>}
58+
<Multiselect
59+
options={options}
60+
selectedValues={selectedValues}
61+
className={`${isOpen && "open-dropdown"}`}
62+
onSelect={onSelect}
63+
onRemove={onRemove}
64+
displayValue={displayValue}
65+
avoidHighlightFirstOption={avoidHighlightFirstOption}
66+
hidePlaceholder={hidePlaceholder}
67+
disable={disabled}
68+
placeholder={placeholder}
69+
customCloseIcon={
70+
<CloseIcon
71+
onClick={onRemove}
72+
color={disabled ? `#AFB4B6`: primaryColor}
73+
data-testid="pill-remove-icon"
74+
aria-label="remove "
75+
/>
76+
}
77+
/>
78+
</div>
79+
);
3180
}

forms-flow-theme/scss/_forms.scss

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ select option:hover {
306306
width: 1em;
307307
height: 1em;
308308
position: absolute;
309-
right: 1rem;
310-
}
309+
right: 1rem;
310+
}
311311
}
312312

313313
.input-group-text {
@@ -412,16 +412,16 @@ select option:hover {
412412
.valiation-astrisk {
413413
color: $primary;
414414
}
415-
//for not allowing for edit in preview
415+
//for not allowing for edit in preview
416416
.form-preview{
417417
pointer-events: none;
418418
cursor: not-allowed;
419419
}
420420
.form-preview-tab {
421421
padding: var(--spacer-200);
422-
height: 100vh;
422+
height: 100vh;
423423
overflow-y: auto;
424-
overflow-x: hidden;
424+
overflow-x: hidden;
425425
}
426426

427427
.dropdown-main {
@@ -467,4 +467,95 @@ select option:hover {
467467
.dashed-line {
468468
width: 8.8125rem;
469469
border-top: 0.1875rem dashed $gray-medium-dark;
470-
}
470+
}
471+
.multiple-select-label {
472+
padding-bottom: var(--spacer-050);
473+
color: $gray-darkest;
474+
font-size: var(--font-size-xs);
475+
font-weight: var(--font-weight-sm);
476+
line-height: var(--text-line-height);
477+
}
478+
479+
.multiselect-container {
480+
width: 100%;
481+
482+
&.disable_ms {
483+
.searchWrapper {
484+
background: var(--ff-gray-light);
485+
border: none;
486+
.chip {
487+
background: var(--ff-white);
488+
color: $gray-darkest;
489+
}
490+
}
491+
}
492+
493+
.searchWrapper {
494+
border-radius: var(--radius-sm);
495+
border: 1px solid $primary;
496+
display: flex;
497+
flex-wrap: wrap;
498+
gap: var(--spacer-050);
499+
500+
.chip {
501+
padding: var(--spacer-050) var(--spacer-100);
502+
align-items: center;
503+
gap: var(--spacer-050);
504+
border-radius: var(--radius-modal);
505+
background: $primary-light; // #e4e3fc
506+
color: $gray-darkest;
507+
text-align: center;
508+
font-size: var(--font-size-sm);
509+
font-weight: var(--font-weight-sm);
510+
line-height: var(--text-line-height);
511+
margin-bottom: 0px !important;
512+
}
513+
514+
.custom-close {
515+
display: flex;
516+
padding: 3px 2px;
517+
flex-direction: column;
518+
justify-content: center;
519+
align-items: center;
520+
cursor: pointer;
521+
}
522+
}
523+
524+
.open-dropdown {
525+
.searchWrapper {
526+
border-bottom-left-radius: 0 !important;
527+
border-bottom-right-radius: 0 !important;
528+
}
529+
}
530+
531+
.optionListContainer {
532+
margin-top: 0px;
533+
border-top: none;
534+
border-radius: 0px !important;
535+
}
536+
537+
.optionContainer {
538+
border-top: none !important;
539+
border-top-left-radius: 0px;
540+
border-top-right-radius: 0px;
541+
border-bottom-left-radius: var(--radius-sm);
542+
border-bottom-right-radius: var(--radius-sm);
543+
display: flex;
544+
padding: var(--spacer-050) 0px;
545+
flex-direction: column;
546+
align-items: flex-start;
547+
flex: 1 0 0;
548+
border: 1px solid $primary;
549+
550+
.option {
551+
&:hover {
552+
background: $primary;
553+
}
554+
display: flex;
555+
padding: var(--spacer-050) var(--spacer-100);
556+
align-items: center;
557+
align-self: stretch;
558+
}
559+
}
560+
}
561+

forms-flow-theme/scss/_theme.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ $theme-colors: map-merge($theme-colors, $custom-colors);
217217
--radius-0125: 1.25rem;
218218
--radius-0150: 1.5rem;
219219
--radius-200: 2rem;
220+
221+
--radius-sm: 1.09375rem; //17.5px
222+
--radius-md: 1.34375rem; //21.5px
223+
--radius-lg: 1.59375rem; //25.5px
224+
--radius-modal: 1.5rem; //24px
220225
//custom
221226
--client-nav: 3rem;
222227
--header-close-btn: 4.625rem;

0 commit comments

Comments
 (0)