From 5b7eb496ab580d0c357780e3cbe1ff4ecc627139 Mon Sep 17 00:00:00 2001 From: Mudit Choudhary Date: Mon, 9 Oct 2023 21:35:33 +0530 Subject: [PATCH 1/6] Create a KTextTruncator component --- lib/KTextTruncator.vue | 138 +++++++++++++++++++++++++++++++++++++++++ lib/KThemePlugin.js | 2 + 2 files changed, 140 insertions(+) create mode 100644 lib/KTextTruncator.vue diff --git a/lib/KTextTruncator.vue b/lib/KTextTruncator.vue new file mode 100644 index 000000000..9ae4b2737 --- /dev/null +++ b/lib/KTextTruncator.vue @@ -0,0 +1,138 @@ + + + + diff --git a/lib/KThemePlugin.js b/lib/KThemePlugin.js index 9434f09a0..cf23b14a5 100644 --- a/lib/KThemePlugin.js +++ b/lib/KThemePlugin.js @@ -31,6 +31,7 @@ import KTabsPanel from './tabs/KTabsPanel'; import KTextbox from './KTextbox'; import KTooltip from './KTooltip'; import KTransition from './KTransition'; +import KTextTruncator from "./KTextTruncator" import { themeTokens, themeBrand, themePalette, themeOutlineStyle } from './styles/theme'; import globalThemeState from './styles/globalThemeState'; @@ -121,4 +122,5 @@ export default function KThemePlugin(Vue) { Vue.component('KTextbox', KTextbox); Vue.component('KTooltip', KTooltip); Vue.component('KTransition', KTransition); + Vue.component('KTextTruncator', KTextTruncator); } From 905e9aee971f64a66dac6a2155f55e895f3939b4 Mon Sep 17 00:00:00 2001 From: Mudit Choudhary Date: Tue, 10 Oct 2023 21:31:36 +0530 Subject: [PATCH 2/6] Made draft docs for the KTextTruncator.vue --- docs/pages/ktexttruncator.vue | 20 ++++++++++++++++++++ docs/tableOfContents.js | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 docs/pages/ktexttruncator.vue diff --git a/docs/pages/ktexttruncator.vue b/docs/pages/ktexttruncator.vue new file mode 100644 index 000000000..e0d12b807 --- /dev/null +++ b/docs/pages/ktexttruncator.vue @@ -0,0 +1,20 @@ + +import KTextTruncator from '../../lib/KTextTruncator.vue'; + diff --git a/docs/tableOfContents.js b/docs/tableOfContents.js index 34e90b851..cb96b09ba 100644 --- a/docs/tableOfContents.js +++ b/docs/tableOfContents.js @@ -387,6 +387,11 @@ export default [ isCode: true, keywords: ['transition'], }), + new Page({ + path: '/ktexttruncator', + title: 'KTextTruncator', + isCode: true, + }), ], }), ]; From 04c5423b3e151c4b517b039fe8a26249c3e5dc60 Mon Sep 17 00:00:00 2001 From: Mudit Choudhary Date: Tue, 17 Oct 2023 21:13:11 +0530 Subject: [PATCH 3/6] Fix linting issue, add documentation string for props and add a constant variable to check CSR --- lib/KTextTruncator.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/KTextTruncator.vue b/lib/KTextTruncator.vue index 9ae4b2737..4657dc0eb 100644 --- a/lib/KTextTruncator.vue +++ b/lib/KTextTruncator.vue @@ -41,10 +41,16 @@ name: 'KTextTruncator', inheritAttrs: false, props: { + /** + * Text to be truncated + */ text: { type: String, required: true, }, + /** + * Maximum number of lines to be shown + */ maxLines: { type: Number, required: false, @@ -62,6 +68,8 @@ }, computed: { truncate() { + const nuxtClientSideRendering = process.client; + /* (A) For one line, use standard ellipsis text overflow @@ -76,7 +84,12 @@ } // 54 is random number only to be able to define `supports` test condition - if (process.client && 'CSS' in window && CSS.supports && CSS.supports('-webkit-line-clamp: 54')) { + if ( + nuxtClientSideRendering && + 'CSS' in window && + CSS.supports && + CSS.supports('-webkit-line-clamp: 54') + ) { /* (B) For multiple lines, use line clamp in browsers that support it From f0d5ec2952b24d38531789bd5f3c205136b78254 Mon Sep 17 00:00:00 2001 From: Mudit Choudhary Date: Tue, 17 Oct 2023 21:14:36 +0530 Subject: [PATCH 4/6] Fix linting issues and removed unneccessary import statement --- docs/pages/ktexttruncator.vue | 2 -- lib/KThemePlugin.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/pages/ktexttruncator.vue b/docs/pages/ktexttruncator.vue index e0d12b807..82751e2ca 100644 --- a/docs/pages/ktexttruncator.vue +++ b/docs/pages/ktexttruncator.vue @@ -1,5 +1,3 @@ - -import KTextTruncator from '../../lib/KTextTruncator.vue';