Skip to content

Commit 0db732d

Browse files
committed
refactor(settings-preview): better handle multi-line string
1 parent 6fada6f commit 0db732d

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

Diff for: lib/components/form/form.css

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@
126126
font-size: 14px;
127127
line-height: 1.4;
128128
margin-top: -1px;
129+
white-space: pre-wrap;
130+
}
131+
132+
.otp .settings-preview .summary.tall {
133+
line-height: 2.6;
129134
}
130135

131136
.otp:not(.mobile) .settings-preview .summary {

Diff for: lib/components/form/settings-preview.js

+6-18
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class SettingsPreview extends Component {
2525
static defaultProps = {
2626
editButtonText: <i className='fa fa-pencil' />,
2727
messages: {
28-
// Label accepted as two-element array or single (not array) string literal.
29-
label: ['Transit Options', '& Preferences']
28+
label: 'Transit Options\n& Preferences'
3029
}
3130
}
3231

@@ -43,24 +42,13 @@ class SettingsPreview extends Component {
4342
{showDot && <div className='dot' />}
4443
</div>
4544
)
46-
45+
// Add tall class to account for vertical centering if there is only
46+
// one line in the label (default is 2).
47+
const addClass = messages.label.match(/\n/) ? '' : ' tall'
4748
return (
4849
<div className='settings-preview' onClick={this.props.onClick}>
49-
<div className='summary'>
50-
{// If settings preview is multiple lines, split
51-
Array.isArray(messages.label)
52-
? <span>
53-
{messages.label[0]}
54-
<br />
55-
{messages.label[1]}
56-
</span>
57-
: <span
58-
// Increase line height if number of lines is 1 for vertical
59-
// centering.
60-
style={{lineHeight: 2.6}}>
61-
{messages.label}
62-
</span>
63-
}
50+
<div className={`summary${addClass}`}>
51+
{messages.label}
6452
</div>
6553
{button}
6654
<div style={{ clear: 'both' }} />

0 commit comments

Comments
 (0)