@teambit/sidebar 0.0.568 → 0.0.569

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/sidebar",
3
- "version": "0.0.568",
3
+ "version": "0.0.569",
4
4
  "homepage": "https://bit.dev/teambit/ui-foundation/sidebar",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.ui-foundation",
8
8
  "name": "sidebar",
9
- "version": "0.0.568"
9
+ "version": "0.0.569"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -17,9 +17,9 @@
17
17
  "@teambit/base-ui.routing.nav-link": "1.0.0",
18
18
  "@teambit/evangelist.elements.icon": "1.0.2",
19
19
  "@teambit/documenter.ui.separator": "4.1.1",
20
- "@teambit/component": "0.0.568",
21
- "@teambit/ui-foundation.ui.tree.drawer": "0.0.471",
22
- "@teambit/ui": "0.0.568",
20
+ "@teambit/component": "0.0.569",
21
+ "@teambit/ui-foundation.ui.tree.drawer": "0.0.472",
22
+ "@teambit/ui": "0.0.569",
23
23
  "@teambit/design.ui.surfaces.menu.section": "0.0.347"
24
24
  },
25
25
  "devDependencies": {
@@ -33,7 +33,7 @@
33
33
  "@types/node": "12.20.4"
34
34
  },
35
35
  "peerDependencies": {
36
- "@teambit/legacy": "1.0.180",
36
+ "@teambit/legacy": "1.0.181",
37
37
  "react-dom": "^16.8.0 || ^17.0.0",
38
38
  "react": "^16.8.0 || ^17.0.0"
39
39
  },
@@ -61,27 +61,12 @@
61
61
  "react": "-"
62
62
  },
63
63
  "peerDependencies": {
64
- "@teambit/legacy": "1.0.180",
64
+ "@teambit/legacy": "1.0.181",
65
65
  "react-dom": "^16.8.0 || ^17.0.0",
66
66
  "react": "^16.8.0 || ^17.0.0"
67
67
  }
68
68
  }
69
69
  },
70
- "files": [
71
- "dist",
72
- "!dist/tsconfig.tsbuildinfo",
73
- "**/*.md",
74
- "**/*.mdx",
75
- "**/*.js",
76
- "**/*.json",
77
- "**/*.sass",
78
- "**/*.scss",
79
- "**/*.less",
80
- "**/*.css",
81
- "**/*.css",
82
- "**/*.jpeg",
83
- "**/*.gif"
84
- ],
85
70
  "private": false,
86
71
  "engines": {
87
72
  "node": ">=12.22.0"
@@ -0,0 +1,49 @@
1
+ import { ComponentModel } from '@teambit/component';
2
+ import { Slot, SlotRegistry } from '@teambit/harmony';
3
+ import { UIRuntime } from '@teambit/ui';
4
+ import React, { ComponentType } from 'react';
5
+
6
+ import type { DrawerType } from '@teambit/ui-foundation.ui.tree.drawer';
7
+ import { SidebarAspect } from './sidebar.aspect';
8
+ import { SideBar, SideBarProps } from './ui';
9
+
10
+ export type ComponentTypeProps = {
11
+ component: ComponentModel;
12
+ };
13
+
14
+ export type SidebarItem = ComponentType;
15
+
16
+ export type SidebarItemSlot = SlotRegistry<SidebarItem[]>;
17
+
18
+ export type DrawerSlot = SlotRegistry<DrawerType>;
19
+
20
+ export class SidebarUI {
21
+ constructor(private drawerSlot: DrawerSlot) {}
22
+
23
+ /**
24
+ * register a new drawer into the component sidebar.
25
+ */
26
+ registerDrawer(drawer: DrawerType) {
27
+ this.drawerSlot.register(drawer);
28
+ return this;
29
+ }
30
+
31
+ /**
32
+ * render the sidebar.
33
+ */
34
+ render = (props: Partial<SideBarProps>) => {
35
+ return <SideBar drawerSlot={this.drawerSlot} {...props}></SideBar>;
36
+ };
37
+
38
+ static runtime = UIRuntime;
39
+
40
+ static slots = [Slot.withType<DrawerType>()];
41
+
42
+ static dependencies = [];
43
+
44
+ static async provider(deps, config, [drawerSlot]: [DrawerSlot]) {
45
+ return new SidebarUI(drawerSlot);
46
+ }
47
+ }
48
+
49
+ SidebarAspect.addRuntime(SidebarUI);
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }
package/ui/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { SideBar, SideBarProps } from './side-bar';
@@ -0,0 +1 @@
1
+ export { OverviewLink } from './overview-link';
@@ -0,0 +1,27 @@
1
+ import { Separator } from '@teambit/documenter.ui.separator';
2
+ import { Icon } from '@teambit/evangelist.elements.icon';
3
+ import { NavLink } from '@teambit/base-ui.routing.nav-link';
4
+ import classNames from 'classnames';
5
+ import React from 'react';
6
+
7
+ import styles from './overview-link.module.scss';
8
+
9
+ export function OverviewLink() {
10
+ return (
11
+ <div className={styles.overview}>
12
+ <NavLink
13
+ exact
14
+ href="/"
15
+ activeClassName={styles.active}
16
+ className={classNames(
17
+ // hoverable, clickable, // TODO - return these somehow @oded
18
+ styles.overviewLink
19
+ )}
20
+ >
21
+ Components
22
+ <Icon of="comps" className={styles.icon} />
23
+ </NavLink>
24
+ <Separator className={styles.separator} />
25
+ </div>
26
+ );
27
+ }
@@ -0,0 +1 @@
1
+ export { SideBar, SideBarProps } from './side-bar';
@@ -0,0 +1,51 @@
1
+ import React, { useState, useMemo } from 'react';
2
+ import { flatten } from 'lodash';
3
+ import { MenuSection } from '@teambit/design.ui.surfaces.menu.section';
4
+ import { DrawerUI } from '@teambit/ui-foundation.ui.tree.drawer';
5
+ import { DrawerSlot, SidebarItemSlot } from '../../sidebar.ui.runtime';
6
+ import styles from './side-bar.module.scss';
7
+
8
+ export type SideBarProps = {
9
+ /**
10
+ * slot of registered drawers.
11
+ */
12
+ drawerSlot: DrawerSlot;
13
+
14
+ itemSlot?: SidebarItemSlot;
15
+ } & React.HTMLAttributes<HTMLDivElement>;
16
+
17
+ /**
18
+ * side bar component.
19
+ */
20
+ export function SideBar({ drawerSlot, itemSlot, ...rest }: SideBarProps) {
21
+ const [openDrawerList, onToggleDrawer] = useState([drawerSlot.toArray()[0][0]]);
22
+ const items = useMemo(() => flatten(itemSlot?.values()), [itemSlot]);
23
+
24
+ const handleDrawerToggle = (id: string) => {
25
+ const isDrawerOpen = openDrawerList.includes(id);
26
+ if (isDrawerOpen) {
27
+ onToggleDrawer((list) => list.filter((drawer) => drawer !== id));
28
+ return;
29
+ }
30
+ onToggleDrawer((list) => list.concat(id));
31
+ };
32
+
33
+ return (
34
+ <div {...rest} className={styles.sidebar}>
35
+ <MenuSection items={items} />
36
+ {drawerSlot.toArray().map(([id, drawer]) => {
37
+ if (!drawer || !drawer.name) return null;
38
+ return (
39
+ <DrawerUI
40
+ isOpen={openDrawerList.includes(id)}
41
+ onToggle={() => handleDrawerToggle(id)}
42
+ key={id}
43
+ name={drawer.name}
44
+ >
45
+ <drawer.render />
46
+ </DrawerUI>
47
+ );
48
+ })}
49
+ </div>
50
+ );
51
+ }