Skip to content

Commit

Permalink
Merge branch 'main' into add-preferredSize-prop
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwalley committed Apr 9, 2022
2 parents 7870881 + aba5086 commit 737f442
Show file tree
Hide file tree
Showing 19 changed files with 1,074 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ export const parameters = {
darkMode: {
stylePreview: true,
},
options: {
storySort: {
order: ["Basic", "Advanced"],
},
},
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ import "allotment/dist/style.css";

### My content is larger than the containing pane. How can I let the user scroll?

The simplest approach is place your content inside a new div with width and height `100%` and overflow `auto`. This div will have the same dimensions as the pane it's inside and if its content overflows the browser will provide scrolling behaviour.
The simplest approach is to place your content inside a new div with width and height `100%` and overflow `auto`. This div will have the same dimensions as the pane it's inside and if its content overflows the browser will provide scrolling behaviour.

### Next.js

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"use-resize-observer": "^8.0.0"
},
"devDependencies": {
"@babel/core": "7.17.8",
"@babel/core": "7.17.9",
"@babel/plugin-proposal-class-properties": "7.16.7",
"@babel/plugin-proposal-private-methods": "7.16.11",
"@babel/plugin-proposal-private-property-in-object": "7.16.7",
Expand All @@ -40,20 +40,21 @@
"@babel/preset-react": "7.16.7",
"@babel/preset-typescript": "7.16.7",
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-commonjs": "21.0.2",
"@rollup/plugin-commonjs": "21.0.3",
"@rollup/plugin-node-resolve": "13.1.3",
"@storybook/addon-actions": "6.4.20",
"@storybook/addon-essentials": "6.4.20",
"@storybook/addon-links": "6.4.20",
"@storybook/react": "6.4.20",
"@testing-library/dom": "8.11.4",
"@testing-library/dom": "8.13.0",
"@types/jest": "27.4.1",
"@types/lodash.clamp": "4.0.6",
"@types/lodash.debounce": "4.0.6",
"@typescript-eslint/parser": "5.16.0",
"@typescript-eslint/parser": "5.18.0",
"@vscode/codicons": "^0.0.29",
"babel-jest": "27.5.1",
"babel-loader": "8.2.4",
"eslint": "8.12.0",
"eslint": "8.13.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-react-hooks": "4.3.0",
"eslint-plugin-simple-import-sort": "7.0.0",
Expand All @@ -71,7 +72,8 @@
"storybook-dark-mode": "1.0.9",
"ts-jest": "27.1.4",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"typescript": "4.6.3",
"xterm": "^4.18.0"
},
"peerDependencies": {
"react": "^17.0.0",
Expand Down
7 changes: 7 additions & 0 deletions stories/advanced.stories.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.container {
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
color: #cccccc;
font-family: sans-serif;
height: 480px;
width: 640px;
}
145 changes: 145 additions & 0 deletions stories/advanced.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import "@vscode/codicons/dist/codicon.css";

import { Meta, Story } from "@storybook/react";
import { useState } from "react";

import { Allotment } from "../src";
import styles from "./advanced.stories.module.css";
import { ActivityBar } from "./components/activity-bar";
import { Editor } from "./components/editor";
import { Panel } from "./components/panel";
import { Sidebar } from "./components/sidebar";

const ACTIVITIES = [
"Explorer",
"Search",
"Source Control",
"Run and Debug",
"Extensions",
];

const DOCUMENTS = [
{ title: "allotment.tsx", icon: "ts" },
{ title: "allotment.module.css", icon: "css" },
];

export interface Document {
title: string;
icon: string;
}

export default {
title: "Advanced",
Component: Allotment,
argTypes: {
activityBar: {
control: { type: "boolean" },
},
primarySideBar: {
control: { type: "boolean" },
},
primarySideBarPosition: {
options: ["left", "right"],
control: { type: "radio" },
},
},
} as Meta;

export const VisualStudioCode: Story = ({
activityBar,
primarySideBar,
primarySideBarPosition,
}) => {
const [editorVisible, setEditorVisible] = useState(true);
const [panelVisible, setPanelVisible] = useState(true);
const [activity, setActivity] = useState(0);

const [openEditors, setOpenEditors] = useState<Document[]>(DOCUMENTS);

const sidebar = (
<Allotment.Pane key="sidebar" minSize={170} visible={primarySideBar} snap>
<Sidebar
title={ACTIVITIES[activity]}
documents={DOCUMENTS}
openEditors={openEditors}
onOpenEditorsChange={(openEditor) => {
setOpenEditors(openEditor);
}}
/>
</Allotment.Pane>
);

return (
<div className={styles.container}>
<Allotment>
<Allotment.Pane
key="activityBar"
minSize={48}
maxSize={48}
visible={activityBar}
>
<ActivityBar
checked={activity}
items={[
"files",
"search",
"source-control",
"debug-alt",
"extensions",
]}
onClick={(index) => {
setActivity(index);
}}
/>
</Allotment.Pane>
{primarySideBarPosition === "left" && sidebar}
<Allotment.Pane key="content" minSize={300}>
<Allotment
vertical
snap
onVisibleChange={(index, value) => {
if (index === 0) {
setEditorVisible(value);
} else if (index === 1) {
setPanelVisible(value);
}
}}
>
<Allotment.Pane key="editor" minSize={70} visible={editorVisible}>
<Editor
documents={openEditors}
onDocumentsChange={(documents) => {
setOpenEditors(documents);
}}
/>
</Allotment.Pane>
<Allotment.Pane key="terminal" minSize={78} visible={panelVisible}>
<Panel
maximized={!editorVisible}
onClose={() => {
setEditorVisible(true);
setPanelVisible(false);
}}
onMaximize={() => {
setEditorVisible(false);
setPanelVisible(true);
}}
onMinimize={() => {
setEditorVisible(true);
setPanelVisible(true);
}}
/>
</Allotment.Pane>
</Allotment>
</Allotment.Pane>
{primarySideBarPosition === "right" && sidebar}
</Allotment>
</div>
);
};

VisualStudioCode.args = {
activityBar: true,
primarySideBar: true,
primarySideBarPosition: "left",
};
44 changes: 44 additions & 0 deletions stories/components/activity-bar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.activitybar {
background-color: rgb(51, 51, 51);
height: 100%;
overflow: hidden;
}

.content {
display: flex;
flex-direction: column;
justify-content: space-between;
}

.actionsContainer {
list-style-type: none;
padding: 0;
margin: 0;
}

.actionItem {
align-items: center;
justify-content: center;
cursor: pointer;
position: relative;
}

.actionItem.checked:before {
content: "";
position: absolute;
z-index: 1;
top: 0;
height: 100%;
width: 0;
border-left: 2px solid;
}

.actionLabel {
display: flex !important;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;
color: rgb(255, 255, 255);
font-size: 24px !important;
}
40 changes: 40 additions & 0 deletions stories/components/activity-bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import "@vscode/codicons/dist/codicon.css";

import classNames from "classnames";

import styles from "./activity-bar.module.css";

export type ActivityBarProps = {
checked: number;
items: string[];
onClick: (index: number) => void;
};

export const ActivityBar = ({ checked, items, onClick }: ActivityBarProps) => {
return (
<div className={styles.activitybar}>
<div className={styles.content}>
<ul className={styles.actionsContainer}>
{items.map((item, index) => (
<li
key={index}
className={classNames(styles.actionItem, {
[styles.checked]: index === checked,
})}
>
<a
className={classNames(
`codicon codicon-${item}`,
styles.actionLabel
)}
onClick={() => {
onClick(index);
}}
></a>
</li>
))}
</ul>
</div>
</div>
);
};
48 changes: 48 additions & 0 deletions stories/components/editor-group-container.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@font-face {
src: url("../seti.woff") format("woff");
font-family: "seti";
font-weight: normal;
font-style: normal;
font-display: block;
}

.allotment {
overflow-x: scroll;
}

.editorGroupContainer {
height: 100%;
}

.title {
background-color: rgb(37, 37, 38);
}

.editorContainer {
background-color: rgb(30, 30, 30);
}

.iconLabel {
display: flex;
line-height: 35px;
}

.iconLabel::before {
color: #519aba;
background-image: unset;
font-family: "seti";
font-size: 150%;
}

.typescriptReactFileIcon::before {
content: "\E099";
}

.cssLangFileIcon::before {
content: "\E01D";
}

.labelName {
cursor: pointer;
font-size: 13px;
}
Loading

0 comments on commit 737f442

Please sign in to comment.