|
1 | 1 | import { ISSUER_FEATURE_BLOCK_TYPE, METADATA_FEATURE_BLOCK_TYPE, SENDER_FEATURE_BLOCK_TYPE, TAG_FEATURE_BLOCK_TYPE } from "@iota/iota.js"; |
| 2 | +import classNames from "classnames"; |
2 | 3 | import React, { Component, ReactNode } from "react"; |
3 | 4 | import { NameHelper } from "../../../utils/nameHelper"; |
| 5 | +import { ReactComponent as DropdownIcon } from "./../../../assets/dropdown-arrow.svg"; |
4 | 6 | import Address from "./Address"; |
5 | 7 | import { FeatureBlockProps } from "./FeatureBlockProps"; |
| 8 | +import { FeatureBlockState } from "./FeatureBlockState"; |
6 | 9 |
|
7 | 10 | /** |
8 | 11 | * Component which will display an Feature Block. |
9 | 12 | */ |
10 | | -class FeatureBlock extends Component<FeatureBlockProps> { |
| 13 | +class FeatureBlock extends Component<FeatureBlockProps, FeatureBlockState> { |
| 14 | + /** |
| 15 | + * Create a new instance of Feature Block. |
| 16 | + * @param props The props. |
| 17 | + */ |
| 18 | + constructor(props: FeatureBlockProps) { |
| 19 | + super(props); |
| 20 | + |
| 21 | + this.state = { |
| 22 | + showDetails: false |
| 23 | + }; |
| 24 | + } |
| 25 | + |
11 | 26 | /** |
12 | 27 | * Render the component. |
13 | 28 | * @returns The node to render. |
14 | 29 | */ |
15 | 30 | public render(): ReactNode { |
16 | 31 | return ( |
17 | 32 | <div className="feature-block padding-t-s"> |
18 | | - <h3>{NameHelper.getFeatureBlockTypeName(this.props.featureBlock.type)}</h3> |
| 33 | + <div |
| 34 | + className="card--content__input" |
| 35 | + onClick={() => this.setState({ showDetails: !this.state.showDetails })} |
| 36 | + > |
19 | 37 |
|
20 | | - {this.props.featureBlock.type === SENDER_FEATURE_BLOCK_TYPE && ( |
21 | | - <React.Fragment> |
22 | | - <div className="card--label"> |
23 | | - Address |
24 | | - </div> |
25 | | - <Address |
26 | | - address={this.props.featureBlock.address} |
27 | | - /> |
28 | | - </React.Fragment> |
29 | | - )} |
30 | | - {this.props.featureBlock.type === ISSUER_FEATURE_BLOCK_TYPE && ( |
31 | | - <React.Fragment> |
32 | | - <div className="card--label"> |
33 | | - Address |
34 | | - </div> |
35 | | - <Address |
36 | | - address={this.props.featureBlock.address} |
37 | | - /> |
38 | | - </React.Fragment> |
39 | | - )} |
40 | | - {this.props.featureBlock.type === METADATA_FEATURE_BLOCK_TYPE && ( |
41 | | - <React.Fragment> |
42 | | - <div className="card--label"> |
43 | | - Data: |
44 | | - </div> |
45 | | - <div className="card--value row"> |
46 | | - {this.props.featureBlock.data} |
47 | | - </div> |
48 | | - </React.Fragment> |
49 | | - )} |
50 | | - {this.props.featureBlock.type === TAG_FEATURE_BLOCK_TYPE && ( |
51 | | - <React.Fragment> |
52 | | - <div className="card--label"> |
53 | | - Tag: |
54 | | - </div> |
55 | | - <div className="card--value row"> |
56 | | - {this.props.featureBlock.tag} |
57 | | - </div> |
58 | | - </React.Fragment> |
| 38 | + <div className={classNames( |
| 39 | + "margin-r-t", |
| 40 | + "card--content__input--dropdown", |
| 41 | + { "opened": this.state.showDetails } |
| 42 | + )} |
| 43 | + > |
| 44 | + <DropdownIcon /> |
| 45 | + </div> |
| 46 | + <h3 className="card--content__input--label"> |
| 47 | + {NameHelper.getFeatureBlockTypeName(this.props.featureBlock.type)} |
| 48 | + </h3> |
| 49 | + </div> |
| 50 | + |
| 51 | + {this.state.showDetails && ( |
| 52 | + <div className="card--content--border-l"> |
| 53 | + {(this.props.featureBlock.type === SENDER_FEATURE_BLOCK_TYPE || |
| 54 | + this.props.featureBlock.type === ISSUER_FEATURE_BLOCK_TYPE) && ( |
| 55 | + <Address |
| 56 | + address={this.props.featureBlock.address} |
| 57 | + /> |
| 58 | + )} |
| 59 | + {this.props.featureBlock.type === METADATA_FEATURE_BLOCK_TYPE && ( |
| 60 | + <React.Fragment> |
| 61 | + <div className="card--label"> |
| 62 | + Data: |
| 63 | + </div> |
| 64 | + <div className="card--value row"> |
| 65 | + {this.props.featureBlock.data} |
| 66 | + </div> |
| 67 | + </React.Fragment> |
| 68 | + )} |
| 69 | + {this.props.featureBlock.type === TAG_FEATURE_BLOCK_TYPE && ( |
| 70 | + <React.Fragment> |
| 71 | + <div className="card--label"> |
| 72 | + Tag: |
| 73 | + </div> |
| 74 | + <div className="card--value row"> |
| 75 | + {this.props.featureBlock.tag} |
| 76 | + </div> |
| 77 | + </React.Fragment> |
| 78 | + )} |
| 79 | + </div> |
59 | 80 | )} |
| 81 | + |
60 | 82 | </div> |
61 | 83 | ); |
62 | 84 | } |
|
0 commit comments