File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,50 @@ export default class extends Component {
120
120
}
121
121
```
122
122
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
+
123
167
## Using an Autocomplete Input for Relations
124
168
125
169
We'll make one last improvement to our admin: transforming the relation selector we just created to use autocompletion.
You can’t perform that action at this time.
0 commit comments