This is a simple template for showing any issues that arise in react-md. It can also be a prototyping playground.
Created
October 18, 2022 04:26
-
-
Save mbisht/e3c356e0383ccb0a69cccf2773ee89b4 to your computer and use it in GitHub Desktop.
react-md - Autocomplete By Api
This file contains hidden or 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
| <div id="app"></div> |
This file contains hidden or 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
| const { | |
| Autocomplete | |
| } = ReactMD; | |
| class App extends React.PureComponent { | |
| constructor(props) { | |
| super(props); | |
| this.state = { users: [], test: [] }; | |
| } | |
| componentDidMount() { | |
| this.callApi(); | |
| } | |
| callApi() { | |
| let favoriteUsers = [1, 2, 3,4,5]; | |
| let users = []; | |
| favoriteUsers.map(user => users.push(this.getUsers(user))); | |
| Promise.all(users) | |
| .then(results => { | |
| this.setState({ | |
| users: results | |
| }); | |
| }) | |
| .catch(err => { | |
| console.log(res); | |
| }); | |
| } | |
| getUsers(prmId) { | |
| let url = "https://jsonplaceholder.typicode.com/users/" + prmId; | |
| return fetch(url) | |
| .then(response => response.json()) | |
| .then(users => { | |
| return users; | |
| }); | |
| } | |
| render() { | |
| if (this.state.users.length > 1) { | |
| const { users } = this.state; | |
| //console.log(users); | |
| } | |
| return ( | |
| <div className="md-text-container" style={{ marginTop: "10em" }}> | |
| <Autocomplete | |
| id="test-autocomplete" | |
| label="Autocomplete" | |
| dataLabel="name" | |
| autocompleteWithLabel | |
| placeholder="Search Users" | |
| data={this.state.users} | |
| onAutocomplete={(...args) => { | |
| this.setState({ test: args[0] }); | |
| console.log(args); | |
| }} | |
| deleteKeys={[ | |
| "id", | |
| "username", | |
| "email", | |
| "address", | |
| "phone", | |
| "website", | |
| "company" | |
| ]} | |
| simplifiedMenu={false} | |
| anchor={{ | |
| x: Autocomplete.HorizontalAnchors.CENTER, | |
| y: Autocomplete.VerticalAnchors.TOP | |
| }} | |
| position={Autocomplete.Positions.BOTTOM} | |
| /> | |
| <pre>{JSON.stringify(this.state.test, null, 2)}</pre> | |
| </div> | |
| ); | |
| } | |
| } | |
| ReactDOM.render(<App />, document.getElementById("app")); |
This file contains hidden or 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
| <script src="https://unpkg.com/react@15/dist/react-with-addons.js"></script> | |
| <script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script> | |
| <script src="https://unpkg.com/[email protected]/dist/react-md.js"></script> |
This file contains hidden or 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
| body { | |
| margin: 0; | |
| } | |
| html { | |
| width: 100%; | |
| } | |
| // simple styles for greeting | |
| .greeting { | |
| left: 50%; | |
| margin: 1em; | |
| max-width: 320px; | |
| position: absolute; | |
| top: 50%; | |
| transform: translate3d(-50%, -50%, 0); | |
| width: 100%; | |
| } | |
| code { | |
| font-family: Consolas, Monaco, 'Andale Mono', monospace; | |
| } |
This file contains hidden or 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
| <link href="https://unpkg.com/[email protected]/dist/react-md.light_blue-pink.min.css" rel="stylesheet" /> | |
| <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700%7CMaterial+Icons" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment