forked from niuware/mui-rte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable atomic component with autocomplete (niuware#115)
* Add property to autocomplete strategy type * Provide editor state instance when inserting atomic block * Update logic to add atomic control with autocomplete * Add autocomplete atomic example * Update package version * Update README
- Loading branch information
Showing
6 changed files
with
135 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, { FunctionComponent } from 'react' | ||
import Avatar from '@material-ui/core/Avatar' | ||
import Chip from '@material-ui/core/Chip' | ||
import MUIRichTextEditor from '../../' | ||
import { TAutocompleteItem } from '../../src/components/Autocomplete' | ||
|
||
const save = (data: string) => { | ||
console.log(data) | ||
} | ||
|
||
const cities: TAutocompleteItem[] = [ | ||
{ | ||
keys: ["mexico"], | ||
value: { | ||
name: "Mexico City", | ||
image: "🇲🇽" | ||
}, | ||
content: "Mexico City", | ||
}, | ||
{ | ||
keys: ["mexico", "beach"], | ||
value: { | ||
name: "Cancun", | ||
image: "🚩" | ||
}, | ||
content: "Cancun", | ||
}, | ||
{ | ||
keys: ["japan", "olympics"], | ||
value: { | ||
name: "Tokyo", | ||
image: "🇯🇵" | ||
}, | ||
content: "Tokyo", | ||
}, | ||
{ | ||
keys: ["japan"], | ||
value: { | ||
name: "Osaka", | ||
image: "🏁" | ||
}, | ||
content: "Osaka", | ||
} | ||
] | ||
|
||
const CityChip: FunctionComponent<any> = (props) => { | ||
const { blockProps } = props | ||
const { value } = blockProps // Get the value provided in the TAutocompleteItem[] | ||
|
||
const handleClick = () => { | ||
console.log(value.name) | ||
} | ||
|
||
return ( | ||
<Chip | ||
avatar={<Avatar>{value.image}</Avatar>} | ||
label={value.name} | ||
onClick={handleClick} | ||
/> | ||
) | ||
} | ||
|
||
const AutocompleteAtomic = () => { | ||
return ( | ||
<MUIRichTextEditor | ||
label="Try typing '/mexico'..." | ||
onSave={save} | ||
customControls={[ | ||
{ | ||
name: "my-city", | ||
type: "atomic", | ||
atomicComponent: CityChip | ||
}, | ||
]} | ||
autocomplete={{ | ||
strategies: [ | ||
{ | ||
items: cities, | ||
triggerChar: "/", | ||
atomicBlockName: "my-city" | ||
} | ||
] | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export default AutocompleteAtomic |
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
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