136 lines
3.4 KiB
Markdown
Raw Normal View History

2018-01-10 11:32:24 +01:00
# Plugin Menu library
```js
// ...
import PluginLeftMenu from 'components/PluginLeftMenu';
// ...
2019-11-07 12:05:39 +01:00
const Foo = props => {
2018-01-10 11:32:24 +01:00
const sections = [
{
name: 'section 1',
items: [
2019-11-07 12:05:39 +01:00
{ icon: 'fa-caret-square-o-right', name: 'link 1' },
{ icon: 'fa-caret-square-o-right', name: 'link 2' },
2018-01-10 11:32:24 +01:00
],
},
];
return (
<div className={styles.foo}>
<div className="container-fluid">
<div className="row">
2019-11-07 12:05:39 +01:00
<PluginLeftMenu sections={sections} />
2018-01-10 11:32:24 +01:00
</div>
</div>
</div>
);
2019-11-07 12:05:39 +01:00
};
2018-01-10 11:32:24 +01:00
export default Foo;
// ...
```
## Usage
2019-11-07 12:05:39 +01:00
| Property | Type | Required | Description |
| :----------------- | :------- | :------- | :------------------------------------------------------------------------------------------- |
| `addCustomSection` | function | no | Allows to add another section after the initial one. |
| `basePath` | string | yes | For example the basePath of the route '/plugins/my-plugin/foo/bar' is 'my-plugin/categories' |
| `renderCustomLink` | function | no | Allows to override the design and the behavior of a link |
| `sections` | array | yes | Sections of the component menu |
2018-01-10 11:32:24 +01:00
## Example
```js
// ...
import PluginLeftMenu from 'components/PluginLeftMenu';
// ...
2019-11-07 12:05:39 +01:00
const addCustomSection = sectionStyles => (
2018-01-10 11:32:24 +01:00
// You have access to the section styles
<div className={sectionStyles.pluginLeftMenuSection}>
2019-11-07 12:05:39 +01:00
<p>DOCUMENTATION</p>
2018-01-10 11:32:24 +01:00
<ul>
<li>
2019-11-07 12:05:39 +01:00
Read more about strapi in our{' '}
<a href="http://strapi.io/documentation" target="_blank">
documentation
</a>
2018-01-10 11:32:24 +01:00
</li>
</ul>
</div>
2019-11-07 12:05:39 +01:00
);
2018-01-10 11:32:24 +01:00
const renderAddLink = (props, customLinkStyles) => (
<li className={customLinkStyles.pluginLeftMenuLink}>
2019-11-07 12:05:39 +01:00
<div
className={`${customLinkStyles.liInnerContainer}`}
onClick={this.handleAddLinkClick}
>
2018-01-10 11:32:24 +01:00
<div>
<i className={`fa ${props.link.icon}`} />
</div>
<span>{props.link.name}</span>
</div>
</li>
2019-11-07 12:05:39 +01:00
);
2018-01-10 11:32:24 +01:00
const renderCustomLink = (props, linkStyles) => {
if (props.link.name === 'bar') return this.renderAddLink(props, linkStyles);
return (
<li className={linkStyles.pluginLeftMenuLink}>
2019-11-07 12:05:39 +01:00
<NavLink
className={linkStyles.link}
to={`/plugins/my-plugin/foo/${props.link.name}`}
activeClassName={linkStyles.linkActive}
>
2018-01-10 11:32:24 +01:00
<div>
<i className={`fa fa-caret-square-o-right`} />
</div>
<div className={styles.contentContainer}>
<span className={spanStyle}>{props.link.name}</span>
</div>
</NavLink>
</li>
);
2019-11-07 12:05:39 +01:00
};
2018-01-10 11:32:24 +01:00
2019-11-07 12:05:39 +01:00
const Foo = props => {
2018-01-10 11:32:24 +01:00
const sections = [
{
name: 'section 1',
items: [
2019-11-07 12:05:39 +01:00
{ icon: 'fa-caret-square-o-right', name: 'link 1' },
{ icon: 'fa-caret-square-o-right', name: 'link 2' },
2018-01-10 11:32:24 +01:00
],
},
];
return (
<div className={styles.foo}>
<div className="container-fluid">
<div className="row">
<PluginLeftMenu
addCustomSection={addCustomSection}
sections={sections}
renderCustomLink={renderCustomLink}
basePath="my-plugins/foo"
/>
</div>
</div>
</div>
);
2019-11-07 12:05:39 +01:00
};
2018-01-10 11:32:24 +01:00
// ...
export default Foo;
```