Skip to content

Commit

Permalink
feat(multi-select): add color prop
Browse files Browse the repository at this point in the history
  • Loading branch information
MrsBolinhu committed Feb 27, 2024
1 parent 72fdfdd commit cdc906d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/components/MultiSelect/MultiSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { fireEvent } from '@testing-library/react'
import { MultiSelect } from '../MultiSelect'
import { render } from '../utils/test/render'

const greenColor = '#6EC531'

const items = [
{ id: 0, name: 'Maringá' },
{ id: 0, name: 'Maringá', color: greenColor },
{ id: 1, name: 'Guarapuava' },
{ id: 2, name: 'São Paulo' },
{ id: 3, name: 'Curitiba' },
Expand Down Expand Up @@ -138,4 +140,13 @@ describe('MultiSelect', () => {

expect(select).toBeDisabled()
})

it('should have custom color when have color prop', () => {
const { getByTestId } = render(
<MultiSelect items={items} value={[items[0]]} />
)

const BadgeItem = getByTestId('select-selected-item')
expect(BadgeItem).toHaveStyle({ backgroundColor: greenColor })
})
})
1 change: 1 addition & 0 deletions src/components/MultiSelect/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MultiSelectStatic } from './MultiSelectStatic'
type Item = {
id: any
name: string
color?: string
}

export interface Props {
Expand Down
3 changes: 2 additions & 1 deletion src/components/MultiSelect/MultiSelectFetchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect, useRef, useState } from 'react'
import styled from 'styled-components'
import { MdClose } from 'react-icons/md'
import { useCombobox, useMultipleSelection } from 'downshift'
import { isEmpty } from 'lodash'

import { Flex } from '../Flex'
import { Box } from '../Box'
Expand Down Expand Up @@ -403,7 +404,7 @@ export const MultiSelectFetchable: React.FC<Props> = ({
border='1px solid #dedede'
{...getMenuProps()}
>
{!isDependent && (
{!isDependent && !isEmpty(filters) && (
<>
<ul>
{filters.map((filter, index) => (
Expand Down
8 changes: 6 additions & 2 deletions src/components/MultiSelect/MultiSelectStatic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { Text } from '../Text'
import { Divider } from '../Divider'
import { Button } from '../Button'
import { InputErrorMessage } from '../InputErrorMessage'
import { isEmpty } from 'lodash'

type Item = {
id: any
name: string
select?: string
color?: string
}

export interface Props {
Expand Down Expand Up @@ -349,7 +351,9 @@ export const MultiSelectStatic: React.FC<Props> = ({
display='flex'
flexDirection='row'
alignItems='center'
backgroundColor={disabled ? 'darkGrey' : 'primary'}
backgroundColor={
disabled ? 'darkGrey' : selectedItem?.color || 'primary'
}
borderRadius='3px'
data-testid='select-selected-item'
>
Expand Down Expand Up @@ -429,7 +433,7 @@ export const MultiSelectStatic: React.FC<Props> = ({
border='1px solid #dedede'
{...getMenuProps()}
>
{!isDependent && !disabled && (
{!isDependent && !disabled && !isEmpty(filters) && (
<>
<ul>
{filters.map((filter, index) => (
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11538,7 +11538,7 @@ react-select@^3.2.0:
react-input-autosize "^3.0.0"
react-transition-group "^4.3.0"

react-spring@^9.6.1:
react-spring@9.6.1:
version "9.6.1"
resolved "https://registry.yarnpkg.com/react-spring/-/react-spring-9.6.1.tgz#e715b2fa523c1a3acfdcf1aaa93e081620b8cc8e"
integrity sha512-BeP80R4SLb1bZHW/Q62nECoScHw/fH+jzGkD7dc892HNGa+lbGIJXURc6U7N8JfZ8peEO46nPxR57aUMuYzquQ==
Expand Down

0 comments on commit cdc906d

Please sign in to comment.