From 92ab4b1ac6f4b8d8558f9ce6e9cb6df8901c0e33 Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Mon, 15 Feb 2021 01:29:58 +0100 Subject: Add blueprintjs's Text component --- .../main/kotlin/com/palantir/blueprintjs/BpText.kt | 30 ++++++++++++++++++++++ .../com/palantir/blueprintjs/blueprintjsHelpers.kt | 16 ++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpText.kt (limited to 'sw-ui/src/main/kotlin') diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpText.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpText.kt new file mode 100644 index 00000000..6bf4323e --- /dev/null +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/BpText.kt @@ -0,0 +1,30 @@ +@file:JsModule("@blueprintjs/core") + +package com.palantir.blueprintjs + +import react.PureComponent +import react.RState +import react.ReactElement + +external interface ITextProps : IProps { + /** + * Indicates that this component should be truncated with an ellipsis if it overflows its container. + * The `title` attribute will also be added when content overflows to show the full text of the children on hover. + * @default false + */ + var ellipsize: Boolean? + /** + * HTML tag name to use for rendered element. + * @default "div" + */ + var tagName: String? +} + +external interface ITextState : RState { + var textContent: String + var isContentOverflowing: Boolean +} + +external class Text : PureComponent { + override fun render(): ReactElement +} diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt index 326f2fc4..5d3c481e 100644 --- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt +++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt @@ -106,6 +106,22 @@ fun RBuilder.bpTag( block() } +fun RBuilder.bpText( + ellipsize: Boolean? = null, + tagName: String? = null, + block: RHandler = {}, +): ReactElement = child(Text::class) { + attrs { + if (ellipsize != null) { + this.ellipsize = ellipsize + } + if (tagName != null) { + this.tagName = tagName + } + } + block() +} + fun RBuilder.bpNonIdealState( icon: IconName? = null, title: ReactElement? = null, -- cgit