vendor: amis 6.13.0 base (fork root)
This commit is contained in:
222
packages/amis-ui/examples/App.tsx
Normal file
222
packages/amis-ui/examples/App.tsx
Normal file
@@ -0,0 +1,222 @@
|
||||
import React from 'react';
|
||||
import {Layout, AsideNav, Spinner, NotFound} from 'amis-ui';
|
||||
import {eachTree, TreeArray, TreeItem} from 'amis-core';
|
||||
import {
|
||||
HashRouter as Router,
|
||||
Route,
|
||||
Redirect,
|
||||
Switch,
|
||||
Link,
|
||||
NavLink
|
||||
} from 'react-router-dom';
|
||||
|
||||
const pages: TreeArray = [
|
||||
{
|
||||
label: '常规',
|
||||
children: [
|
||||
{
|
||||
label: '按钮',
|
||||
path: '/basic/button',
|
||||
component: React.lazy(() => import('./basic/Button'))
|
||||
},
|
||||
{
|
||||
label: '文字提示',
|
||||
path: '/basic/overflow-tpl',
|
||||
component: React.lazy(() => import('./basic/OverflowTpl'))
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
label: '表单',
|
||||
children: [
|
||||
{
|
||||
label: '受控表单',
|
||||
path: '/form/controlled-form',
|
||||
component: React.lazy(() => import('./form/ControlledForm'))
|
||||
},
|
||||
{
|
||||
label: 'InputTable',
|
||||
path: '/form/input-table',
|
||||
component: React.lazy(() => import('./form/InputTable'))
|
||||
},
|
||||
|
||||
{
|
||||
label: 'Combo',
|
||||
path: '/form/combo',
|
||||
component: React.lazy(() => import('./form/Combo'))
|
||||
},
|
||||
|
||||
{
|
||||
label: 'MixedInput',
|
||||
path: '/form/mixed-input',
|
||||
component: React.lazy(() => import('./form/MixedInput'))
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
label: '弹框',
|
||||
children: [
|
||||
{
|
||||
label: 'PickContainer',
|
||||
path: '/modal/pick-conatiner',
|
||||
component: React.lazy(() => import('./modal/PickerContainer'))
|
||||
},
|
||||
|
||||
{
|
||||
label: 'ConfirmBox',
|
||||
path: '/modal/confirm-box',
|
||||
component: React.lazy(() => import('./modal/ConfirmBox'))
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
function getPath(path: string) {
|
||||
return path ? (path[0] === '/' ? path : `/${path}`) : '';
|
||||
}
|
||||
|
||||
function isActive(link: any, location: any) {
|
||||
return !!(link.path && getPath(link.path) === location.pathname);
|
||||
}
|
||||
|
||||
export function navigations2route(
|
||||
navigations: any,
|
||||
additionalProperties?: any
|
||||
) {
|
||||
let routes: any = [];
|
||||
|
||||
navigations.forEach((root: any) => {
|
||||
root.children &&
|
||||
eachTree(root.children, (item: any) => {
|
||||
if (item.path && item.component) {
|
||||
routes.push(
|
||||
additionalProperties ? (
|
||||
<Route
|
||||
key={routes.length + 1}
|
||||
path={item.path[0] === '/' ? item.path : `/${item.path}`}
|
||||
render={(props: any) => (
|
||||
<item.component {...additionalProperties} {...props} />
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<Route
|
||||
key={routes.length + 1}
|
||||
path={item.path[0] === '/' ? item.path : `/${item.path}`}
|
||||
component={item.component}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
function renderAside() {
|
||||
return (
|
||||
<AsideNav
|
||||
navigations={pages.map((item: any) => ({
|
||||
...item,
|
||||
children: item.children
|
||||
? item.children.map((item: any) => ({
|
||||
...item,
|
||||
className: 'is-top'
|
||||
}))
|
||||
: []
|
||||
}))}
|
||||
renderLink={({
|
||||
link,
|
||||
active,
|
||||
toggleExpand,
|
||||
classnames: cx,
|
||||
depth
|
||||
}: any) => {
|
||||
let children = [];
|
||||
|
||||
if (link.children && link.children.length) {
|
||||
children.push(
|
||||
<span
|
||||
key="expand-toggle"
|
||||
className={cx('AsideNav-itemArrow')}
|
||||
onClick={e => toggleExpand(link, e)}
|
||||
></span>
|
||||
);
|
||||
}
|
||||
|
||||
link.badge &&
|
||||
children.push(
|
||||
<b
|
||||
key="badge"
|
||||
className={cx(
|
||||
`AsideNav-itemBadge`,
|
||||
link.badgeClassName || 'bg-info'
|
||||
)}
|
||||
>
|
||||
{link.badge}
|
||||
</b>
|
||||
);
|
||||
|
||||
if (link.icon) {
|
||||
children.push(
|
||||
<i key="icon" className={cx(`AsideNav-itemIcon`, link.icon)} />
|
||||
);
|
||||
}
|
||||
|
||||
children.push(
|
||||
<span className={cx('AsideNav-itemLabel')} key="label">
|
||||
{link.label}
|
||||
</span>
|
||||
);
|
||||
|
||||
return link.path ? (
|
||||
/^https?\:/.test(link.path) ? (
|
||||
<a target="_blank" href={link.path} rel="noopener">
|
||||
{children}
|
||||
</a>
|
||||
) : (
|
||||
<Link
|
||||
to={
|
||||
getPath(link.path) ||
|
||||
(link.children && getPath(link.children[0].path))
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</Link>
|
||||
)
|
||||
) : (
|
||||
<a onClick={link.children ? () => toggleExpand(link) : undefined}>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
}}
|
||||
isActive={(link: any) => isActive(link, location)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Router>
|
||||
<Layout
|
||||
header={
|
||||
<div id="headerBar" className="box-shadow bg-dark">
|
||||
<div className={`cxd-Layout-brand`}>amis-ui 示例</div>
|
||||
</div>
|
||||
}
|
||||
aside={renderAside()}
|
||||
>
|
||||
<React.Suspense
|
||||
fallback={<Spinner overlay spinnerClassName="m-t-lg" size="lg" />}
|
||||
>
|
||||
<Switch>
|
||||
{navigations2route(pages)}
|
||||
<Route render={() => <NotFound description="Not found" />} />
|
||||
</Switch>
|
||||
</React.Suspense>
|
||||
</Layout>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
11
packages/amis-ui/examples/basic/Button.tsx
Normal file
11
packages/amis-ui/examples/basic/Button.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import {Button} from 'amis-ui';
|
||||
|
||||
export default function ButtonExamples() {
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<p>示例: </p>
|
||||
<Button>Button</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
29
packages/amis-ui/examples/basic/OverflowTpl.tsx
Normal file
29
packages/amis-ui/examples/basic/OverflowTpl.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import {OverflowTpl} from 'amis-ui';
|
||||
|
||||
export default function ButtonExamples() {
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<div className="flex justify-items-start items-center">
|
||||
{[
|
||||
{text: 'Transforming business'},
|
||||
{
|
||||
text: "Innovating, creating, succeeding. Let's make a difference together."
|
||||
},
|
||||
{text: 'Bringing technology to the forefront'},
|
||||
{text: 'Driving change in the industry'},
|
||||
{text: 'Enriching the journey with'}
|
||||
].map((item, index) => (
|
||||
<div
|
||||
className="text-xs inline-flex items-center font-bold leading-sm uppercase px-3 py-1 bg-blue-200 text-blue-700 rounded-full"
|
||||
style={{maxWidth: '190px'}}
|
||||
>
|
||||
<OverflowTpl key={index} tooltip={item.text}>
|
||||
{item.text}
|
||||
</OverflowTpl>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
59
packages/amis-ui/examples/form/Combo.tsx
Normal file
59
packages/amis-ui/examples/form/Combo.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
import React from 'react';
|
||||
import {Button, Combo, Form, Controller, InputBox} from 'amis-ui';
|
||||
|
||||
export default function ButtonExamples() {
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
console.log('submit', data);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form defaultValue={{items: [{a: 1, b: 2}]}} onSubmit={handleSubmit}>
|
||||
{({control, onSubmit}) => {
|
||||
return (
|
||||
<>
|
||||
<Combo
|
||||
name="items"
|
||||
control={control}
|
||||
minLength={2}
|
||||
maxLength={5}
|
||||
itemRender={({control}) => (
|
||||
<>
|
||||
<Controller
|
||||
name="key"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Key"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="title"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Title"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
63
packages/amis-ui/examples/form/ControlledForm.tsx
Normal file
63
packages/amis-ui/examples/form/ControlledForm.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import React from 'react';
|
||||
import {Button, Combo, Form, Controller, InputBox} from 'amis-ui';
|
||||
|
||||
export default function ControlledFormExamples() {
|
||||
const [formValues, setFormValues] = React.useState<{
|
||||
a: any;
|
||||
b: any;
|
||||
}>({a: 1, b: 2});
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
console.log('submit', data);
|
||||
}, []);
|
||||
const handleChange = React.useCallback((values: any) => {
|
||||
setFormValues(values);
|
||||
}, []);
|
||||
const handleRandomChange = React.useCallback(() => {
|
||||
setFormValues({
|
||||
a: Math.random(),
|
||||
b: Math.random()
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form value={formValues} onSubmit={handleSubmit} onChange={handleChange}>
|
||||
{({control, onSubmit}) => {
|
||||
return (
|
||||
<>
|
||||
<Controller
|
||||
name="a"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Key"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="b"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Title"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Button onClick={handleRandomChange}>修改</Button>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
50
packages/amis-ui/examples/form/InputTable.tsx
Normal file
50
packages/amis-ui/examples/form/InputTable.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import {Button, InputTable, Form, Controller, InputBox} from 'amis-ui';
|
||||
|
||||
export default function ButtonExamples() {
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
console.log('submit', data);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form defaultValue={{items: [{a: 1, b: 2}]}} onSubmit={handleSubmit}>
|
||||
{({control, onSubmit}) => {
|
||||
return (
|
||||
<>
|
||||
<InputTable
|
||||
name="items"
|
||||
control={control}
|
||||
minLength={2}
|
||||
maxLength={5}
|
||||
columns={[
|
||||
{
|
||||
title: 'Name',
|
||||
tdRender: ({control}) => {
|
||||
return (
|
||||
<Controller
|
||||
name="key"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Key"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
]}
|
||||
/>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
71
packages/amis-ui/examples/form/MixedInput.tsx
Normal file
71
packages/amis-ui/examples/form/MixedInput.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import React from 'react';
|
||||
import {Button, InputTable, Form, Controller, MixedInput} from 'amis-ui';
|
||||
|
||||
export default function MixedInputExamples() {
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
alert(JSON.stringify(data, null, 2));
|
||||
}, []);
|
||||
|
||||
const methods = React.useMemo(
|
||||
() => [
|
||||
{
|
||||
label: '%',
|
||||
pipeIn: (value: any) => {
|
||||
return value ? value.replace('%', '') : '';
|
||||
},
|
||||
pipeOut: (value: any) => {
|
||||
return value ? `${value}%` : '';
|
||||
},
|
||||
test: (value: any) => {
|
||||
return typeof value === 'string' && value.endsWith('%');
|
||||
},
|
||||
value: 'percent'
|
||||
},
|
||||
{
|
||||
label: 'px',
|
||||
type: 'number',
|
||||
inputSettings: {
|
||||
precision: 2
|
||||
},
|
||||
pipeIn: (value: any) => {
|
||||
return value ? parseFloat(value.replace('px', '')) || 0 : '';
|
||||
},
|
||||
pipeOut: (value: any) => {
|
||||
return value ? `${value}px` : '';
|
||||
},
|
||||
test: (value: any) => {
|
||||
return typeof value === 'string' && value.endsWith('px');
|
||||
},
|
||||
value: 'pixel'
|
||||
}
|
||||
],
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form defaultValue={{}} onSubmit={handleSubmit}>
|
||||
{({control, onSubmit, getValues}) => {
|
||||
return (
|
||||
<>
|
||||
<Controller
|
||||
name="a"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<MixedInput
|
||||
{...field}
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
methods={methods}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
80
packages/amis-ui/examples/modal/ConfirmBox.tsx
Normal file
80
packages/amis-ui/examples/modal/ConfirmBox.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import React from 'react';
|
||||
import {Button, ConfirmBox, Controller, Form, InputBox} from 'amis-ui';
|
||||
|
||||
export default function ButtonExamples() {
|
||||
const [isShow, setIsShow] = React.useState(false);
|
||||
const handleClick = React.useCallback(() => {
|
||||
setIsShow(!isShow);
|
||||
}, [isShow]);
|
||||
const handleCancel = React.useCallback(() => {
|
||||
setIsShow(false);
|
||||
}, []);
|
||||
// const beforeConfirm = React.useCallback(async () => {
|
||||
// return false;
|
||||
// }, []);
|
||||
const handleConfirm = React.useCallback((data: any) => {
|
||||
console.log('confirmed', data);
|
||||
setIsShow(false);
|
||||
}, []);
|
||||
|
||||
async function handleValidate() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
// setTimeout(() => reject('error message'), 200);
|
||||
setTimeout(() => resolve(), 200);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Button onClick={handleClick}>Open</Button>
|
||||
<ConfirmBox
|
||||
type="drawer"
|
||||
size="md"
|
||||
position="bottom"
|
||||
onConfirm={handleConfirm}
|
||||
show={isShow}
|
||||
onCancel={handleCancel}
|
||||
>
|
||||
{({bodyRef}) => (
|
||||
<Form ref={bodyRef} onValidate={handleValidate}>
|
||||
{({control}) => (
|
||||
<>
|
||||
<Controller
|
||||
mode="horizontal"
|
||||
label="A"
|
||||
name="a"
|
||||
control={control}
|
||||
rules={{maxLength: 20}}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
mode="horizontal"
|
||||
label="B"
|
||||
name="b"
|
||||
control={control}
|
||||
rules={{maxLength: 20}}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Form>
|
||||
)}
|
||||
</ConfirmBox>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
66
packages/amis-ui/examples/modal/PickerContainer.tsx
Normal file
66
packages/amis-ui/examples/modal/PickerContainer.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import React from 'react';
|
||||
import {PickerContainer, Button, Form, Controller, InputBox} from 'amis-ui';
|
||||
|
||||
export default function () {
|
||||
const body = React.createRef<any>();
|
||||
const beforeConfirm = React.useCallback(() => {
|
||||
return body.current?.submit();
|
||||
}, []);
|
||||
const handleConfirm = React.useCallback((data: any) => {
|
||||
console.log('confirmed', data);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<PickerContainer
|
||||
beforeConfirm={beforeConfirm}
|
||||
onConfirm={handleConfirm}
|
||||
bodyRender={() => (
|
||||
<Form ref={body}>
|
||||
{({control}) => (
|
||||
<>
|
||||
<Controller
|
||||
mode="horizontal"
|
||||
label="A"
|
||||
name="a"
|
||||
control={control}
|
||||
rules={{maxLength: 20}}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
mode="horizontal"
|
||||
label="B"
|
||||
name="b"
|
||||
control={control}
|
||||
rules={{maxLength: 20}}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Form>
|
||||
)}
|
||||
>
|
||||
{({isOpened, onClick}) => (
|
||||
<Button active={isOpened} onClick={onClick}>
|
||||
Open
|
||||
</Button>
|
||||
)}
|
||||
</PickerContainer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user