Skip to content

Commit 81ee38e

Browse files
Olcinadunglas
authored andcommitted
Adding a customized Icon to a Resource (#674)
* Adding a customized Icon to a Resource * fix: add reviewers changes
1 parent 4f05537 commit 81ee38e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

admin/handling-relations-to-collections.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,50 @@ export default class extends Component {
120120
}
121121
```
122122

123+
124+
## Customizing an Icon
125+
126+
Now that our `authors` property is displaying the name instead of an 'id', let's change the icon shown in the list menu.
127+
128+
Just add an import statement from `@material-ui` for adding the icon, in this case, a user icon:
129+
130+
`import UserIcon from '@material-ui/icons/People';`
131+
132+
and add it to the `authors.icon` property
133+
134+
The code for just customizing the icon will be:
135+
136+
```javascript
137+
import React, { Component } from 'react';
138+
import { AdminBuilder, hydraClient } from '@api-platform/admin';
139+
import parseHydraDocumentation from '@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation';
140+
import UserIcon from '@material-ui/icons/People';
141+
142+
const entrypoint = 'https://demo.api-platform.com';
143+
144+
export default class extends Component {
145+
state = { api: null }
146+
147+
componentDidMount() {
148+
parseHydraDocumentation(entrypoint).then(({api}) => {
149+
const authors = books.fields.find(({ name }) => 'authors' === name)
150+
151+
// Set the icon
152+
authors.icon = UserIcon
153+
154+
this.setState({ api });
155+
}
156+
)
157+
}
158+
159+
render() {
160+
if (null === this.state.api) return <div>Loading...</div>;
161+
162+
return <AdminBuilder api={ this.state.api } dataProvider={ hydraClient(this.state.api) }/>
163+
}
164+
}
165+
```
166+
123167
## Using an Autocomplete Input for Relations
124168

125169
We'll make one last improvement to our admin: transforming the relation selector we just created to use autocompletion.

0 commit comments

Comments
 (0)