Skip to content

Commit d605a66

Browse files
[FRNT-457]: add category to menu (#15)
* add category to menu * Update gatsby-theme-woly/src/components/components-menu.js Co-authored-by: Sergey Sova <5620073+sergeysova@users.noreply.github.com>
1 parent 1c04966 commit d605a66

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as React from 'react';
2+
3+
export const InputPassword = () => <input type="password" />;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: input-password
3+
category: molecules
4+
package: 'woly'
5+
---
6+
7+
import { InputPassword } from './example';
8+
9+
Hello! It is InputPassword
10+
11+
<InputPassword />
12+
13+
### Props
14+
15+
| Name | Type | Default | Description |
16+
| ------- | ------------------------ | -------- | ---------------------------------------------------------- | ---------- | ----------------------- |
17+
| `text` | `React.ReactNode` | | Text appeared on the button |
18+
| `left` | `React.ReactNode` | `null` | Component to show on the left side of the text (ex.: Icon) |
19+
| `right` | `React.ReactNode` | `null` | Component on the right side of the text |
20+
| `type` | `'button' | 'submit' | 'reset'` | `'button'` | HTML type of the button |
21+
| `...` | `HTMLButtonElementProps` | `{}` | Other props is inherited from `HTMLButtonElement` |

gatsby-theme-woly/src/components/components-menu.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const ComponentsMenu = ({ menu, isVisible, buttonClicked }) => {
2121
<>
2222
<BurgerButton buttonClicked={buttonClicked} />
2323
<Block isVisible={isVisible}>
24-
<h3>Components</h3>
2524
{menu.map((group) => (
2625
<Group key={group.name} group={group} activeMenu={activeMenu} />
2726
))}
@@ -34,15 +33,28 @@ const Group = ({ group, activeMenu }) => (
3433
<div>
3534
<MenuHeader>{group.name}</MenuHeader>
3635
<MenuItems>
37-
{group.components.map((com) => (
38-
<MenuItem key={com.id} active={com.name === activeMenu ? true : false}>
39-
<Link to={com.path}>{com.name}</Link>
40-
</MenuItem>
36+
{Object.keys(group.components).map((key) => (
37+
<GroupItems
38+
name={key}
39+
groupItems={group.components[key]}
40+
activeMenu={activeMenu}
41+
/>
4142
))}
4243
</MenuItems>
4344
</div>
4445
);
4546

47+
export const GroupItems = ({ name, groupItems, activeMenu }) => (
48+
<>
49+
<CategoryHead>{name}</CategoryHead>
50+
{groupItems.map((com) => (
51+
<MenuItem key={com.id} active={com.name === activeMenu}>
52+
<Link to={com.path}>{com.name}</Link>
53+
</MenuItem>
54+
))}
55+
</>
56+
);
57+
4658
export const Burger = styled.div`
4759
display: block;
4860
position: fixed;
@@ -129,11 +141,17 @@ const Block = styled.nav`
129141
}
130142
`;
131143

132-
export const MenuHeader = styled.h4`
144+
export const MenuHeader = styled.h3`
133145
text-transform: capitalize;
134146
font-weight: 300;
135147
border-bottom: 1px solid var(--base);
136-
padding: 20px 0 10px 0.3rem;
148+
padding: 0 0 10px 0;
149+
margin-bottom: 0px;
150+
margin-top: 20px;
151+
`;
152+
153+
export const CategoryHead = styled.h4`
154+
padding: 0.5rem 5rem 0.5rem 0.5rem;
137155
margin-bottom: 0px;
138156
`;
139157

gatsby-theme-woly/src/components/layout.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ function createMapping(data) {
4949
const packages = {};
5050
for (const component of data.mdx.components) {
5151
if (!packages[component.meta.package]) {
52-
packages[component.meta.package] = [];
52+
packages[component.meta.package] = {};
5353
}
54+
55+
if (!packages[component.meta.package][component.meta.category]) {
56+
packages[component.meta.package][component.meta.category] = [];
57+
}
58+
5459
const prefix = data.pathPrefix || '';
5560

5661
if (!isHiddenCategory(component.meta.category)) {
57-
packages[component.meta.package].push({
62+
packages[component.meta.package][component.meta.category].push({
5863
...component.meta,
5964
path: prefix + paths.componentUsage(component.meta),
6065
id: component.id,

0 commit comments

Comments
 (0)