import ConfigProvider from '../config-provider';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import cls from 'classnames';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { Button, Dialog, Icon } from '../index';
import { CommonThemeProps } from '../types';
import { CardProps as NextCardProps, UploadProps as NextUploadProps } from '@alifd/next/types/upload';
import { Upload as NextUpload } from '@alifd/next';
import { getTheme } from '../utils/getTheme';
interface UploadProps extends NextUploadProps, CommonThemeProps {
size?: 'small' | 'medium' | 'large';
}
interface DraggerProps extends UploadProps { }
interface CardProps extends NextCardProps, CommonThemeProps { }
interface IUploadState {
value?: any;
progress?: boolean;
}
// CardUpload
// 图片预览功能,只有图片列表在全部完成上传状态时才有
const showImg = url => {
Dialog.show({
title: 'img preview',
content:
,
footer: false,
});
};
class CardUpload extends Component {
static contextTypes = {
theme: PropTypes.string,
};
render() {
const { prefix = 'next-', className } = this.props;
const theme = getTheme(this.context, this.props);
// card预览功能
const itemRender = (file, obj) => {
const remove = obj && obj.remove || (() => { console.log('暂无删除回调。'); });
if (file.state === 'done') {
return
;
} else if (file.state === 'error') {
return
;
}
};
return (
);
}
}
// DraggerUpload
class DraggerUpload extends Component {
constructor(props) {
super(props);
this.state = {
progress: false,
};
}
handleProgress = () => {
this.setState({
progress: true,
});
};
handleChange = () => {
this.setState({
progress: false,
});
};
static contextTypes = {
theme: PropTypes.string,
};
render() {
const { prefix = 'next-', listType = 'text', className, children, onProgress, size } = this.props;
const theme = getTheme(this.context, this.props);
return (
{children}
);
}
}
// Upload
class Upload extends Component {
static contextTypes: any;
static Card: any;
static Dragger: any;
static Uploader: typeof NextUpload.Uploader;
static Selecter: typeof NextUpload.Selecter;
constructor(props) {
super(props);
this.state = {
progress: false,
value: props.value || props.defaultValue,
};
}
handleProgress = () => {
this.setState({
progress: true,
});
};
handleChange = (...args) => {
this.setState({
value: args[0],
progress: false,
});
const { onChange } = this.props;
onChange && onChange.apply(null, [ ...args ]);
};
// 图片预览功能,只有图片列表在全部完成上传状态时才有
showImg = url => {
Dialog.show({
title: 'img preview',
content:
,
footer: false,
});
};
actionRender = file => {
return (
);
};
render() {
const theme = getTheme(this.context, this.props);
const { prefix = 'next-', className, onProgress, size = 'small', listType, actionRender } = this.props;
return ();
}
}
hoistNonReactStatics(Upload, NextUpload);
Upload.contextTypes = {
theme: PropTypes.string,
};
Upload.Card = ConfigProvider.config(CardUpload);
Upload.Dragger = ConfigProvider.config(DraggerUpload);
export default ConfigProvider.config(Upload);