/* * << * Davinci * == * Copyright (C) 2016 - 2017 EDP * == * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * >> */ import React, { useContext } from 'react' import classnames from 'classnames' import { Input, InputNumber, Radio, Checkbox, Select, Form, Icon, Col } from 'antd' const RadioGroup = Radio.Group const CheckboxGroup = Checkbox.Group const { Option } = Select const FormItem = Form.Item import { GetFieldDecoratorOptions } from 'antd/lib/form/Form' import ColorPicker from 'components/ColorPicker' import Upload from 'components/Upload' import IconFont from 'components/IconFont' import { SettingItem } from './types' import { SlideSettingContext } from './util' import api from 'utils/api' import utilStyles from 'assets/less/util.less' import { ASSETS_HOST } from 'app/globalConstants' interface IItemProps { item: SettingItem } const Item: React.FC = (props) => { const { item } = props const { form, size, slideId, layerId } = useContext(SlideSettingContext) let visible = true const { relatedItems } = item if (Array.isArray(relatedItems)) { relatedItems.some(({ name, values }) => { const relatedValue = form.getFieldValue(name) if (values.findIndex((val) => val === relatedValue) < 0) { visible = false return true } }) } const itemCls = classnames({ [utilStyles.hide]: !visible }) const { getFieldDecorator } = form const options: GetFieldDecoratorOptions = { initialValue: item.default } let control: React.ReactNode switch (item.component) { case 'input': control = break case 'inputnumber': control = ( ) break case 'radio': control = ( {item.values.map(({ value, name }) => ( {name} ))} ) break case 'checkbox': control = options.valuePropName = item.valuePropName break case 'checkboxGroup': control = break case 'select': control = ( ) break case 'colorPicker': let color = form.getFieldValue(item.name) if (color) { color = `rgba(${color.join()})` } control = ( ) break case 'upload': const action = `${api.display}/${item.action}` .replace(/({slideId})/, slideId ? `${slideId}` : '') .replace(/({layerId})/, layerId ? `${layerId}` : '') const img = form.getFieldValue(item.name) control = ( {img ? (
{item.title} { e.stopPropagation() form.setFieldsValue({ [item.name]: null }) }} />
) : ( )}
) break } const { labelCol, wrapperCol, span } = item return ( {getFieldDecorator(item.name, options)(control)} ) } export default Item