Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add layout component with flow pkg #241

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-otters-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alita/flow': minor
---

Add expand container component, add fill container component, add shrink container component, three components for page module layout
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ $ pnpm i
$ pnpm build
$ cd examples/boilerplate
$ pnpm dev
```
```
7 changes: 7 additions & 0 deletions examples/flow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.env.local
/.umirc.local.ts
/.umirc.local.js
/config/config.local.ts
/config/config.local.js
/src/.umi
/.umi
7 changes: 7 additions & 0 deletions examples/flow/.umirc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
appType: 'h5',
polyfill: false,
// mainPath:'users',
mfsu: false,
hash: false,
};
Binary file added examples/flow/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions examples/flow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "boilerplate",
"private": true,
"version": "1.0.0",
"scripts": {
"dev": "rm -rf .mfsu && alita dev",
"build": "alita build",
"plugin": "alita plugin list"
},
"dependencies": {
"@alita/flow": "workspace:*",
"alita": "workspace:*"
}
}
3 changes: 3 additions & 0 deletions examples/flow/src/pages/global.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a {
color: green;
}
3 changes: 3 additions & 0 deletions examples/flow/src/pages/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title {
font-size: 30px;
}
59 changes: 59 additions & 0 deletions examples/flow/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { FillContainer, FlexContent, ShrinkingModule } from '@alita/flow';
import React from 'react';
import './global.less';

/**
* 生成一个随机数组 用来模拟图表数据变化
* @param n 数组的长度
* @param max 数组的最大值
* @returns {Array} 一个指定长度的随机数组
*/
const getRandomArr = (n: number, max = 31) => {
let maxNum = max;
//大于数组长度时,取数组长度
if (n > 31) n = 31;
let number = [];
while (n) {
//随机数的选取方法31为所需的数组长度
let num = Math.floor(Math.random() * maxNum) + 2;
//数组查重的方法
if (number.indexOf(num) < 0) {
number.push(num);
n--;
}
}
return number;
};

const RainbowColor = [
'red',
'orange',
'yellow',
'green',
'cyan',
'blue',
'purple',
];

const DemoPage: React.FC = () => {
const renderAtr = getRandomArr(12);
return (
<FillContainer>
<ShrinkingModule backgroundColor="blue">
<div>header</div>
</ShrinkingModule>
<FlexContent>
{renderAtr.map((num, index) => (
<ShrinkingModule key={num} backgroundColor={RainbowColor[index % 7]}>
<div>{RainbowColor[index % 7]}</div>
</ShrinkingModule>
))}
</FlexContent>
<ShrinkingModule backgroundColor="red">
<div>footer</div>
</ShrinkingModule>
</FillContainer>
);
};

export default DemoPage;
30 changes: 30 additions & 0 deletions examples/flow/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "dist",
"sourceMap": true,
"jsx": "react",
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2017",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"allowSyntheticDefaultImports": true,
"rootDirs": ["/src", "/test", "/mock", "./typings"],
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"strict": true,
"paths": {
"@/*": ["./src/*"],
"@@/*": ["./src/.umi/*"]
}
}
}
13 changes: 13 additions & 0 deletions examples/flow/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module '*.css';
declare module '*.less';
declare module '*.scss';
declare module '*.sass';
declare module '*.svg';
declare module '*.png';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.gif';
declare module '*.bmp';
declare module '*.tiff';
declare module '*.json';

55 changes: 55 additions & 0 deletions packages/flow/src/components/FillContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';

interface FillContainerProps {
/**
* @description 自定义样式
* @default ''
*/
classname?: string;
/**
* @description 背景颜色
* @default ''
*/
backgroundColor?: string;
/**
* @description 布局方向
* @default 'column'
*/
flexDirection?: 'column' | 'row';
/**
* @description 内容滚动配置
* @default 'hidden'
*/
overflow?: string;
}

const FillContainer: React.FC<FillContainerProps> = (props) => {
const {
backgroundColor = '',
flexDirection = 'column',
overflow = 'hidden',
children,
classname = '',
} = props;
const childs = React.Children.toArray(children);
return (
<div
className={`${classname}`}
style={{
position: 'absolute',
inset: 0,
display: 'flex',
backgroundColor,
flexDirection,
overflow,
}}
>
{!!childs &&
childs.map((child: any, index: number) => {
return React.cloneElement(child, { ...child.props, key: index });
})}
</div>
);
};

export default FillContainer;
55 changes: 55 additions & 0 deletions packages/flow/src/components/FlexContent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
// import './index.less';

interface FlexContentProps {
/**
* @description 自定义样式
* @default ''
*/
classname?: string;
/**
* @description 背景颜色
* @default ''
*/
backgroundColor?: string;
/**
* @description 布局方向
* @default 'column'
*/
flexDirection?: 'column' | 'row';
/**
* @description 内容滚动配置
* @default 'scroll'
*/
overflow?: string;
}

const FlexContent: React.FC<FlexContentProps> = (props) => {
const {
backgroundColor = '',
flexDirection = 'column',
overflow = 'scroll',
children,
classname = '',
} = props;
const childs = React.Children.toArray(children);
return (
<div
className={`${classname}`}
style={{
display: 'flex',
flex: 1,
backgroundColor,
flexDirection,
overflow,
}}
>
{!!childs &&
childs.map((child: any, index: number) => {
return React.cloneElement(child, { ...child.props, key: index });
})}
</div>
);
};

export default FlexContent;
54 changes: 54 additions & 0 deletions packages/flow/src/components/ShrinkingModule/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';

interface ShrinkingModuleProps {
/**
* @description 自定义样式
* @default ''
*/
classname?: string;
/**
* @description 背景颜色
* @default ''
*/
backgroundColor?: string;
/**
* @description 布局排列方向
* @default 'column'
*/
flexDirection?: 'column' | 'row';
/**
* @description 内容滚动配置
* @default 'hidden'
*/
overflow?: string;
}

const ShrinkingModule: React.FC<ShrinkingModuleProps> = (props) => {
const {
backgroundColor = '',
flexDirection = 'column',
overflow = 'hidden',
children,
classname = '',
} = props;
const childs = React.Children.toArray(children);
return (
<div
className={`${classname}`}
style={{
display: 'flex',
flexShrink: 0,
backgroundColor,
flexDirection,
overflow,
}}
>
{!!childs &&
childs.map((child: any, index: number) => {
return React.cloneElement(child, { ...child.props, key: index });
})}
</div>
);
};

export default ShrinkingModule;
3 changes: 3 additions & 0 deletions packages/flow/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { ErrorBoundary, withErrorBoundary } from './components/ErrorBoundary';
export { default as FillContainer } from './components/FillContainer';
export { default as FlexContent } from './components/FlexContent';
export { default as For } from './components/For';
export { default as Show } from './components/Show';
export { default as ShrinkingModule } from './components/ShrinkingModule';
export { default as Switch, Match } from './components/Switch';
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.