forked from pinterest/gestalt
/
Upsell.doc.js
252 lines (242 loc) · 9.03 KB
/
Upsell.doc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// @flow strict
import React, { type Node } from 'react';
import PropTable from './components/PropTable.js';
import Example from './components/Example.js';
import PageHeader from './components/PageHeader.js';
const cards: Array<Node> = [];
const card = (c) => cards.push(c);
card(
<PageHeader
name="Upsell"
description="Upsells are banners that display short messages that focus on selling or upgrading something the user already has."
/>
);
card(
<PropTable
props={[
{
name: 'message',
type: 'string',
required: true,
defaultValue: null,
description: [
'Text to render inside the Upsell to convey detailed information to the user. The message text has a fixed size.',
],
href: '',
},
{
name: 'dismissButton',
type: '{| accessibilityLabel: string, onDismiss: () => void, |}',
required: false,
defaultValue: null,
description: [
'Callback fired when the dismiss button is clicked (pressed and released) with a mouse or keyboard.',
'Supply a short, descriptive label for screen-readers to provide sufficient context about the dismiss button action. IconButtons do not render text for screen readers to read requiring an accessibility label.',
'Accessibility: `accessibilityLabel` populates aria-label.',
],
href: '',
},
{
name: 'imageData',
type:
'{| component: typeof Image | typeof Icon, width?: number, mask: { rounding: "circle" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8, wash: boolean} |}',
required: false,
defaultValue: null,
description: [
'Either <Image /> or <Icon /> to render on left side of banner. Width is not used with Icon. Image width defaults to 128 px. Max width of image is 128 px.',
],
href: 'Image',
},
{
name: 'primaryAction',
type:
'{| accessibilityLabel?: string , href: string, label: string, onClick?: ({ event: SyntheticMouseEvent<HTMLAnchorElement> | SyntheticKeyboardEvent<HTMLAnchorElement | SyntheticMouseEvent<HTMLButtonElement> | SyntheticKeyboardEvent<HTMLButtonElement> }) => void |}',
required: false,
defaultValue: null,
description: [
'Button to render inside the callout as the main call-to-action to the user. The label text has a fixed size.',
'- href: If href is supplied, the action will serve as a link, while if no href is supplied, the action will be a button',
'- label: Text to render inside the button to convey the function and purpose of the button. The button text has a fixed size.',
'- accessibilityLabel: Supply a short, descriptive label for screen-readers to replace button texts that do not provide sufficient context about the button component behavior. Texts like `Click Here,` `Follow,` or `Read More` can be confusing when a screen reader reads them out of context. In those cases, we must pass an alternative text to replace the button text.',
'- onClick: Callback fired when the button component is clicked (pressed and released) with a mouse or keyboard.',
'Accessibility: `accessibilityLabel` populates aria-label. Screen readers read the `accessibilityLabel` prop, if present, instead of the button `text`.',
],
href: '',
},
{
name: 'secondaryAction',
type:
'{| accessibilityLabel?: string , href: string, label: string, onClick?: ({ event: SyntheticMouseEvent<HTMLAnchorElement> | SyntheticKeyboardEvent<HTMLAnchorElement | SyntheticMouseEvent<HTMLButtonElement> | SyntheticKeyboardEvent<HTMLButtonElement> }) => void |}',
required: false,
defaultValue: null,
description: [
'Button to render inside the callout as the secondary call-to-action to the user. The label text has a fixed size.',
'- href: If href is supplied, the action will serve as a link, while if no href is supplied, the action will be a button',
'- label: Text to render inside the button to convey the function and purpose of the button. The button text has a fixed size.',
'- accessibilityLabel: Supply a short, descriptive label for screen-readers to replace button texts that do not provide sufficient context about the button component behavior. Texts like `Click Here,` `Follow,` or `Read More` can be confusing when a screen reader reads them out of context. In those cases, we must pass an alternative text to replace the button text.',
'- onClick: Callback fired when the button component is clicked (pressed and released) with a mouse or keyboard.',
'Accessibility: `accessibilityLabel` populates aria-label. Screen readers read the `accessibilityLabel` prop, if present, instead of the button `text`.',
],
href: '',
},
{
name: 'title',
type: 'string',
required: false,
defaultValue: null,
description: [
'Heading to render inside the Upsell above the message to convey the Upsell topic to the user. The message text has a fixed size.',
],
href: '',
},
]}
/>
);
card(
<Example
name="Simple message"
defaultCode={`
<Upsell
message="Single line upsell with no title or call to action."
dismissButton={{
accessibilityLabel: 'Dismiss banner',
onDismiss: ()=>{},
}}
/>
`}
/>
);
card(
<Example
name="Icon"
defaultCode={`
<Upsell
title="Give $30, get $60 in ads credit"
message="Earn $60 of ads credit, and give $30 of ads credit to a friend"
primaryAction={{href: "https://pinterest.com", label:"Send invite"}}
dismissButton={{
accessibilityLabel: 'Dismiss banner',
onDismiss: ()=>{},
}}
imageData={{
component: <Icon icon="pinterest" accessibilityLabel="Pin" color="darkGray" size={32}/>
}}
/>
`}
/>
);
card(
<Example
name="Image"
defaultCode={`
<Upsell
title="Stay healthy and safe"
message="Check out our resources for adapting to these times."
primaryAction={{href: "https://pinterest.com", label:"Visit"}}
dismissButton={{
accessibilityLabel: 'Dismiss banner',
onDismiss: ()=>{},
}}
imageData={{
component:
<Image
alt="Check out our resources for adapting to these times."
color="rgb(231, 186, 176)"
naturalHeight={751}
naturalWidth={564}
src="https://i.ibb.co/7bQQYkX/stock2.jpg"
/>,
mask: {rounding: 4},
width: 128,
}}
/>
`}
/>
);
card(
<Example
name="Link Call to Actions"
description={`
When \`href\` is supplied to \`primaryAction\` and \`secondaryAction\` the action button defaults to a link-role button.
`}
defaultCode={`
<Upsell
title="Join the Verified Merchant Program"
message="Apply to the Verified Merchant Program—it’s free"
primaryAction={{href: "https://pinterest.com", label:"Apply now"}}
secondaryAction={{href: "https://pinterest.com", label:"Learn more"}}
dismissButton={{
accessibilityLabel: 'Dismiss banner',
onDismiss: ()=>{},
}}
/>
`}
/>
);
card(
<Example
name="Button Call to Actions"
description={`
\`primaryAction\` and \`secondaryAction\` can be used as buttons when no \`href\` is supplied.
`}
defaultCode={`
function Example(props) {
const [showModal, setShowModal] = React.useState(false);
return (
<Box marginLeft={-1} marginRight={-1}>
<Upsell
title="Give $30, get $60 in ads credit"
message="Earn $60 of ads credit, and give $30 of ads credit to a friend"
primaryAction={{onClick: () => { setShowModal(!showModal) }, label:"Send invite"}}
dismissButton={{
accessibilityLabel: 'Dismiss banner',
onDismiss: ()=>{},
}}
imageData={{
component: <Icon icon="pinterest" accessibilityLabel="Pin" color="darkGray" size={32}/>
}}
/>
{showModal && (
<Layer>
<Modal
accessibilityModalLabel="Would you like to sign up"
heading="Invite Friends?"
onDismiss={() => { setShowModal(!showModal) }}
footer={
<Box
display="flex"
justifyContent="center"
>
<ButtonGroup>
<Button
size="lg"
text="Cancel"
onClick={() => { setShowModal(!showModal) }}
/>
<Button
size="lg"
color="red"
text="Sign up"
onClick={() => { setShowModal(!showModal) }}
/>
</ButtonGroup>
</Box>
}
role="alertdialog"
size="sm"
>
<Box paddingX={8}>
<Text align="center">
When your friend spends their first $30 on ads, you’ll earn $60 of ads credit, and they’ll get $30 of ads credit, too
</Text>
</Box>
</Modal>
</Layer>
)}
</Box>
);
}
`}
/>
);
export default cards;