I can not show you the full code since it is done for a client but I can try to separate important bits.
It really is not that hard if you read the docs - which I highly recommend. There are some gotchas as in everything, so docs will help.
- Create a normal React component where you can use Strapi Design elements (put it into /src/admin/extensions/components folder) - for example a simple Button can be shown like this:
import React from "react"
import { Button } from "@strapi/design-system"
import IconCog from "@strapi/icons/Command"
const TestButton = ({}) => {
const handleClick = () => {
console.log("TEST button clicked!")
}
return (
<Button variant="secondary" startIcon={<IconCog />} onClick={handleClick}>
TEST
</Button>
)
}
export default TestButton
- Inject that button into listview or editview (you have that in Strapi docs) - you need to add this code into bootstrap part of app.js
bootstrap(app) {
app.injectContentManagerComponent(
"listView",
"actions",
{
name: "TEST Button",
Component: TestButton, // you need to import this component into app.js of course
}
)
}
This way you will get this button on every listview (browse) screen.
If you want to limit that - you have a simple solution - check for location and show button accordingly.
I do my checks with something like this:
const validPathNames = [
"/content-manager/collectionType/api::order.order"
]
let isButtonDisplayed = false
for (let vp of validPathNames) {
isButtonDisplayed = useLocation().pathname.includes(vp)
if (isButtonDisplayed) break
}
And then it is a simple value check to render it or not.