Skip to content

Commit 4285e66

Browse files
committed
Add ModuleGrid Component
1 parent cd3c4a7 commit 4285e66

File tree

3 files changed

+145
-38
lines changed

3 files changed

+145
-38
lines changed

rollup.config.js

Lines changed: 64 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,72 @@
1+
// -----------------------------------------------------------------------------
2+
// Deps
3+
// -----------------------------------------------------------------------------
4+
15
import typescript from 'rollup-plugin-typescript2';
26
import commonjs from 'rollup-plugin-commonjs';
37
import external from 'rollup-plugin-peer-deps-external';
48
import resolve from 'rollup-plugin-node-resolve';
59

610
import pkg from './package.json';
711

8-
export default {
9-
input: 'src/index.tsx',
10-
output: [
11-
{
12-
file: pkg.main,
13-
format: 'cjs',
14-
exports: 'named',
15-
sourcemap: true
16-
},
17-
{
18-
file: pkg.module,
19-
format: 'es',
20-
exports: 'named',
21-
sourcemap: true
22-
}
23-
],
24-
plugins: [
25-
external(),
26-
resolve(),
27-
typescript({
28-
rollupCommonJSResolveHack: true,
29-
exclude: '**/__tests__/**',
30-
clean: true
31-
}),
32-
commonjs({
33-
include: ['node_modules/**'],
34-
namedExports: {
35-
'node_modules/react/react.js': [
36-
'Children',
37-
'Component',
38-
'PropTypes',
39-
'createElement'
40-
],
41-
'node_modules/react-dom/index.js': ['render']
12+
// -----------------------------------------------------------------------------
13+
// Files
14+
// -----------------------------------------------------------------------------
15+
16+
const files = [
17+
{
18+
input: 'src/ModuleGrid/index.tsx',
19+
output: 'components/ModuleGrid/index.js',
20+
outputES: 'components/ModuleGrid/index.es.js'
21+
},
22+
{
23+
input: 'src/index.tsx',
24+
output: pkg.main,
25+
outputES: pkg.module
26+
}
27+
];
28+
29+
// -----------------------------------------------------------------------------
30+
// Config
31+
// -----------------------------------------------------------------------------
32+
33+
export default files.map((file) => {
34+
return {
35+
input: file.input,
36+
output: [
37+
{
38+
file: file.output,
39+
format: 'cjs',
40+
exports: 'named',
41+
sourcemap: true
42+
},
43+
{
44+
file: file.outputES,
45+
format: 'es',
46+
exports: 'named',
47+
sourcemap: true
4248
}
43-
})
44-
]
45-
};
49+
],
50+
plugins: [
51+
external(),
52+
resolve(),
53+
typescript({
54+
rollupCommonJSResolveHack: true,
55+
exclude: '**/__tests__/**',
56+
clean: true
57+
}),
58+
commonjs({
59+
include: ['node_modules/**'],
60+
namedExports: {
61+
'node_modules/react/react.js': [
62+
'Children',
63+
'Component',
64+
'PropTypes',
65+
'createElement'
66+
],
67+
'node_modules/react-dom/index.js': ['render']
68+
}
69+
})
70+
]
71+
}
72+
});

src/ModuleGrid/index.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// -----------------------------------------------------------------------------
2+
// Deps
3+
// -----------------------------------------------------------------------------
4+
5+
import * as React from 'react';
6+
7+
// -----------------------------------------------------------------------------
8+
// Types
9+
// -----------------------------------------------------------------------------
10+
11+
export type ModuleGridCol = 'auto' | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
12+
13+
export interface ModuleGridProps {
14+
cols?: ModuleGridCol;
15+
xxsCols?: ModuleGridCol;
16+
xsCols?: ModuleGridCol;
17+
smCols?: ModuleGridCol;
18+
mdCols?: ModuleGridCol;
19+
dfCols?: ModuleGridCol;
20+
lgCols?: ModuleGridCol;
21+
xlCols?: ModuleGridCol;
22+
xxlCols?: ModuleGridCol;
23+
hdCols?: ModuleGridCol;
24+
}
25+
26+
// -----------------------------------------------------------------------------
27+
// ModuleGrid Component
28+
// -----------------------------------------------------------------------------
29+
30+
const colClassName = (col?: ModuleGridCol, mq: string = ''): string | boolean => {
31+
return typeof col === 'number' || col === 'auto'
32+
? `_${mq}module-grid--${col}`
33+
: false;
34+
};
35+
36+
export const ModuleGrid: React.FC<ModuleGridProps> = ({
37+
cols,
38+
xxsCols,
39+
xsCols,
40+
children
41+
}) => {
42+
const classes = [
43+
'_module-grid',
44+
colClassName(cols),
45+
colClassName(xxsCols, 'xxs:'),
46+
colClassName(xsCols, 'xs:')
47+
];
48+
49+
return <div className={classes.filter(Boolean).join(' ')}>{children}</div>;
50+
};
51+
52+
// -----------------------------------------------------------------------------
53+
// ModuleCell Component
54+
// -----------------------------------------------------------------------------
55+
56+
export type ModuleCellSpan = 'auto' | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
57+
58+
export type ModuleCellProps = {
59+
span?: ModuleCellSpan;
60+
xxsSpan?: ModuleCellSpan;
61+
xsSpan?: ModuleCellSpan;
62+
smSpan?: ModuleCellSpan;
63+
mdSpan?: ModuleCellSpan;
64+
dfSpan?: ModuleCellSpan;
65+
lgSpan?: ModuleCellSpan;
66+
xlSpan?: ModuleCellSpan;
67+
xxlSpan?: ModuleCellSpan;
68+
hdSpan?: ModuleCellSpan;
69+
};
70+
71+
const spanClassName = (span?: ModuleCellSpan, mq: string = ''): string | boolean => {
72+
return typeof span === 'number' || span === 'auto'
73+
? `_${mq}module-cell--${span}`
74+
: false;
75+
};
76+
77+
export const ModuleCell: React.FC<ModuleCellProps> = ({ span, children }) => {
78+
const classes = ['_module-cell', spanClassName(span)];
79+
return <div className={classes.join(' ')}>{children}</div>;
80+
};

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"outDir": "build",
3+
"outDir": "components",
44
"module": "esnext",
55
"target": "es5",
66
"lib": ["es6", "dom", "es2016", "es2017"],

0 commit comments

Comments
 (0)