Skip to content

Commit e2b0411

Browse files
authored
[PLAY-1465] Fix Linting Errors - Typeahead Kit (#4091)
**What does this PR do?** A clear and concise description with your runway ticket url. This story fixes the typeahead kit linting errors. Ran yarn eslint --fix for each file other than the index file and none of the warnings were corrected. I believe them to be unsafe changes and will require manual intervention. **Screenshots:** Screenshots to visualize your addition/change **How to test?** Steps to confirm the desired behavior: 1. Go to 'Typeahead kit page 2. Should still work as expected #### Checklist: - [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [ ] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code.
1 parent 477ba28 commit e2b0411

11 files changed

+86
-33
lines changed

playbook/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ type TypeaheadProps = {
4242
id?: string,
4343
label?: string,
4444
loadOptions?: string | Noop,
45-
getOptionLabel?: string | (() => any),
46-
getOptionValue?: string | (() => any),
45+
getOptionLabel?: string | (() => string),
46+
getOptionValue?: string | (() => string),
4747
name?: string,
4848
marginBottom?: "none" | "xxs" | "xs" | "sm" | "md" | "lg" | "xl",
4949
pillColor?: "primary" | "neutral" | "success" | "warning" | "error" | "info" | "data_1" | "data_2" | "data_3" | "data_4" | "data_5" | "data_6" | "data_7" | "data_8" | "windows" | "siding" | "roofing" | "doors" | "gutters" | "solar" | "insulation" | "accessories",
@@ -109,6 +109,7 @@ const Typeahead = ({
109109
multiKit: '',
110110
onCreateOption: null as null,
111111
plusIcon: false,
112+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
112113
onMultiValueClick: (_option: SelectValueType): any => undefined,
113114
pillColor: pillColor,
114115
...props,

playbook/app/pb_kits/playbook/pb_typeahead/components/ClearIndicator.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import React, { useEffect } from 'react'
22
import { components } from 'react-select'
33

4-
const ClearContainer = (props: any) => {
4+
type ClearContainerProps = {
5+
children: React.ReactNode,
6+
selectProps?: {
7+
id: string,
8+
},
9+
clearValue: () => void,
10+
}
11+
12+
const ClearContainer = (props: ClearContainerProps): React.ReactElement => {
513
const { selectProps, clearValue } = props
614
useEffect(() => {
715
document.addEventListener(`pb-typeahead-kit-${selectProps.id}:clear`, clearValue)
8-
}, [true])
16+
}, [clearValue, selectProps.id])
917

1018
return (
1119
<components.ClearIndicator
12-
className="clear_indicator"
13-
{...props}
20+
className="clear_indicator"
21+
{...props}
1422
/>
1523
)
1624
}

playbook/app/pb_kits/playbook/pb_typeahead/components/Control.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import Flex from '../../pb_flex/_flex'
55
import TextInput from '../../pb_text_input/_text_input'
66

77
type Props = {
8-
selectProps: any,
8+
selectProps: {
9+
dark?: boolean,
10+
label: string,
11+
error?: string,
12+
},
913
}
1014

1115
const TypeaheadControl = (props: Props) => (

playbook/app/pb_kits/playbook/pb_typeahead/components/IndicatorsContainer.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import React from 'react'
22
import { components } from 'react-select'
33

4-
const IndicatorsContainer = (props: any) => (
4+
type IndicatorsContainerProps = {
5+
children: React.ReactNode,
6+
}
7+
8+
9+
const IndicatorsContainer = (props: IndicatorsContainerProps): React.ReactElement => (
510
<components.IndicatorsContainer
6-
className="text_input_indicators"
7-
{...props}
11+
className="text_input_indicators"
12+
{...props}
813
/>
914
)
1015

playbook/app/pb_kits/playbook/pb_typeahead/components/MenuList.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React from 'react'
22
import { components } from 'react-select'
33

4-
const MenuList = (props: any) => {
4+
type MenuListProps = {
5+
children: React.ReactNode,
6+
footer: React.ReactNode,
7+
}
8+
9+
const MenuList = (props: MenuListProps): React.ReactElement => {
510
return (
611
<components.MenuList {...props}>
712
{props.children}

playbook/app/pb_kits/playbook/pb_typeahead/components/Option.tsx

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@ import { components } from 'react-select'
33

44
import User from '../../pb_user/_user'
55

6-
const Option = (props: any) => {
6+
type OptionProps = {
7+
children: React.ReactNode,
8+
label?: string,
9+
data: {
10+
imageUrl?: string,
11+
},
12+
selectProps: {
13+
dark?: boolean,
14+
valueComponent?: (data: {
15+
imageUrl?: string,
16+
}) => React.ReactNode,
17+
},
18+
}
19+
20+
21+
const Option = (props: OptionProps): React.ReactElement => {
722
const {
823
imageUrl,
924
} = props.data
@@ -14,11 +29,11 @@ const Option = (props: any) => {
1429
<>
1530
{!valueComponent && imageUrl &&
1631
<User
17-
align="left"
18-
avatarUrl={imageUrl}
19-
dark={props.selectProps.dark}
20-
name={props.label}
21-
orientation="horizontal"
32+
align="left"
33+
avatarUrl={imageUrl}
34+
dark={props.selectProps.dark}
35+
name={props.label}
36+
orientation="horizontal"
2237
/>
2338
}
2439

playbook/app/pb_kits/playbook/pb_typeahead/components/Placeholder.tsx

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ import { components } from 'react-select'
44
import Flex from '../../pb_flex/_flex'
55
import Icon from '../../pb_icon/_icon'
66

7-
const Placeholder = (props: any) => (
7+
type PlaceholderProps = {
8+
children: React.ReactNode,
9+
selectProps: {
10+
plusIcon?: boolean,
11+
},
12+
}
13+
14+
const Placeholder = (props: PlaceholderProps): React.ReactElement => (
815
<>
916
<Flex
10-
align="center"
11-
className="placeholder"
17+
align="center"
18+
className="placeholder"
1219
>
1320
<components.IndicatorsContainer
14-
{...props}
21+
{...props}
1522
/>
1623
{props.selectProps.plusIcon &&
1724
<Icon
18-
className="typeahead-plus-icon"
19-
icon="plus"
25+
className="typeahead-plus-icon"
26+
icon="plus"
2027
/>
2128
}
2229
</Flex>

playbook/app/pb_kits/playbook/pb_typeahead/components/ValueContainer.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from 'react'
22
import { components } from 'react-select'
33

4-
const ValueContainer = (props: any) => (
4+
type ValueContainerProps = {
5+
children: React.ReactNode,
6+
}
7+
8+
const ValueContainer = (props: ValueContainerProps): React.ReactElement => (
59
<components.ValueContainer
6-
className="text_input_value_container"
7-
{...props}
10+
className="text_input_value_container"
11+
{...props}
812
/>
913
)
1014

playbook/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_custom_menu_list.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable react/no-multi-comp */
2+
13
import React, { useState } from 'react'
24

35
import {

playbook/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_async.jsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ const promiseOptions = (inputValue) =>
4545

4646
const TypeaheadWithPillsAsync = (props) => {
4747
const [users, setUsers] = useState([])
48-
const handleOnChange = (value) => setUsers(formatUsers(value))
49-
const formatValue = (users) => formatUsers(users)
48+
5049
const formatUsers = (users) => {
5150
const results = () => (users.map((user) => {
5251
if (Object.keys(user)[0] === 'name' || Object.keys(user)[1] === 'id'){
@@ -58,6 +57,9 @@ const TypeaheadWithPillsAsync = (props) => {
5857
return results()
5958
}
6059

60+
const handleOnChange = (value) => setUsers(formatUsers(value))
61+
const formatValue = (users) => formatUsers(users)
62+
6163
return (
6264
<>
6365
{users && users.length > 0 && (

playbook/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_pills_async_custom_options.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ const TypeaheadWithPillsAsyncCustomOptions = (props) => {
8383
onChange={handleOnChange}
8484
onMultiValueClick={handleOnMultiValueClick}
8585
placeholder="type the name of a Github user"
86-
valueComponent={(props) => (
86+
valueComponent={({imageUrl, label, territory, type}) => (
8787
<User
8888
avatar
89-
avatarUrl={props.imageUrl}
90-
name={props.label}
91-
territory={props.territory}
92-
title={props.type}
89+
avatarUrl={imageUrl}
90+
name={label}
91+
territory={territory}
92+
title={type}
9393
/>
9494
)}
9595
{...props}

0 commit comments

Comments
 (0)