-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reintroduce dropped typeahead stories (#721)
During a refactor a few of these examples got dropped and stopped functioning. Adding them back in to help with regression testing of the downshift upgrade. Additionally I discovered that the complex list items example doesn't work even when adding back in args to the default. This apparently has not worked since some time in 2019, as of the following commit 1c01ea9 Thus, I removed it completely rather than trying to untangle it. We evidently have not needed it.
- Loading branch information
Russell Anderson
authored
May 20, 2022
1 parent
ac511ba
commit 9a3511b
Showing
4 changed files
with
81 additions
and
118 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
packages/textInput/stories/helpers/TextInputWithBadgesTypeaheadStoryHelper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 25 additions & 48 deletions
73
packages/typeahead/stories/helpers/MultiselectTypeahead.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,46 @@ | ||
import * as React from "react"; | ||
import { cx } from "@emotion/css"; | ||
import { Item } from "../../components/Typeahead"; | ||
import { | ||
flex, | ||
flexItem, | ||
padding, | ||
textWeight | ||
} from "../../../shared/styles/styleUtils"; | ||
import { items } from "./itemMocks"; | ||
|
||
interface RenderProps { | ||
items: Item[]; | ||
selectedItems: string[]; | ||
selectHandler: (selectedItems: string[]) => void; | ||
onSelect: (selectedItems: string[]) => void; | ||
} | ||
|
||
interface MultiselectTypeaheadProps { | ||
children: (renderProps: RenderProps) => React.ReactNode; | ||
} | ||
|
||
interface MultiselectTypeaheadState { | ||
selectedItems: string[]; | ||
} | ||
|
||
class MultiselectTypeahead extends React.PureComponent< | ||
MultiselectTypeaheadProps, | ||
MultiselectTypeaheadState | ||
> { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.selectHandler = this.selectHandler.bind(this); | ||
const MultiSelectTypeahead = ({ children }: MultiselectTypeaheadProps) => { | ||
const [selectedItems, setSelectedItems] = React.useState<string[]>([]); | ||
|
||
this.state = { | ||
selectedItems: props.selectedItems || [] | ||
}; | ||
} | ||
const handleSelect = newlySelectedItems => { | ||
setSelectedItems(newlySelectedItems); | ||
}; | ||
|
||
selectHandler(selectedItems) { | ||
this.setState({ selectedItems }); | ||
} | ||
|
||
render() { | ||
const { children } = this.props; | ||
|
||
return ( | ||
<div className={flex()}> | ||
<div className={flexItem("grow")}> | ||
{children({ | ||
selectedItems: this.state.selectedItems, | ||
selectHandler: this.selectHandler, | ||
items | ||
})} | ||
</div> | ||
<div className={cx(flexItem("grow"), padding("left"))}> | ||
<span className={textWeight("medium")}>Selections:</span> | ||
<ul> | ||
{this.state.selectedItems.map((item, i) => ( | ||
<li key={i}>{item}</li> | ||
))} | ||
</ul> | ||
</div> | ||
return ( | ||
<div className={flex()}> | ||
<div className={flexItem("grow")}> | ||
{children({ | ||
selectedItems, | ||
onSelect: handleSelect | ||
})} | ||
</div> | ||
); | ||
} | ||
} | ||
<div className={cx(flexItem("grow"), padding("left"))}> | ||
<span className={textWeight("medium")}>Selections:</span> | ||
<ul> | ||
{selectedItems.map((item, i) => ( | ||
<li key={i}>{item}</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MultiselectTypeahead; | ||
export default React.memo(MultiSelectTypeahead); |
This file was deleted.
Oops, something went wrong.