Skip to content

Commit 31e2b6a

Browse files
Merge pull request #310 from dd3tech/fix/small-adjustments-components
Fix: Small adjustments were made to several components
2 parents 1dcc108 + ffa096a commit 31e2b6a

8 files changed

Lines changed: 111 additions & 41 deletions

File tree

src/components/AsideModalV2/AsideModalV2.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const AsideModalV2: FC<AsideModalProps> = ({
204204
<Flex
205205
gap="4"
206206
className={composeClasses(
207-
'bg-gray-50 px-10 py-6 flex-col',
207+
'bg-gray-50 px-10 pt-6 pb-4 flex-col',
208208
isStickyTitle && 'sticky top-0 z-50'
209209
)}
210210
>

src/components/Badge/Badge.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('<Badge />', () => {
1616

1717
expect(badge.className).toContain('bg-yellow-400')
1818
expect(badge.className).toContain('text-white')
19-
expect(badge.className).toContain('rounded-2xl')
19+
expect(badge.className).toContain('rounded-full')
2020
expect(badge.className).toContain('text-xs')
2121
expect(badge.className).toContain('font-medium')
2222
})

src/components/Badge/Badge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Badge = ({ value, variant = 'default' }: IBadge) => {
3232
justifyContent="center"
3333
alignItems="center"
3434
className={composeClasses(
35-
'rounded-2xl text-xs font-medium px-1 text-white',
35+
'rounded-full text-xs font-medium px-1 text-white',
3636
badgeColor
3737
)}
3838
style={{ height: 24, width: 24 }}

src/components/Buttons/FilterBarButton.tsx

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactNode, useState } from 'react'
1+
import { ReactNode, useState, useCallback } from 'react'
22
import { XIcon } from '@heroicons/react/outline'
33
import { composeClasses } from 'lib/classes'
44

@@ -36,11 +36,31 @@ const FilterBarButton = ({
3636
principalButton
3737
}: IFilterBarButton) => {
3838
const [showPopover, setShowPopover] = useState(false)
39+
const [isClosing, setIsClosing] = useState(false)
3940

40-
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
41-
setShowPopover(!showPopover)
42-
principalButton?.onClick?.(e)
43-
}
41+
const handleClick = useCallback(
42+
(e: React.MouseEvent<HTMLButtonElement>) => {
43+
if (showPopover) {
44+
setIsClosing(true)
45+
setTimeout(() => {
46+
setShowPopover(false)
47+
setIsClosing(false)
48+
}, 200)
49+
} else {
50+
setShowPopover(true)
51+
}
52+
principalButton?.onClick?.(e)
53+
},
54+
[showPopover, principalButton, setShowPopover, setIsClosing]
55+
)
56+
57+
const handleClose = useCallback(() => {
58+
setIsClosing(true)
59+
setTimeout(() => {
60+
setShowPopover(false)
61+
setIsClosing(false)
62+
}, 200)
63+
}, [setIsClosing, setShowPopover])
4464

4565
return (
4666
<>
@@ -67,12 +87,19 @@ const FilterBarButton = ({
6787
</Flex>
6888
</Button>
6989

70-
{showPopover && (
71-
<Transition className="w-full">
90+
{(showPopover || isClosing) && (
91+
<Transition
92+
className="w-full"
93+
show={!isClosing}
94+
animationStart="fadeIn"
95+
animationEnd="fadeOut"
96+
duration={200}
97+
alwaysRender
98+
>
7299
<div
73100
className={composeClasses(
74101
classNamePopover,
75-
'bg-white border mt-1 rounded-xl shadow-md transition-all duration-200 ease-out opacity-100 translate-y-0 z-50'
102+
'bg-white border mt-1 rounded-xl shadow-md z-50'
76103
)}
77104
style={{ width: 468 }}
78105
>
@@ -81,10 +108,7 @@ const FilterBarButton = ({
81108
justifyContent="between"
82109
>
83110
<Text bold>{titlePopover ?? 'Title'}</Text>
84-
<XIcon
85-
className="h-5 w-5 cursor-pointer"
86-
onClick={() => setShowPopover(false)}
87-
/>
111+
<XIcon className="h-5 w-5 cursor-pointer" onClick={handleClose} />
88112
</Flex>
89113
{childrenPopover}
90114
<Flex

src/components/Form/MultiSelect.test.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('<MultiSelect />', () => {
3131
expect(getByText('Select options')).toBeInTheDocument()
3232
expect(selectContainer).toBeInTheDocument()
3333
})
34+
3435
it('should open dropdown when clicked', () => {
3536
const { getByTestId } = render(<MultiSelect {...defaultProps} />)
3637

@@ -47,7 +48,7 @@ describe('<MultiSelect />', () => {
4748
const { getByTestId } = render(<MultiSelect {...defaultProps} />)
4849

4950
fireEvent.click(getByTestId('select-container'))
50-
51+
fireEvent.click(getByTestId('select-all'))
5152
const checkbox = getByTestId('option-1')
5253
fireEvent.click(checkbox)
5354

@@ -71,6 +72,7 @@ describe('<MultiSelect />', () => {
7172

7273
const allCheckbox = getByTestId('select-all')
7374
fireEvent.click(allCheckbox)
75+
fireEvent.click(allCheckbox)
7476

7577
const option1Checkbox = getByTestId('option-1')
7678
const option2Checkbox = getByTestId('option-2')
@@ -141,4 +143,25 @@ describe('<MultiSelect />', () => {
141143
expect(getByTestId('option-4')).toBeInTheDocument()
142144
expect(getByTestId('option-5')).toBeInTheDocument()
143145
})
146+
147+
it('should have all non-disabled options selected by default', () => {
148+
const { getByTestId } = render(<MultiSelect {...defaultProps} />)
149+
150+
fireEvent.click(getByTestId('select-container'))
151+
const option1Checkbox = getByTestId('option-1')
152+
const option2Checkbox = getByTestId('option-2')
153+
const option3Checkbox = getByTestId('option-3')
154+
155+
expect(option1Checkbox).toBeChecked()
156+
expect(option2Checkbox).toBeChecked()
157+
expect(option3Checkbox).not.toBeChecked()
158+
})
159+
160+
it('should not show blue background when all options are selected', () => {
161+
const { getByTestId } = render(<MultiSelect {...defaultProps} />)
162+
const selectContainer = getByTestId('select-container')
163+
164+
expect(selectContainer).not.toHaveClass('bg-blue-100')
165+
expect(selectContainer).not.toHaveClass('border-blue-600')
166+
})
144167
})

src/components/Form/MultiSelect.tsx

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
useEffect,
99
useRef,
1010
useState,
11-
useMemo
11+
useMemo,
12+
useCallback
1213
} from 'react'
14+
import { XIcon } from '@heroicons/react/outline'
1315
import { ChevronDownIcon } from '@heroicons/react/solid'
1416
import { StyleObject } from 'lib/styles'
1517
import { composeClasses } from 'lib/classes'
@@ -72,9 +74,8 @@ function MultiSelect({
7274
const selectRef = useRef<HTMLInputElement>(null)
7375
const [isOpen, setIsOpen] = useState(false)
7476
const [selectedOptions, setSelectedOptions] = useState<IMultiSelectOption[]>(
75-
[]
77+
optionsList.filter((opt) => !opt.disabled)
7678
)
77-
7879
const [options, setOptions] = useState<IMultiSelectOption[]>(optionsList)
7980

8081
const styles = {
@@ -94,10 +95,10 @@ function MultiSelect({
9495
)
9596
}
9697

97-
const handleClick = () => {
98+
const handleClick = useCallback(() => {
9899
if (isDisabled) return
99100
setIsOpen(!isOpen)
100-
}
101+
}, [isDisabled, isOpen, setIsOpen])
101102

102103
const handleOptionToggle = (option: IMultiSelectOption) => {
103104
if (option.disabled) return
@@ -119,13 +120,20 @@ function MultiSelect({
119120
.every((opt) => selectedOptions.some((sel) => sel.value === opt.value)),
120121
[options, selectedOptions]
121122
)
122-
const handleSelectAll = () => {
123+
const handleSelectAll = useCallback(() => {
123124
allSelected
124125
? setSelectedOptions([])
125126
: setSelectedOptions(options.filter((opt) => !opt.disabled))
126-
}
127+
}, [allSelected, options, setSelectedOptions])
127128

128-
const handleClear = () => setSelectedOptions([])
129+
const handleClear = useCallback(() => {
130+
setSelectedOptions([])
131+
}, [setSelectedOptions])
132+
133+
const onSubmit = useCallback(() => {
134+
buttonSubmit?.onClick()
135+
setIsOpen(false)
136+
}, [buttonSubmit, setIsOpen])
129137

130138
useEffect(() => {
131139
const handleClickOutside = (e: globalThis.MouseEvent) => {
@@ -153,7 +161,9 @@ function MultiSelect({
153161
role="select-container"
154162
className={composeClasses(
155163
styles.container,
156-
selectedOptions.length > 0 && 'bg-blue-100 border border-blue-600'
164+
selectedOptions.length > 0 &&
165+
!allSelected &&
166+
'bg-blue-100 border border-blue-600'
157167
)}
158168
style={{ zIndex: 2, ...style }}
159169
onClick={handleClick}
@@ -180,19 +190,23 @@ function MultiSelect({
180190
)}
181191
</div>
182192
</div>
183-
<Transition
184-
alwaysRender
185-
show={isOpen && !isDisabled}
186-
animationStart="rotateRight"
187-
animationEnd="rotateRightBack"
188-
duration={200}
189-
>
190-
<ChevronDownIcon
191-
role="chevron"
192-
className="text-gray-400"
193-
width={20}
194-
/>
195-
</Transition>
193+
{selectedOptions.length > 0 && !allSelected ? (
194+
<XIcon onClick={handleClear} className="text-gray-400" width={30} />
195+
) : (
196+
<Transition
197+
alwaysRender
198+
show={isOpen && !isDisabled}
199+
animationStart="rotateRight"
200+
animationEnd="rotateRightBack"
201+
duration={200}
202+
>
203+
<ChevronDownIcon
204+
role="chevron"
205+
className="text-gray-400"
206+
width={20}
207+
/>
208+
</Transition>
209+
)}
196210
</div>
197211
{isOpen && !isDisabled && (
198212
<Transition
@@ -241,7 +255,7 @@ function MultiSelect({
241255
>
242256
{buttonClear?.label}
243257
</Button>
244-
<Button onClick={buttonSubmit?.onClick} className="px-8">
258+
<Button onClick={onSubmit} className="px-8">
245259
{buttonSubmit?.label}
246260
</Button>
247261
</Flex>

src/components/Form/SingleSelect.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ function SingleSelect({
194194
'absolute left-0 z-10 w-full bg-white overflow-y-auto top-13 rounded-lg shadow-lg'
195195
)}
196196
style={{
197-
...getAnimationStyle(isOpen)
197+
...getAnimationStyle(isOpen),
198+
border: '1px solid #F9FAFB'
198199
}}
199200
>
200201
<div className="h-8 p-2">
@@ -208,7 +209,7 @@ function SingleSelect({
208209
return (
209210
<Flex
210211
className={composeClasses(
211-
'w-full px-2 py-2 hover:bg-blue-100 hover:text-blue-800 hover:font-bold',
212+
'w-full px-2 py-2 hover:bg-blue-50 hover:text-blue-800 hover:font-bold',
212213
option.selected && 'text-blue-700'
213214
)}
214215
justifyContent="between"

src/stories/FilterBarButton.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export const Default: Story = {
1919
iconLeft: <XCircleIcon width={20} />,
2020
iconRight: <XCircleIcon width={20} />,
2121
titlePopover: 'More Filter',
22+
secondaryButton: {
23+
label: 'Cancel',
24+
onClick: () => alert('Cancel')
25+
},
26+
primaryButton: {
27+
label: 'Submit',
28+
onClick: () => alert('Submit')
29+
},
2230
childrenPopover: (
2331
<Flex
2432
justifyContent="center"

0 commit comments

Comments
 (0)