-
-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use common component for ip address display (#4042)
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Component, { ComponentAttrs } from '../Component'; | ||
import type Mithril from 'mithril'; | ||
import ItemList from '../utils/ItemList'; | ||
|
||
export interface IIPAddressAttrs extends ComponentAttrs { | ||
ip: string | undefined | null; | ||
} | ||
|
||
/** | ||
* A component to wrap an IP address for display. | ||
* Designed to be customizable for different use cases. | ||
* | ||
* @example | ||
* <IPAddress ip="127.0.0.1" /> | ||
* @example | ||
* <IPAddress ip={post.data.attributes.ipAddress} /> | ||
*/ | ||
export default class IPAddress<CustomAttrs extends IIPAddressAttrs = IIPAddressAttrs> extends Component<CustomAttrs> { | ||
ip!: string; | ||
|
||
oninit(vnode: Mithril.Vnode<CustomAttrs, this>) { | ||
super.oninit(vnode); | ||
|
||
this.ip = this.attrs.ip || ''; | ||
} | ||
|
||
view() { | ||
return <span className="IPAddress">{this.viewItems().toArray()}</span>; | ||
} | ||
|
||
viewItems(): ItemList<Mithril.Children> { | ||
const items = new ItemList<Mithril.Children>(); | ||
|
||
items.add('ip', <span>{this.ip}</span>, 100); | ||
|
||
return items; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters