Skip to content

Commit 24298c1

Browse files
authored
support inline actions in Kb.Banner and better API (keybase#18294)
* Kb.Banner improvements * support multiple paragraphs in Kb.Banner * review feedback from chrisnojima * underline link and remove underline when hover * fix mobile underline * review feedback from chrisnojima
1 parent 5b4037a commit 24298c1

38 files changed

Lines changed: 1251 additions & 738 deletions

File tree

‎shared/chat/create-channel/index.desktop.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const CreateChannel = (props: Props) => (
1515
New chat channel
1616
</Kb.Text>
1717
</Kb.Box>
18-
{!!props.errorText && <Kb.Banner color="red" text={props.errorText} />}
18+
{!!props.errorText && (
19+
<Kb.Banner color="red">
20+
<Kb.BannerParagraph bannerColor="red" content={props.errorText} />
21+
</Kb.Banner>
22+
)}
1923
<Kb.Box style={_boxStyle}>
2024
<Kb.Box style={_backStyle} onClick={props.onBack}>
2125
<Kb.Icon style={_backIcon} type="iconfont-arrow-left" />

‎shared/chat/create-channel/index.native.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {Props} from './index.types'
66

77
const CreateChannel = (props: Props) => (
88
<Kb.Box>
9-
{!!props.errorText && <Kb.Banner color="red" text={props.errorText} />}
9+
{!!props.errorText && (
10+
<Kb.Banner color="red">
11+
<Kb.BannerParagraph bannerColor="red" content={props.errorText} />
12+
</Kb.Banner>
13+
)}
1014
<Kb.Box style={_boxStyle}>
1115
<Kb.Box style={_inputStyle}>
1216
<Kb.Input

‎shared/chat/manage-channels/edit-channel.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ class _EditChannel extends React.Component<Props, State> {
7070
</Kb.Text>
7171
)
7272
)}
73-
{!!this.props.errorText && <Kb.Banner color="red" text={this.props.errorText} />}
73+
{!!this.props.errorText && (
74+
<Kb.Banner color="red">
75+
<Kb.BannerParagraph bannerColor="red" content={this.props.errorText} />
76+
</Kb.Banner>
77+
)}
7478
<Kb.Box style={{position: 'relative'}}>
7579
<Kb.Input
7680
onChangeText={this._onChangeChannelName}

‎shared/common-adapters/banner.stories.tsx‎

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,83 @@
11
import * as React from 'react'
2-
import {Box2, Banner} from '.'
2+
import {Box2} from './box'
3+
import {Banner, BannerParagraph} from './banner'
34
import * as Sb from '../stories/storybook'
45

56
const load = () => {
67
Sb.storiesOf('Common', module)
78
.addDecorator(Sb.scrollViewDecorator)
89
.add('Banner', () => (
910
<Box2 direction="vertical" fullWidth={true} gap="small">
10-
<Banner key="1" color="red" text="this is a red banner with no action" />
11-
<Banner key="2" color="blue" text="this is a blue banner with no action" />
12-
<Banner key="3" color="yellow" text="this is a yellow banner with no action" />
13-
<Banner key="4" color="green" text="this is a green banner with no action" />
14-
<Banner key="5" color="grey" text="this is a grey banner with no action" />
15-
<Banner
16-
key="6"
17-
color="red"
18-
text="this is a red banner with super long text blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah yes very long"
19-
/>
20-
<Banner
21-
key="7"
22-
color="red"
23-
text="this is a red closable banner with super long text blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah yes very long"
24-
onClose={Sb.action('onClose')}
25-
/>
26-
<Banner key="8" color="red" text="this is a closable red banner" onClose={Sb.action('onClose')} />
27-
<Banner
28-
key="9"
29-
color="red"
30-
text="this is a red banner with actions and is closable"
31-
onClose={Sb.action('onClose')}
32-
actions={[
33-
{onClick: Sb.action('onClick-action1'), title: 'action1'},
34-
{onClick: Sb.action('onClick-action2'), title: 'action2'},
35-
]}
36-
/>
37-
<Banner
38-
key="10"
39-
color="red"
40-
text="this is a red banner with actions and super long text blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah yes very long"
41-
actions={[
42-
{onClick: Sb.action('onClick-action1'), title: 'action1'},
43-
{onClick: Sb.action('onClick-action2'), title: 'action2'},
44-
]}
45-
/>
46-
<Banner
47-
key="10"
48-
color="red"
49-
text="this is a narrow red banner with actions and super long text blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah yes very long"
50-
actions={[
51-
{onClick: Sb.action('onClick-action1'), title: 'action1'},
52-
{onClick: Sb.action('onClick-action2'), title: 'action2'},
53-
]}
54-
narrow={true}
55-
/>
11+
<Banner key="1" color="red">
12+
This is a red banner with no action.
13+
</Banner>
14+
<Banner key="2" color="blue">
15+
This is a blue banner with no action.
16+
</Banner>
17+
<Banner key="3" color="yellow">
18+
This is a yellow banner with no action.
19+
</Banner>
20+
<Banner key="4" color="green">
21+
This is a green banner with no action.
22+
</Banner>
23+
<Banner key="5" color="grey">
24+
This is a grey banner with no action.
25+
</Banner>
26+
<Banner key="6" color="red">
27+
This is a red banner with super long text blah blah blah blah blah blah blah blah blah blah blah
28+
blah blah blah blah blah blah blah blah blah blah blah blah blah yes very long.
29+
</Banner>
30+
<Banner key="7" color="red" onClose={Sb.action('onClose')}>
31+
This is a red closable banner with super long text blah blah blah blah blah blah blah blah blah blah
32+
blah blah blah blah blah blah blah blah blah blah blah blah blah blah yes very long.
33+
</Banner>
34+
<Banner key="8" color="red" onClose={Sb.action('onClose')}>
35+
This is a closable red banner.
36+
</Banner>
37+
<Banner key="9" color="red" onClose={Sb.action('onClose')}>
38+
<BannerParagraph
39+
bannerColor="red"
40+
content={[
41+
'A banner with array content',
42+
null && 'not shown',
43+
' and ',
44+
false && 'also not shown',
45+
'that has null and false inside.',
46+
]}
47+
/>
48+
</Banner>
49+
<Banner key="10" color="red" onClose={Sb.action('onClose')}>
50+
<BannerParagraph
51+
bannerColor="red"
52+
content={[
53+
'A banner with inline actions ',
54+
{onClick: Sb.action('action1'), text: 'action1'},
55+
' and ',
56+
{onClick: Sb.action('action2'), text: 'action2'},
57+
' and new line actions.',
58+
]}
59+
/>
60+
<BannerParagraph
61+
bannerColor="red"
62+
content={[
63+
{onClick: Sb.action('action3'), text: 'action3'},
64+
', ',
65+
{onClick: Sb.action('action4'), text: 'action4'},
66+
]}
67+
/>
68+
</Banner>
69+
<Banner key="11" color="red" onClose={Sb.action('onClose')}>
70+
<BannerParagraph
71+
bannerColor="red"
72+
content={[
73+
'Here is a super long banner message with ',
74+
{onClick: Sb.action('action1'), text: 'action1'},
75+
' and ',
76+
{onClick: Sb.action('action2'), text: 'action2'},
77+
'. Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.',
78+
]}
79+
/>
80+
</Banner>
5681
</Box2>
5782
))
5883
}

‎shared/common-adapters/banner.tsx‎

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,62 @@ import * as Styles from '../styles'
66

77
type Color = 'blue' | 'red' | 'yellow' | 'green' | 'grey'
88

9-
type Props = {
10-
actions?: Array<{
11-
title: string
12-
onClick: () => void
13-
}>
9+
type _Segment = {
10+
newline?: boolean
11+
onClick?: () => void
12+
text: string
13+
}
14+
type Segment = _Segment | string | null | false
15+
16+
type BannerParagraphProps = {
17+
bannerColor: Color
18+
content: string | Array<Segment>
19+
}
20+
21+
export const BannerParagraph = (props: BannerParagraphProps) => (
22+
<Text type="BodySmallSemibold" style={styles.text}>
23+
{(Array.isArray(props.content) ? props.content : [props.content])
24+
.filter(Boolean)
25+
.map(segment => (typeof segment === 'string' ? {text: segment} : segment))
26+
.map((segment: _Segment, index) =>
27+
segment.text === ' ' ? (
28+
<>&nbsp;</>
29+
) : (
30+
<React.Fragment key={index.toString()}>
31+
{segment.text.startsWith(' ') && <>&nbsp;</>}
32+
<Text
33+
type="BodySmallSemibold"
34+
style={Styles.collapseStyles([
35+
colorToTextColorStyles[props.bannerColor],
36+
!!segment.onClick && styles.underline,
37+
])}
38+
className={Styles.classNames({
39+
'underline-hover-no-underline': !!segment.onClick,
40+
})}
41+
onClick={segment.onClick}
42+
>
43+
{segment.text}
44+
</Text>
45+
{segment.text.endsWith(' ') && <>&nbsp;</>}
46+
</React.Fragment>
47+
)
48+
)}
49+
</Text>
50+
)
51+
52+
type BannerProps = {
1453
color: Color
54+
children:
55+
| string
56+
| React.ReactElement<typeof BannerParagraph>
57+
| Array<React.ReactElement<typeof BannerParagraph>>
1558
inline?: boolean
1659
narrow?: boolean
1760
onClose?: () => void
18-
text: string
1961
style?: Styles.StylesCrossPlatform | null
2062
}
2163

22-
const Banner = (props: Props) => (
64+
export const Banner = (props: BannerProps) => (
2365
<Box2
2466
direction="horizontal"
2567
fullWidth={true}
@@ -32,34 +74,15 @@ const Banner = (props: Props) => (
3274
>
3375
<Box2
3476
key="textBox"
35-
direction="horizontal"
77+
direction="vertical"
3678
style={props.narrow ? styles.narrowTextContainer : styles.textContainer}
3779
centerChildren={true}
3880
>
39-
<Text
40-
type="BodySmallSemibold"
41-
style={Styles.collapseStyles([styles.text, colorToTextColorStyles[props.color]])}
42-
>
43-
{props.text}
44-
{!!props.actions &&
45-
props.actions.reduce(
46-
(parts, {title, onClick}, index) => [
47-
...parts,
48-
<Text key={`space-${index}`} type="BodySmallSemibold">
49-
&nbsp;
50-
</Text>,
51-
<Text
52-
key={`action-${index}`}
53-
type="BodySmallSemibold"
54-
onClick={onClick}
55-
style={Styles.collapseStyles([colorToTextColorStyles[props.color], styles.underline])}
56-
>
57-
{title}
58-
</Text>,
59-
],
60-
[]
61-
)}
62-
</Text>
81+
{typeof props.children === 'string' ? (
82+
<BannerParagraph bannerColor={props.color} content={props.children} />
83+
) : (
84+
props.children
85+
)}
6386
</Box2>
6487
{!!props.onClose && (
6588
<Box key="iconBox" style={styles.iconContainer}>
@@ -137,9 +160,11 @@ const styles = Styles.styleSheetCreate({
137160
paddingRight: Styles.globalMargins.medium,
138161
},
139162
}),
140-
underline: {
141-
textDecorationLine: 'underline',
142-
},
163+
underline: Styles.platformStyles({
164+
isMobile: {
165+
textDecorationLine: 'underline',
166+
},
167+
}),
143168
})
144169

145170
const colorToBackgroundColorStyles = Styles.styleSheetCreate({
@@ -173,5 +198,3 @@ const colorToIconHoverColor = {
173198
red: Styles.globalColors.white,
174199
yellow: Styles.globalColors.brown,
175200
}
176-
177-
export default Banner

‎shared/common-adapters/confirm-modal/index.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import WaitingButton from '../waiting-button'
33
import {Box, Box2} from '../box'
44
import HeaderOrPopup from '../header-or-popup'
55
import ButtonBar from '../button-bar'
6-
import Banner from '../banner'
6+
import {Banner, BannerParagraph} from '../banner'
77
import Icon from '../icon'
88
import ScrollView from '../scroll-view'
99
import Text from '../text'
@@ -41,7 +41,15 @@ class ConfirmModal extends React.PureComponent<Props> {
4141
}
4242
: undefined
4343
}
44-
banners={this.props.error ? [<Banner key="error" color="red" text={this.props.error} />] : []}
44+
banners={
45+
this.props.error
46+
? [
47+
<Banner key="error" color="red">
48+
<BannerParagraph bannerColor="red" content={this.props.error} />
49+
</Banner>,
50+
]
51+
: []
52+
}
4553
footer={{
4654
content: (
4755
<ButtonBar direction="row" fullWidth={true} style={styles.buttonBar}>

‎shared/common-adapters/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export {default as AvatarLine} from './avatar-line'
1313
export {default as BackButton} from './back-button'
1414
export {default as BackgroundRepeatBox} from './background-repeat-box'
1515
export {default as Badge} from './badge'
16-
export {default as Banner} from './banner'
16+
export {Banner, BannerParagraph} from './banner'
1717
export {default as Box, Box2} from './box'
1818
export {default as ButtonBar} from './button-bar'
1919
export {default as Button} from './button'

‎shared/common-adapters/modal/index.stories.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ const load = () => {
148148
</Modal>
149149
))
150150
.add('Banner', () => (
151-
<Modal onClose={onClose} banners={[<Kb.Banner key="red" color="red" text="hey" />]}>
151+
<Modal
152+
onClose={onClose}
153+
banners={[
154+
<Kb.Banner key="red" color="red">
155+
<Kb.BannerParagraph bannerColor="red" content="hey" />
156+
</Kb.Banner>,
157+
]}
158+
>
152159
{filler}
153160
</Modal>
154161
))

‎shared/common-adapters/standard-screen.native.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@ import {Props} from './standard-screen'
33
import {NativeScrollView} from './native-wrappers.native'
44
import HeaderHoc from './header-hoc'
55
import * as Styles from '../styles'
6-
import Banner from './banner'
6+
import {Banner, BannerParagraph} from './banner'
77
import Box from './box'
88
import Text from './text'
99

1010
const Kb = {
1111
Banner,
12+
BannerParagraph,
1213
Box,
1314
NativeScrollView,
1415
Text,
1516
}
1617

1718
const StandardScreen = (props: Props) => {
19+
const color = props.notification.type === 'error' ? 'red' : 'blue'
1820
return (
1921
// @ts-ignore for now
2022
<Kb.NativeScrollView scrollEnabled={props.scrollEnabled}>
2123
{!!props.notification && (
22-
<Kb.Banner
23-
color={props.notification.type === 'error' ? 'red' : 'blue'}
24-
text={props.notification.message}
25-
/>
24+
<Kb.Banner color={color}>
25+
<Kb.BannerParagraph bannerColor={color} content={props.notification.message} />
26+
</Kb.Banner>
2627
)}
2728
<Kb.Box
2829
style={Styles.collapseStyles([

0 commit comments

Comments
 (0)