|
8 | 8 | ListItem,
|
9 | 9 | ListItemAvatar,
|
10 | 10 | ListItemIcon,
|
| 11 | + ListItemProps, |
11 | 12 | ListItemSecondaryAction,
|
12 | 13 | ListItemText,
|
13 | 14 | } from '@material-ui/core';
|
@@ -129,76 +130,69 @@ const SimpleList = <RecordType extends Record = Record>(
|
129 | 130 | basePath={basePath}
|
130 | 131 | id={id}
|
131 | 132 | record={data[id]}
|
| 133 | + style={ |
| 134 | + rowStyle |
| 135 | + ? rowStyle(data[id], rowIndex) |
| 136 | + : undefined |
| 137 | + } |
132 | 138 | >
|
133 |
| - <ListItem |
134 |
| - button={!!linkType as any} |
135 |
| - style={ |
136 |
| - rowStyle |
137 |
| - ? rowStyle(data[id], rowIndex) |
138 |
| - : undefined |
139 |
| - } |
140 |
| - > |
141 |
| - {leftIcon && ( |
142 |
| - <ListItemIcon> |
143 |
| - {leftIcon(data[id], id)} |
144 |
| - </ListItemIcon> |
145 |
| - )} |
146 |
| - {leftAvatar && ( |
147 |
| - <ListItemAvatar> |
148 |
| - {renderAvatar(id, leftAvatar)} |
149 |
| - </ListItemAvatar> |
150 |
| - )} |
151 |
| - <ListItemText |
152 |
| - primary={ |
153 |
| - <div> |
154 |
| - {isValidElement(primaryText) |
155 |
| - ? primaryText |
156 |
| - : primaryText(data[id], id)} |
| 139 | + {leftIcon && ( |
| 140 | + <ListItemIcon> |
| 141 | + {leftIcon(data[id], id)} |
| 142 | + </ListItemIcon> |
| 143 | + )} |
| 144 | + {leftAvatar && ( |
| 145 | + <ListItemAvatar> |
| 146 | + {renderAvatar(id, leftAvatar)} |
| 147 | + </ListItemAvatar> |
| 148 | + )} |
| 149 | + <ListItemText |
| 150 | + primary={ |
| 151 | + <div> |
| 152 | + {isValidElement(primaryText) |
| 153 | + ? primaryText |
| 154 | + : primaryText(data[id], id)} |
157 | 155 |
|
158 |
| - {!!tertiaryText && |
159 |
| - (isValidElement( |
160 |
| - tertiaryText |
161 |
| - ) ? ( |
162 |
| - tertiaryText |
163 |
| - ) : ( |
164 |
| - <span |
165 |
| - className={ |
166 |
| - classes.tertiary |
167 |
| - } |
168 |
| - > |
169 |
| - {tertiaryText( |
170 |
| - data[id], |
171 |
| - id |
172 |
| - )} |
173 |
| - </span> |
174 |
| - ))} |
175 |
| - </div> |
176 |
| - } |
177 |
| - secondary={ |
178 |
| - !!secondaryText && |
179 |
| - (isValidElement(secondaryText) |
180 |
| - ? secondaryText |
181 |
| - : secondaryText(data[id], id)) |
182 |
| - } |
183 |
| - /> |
184 |
| - {(rightAvatar || rightIcon) && ( |
185 |
| - <ListItemSecondaryAction> |
186 |
| - {rightAvatar && ( |
187 |
| - <Avatar> |
188 |
| - {renderAvatar( |
189 |
| - id, |
190 |
| - rightAvatar |
191 |
| - )} |
192 |
| - </Avatar> |
193 |
| - )} |
194 |
| - {rightIcon && ( |
195 |
| - <ListItemIcon> |
196 |
| - {rightIcon(data[id], id)} |
197 |
| - </ListItemIcon> |
198 |
| - )} |
199 |
| - </ListItemSecondaryAction> |
200 |
| - )} |
201 |
| - </ListItem> |
| 156 | + {!!tertiaryText && |
| 157 | + (isValidElement( |
| 158 | + tertiaryText |
| 159 | + ) ? ( |
| 160 | + tertiaryText |
| 161 | + ) : ( |
| 162 | + <span |
| 163 | + className={ |
| 164 | + classes.tertiary |
| 165 | + } |
| 166 | + > |
| 167 | + {tertiaryText( |
| 168 | + data[id], |
| 169 | + id |
| 170 | + )} |
| 171 | + </span> |
| 172 | + ))} |
| 173 | + </div> |
| 174 | + } |
| 175 | + secondary={ |
| 176 | + !!secondaryText && |
| 177 | + (isValidElement(secondaryText) |
| 178 | + ? secondaryText |
| 179 | + : secondaryText(data[id], id)) |
| 180 | + } |
| 181 | + /> |
| 182 | + {(rightAvatar || rightIcon) && ( |
| 183 | + <ListItemSecondaryAction> |
| 184 | + {rightAvatar && ( |
| 185 | + <Avatar> |
| 186 | + {renderAvatar(id, rightAvatar)} |
| 187 | + </Avatar> |
| 188 | + )} |
| 189 | + {rightIcon && ( |
| 190 | + <ListItemIcon> |
| 191 | + {rightIcon(data[id], id)} |
| 192 | + </ListItemIcon> |
| 193 | + )} |
| 194 | + </ListItemSecondaryAction> |
| 195 | + )} |
202 | 196 | </LinkOrNot>
|
203 | 197 | </li>
|
204 | 198 | </RecordContextProvider>
|
@@ -255,40 +249,68 @@ export interface SimpleListProps<RecordType extends Record = Record>
|
255 | 249 |
|
256 | 250 | const useLinkOrNotStyles = makeStyles(
|
257 | 251 | {
|
258 |
| - link: { |
259 |
| - textDecoration: 'none', |
260 |
| - color: 'inherit', |
261 |
| - }, |
| 252 | + link: {}, |
262 | 253 | },
|
263 | 254 | { name: 'RaLinkOrNot' }
|
264 | 255 | );
|
265 | 256 |
|
266 |
| -const LinkOrNot = (props: LinkOrNotProps) => { |
| 257 | +const LinkOrNot = ( |
| 258 | + props: LinkOrNotProps & Omit<ListItemProps, 'button' | 'component' | 'id'> |
| 259 | +) => { |
267 | 260 | const {
|
268 | 261 | classes: classesOverride,
|
269 | 262 | linkType,
|
270 | 263 | basePath,
|
271 | 264 | id,
|
272 | 265 | children,
|
273 | 266 | record,
|
| 267 | + ...rest |
274 | 268 | } = props;
|
275 | 269 | const classes = useLinkOrNotStyles({ classes: classesOverride });
|
276 | 270 | const link =
|
277 | 271 | typeof linkType === 'function' ? linkType(record, id) : linkType;
|
278 | 272 |
|
279 | 273 | return link === 'edit' || link === true ? (
|
280 |
| - <Link to={linkToRecord(basePath, id)} className={classes.link}> |
| 274 | + <ListItem |
| 275 | + button |
| 276 | + // @ts-ignore |
| 277 | + component={Link} |
| 278 | + to={linkToRecord(basePath, id)} |
| 279 | + className={classes.link} |
| 280 | + {...rest} |
| 281 | + > |
281 | 282 | {children}
|
282 |
| - </Link> |
| 283 | + </ListItem> |
283 | 284 | ) : link === 'show' ? (
|
284 |
| - <Link |
| 285 | + <ListItem |
| 286 | + button |
| 287 | + // @ts-ignore |
| 288 | + component={Link} |
285 | 289 | to={`${linkToRecord(basePath, id)}/show`}
|
286 | 290 | className={classes.link}
|
| 291 | + {...rest} |
| 292 | + > |
| 293 | + {children} |
| 294 | + </ListItem> |
| 295 | + ) : link !== false ? ( |
| 296 | + <ListItem |
| 297 | + button |
| 298 | + // @ts-ignore |
| 299 | + component={Link} |
| 300 | + to={link} |
| 301 | + className={classes.link} |
| 302 | + {...rest} |
287 | 303 | >
|
288 | 304 | {children}
|
289 |
| - </Link> |
| 305 | + </ListItem> |
290 | 306 | ) : (
|
291 |
| - <span>{children}</span> |
| 307 | + <ListItem |
| 308 | + // @ts-ignore |
| 309 | + component="div" |
| 310 | + {...rest} |
| 311 | + > |
| 312 | + {children} |
| 313 | + </ListItem> |
292 | 314 | );
|
293 | 315 | };
|
294 | 316 |
|
|
0 commit comments