Files
skyline-console/src/components/FormItem/Label/index.jsx
Jingwei.Zhang 2b68f2a3d7 fix: Update component && validate
1. Add 'ready' status to State component
2. Add price render in table
3. Support children column in table
4. Fix image/instance name validate
5. Support loading in Label component
6. Fix MagicInput component style
7. Fix role check in layout
8. Update class export
9. Remove useless component

Change-Id: I0e5d7e4a23fb0a68e17ae57eba83608be3a3df0e
2021-09-08 15:49:11 +08:00

103 lines
2.6 KiB
JavaScript

// Copyright 2021 99cloud
//
// 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, { Component } from 'react';
import PropTypes from 'prop-types';
import imageSvg from 'src/asset/image/image.svg';
import {
DesktopOutlined,
BorderOuterOutlined,
SecurityScanOutlined,
InboxOutlined,
GlobalOutlined,
GatewayOutlined,
UserOutlined,
CameraOutlined,
SaveOutlined,
KeyOutlined,
ClusterOutlined,
TagOutlined,
HddOutlined,
CloudServerOutlined,
LoadingOutlined,
} from '@ant-design/icons';
import styles from './index.less';
const ImageIcon = (
<img src={imageSvg} alt="image_icon" style={{ width: '12px' }} />
);
const iconTypeMap = {
instance: <DesktopOutlined />,
router: <BorderOuterOutlined />,
externalNetwork: <GlobalOutlined />,
network: <GlobalOutlined />,
firewall: <SecurityScanOutlined />,
volume: <InboxOutlined />,
gateway: <GatewayOutlined />,
user: <UserOutlined />,
snapshot: <CameraOutlined />,
backup: <SaveOutlined />,
keypair: <KeyOutlined />,
image: ImageIcon,
aggregate: <ClusterOutlined />,
metadata: <TagOutlined />,
flavor: <HddOutlined />,
host: <CloudServerOutlined />,
};
export default class index extends Component {
static propTypes = {
content: PropTypes.any,
value: PropTypes.any,
icon: PropTypes.node,
iconType: PropTypes.string,
};
static defaultProps = {
icon: null,
iconType: '',
content: '',
value: null,
};
renderIcon() {
const { icon, iconType } = this.props;
if (iconType) {
const iconComp = iconTypeMap[iconType] || null;
return <span className={styles.icon}>{iconComp}</span>;
}
return <span className={styles.icon}>{icon || null}</span>;
}
render() {
const { content, value, iconType, showLoading, ...rest } = this.props;
const failValues = [undefined, null, ''];
if (content) {
return content;
}
return (
<span {...rest}>
{this.renderIcon()}
{showLoading && failValues.includes(value) ? (
<LoadingOutlined />
) : (
value
)}
</span>
);
}
}