@khanacademy/perseus 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,437 +0,0 @@
1
- // @flow
2
- import {StyleSheet, css} from "aphrodite";
3
- import * as React from "react";
4
-
5
- import FlexiblePosition from "../flexible-position.jsx";
6
-
7
- type StoryArgs = {||};
8
-
9
- type Story = {|
10
- title: string,
11
- |};
12
-
13
- export default ({
14
- title: "Perseus/Components/Flexible Position",
15
- }: Story);
16
-
17
- const styles = StyleSheet.create({
18
- wrapper: {
19
- background: "#fcfcfc",
20
- borderColor: "gray",
21
- borderStyle: "solid",
22
- borderWidth: "2px 0",
23
- boxSizing: "content-box",
24
- margin: "0 auto",
25
- width: 800,
26
- },
27
-
28
- wrapperVertical: {
29
- borderWidth: "0 2px",
30
- height: 800,
31
- width: 200,
32
- },
33
-
34
- wrapperSmall: {
35
- width: 100,
36
- },
37
-
38
- wrapperSmallVertical: {
39
- height: 100,
40
- },
41
-
42
- // `content` and `contentInner` together have a natural width of 200px.
43
- // However, if the available space is smaller, `content` will overflow with
44
- // scrollbars in order to fit the content in the available space. This
45
- // effect is visible in the "very small container" fixture.
46
- content: {
47
- background: "#fcc",
48
- borderColor: "red",
49
- borderStyle: "solid",
50
- borderWidth: "0 2px",
51
- boxSizing: "border-box",
52
- textAlign: "center",
53
- overflow: "auto",
54
- },
55
-
56
- contentVertical: {
57
- borderWidth: "2px 0",
58
- },
59
-
60
- contentInner: {
61
- width: 196,
62
- },
63
-
64
- contentInnerVertical: {
65
- height: 196,
66
- },
67
- });
68
-
69
- const Wrapper = (props: React.ElementConfig<typeof FlexiblePosition>) => (
70
- <div className={css(styles.wrapper)}>
71
- <FlexiblePosition {...props} />
72
- </div>
73
- );
74
-
75
- const SmallWrapper = (props: React.ElementConfig<typeof FlexiblePosition>) => (
76
- <div className={css(styles.wrapper, styles.wrapperSmall)}>
77
- <FlexiblePosition {...props} />
78
- </div>
79
- );
80
-
81
- const VerticalWrapper = (
82
- props: React.ElementConfig<typeof FlexiblePosition>,
83
- ) => (
84
- <div className={css(styles.wrapper, styles.wrapperVertical)}>
85
- <FlexiblePosition {...props} />
86
- </div>
87
- );
88
-
89
- const SmallVerticalWrapper = (
90
- props: React.ElementConfig<typeof FlexiblePosition>,
91
- ) => (
92
- <div
93
- className={css(
94
- styles.wrapper,
95
- styles.wrapperVertical,
96
- styles.wrapperSmallVertical,
97
- )}
98
- >
99
- <FlexiblePosition {...props} />
100
- </div>
101
- );
102
-
103
- export const CenteredAtHalfHorizontal = (args: StoryArgs): React.Node => {
104
- const params = {
105
- direction: "horizontal",
106
- pxFromStart: 400,
107
- pxFromEnd: 400,
108
- children: (
109
- <div className={css(styles.content)}>
110
- <div className={css(styles.contentInner)}>Hello, world!</div>
111
- </div>
112
- ),
113
- };
114
- return <Wrapper {...params} />;
115
- };
116
-
117
- export const CenteredAtQuarterFromLeftHorizontal = (
118
- args: StoryArgs,
119
- ): React.Node => {
120
- const params = {
121
- direction: "horizontal",
122
- pxFromStart: 200,
123
- pxFromEnd: 600,
124
- children: (
125
- <div className={css(styles.content)}>
126
- <div className={css(styles.contentInner)}>Hello, world!</div>
127
- </div>
128
- ),
129
- };
130
- return <Wrapper {...params} />;
131
- };
132
-
133
- export const CenteredAtQuarterFromRightHorizontal = (
134
- args: StoryArgs,
135
- ): React.Node => {
136
- const params = {
137
- direction: "horizontal",
138
- pxFromStart: 600,
139
- pxFromEnd: 200,
140
- children: (
141
- <div className={css(styles.content)}>
142
- <div className={css(styles.contentInner)}>Hello, world!</div>
143
- </div>
144
- ),
145
- };
146
- return <Wrapper {...params} />;
147
- };
148
-
149
- export const CenteredAtEigthFromLeftExactlyAtEdgeHorizontal = (
150
- args: StoryArgs,
151
- ): React.Node => {
152
- const params = {
153
- direction: "horizontal",
154
- pxFromStart: 100,
155
- pxFromEnd: 700,
156
- children: (
157
- <div className={css(styles.content)}>
158
- <div className={css(styles.contentInner)}>Hello, world!</div>
159
- </div>
160
- ),
161
- };
162
- return <Wrapper {...params} />;
163
- };
164
-
165
- export const CenteredAtEigthFromRightExactlyAtEdgeHorizontal = (
166
- args: StoryArgs,
167
- ): React.Node => {
168
- const params = {
169
- direction: "horizontal",
170
- pxFromStart: 700,
171
- pxFromEnd: 100,
172
- children: (
173
- <div className={css(styles.content)}>
174
- <div className={css(styles.contentInner)}>Hello, world!</div>
175
- </div>
176
- ),
177
- };
178
- return <Wrapper {...params} />;
179
- };
180
-
181
- export const CenteredAtSixteengthFromLeftWouldOverflowHorizontal = (
182
- args: StoryArgs,
183
- ): React.Node => {
184
- const params = {
185
- direction: "horizontal",
186
- pxFromStart: 50,
187
- pxFromEnd: 750,
188
- children: (
189
- <div className={css(styles.content)}>
190
- <div className={css(styles.contentInner)}>Hello, world!</div>
191
- </div>
192
- ),
193
- };
194
- return <Wrapper {...params} />;
195
- };
196
-
197
- export const CenteredAtSixteengthFromRightWouldOverflowHorizontal = (
198
- args: StoryArgs,
199
- ): React.Node => {
200
- const params = {
201
- direction: "horizontal",
202
- pxFromStart: 750,
203
- pxFromEnd: 50,
204
- children: (
205
- <div className={css(styles.content)}>
206
- <div className={css(styles.contentInner)}>Hello, world!</div>
207
- </div>
208
- ),
209
- };
210
- return <Wrapper {...params} />;
211
- };
212
-
213
- export const CenteredAt0FromLeftWouldOverflowHorizontal = (
214
- args: StoryArgs,
215
- ): React.Node => {
216
- const params = {
217
- direction: "horizontal",
218
- pxFromStart: 0,
219
- pxFromEnd: 800,
220
- children: (
221
- <div className={css(styles.content)}>
222
- <div className={css(styles.contentInner)}>Hello, world!</div>
223
- </div>
224
- ),
225
- };
226
- return <Wrapper {...params} />;
227
- };
228
-
229
- export const CenteredAt0FromRightWouldOverflowHorizontal = (
230
- args: StoryArgs,
231
- ): React.Node => {
232
- const params = {
233
- direction: "horizontal",
234
- pxFromStart: 800,
235
- pxFromEnd: 0,
236
- children: (
237
- <div className={css(styles.content)}>
238
- <div className={css(styles.contentInner)}>Hello, world!</div>
239
- </div>
240
- ),
241
- };
242
- return <Wrapper {...params} />;
243
- };
244
-
245
- export const CenteredInVerySmallContainerWouldOverflowHorizontal = (
246
- args: StoryArgs,
247
- ): React.Node => {
248
- const params = {
249
- direction: "horizontal",
250
- pxFromStart: 50,
251
- pxFromEnd: 50,
252
- children: (
253
- <div className={css(styles.content)}>
254
- <div className={css(styles.contentInner)}>Hello, world!</div>
255
- </div>
256
- ),
257
- };
258
- return <SmallWrapper {...params} />;
259
- };
260
-
261
- export const CenteredAtHalfVertical = (args: StoryArgs): React.Node => {
262
- const params = {
263
- direction: "vertical",
264
- pxFromStart: 400,
265
- pxFromEnd: 400,
266
- children: (
267
- <div className={css(styles.content, styles.contentVertical)}>
268
- <div className={css(styles.contentInnerVertical)}>
269
- Hello, world!
270
- </div>
271
- </div>
272
- ),
273
- };
274
- return <VerticalWrapper {...params} />;
275
- };
276
-
277
- export const CenteredAtQuarterFromTopVertical = (
278
- args: StoryArgs,
279
- ): React.Node => {
280
- const params = {
281
- direction: "vertical",
282
- pxFromStart: 200,
283
- pxFromEnd: 600,
284
- children: (
285
- <div className={css(styles.content, styles.contentVertical)}>
286
- <div className={css(styles.contentInnerVertical)}>
287
- Hello, world!
288
- </div>
289
- </div>
290
- ),
291
- };
292
- return <VerticalWrapper {...params} />;
293
- };
294
-
295
- export const CenteredAtQuarterFromBottomVertical = (
296
- args: StoryArgs,
297
- ): React.Node => {
298
- const params = {
299
- direction: "vertical",
300
- pxFromStart: 600,
301
- pxFromEnd: 200,
302
- children: (
303
- <div className={css(styles.content, styles.contentVertical)}>
304
- <div className={css(styles.contentInnerVertical)}>
305
- Hello, world!
306
- </div>
307
- </div>
308
- ),
309
- };
310
- return <VerticalWrapper {...params} />;
311
- };
312
-
313
- export const CenteredAtEigthFromTopExactlyAtEdgeVertical = (
314
- args: StoryArgs,
315
- ): React.Node => {
316
- const params = {
317
- direction: "vertical",
318
- pxFromStart: 100,
319
- pxFromEnd: 700,
320
- children: (
321
- <div className={css(styles.content, styles.contentVertical)}>
322
- <div className={css(styles.contentInnerVertical)}>
323
- Hello, world!
324
- </div>
325
- </div>
326
- ),
327
- };
328
- return <VerticalWrapper {...params} />;
329
- };
330
-
331
- export const CenteredAtEigthFromBottomExactlyAtEdgeVertical = (
332
- args: StoryArgs,
333
- ): React.Node => {
334
- const params = {
335
- direction: "vertical",
336
- pxFromStart: 700,
337
- pxFromEnd: 100,
338
- children: (
339
- <div className={css(styles.content, styles.contentVertical)}>
340
- <div className={css(styles.contentInnerVertical)}>
341
- Hello, world!
342
- </div>
343
- </div>
344
- ),
345
- };
346
- return <VerticalWrapper {...params} />;
347
- };
348
-
349
- export const CenteredAtSixteengthFromTopWouldOverflowVertical = (
350
- args: StoryArgs,
351
- ): React.Node => {
352
- const params = {
353
- direction: "vertical",
354
- pxFromStart: 50,
355
- pxFromEnd: 750,
356
- children: (
357
- <div className={css(styles.content, styles.contentVertical)}>
358
- <div className={css(styles.contentInnerVertical)}>
359
- Hello, world!
360
- </div>
361
- </div>
362
- ),
363
- };
364
- return <VerticalWrapper {...params} />;
365
- };
366
-
367
- export const CenteredAtSixteengthFromBottomWouldOverflowVertical = (
368
- args: StoryArgs,
369
- ): React.Node => {
370
- const params = {
371
- direction: "vertical",
372
- pxFromStart: 750,
373
- pxFromEnd: 50,
374
- children: (
375
- <div className={css(styles.content, styles.contentVertical)}>
376
- <div className={css(styles.contentInnerVertical)}>
377
- Hello, world!
378
- </div>
379
- </div>
380
- ),
381
- };
382
- return <VerticalWrapper {...params} />;
383
- };
384
-
385
- export const CenteredAt0FromTopWouldOverflowVertical = (
386
- args: StoryArgs,
387
- ): React.Node => {
388
- const params = {
389
- direction: "vertical",
390
- pxFromStart: 0,
391
- pxFromEnd: 800,
392
- children: (
393
- <div className={css(styles.content, styles.contentVertical)}>
394
- <div className={css(styles.contentInnerVertical)}>
395
- Hello, world!
396
- </div>
397
- </div>
398
- ),
399
- };
400
- return <VerticalWrapper {...params} />;
401
- };
402
-
403
- export const CenteredAt0FromBottomWouldOverflowVertical = (
404
- args: StoryArgs,
405
- ): React.Node => {
406
- const params = {
407
- direction: "vertical",
408
- pxFromStart: 800,
409
- pxFromEnd: 0,
410
- children: (
411
- <div className={css(styles.content, styles.contentVertical)}>
412
- <div className={css(styles.contentInnerVertical)}>
413
- Hello, world!
414
- </div>
415
- </div>
416
- ),
417
- };
418
- return <VerticalWrapper {...params} />;
419
- };
420
-
421
- export const CenteredInVerySmallContainerWouldOverflowVertical = (
422
- args: StoryArgs,
423
- ): React.Node => {
424
- const params = {
425
- direction: "vertical",
426
- pxFromStart: 50,
427
- pxFromEnd: 50,
428
- children: (
429
- <div className={css(styles.content, styles.contentVertical)}>
430
- <div className={css(styles.contentInnerVertical)}>
431
- Hello, world!
432
- </div>
433
- </div>
434
- ),
435
- };
436
- return <SmallVerticalWrapper {...params} />;
437
- };
@@ -1,70 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
-
4
- import TooltipArrow from "../tooltip-arrow.jsx";
5
-
6
- type StoryArgs = {||};
7
-
8
- type Story = {|
9
- title: string,
10
- |};
11
-
12
- export default ({
13
- title: "Perseus/Components/Tooltip Arrow",
14
- }: Story);
15
-
16
- export const DownPointingArrow = (args: StoryArgs): React.Node => {
17
- const props = {
18
- tooltipProps: {
19
- inverted: false,
20
- color: "red", // this should have no effect because we're not inverted
21
- side: "top",
22
- },
23
- };
24
-
25
- return <TooltipArrow {...props} />;
26
- };
27
-
28
- export const BlueDownPointingArrow = (args: StoryArgs): React.Node => {
29
- const props = {
30
- tooltipProps: {
31
- inverted: true,
32
- color: "blue",
33
- side: "top",
34
- },
35
- };
36
- return <TooltipArrow {...props} />;
37
- };
38
-
39
- export const UpPointingArrow = (args: StoryArgs): React.Node => {
40
- const props = {
41
- tooltipProps: {
42
- inverted: false,
43
- color: "red", // this should have no effect because we're not inverted
44
- side: "bottom",
45
- },
46
- };
47
- return <TooltipArrow {...props} />;
48
- };
49
-
50
- export const RightPointingArrow = (args: StoryArgs): React.Node => {
51
- const props = {
52
- tooltipProps: {
53
- inverted: false,
54
- color: "red", // this should have no effect because we're not inverted
55
- side: "left",
56
- },
57
- };
58
- return <TooltipArrow {...props} />;
59
- };
60
-
61
- export const LeftPointingArrow = (args: StoryArgs): React.Node => {
62
- const props = {
63
- tooltipProps: {
64
- inverted: false,
65
- color: "red", // this should have no effect because we're not inverted
66
- side: "right",
67
- },
68
- };
69
- return <TooltipArrow {...props} />;
70
- };
@@ -1,98 +0,0 @@
1
- // @flow
2
- import Color from "@khanacademy/wonder-blocks-color";
3
- import {action} from "@storybook/addon-actions";
4
- import * as React from "react";
5
-
6
- import TooltipBubble from "../tooltip-bubble.jsx";
7
-
8
- type StoryArgs = {||};
9
-
10
- type Story = {|
11
- title: string,
12
- |};
13
-
14
- export default ({
15
- title: "Perseus/Components/Tooltip Bubble",
16
- }: Story);
17
-
18
- const defaultProps = {
19
- side: "top",
20
- offset: 0,
21
- offsetFrom: "bubble",
22
- tooltipMargin: 0,
23
- noPadding: false,
24
- color: Color.offBlack16,
25
- inverted: false,
26
- dismissOnClickClose: false,
27
- toggleOnHover: true,
28
- showOnMount: false,
29
- };
30
-
31
- const logDismissAction = (...args) => action("dismiss")(...args);
32
-
33
- export const DefaultBubble = (args: StoryArgs): React.Node => {
34
- const params = {
35
- tooltipProps: {
36
- ...defaultProps,
37
- content: "Hello, world!",
38
- a11y: {title: "Default bubble"},
39
- },
40
- dismiss: logDismissAction,
41
- };
42
- return <TooltipBubble {...params} />;
43
- };
44
-
45
- export const DefaultBubbleWithCloseButton = (args: StoryArgs): React.Node => {
46
- const params = {
47
- tooltipProps: {
48
- ...defaultProps,
49
- content: "Hello, world!",
50
- dismissOnClickClose: true,
51
- a11y: {title: "Default bubble with close button"},
52
- },
53
- dismiss: logDismissAction,
54
- };
55
- return <TooltipBubble {...params} />;
56
- };
57
-
58
- export const BlueTextOnWhiteBubble = (args: StoryArgs): React.Node => {
59
- const params = {
60
- tooltipProps: {
61
- ...defaultProps,
62
- content: "Hello, world!",
63
- color: "blue",
64
- dismissOnClickClose: true,
65
- a11y: {title: "Blue text on white bubble"},
66
- },
67
- dismiss: logDismissAction,
68
- };
69
- return <TooltipBubble {...params} />;
70
- };
71
-
72
- export const WhiteTextOnBlueBubble = (args: StoryArgs): React.Node => {
73
- const params = {
74
- tooltipProps: {
75
- ...defaultProps,
76
- content: "Hello, world!",
77
- color: "blue",
78
- inverted: true,
79
- dismissOnClickClose: true,
80
- a11y: {title: "White text on blue bubble"},
81
- },
82
- dismiss: logDismissAction,
83
- };
84
- return <TooltipBubble {...params} />;
85
- };
86
-
87
- export const NoPaddingAroundContentInBubble = (args: StoryArgs): React.Node => {
88
- const params = {
89
- tooltipProps: {
90
- ...defaultProps,
91
- content: "Hello, world!",
92
- noPadding: true,
93
- a11y: {title: "No padding around content in bubble"},
94
- },
95
- dismiss: logDismissAction,
96
- };
97
- return <TooltipBubble {...params} />;
98
- };
@@ -1,47 +0,0 @@
1
- // @flow
2
- import Color from "@khanacademy/wonder-blocks-color";
3
- import * as React from "react";
4
-
5
- import {getTooltipColors} from "../util.js";
6
-
7
- const defaultProps = {
8
- side: "top",
9
- offset: 0,
10
- offsetFrom: "bubble",
11
- tooltipMargin: 0,
12
- noPadding: false,
13
- color: Color.offBlack16,
14
- inverted: false,
15
- dismissOnClickClose: false,
16
- toggleOnHover: true,
17
- showOnMount: false,
18
- };
19
-
20
- describe("getTooltipColors", () => {
21
- it("returns <color>-on-white when not inverted", () => {
22
- const {backgroundColor, textColor} = getTooltipColors({
23
- ...defaultProps,
24
- children: <div>(unused)</div>,
25
- content: "Hello, world!",
26
- color: "#123",
27
- a11y: {title: "returns <color>-on-white when not inverted"}, // Does nothing
28
- });
29
-
30
- expect(backgroundColor).toEqual(Color.white);
31
- expect(textColor).toEqual("#123");
32
- });
33
-
34
- it("returns white-on-<color> when inverted", () => {
35
- const {backgroundColor, textColor} = getTooltipColors({
36
- ...defaultProps,
37
- children: <div>(unused)</div>,
38
- content: "Hello, world!",
39
- color: "#123",
40
- inverted: true,
41
- a11y: {title: "returns white-on-<color> when inverted"}, // Does nothing
42
- });
43
-
44
- expect(backgroundColor).toEqual("#123");
45
- expect(textColor).toEqual(Color.white);
46
- });
47
- });