Skip to content

Commit b4bc7e3

Browse files
authored
Changed panels to panes (#42)
1 parent ced713c commit b4bc7e3

File tree

14 files changed

+2239
-2055
lines changed

14 files changed

+2239
-2055
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"dist",
2020
"setupTests.ts",
2121
"babel.config.js",
22-
"www"
22+
"www",
23+
"src/**/__tests__/*"
2324
],
2425
"rules": {
2526
"comma-dangle": "off",

package-lock.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@babel/preset-typescript": "^7.13.0",
2424
"@types/enzyme": "^3.10.8",
2525
"@types/enzyme-adapter-react-16": "^1.0.6",
26+
"@types/jest": "^26.0.20",
2627
"@types/react": "^17.0.2",
2728
"@types/react-dom": "^16.9.11",
2829
"@typescript-eslint/eslint-plugin": "^4.15.2",

src/components/Card/Card.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
1616
}
1717

1818
// Static properties are not given yet, when declaring the card const. Therefore, the error saying
19-
// that Card is missing above CardStatics properties. These will defined after the card component
19+
// that Card is missing above CardStatics properties. These will defined after the card component
2020
// is defined.
2121
// @ts-ignore
2222
const Card: ForwardComponentWithStatics<HTMLDivElement, CardProps, CardStatics> = React.forwardRef((

src/components/Panel/Container.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import PropTypes from 'prop-types';
3+
import clsx from 'clsx';
4+
5+
export interface PanelContainerProps extends React.HTMLAttributes<HTMLDivElement> {
6+
vertical?: boolean;
7+
}
8+
9+
const PanelContainer = React.forwardRef<HTMLDivElement, PanelContainerProps>((
10+
{
11+
children,
12+
vertical
13+
},
14+
ref
15+
): React.ReactElement => (
16+
<div
17+
ref={ref}
18+
className={clsx(
19+
'pane-container',
20+
vertical && 'vertical'
21+
)}
22+
>
23+
{children}
24+
</div>
25+
));
26+
27+
PanelContainer.displayName = 'PanelContainer';
28+
PanelContainer.propTypes = {
29+
children: PropTypes.node,
30+
vertical: PropTypes.bool
31+
}
32+
33+
export default PanelContainer;

src/components/Panel/Content.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react';
2+
import PropTypes from 'prop-types';
3+
import clsx from 'clsx';
4+
5+
export type PaneContentProps = React.HTMLAttributes<HTMLDivElement>;
6+
7+
const PaneContent = React.forwardRef<HTMLDivElement, PaneContentProps>((
8+
{
9+
children,
10+
className
11+
},
12+
ref
13+
): React.ReactElement => (
14+
<div
15+
ref={ref}
16+
className={clsx(
17+
'pane-content',
18+
className
19+
)}
20+
>
21+
{children}
22+
</div>
23+
));
24+
25+
PaneContent.displayName = 'PaneContent';
26+
PaneContent.propTypes = {
27+
children: PropTypes.node,
28+
className: PropTypes.string
29+
}
30+
31+
export default PaneContent;

src/components/Panel/Pane.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as React from 'react';
2+
import PropTypes from 'prop-types';
3+
import clsx from 'clsx';
4+
import PaneContent from './Content';
5+
import { ForwardComponentWithStatics } from '../utils';
6+
import { PaneContainer } from './index';
7+
8+
export type PaneStatics = {
9+
Content: typeof PaneContent;
10+
Container: typeof PaneContainer;
11+
}
12+
13+
export interface PaneProps extends React.HTMLAttributes<HTMLDivElement> {
14+
horizontal?: boolean;
15+
}
16+
17+
// Static properties are not given yet, when declaring the card const. Therefore, the error saying
18+
// that Pane is missing above PaneStatics properties. These will defined after the pane component
19+
// is defined.
20+
// @ts-ignore
21+
const Pane: ForwardComponentWithStatics<HTMLDivElement, PaneProps, PaneStatics> = React.forwardRef<HTMLDivElement, PaneProps>((
22+
{
23+
children,
24+
className,
25+
horizontal
26+
},
27+
ref
28+
): React.ReactElement => (
29+
<div
30+
ref={ref}
31+
className={clsx(
32+
'pane',
33+
horizontal && 'horizontal',
34+
className
35+
)}
36+
>
37+
{children}
38+
</div>
39+
));
40+
41+
Pane.displayName = 'Pane';
42+
Pane.propTypes = {
43+
children: PropTypes.node,
44+
className: PropTypes.string,
45+
horizontal: PropTypes.bool
46+
}
47+
48+
Pane.Content = PaneContent;
49+
Pane.Container = PaneContainer;
50+
51+
export default Pane;

src/components/Panel/Panel.tsx

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { mount, shallow } from 'enzyme';
2+
import React from 'react';
3+
import Pane from '../Pane';
4+
import PaneContainer from '../Container';
5+
import PaneContent from '../Content';
6+
7+
describe('Pane test', () => {
8+
it('should render pane container', () => {
9+
const container = shallow(
10+
<PaneContainer>
11+
Hello world
12+
</PaneContainer>
13+
);
14+
15+
expect(container.find('.pane-container').length).toBe(1);
16+
});
17+
18+
it('should render vertical pane container', () => {
19+
const container = shallow(
20+
<PaneContainer vertical>
21+
Hello world
22+
</PaneContainer>
23+
);
24+
25+
expect(container.find('.pane-container.vertical').length).toBe(1);
26+
});
27+
28+
it('should render pane', () => {
29+
const container = shallow(
30+
<Pane>
31+
Hello world
32+
</Pane>
33+
);
34+
35+
expect(container.find('.pane').length).toBe(1);
36+
});
37+
38+
it('should render horizontal pane', () => {
39+
const container = shallow(
40+
<Pane horizontal>
41+
Hello world
42+
</Pane>
43+
);
44+
45+
expect(container.find('.pane.horizontal').length).toBe(1);
46+
});
47+
it('should render pane content', () => {
48+
const container = mount(
49+
<div>
50+
<PaneContent>
51+
Hello world
52+
</PaneContent>
53+
<Pane.Content>
54+
Hello world
55+
</Pane.Content>
56+
</div>
57+
);
58+
59+
expect(container.find('.pane-content').length).toBe(2);
60+
});
61+
});

src/components/Panel/__tests__/Panel.test.tsx

-25
This file was deleted.

src/components/Panel/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
export { default as Panel } from './Panel';
2-
export type { PanelProps } from './Panel'
1+
export { default as PaneContainer} from './Container';
2+
export type { PanelContainerProps } from './Container';
3+
4+
export { default as PaneContent } from './Content';
5+
export type { PaneContentProps } from './Content';
6+
7+
export { default as Panel } from './Pane';
8+
export type { PaneProps } from './Pane'

src/style/base/_variables.scss

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* 1. Colors
2+
* Colors
33
*/
44
$colors: (
55
'red': (
@@ -147,7 +147,7 @@ $colors: (
147147
}
148148

149149
/**
150-
* 2. Base
150+
* Base
151151
*/
152152
$base-background-color: color('gray', 'background') !default;
153153
$base-body-gutter: 0 !default;
@@ -206,18 +206,7 @@ $success-color-active: color('green', 'active') !default;
206206
}
207207

208208
/**
209-
* 3. Panel
210-
*/
211-
$panel-background: #fff !default;
212-
$panel-gutter: 2rem !default;
213-
214-
:root {
215-
--panel-background: #{$panel-background};
216-
--panel-gutter: #{$panel-gutter}
217-
}
218-
219-
/**
220-
* 4. Page
209+
* Page
221210
*/
222211
$page-gutter: 2rem !default;
223212

@@ -226,7 +215,7 @@ $page-gutter: 2rem !default;
226215
}
227216

228217
/**
229-
* 5. Button
218+
* Button
230219
*/
231220
$button-padding: 1rem !default;
232221
$button-font-weight: 600 !default;
@@ -277,7 +266,7 @@ $danger-button-ghost-active-background: color('red', 'background-hover') !defaul
277266
}
278267

279268
/**
280-
* 6. Cards
269+
* Cards
281270
*/
282271
$card-padding: 1.5rem !default;
283272
$card-background: #fff !default;
@@ -288,7 +277,7 @@ $card-background: #fff !default;
288277
}
289278

290279
/**
291-
* 7. Form fields
280+
* Form fields
292281
*/
293282
$form-field-padding: 1rem !default;
294283
$form-field-font-weight: 500 !default;
@@ -301,7 +290,7 @@ $form-field-font-size: 1rem !default;
301290
}
302291

303292
/**
304-
* 8. Icons
293+
* Icons
305294
*/
306295
$iconPath: '../icons' !default;
307296
$icons: (
@@ -556,7 +545,7 @@ $icons: (
556545
}
557546

558547
/**
559-
* 8. Form fields
548+
* Form fields
560549
*/
561550
$form-field-padding: 1rem !default;
562551
$form-field-font-weight: 500 !default;

src/style/components/_panel.scss

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
.panel {
1+
.pane-container {
2+
display: flex;
3+
4+
&.vertical {
5+
flex-direction: column;
6+
}
7+
}
8+
9+
.pane {
210
background: var(--panel-background);
11+
display: flex;
12+
flex-direction: column;
13+
flex: 1 auto;
14+
position: relative;
15+
16+
&.horizontal {
17+
flex-direction: row;
18+
}
19+
20+
.pane-content {
21+
padding: var(--base-gutter);
22+
}
323

4-
&.panel-spaced {
5-
padding: var(--panel-gutter);
24+
.pane-header {
25+
padding: var(--base-gutter);
626
}
727
}

0 commit comments

Comments
 (0)