1// Copyright (C) 2023 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import m from 'mithril'; 16import {classNames} from '../base/classnames'; 17 18export interface TextParagraphAttrs { 19 // Paragraph text. 20 text: string; 21 // Whether to compress multiple spaces (e.g. the string is multi-line but 22 // should render with the default UI wrapping) 23 compressSpace?: boolean; 24} 25 26export class TextParagraph implements m.ClassComponent<TextParagraphAttrs> { 27 view({attrs}: m.CVnode<TextParagraphAttrs>) { 28 let {text, compressSpace} = attrs; 29 if (compressSpace === undefined) { 30 compressSpace = true; 31 } 32 return m( 33 `div.pf-text-paragraph`, 34 compressSpace ? text.replace(/\s\s+/g, ' ') : text, 35 ); 36 } 37} 38 39interface MultiParagraphTextAttrs { 40 // Space delimited class list applied to element. 41 className?: string; 42} 43 44export class MultiParagraphText 45 implements m.ClassComponent<MultiParagraphTextAttrs> 46{ 47 view({attrs, children}: m.Vnode<MultiParagraphTextAttrs>): m.Children { 48 const {className = ''} = attrs; 49 50 const classes = classNames(className); 51 52 return m('div', {class: classes}, children); 53 } 54} 55