@khanacademy/perseus 4.0.2 → 6.0.0
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.
- package/CHANGELOG.md +57 -0
- package/dist/components/fixed-to-responsive.d.ts +27 -1
- package/dist/components/fixed-to-responsive.js.flow +27 -1
- package/dist/components/graph.d.ts +42 -26
- package/dist/components/graph.js.flow +42 -28
- package/dist/components/graphie.d.ts +34 -22
- package/dist/components/graphie.js.flow +37 -24
- package/dist/components/highlighting/highlightable-content.d.ts +4 -4
- package/dist/components/highlighting/highlightable-content.js.flow +4 -7
- package/dist/components/highlighting/ui/highlight-renderer.d.ts +6 -6
- package/dist/components/highlighting/ui/highlight-renderer.js.flow +6 -8
- package/dist/components/highlighting/ui/highlight-set-renderer.d.ts +5 -5
- package/dist/components/highlighting/ui/highlight-set-renderer.js.flow +5 -8
- package/dist/components/highlighting/ui/highlight-tooltip.d.ts +2 -2
- package/dist/components/highlighting/ui/highlight-tooltip.js.flow +2 -4
- package/dist/components/highlighting/ui/highlighting-ui.d.ts +2 -2
- package/dist/components/highlighting/ui/highlighting-ui.js.flow +2 -2
- package/dist/components/highlighting/ui/selection-tracker.d.ts +5 -5
- package/dist/components/highlighting/ui/selection-tracker.js.flow +5 -7
- package/dist/components/highlighting/word-indexer.d.ts +2 -2
- package/dist/components/highlighting/word-indexer.js.flow +2 -2
- package/dist/components/hud.d.ts +8 -14
- package/dist/components/hud.js.flow +7 -14
- package/dist/components/inline-icon.d.ts +27 -3
- package/dist/components/inline-icon.js.flow +26 -3
- package/dist/components/lint.d.ts +41 -13
- package/dist/components/lint.js.flow +42 -13
- package/dist/components/math-output.d.ts +15 -11
- package/dist/components/math-output.js.flow +15 -11
- package/dist/components/simple-keypad-input.d.ts +1 -1
- package/dist/components/simple-keypad-input.js.flow +1 -1
- package/dist/components/sortable.d.ts +17 -9
- package/dist/components/sortable.js.flow +22 -9
- package/dist/components/svg-image.d.ts +5 -3
- package/dist/components/svg-image.js.flow +5 -3
- package/dist/components/tex-buttons.d.ts +2 -2
- package/dist/components/tex-buttons.js.flow +2 -2
- package/dist/components/tooltip.d.ts +45 -4
- package/dist/components/tooltip.js.flow +44 -31
- package/dist/error-boundary.d.ts +4 -4
- package/dist/error-boundary.js.flow +4 -6
- package/dist/es/index.css +0 -3
- package/dist/es/index.js +484 -658
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +0 -3
- package/dist/index.js +488 -655
- package/dist/index.js.map +1 -1
- package/dist/perseus-types.d.ts +11 -10
- package/dist/perseus-types.js.flow +11 -10
- package/dist/renderer.d.ts +2 -2
- package/dist/renderer.js.flow +1 -3
- package/dist/styles/shared.d.ts +0 -1
- package/dist/styles/shared.js.flow +0 -1
- package/dist/types.d.ts +0 -10
- package/dist/types.js.flow +0 -13
- package/dist/util/a11y.d.ts +0 -1
- package/dist/util/a11y.js.flow +0 -1
- package/dist/util/interactive.d.ts +2 -0
- package/dist/util/interactive.js.flow +2 -0
- package/dist/util.d.ts +3 -3
- package/dist/util.js.flow +4 -3
- package/dist/widgets/__stories__/test-keypad-context-wrapper.d.ts +2 -2
- package/dist/widgets/__stories__/test-keypad-context-wrapper.js.flow +2 -4
- package/dist/widgets/expression.d.ts +2 -2
- package/dist/widgets/expression.js.flow +2 -2
- package/dist/widgets/grapher.d.ts +1 -1
- package/dist/widgets/grapher.js.flow +12 -3
- package/dist/widgets/interaction/element-container.d.ts +5 -4
- package/dist/widgets/interaction/element-container.js.flow +6 -11
- package/dist/widgets/label-image/marker.d.ts +4 -4
- package/dist/widgets/label-image/marker.js.flow +4 -6
- package/dist/widgets/matcher.d.ts +7 -3
- package/dist/widgets/matcher.js.flow +7 -3
- package/dist/widgets/number-line.d.ts +1 -1
- package/dist/widgets/number-line.js.flow +1 -1
- package/dist/widgets/numeric-input.d.ts +0 -2
- package/dist/widgets/numeric-input.js.flow +0 -4
- package/dist/widgets/radio/base-radio.d.ts +7 -1
- package/dist/widgets/radio/base-radio.js.flow +7 -1
- package/dist/widgets/radio/choice-icon/choice-icon.d.ts +1 -1
- package/dist/widgets/radio/choice-icon/choice-icon.js.flow +1 -1
- package/dist/widgets/radio/choice-icon/cross-out-line.d.ts +2 -2
- package/dist/widgets/radio/choice-icon/cross-out-line.js.flow +2 -2
- package/dist/widgets/radio/focus-ring.d.ts +8 -1
- package/dist/widgets/radio/focus-ring.js.flow +8 -1
- package/dist/widgets/radio/option-status.d.ts +2 -2
- package/dist/widgets/radio/option-status.js.flow +2 -2
- package/dist/widgets/video-transcript-link.d.ts +1 -1
- package/dist/widgets/video-transcript-link.js.flow +1 -1
- package/package.json +4 -4
- package/src/__stories__/item-renderer.stories.tsx +2 -6
- package/src/__stories__/server-item-renderer.stories.tsx +2 -6
- package/src/__tests__/__snapshots__/item-renderer.test.tsx.snap +151 -159
- package/src/__tests__/__snapshots__/renderer.test.tsx.snap +358 -394
- package/src/__tests__/__snapshots__/server-item-renderer.test.tsx.snap +169 -189
- package/src/components/__stories__/button-group.stories.tsx +2 -6
- package/src/components/__stories__/fixed-to-responsive.stories.tsx +14 -16
- package/src/components/__stories__/graph.stories.tsx +3 -5
- package/src/components/__stories__/graphie.stories.tsx +3 -5
- package/src/components/__stories__/hud.stories.tsx +2 -6
- package/src/components/__stories__/icon.stories.tsx +1 -1
- package/src/components/__stories__/image-loader.stories.tsx +4 -4
- package/src/components/__stories__/info-tip.stories.tsx +2 -6
- package/src/components/__stories__/inline-icon.stories.tsx +4 -8
- package/src/components/__stories__/input-with-examples.stories.tsx +6 -10
- package/src/components/__stories__/lint.stories.tsx +62 -27
- package/src/components/__stories__/math-input.stories.tsx +4 -8
- package/src/components/__stories__/math-output.stories.tsx +3 -5
- package/src/components/__stories__/multi-button-group.stories.tsx +2 -6
- package/src/components/__stories__/number-input.stories.tsx +6 -8
- package/src/components/__stories__/prop-check-box.stories.tsx +9 -9
- package/src/components/__stories__/range-input.stories.tsx +4 -6
- package/src/components/__stories__/simple-keypad-input.stories.tsx +2 -4
- package/src/components/__stories__/sortable.stories.tsx +20 -20
- package/src/components/__stories__/stub-tag-editor.stories.tsx +5 -9
- package/src/components/__stories__/svg-image.stories.tsx +10 -18
- package/src/components/__stories__/tex.stories.tsx +1 -3
- package/src/components/__stories__/text-buttons.stories.tsx +10 -22
- package/src/components/__stories__/text-input.stories.tsx +4 -10
- package/src/components/__stories__/text-list-editor.stories.tsx +1 -3
- package/src/components/__stories__/tooltip.stories.tsx +52 -0
- package/src/components/__stories__/zoomable-tex.stories.tsx +6 -4
- package/src/components/__stories__/zoomable.stories.tsx +1 -3
- package/src/components/__tests__/__snapshots__/sortable.test.tsx.snap +114 -30
- package/src/components/__tests__/__snapshots__/sorter.test.tsx.snap +172 -204
- package/src/components/__tests__/sortable.test.tsx +54 -16
- package/src/components/__tests__/sorter.test.tsx +12 -9
- package/src/components/fixed-to-responsive.tsx +43 -38
- package/src/components/graph.tsx +95 -81
- package/src/components/graphie.tsx +62 -32
- package/src/components/highlighting/highlightable-content.tsx +4 -7
- package/src/components/highlighting/ui/highlight-renderer.tsx +6 -9
- package/src/components/highlighting/ui/highlight-set-renderer.tsx +5 -8
- package/src/components/highlighting/ui/highlight-tooltip.tsx +2 -2
- package/src/components/highlighting/ui/highlighting-ui.tsx +2 -2
- package/src/components/highlighting/ui/selection-tracker.tsx +5 -8
- package/src/components/highlighting/word-indexer.tsx +2 -2
- package/src/components/hud.tsx +104 -115
- package/src/components/inline-icon.tsx +17 -34
- package/src/components/input-with-examples.tsx +4 -4
- package/src/components/lint.tsx +47 -41
- package/src/components/math-output.tsx +17 -11
- package/src/components/simple-keypad-input.tsx +4 -4
- package/src/components/sortable.tsx +134 -94
- package/src/components/svg-image.tsx +10 -11
- package/src/components/tex-buttons.tsx +2 -2
- package/src/components/tooltip.tsx +189 -171
- package/src/components/visibility-observer/__stories__/visibility-observer.stories.tsx +1 -3
- package/src/error-boundary.tsx +4 -7
- package/src/interactive2/types.ts +2 -2
- package/src/multi-items/__stories__/multi-renderer.stories.tsx +1 -1
- package/src/multi-items/__tests__/__snapshots__/multi-renderer.test.tsx.snap +708 -764
- package/src/multi-items/__tests__/multi-renderer.test.tsx +2 -3
- package/src/perseus-types.ts +13 -12
- package/src/renderer.tsx +11 -22
- package/src/types.ts +0 -18
- package/src/util/graphie.ts +3 -3
- package/src/util/interactive.ts +18 -5
- package/src/util/tex.ts +13 -77
- package/src/util.ts +3 -4
- package/src/widgets/__stories__/categorizer.stories.tsx +1 -1
- package/src/widgets/__stories__/cs-program.stories.tsx +1 -1
- package/src/widgets/__stories__/definition.stories.tsx +3 -7
- package/src/widgets/__stories__/dropdown.stories.tsx +1 -1
- package/src/widgets/__stories__/explanation.stories.tsx +2 -2
- package/src/widgets/__stories__/expression.stories.tsx +5 -11
- package/src/widgets/__stories__/graded-group-set.stories.tsx +1 -1
- package/src/widgets/__stories__/graded-group.stories.tsx +1 -1
- package/src/widgets/__stories__/grapher.stories.tsx +7 -21
- package/src/widgets/__stories__/group.stories.tsx +1 -1
- package/src/widgets/__stories__/iframe.stories.tsx +1 -1
- package/src/widgets/__stories__/image.stories.tsx +1 -1
- package/src/widgets/__stories__/input-number.stories.tsx +3 -12
- package/src/widgets/__stories__/interaction.stories.tsx +1 -1
- package/src/widgets/__stories__/interactive-graph.stories.tsx +9 -9
- package/src/widgets/__stories__/matcher.stories.tsx +1 -1
- package/src/widgets/__stories__/matrix.stories.tsx +1 -1
- package/src/widgets/__stories__/number-line.stories.tsx +1 -1
- package/src/widgets/__stories__/numeric-input.stories.tsx +3 -5
- package/src/widgets/__stories__/orderer.stories.tsx +1 -1
- package/src/widgets/__stories__/passage-ref.stories.tsx +2 -2
- package/src/widgets/__stories__/passage.stories.tsx +3 -9
- package/src/widgets/__stories__/radio.stories.tsx +3 -5
- package/src/widgets/__stories__/sorter.stories.tsx +1 -1
- package/src/widgets/__stories__/test-keypad-context-wrapper.tsx +2 -4
- package/src/widgets/__stories__/transformer.stories.tsx +1 -1
- package/src/widgets/__stories__/unit.stories.tsx +1 -3
- package/src/widgets/__stories__/video-transcript-link.stories.tsx +2 -6
- package/src/widgets/__stories__/video.stories.tsx +1 -1
- package/src/widgets/__testdata__/group.testdata.ts +0 -2
- package/src/widgets/__tests__/__snapshots__/categorizer.test.ts.snap +717 -773
- package/src/widgets/__tests__/__snapshots__/cs-program.test.ts.snap +28 -36
- package/src/widgets/__tests__/__snapshots__/definition.test.ts.snap +52 -60
- package/src/widgets/__tests__/__snapshots__/dropdown.test.ts.snap +100 -108
- package/src/widgets/__tests__/__snapshots__/explanation.test.ts.snap +212 -260
- package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt.test.ts.snap +613 -641
- package/src/widgets/__tests__/__snapshots__/graded-group-set.test.ts.snap +249 -261
- package/src/widgets/__tests__/__snapshots__/graded-group.test.ts.snap +671 -735
- package/src/widgets/__tests__/__snapshots__/grapher.test.ts.snap +2676 -2684
- package/src/widgets/__tests__/__snapshots__/group.test.tsx.snap +938 -1002
- package/src/widgets/__tests__/__snapshots__/iframe.test.ts.snap +28 -36
- package/src/widgets/__tests__/__snapshots__/image.test.ts.snap +227 -255
- package/src/widgets/__tests__/__snapshots__/input-number.test.ts.snap +353 -357
- package/src/widgets/__tests__/__snapshots__/interaction.test.ts.snap +255 -259
- package/src/widgets/__tests__/__snapshots__/interactive-graph.test.ts.snap +2401 -2433
- package/src/widgets/__tests__/__snapshots__/matcher.test.tsx.snap +600 -756
- package/src/widgets/__tests__/__snapshots__/matrix.test.ts.snap +420 -428
- package/src/widgets/__tests__/__snapshots__/number-line.test.ts.snap +762 -770
- package/src/widgets/__tests__/__snapshots__/numeric-input.test.ts.snap +373 -393
- package/src/widgets/__tests__/__snapshots__/orderer.test.ts.snap +116 -148
- package/src/widgets/__tests__/__snapshots__/passage-ref.test.ts.snap +289 -301
- package/src/widgets/__tests__/__snapshots__/passage.test.tsx.snap +1679 -1711
- package/src/widgets/__tests__/__snapshots__/radio.test.ts.snap +2692 -2960
- package/src/widgets/__tests__/__snapshots__/video.test.ts.snap +90 -98
- package/src/widgets/__tests__/group.test.tsx +0 -2
- package/src/widgets/__tests__/matcher.test.tsx +33 -9
- package/src/widgets/__tests__/radio/focus-ring.test.tsx +0 -1
- package/src/widgets/expression.tsx +12 -9
- package/src/widgets/grapher.tsx +3 -3
- package/src/widgets/image.tsx +2 -2
- package/src/widgets/interaction/element-container.tsx +7 -8
- package/src/widgets/interactive-graph.tsx +5 -5
- package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +2 -4
- package/src/widgets/label-image/__stories__/marker.stories.tsx +9 -19
- package/src/widgets/label-image/marker.tsx +4 -4
- package/src/widgets/matcher.tsx +43 -24
- package/src/widgets/number-line.tsx +1 -1
- package/src/widgets/numeric-input.tsx +0 -3
- package/src/widgets/passage/passage-markdown.tsx +2 -2
- package/src/widgets/radio/__stories__/base-radio.stories.tsx +11 -19
- package/src/widgets/radio/__stories__/choice-icon.stories.tsx +9 -11
- package/src/widgets/radio/__stories__/choice-none-above.stories.tsx +1 -1
- package/src/widgets/radio/__stories__/choice.stories.tsx +4 -4
- package/src/widgets/radio/__stories__/focus-ring.stories.tsx +1 -1
- package/src/widgets/radio/__stories__/option-status.stories.tsx +2 -4
- package/src/widgets/radio/base-radio.tsx +1 -1
- package/src/widgets/radio/choice-icon/choice-icon.tsx +5 -5
- package/src/widgets/radio/choice-icon/cross-out-line.tsx +1 -3
- package/src/widgets/radio/choice-none-above.tsx +2 -2
- package/src/widgets/radio/choice.tsx +1 -3
- package/src/widgets/radio/focus-ring.tsx +1 -1
- package/src/widgets/radio/option-status.tsx +2 -4
- package/src/widgets/radio/widget.tsx +0 -1
- package/src/widgets/reaction-diagram.tsx +2 -2
- package/src/widgets/simulator.tsx +4 -6
- package/src/widgets/video-transcript-link.tsx +1 -1
- package/{tsconfig.json → tsconfig-build.json} +6 -6
- package/tsconfig-build.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react/no-unsafe */
|
|
1
2
|
/**
|
|
2
3
|
* A generic tooltip library for React.js
|
|
3
4
|
*
|
|
@@ -7,9 +8,9 @@
|
|
|
7
8
|
* import Tooltip from "./tooltip";
|
|
8
9
|
* <Tooltip
|
|
9
10
|
* className="class-for-tooltip-contents"
|
|
10
|
-
* horizontalPosition=
|
|
11
|
-
* horizontalAlign=
|
|
12
|
-
* verticalPosition=
|
|
11
|
+
* horizontalPosition={HoriziontalDirection.Left}
|
|
12
|
+
* horizontalAlign={HoriziontalDirection.Left}
|
|
13
|
+
* verticalPosition={VerticalDirection.Top}
|
|
13
14
|
* arrowSize={10} // arrow size in pixels
|
|
14
15
|
* borderColor="#ccc" // color of the border for the tooltip
|
|
15
16
|
* show={true} // whether the tooltip should currently be visible
|
|
@@ -40,136 +41,142 @@
|
|
|
40
41
|
// TODO(joel/aria) fix z-index issues https://s3.amazonaws.com/uploads.hipchat.com/6574/29028/yOApjwmgiMhEZYJ/Screen%20Shot%202014-05-30%20at%203.34.18%20PM.png
|
|
41
42
|
// z-index: 3 on perseus-formats-tooltip seemed to work
|
|
42
43
|
|
|
43
|
-
import createReactClass from "create-react-class";
|
|
44
|
-
import PropTypes from "prop-types";
|
|
45
44
|
import * as React from "react";
|
|
46
45
|
import ReactDOM from "react-dom";
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const Triangle = createReactClass({
|
|
51
|
-
propTypes: {
|
|
52
|
-
color: PropTypes.string.isRequired,
|
|
53
|
-
left: PropTypes.number.isRequired,
|
|
54
|
-
top: PropTypes.number.isRequired,
|
|
55
|
-
width: PropTypes.number.isRequired,
|
|
56
|
-
height: PropTypes.number.isRequired,
|
|
57
|
-
horizontalDirection: PropTypes.oneOf(["left", "right"]).isRequired,
|
|
58
|
-
verticalDirection: PropTypes.oneOf(["top", "bottom"]).isRequired,
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
render: function () {
|
|
62
|
-
let borderLeft;
|
|
63
|
-
let borderRight;
|
|
64
|
-
let borderTop;
|
|
65
|
-
let borderBottom;
|
|
66
|
-
|
|
67
|
-
const hBorder = `${this.props.width}px solid transparent`;
|
|
68
|
-
if (this.props.horizontalDirection === "right") {
|
|
69
|
-
borderLeft = hBorder;
|
|
70
|
-
} else {
|
|
71
|
-
borderRight = hBorder;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const vBorder = `${this.props.height}px solid ${this.props.color}`;
|
|
75
|
-
if (this.props.verticalDirection === "top") {
|
|
76
|
-
borderTop = vBorder;
|
|
77
|
-
} else {
|
|
78
|
-
borderBottom = vBorder;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<div
|
|
83
|
-
style={{
|
|
84
|
-
display: "block",
|
|
85
|
-
height: 0,
|
|
86
|
-
width: 0,
|
|
87
|
-
position: "absolute",
|
|
88
|
-
left: this.props.left,
|
|
89
|
-
top: this.props["top"],
|
|
90
|
-
borderLeft: borderLeft,
|
|
91
|
-
borderRight: borderRight,
|
|
92
|
-
borderTop: borderTop,
|
|
93
|
-
borderBottom: borderBottom,
|
|
94
|
-
}}
|
|
95
|
-
/>
|
|
96
|
-
);
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const TooltipArrow = createReactClass({
|
|
101
|
-
propTypes: {
|
|
102
|
-
position: PropTypes.string,
|
|
103
|
-
visibility: PropTypes.string,
|
|
104
|
-
left: PropTypes.number,
|
|
105
|
-
top: PropTypes.number,
|
|
106
|
-
color: PropTypes.string.isRequired, // a css color
|
|
107
|
-
border: PropTypes.string.isRequired, // a css color
|
|
108
|
-
width: PropTypes.number.isRequired,
|
|
109
|
-
height: PropTypes.number.isRequired,
|
|
110
|
-
horizontalDirection: PropTypes.oneOf(["left", "right"]).isRequired,
|
|
111
|
-
verticalDirection: PropTypes.oneOf(["top", "bottom"]).isRequired,
|
|
112
|
-
},
|
|
47
|
+
import type {Property} from "csstype";
|
|
113
48
|
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
position: "relative",
|
|
117
|
-
visibility: "visible",
|
|
118
|
-
left: 0,
|
|
119
|
-
top: 0,
|
|
120
|
-
};
|
|
121
|
-
},
|
|
49
|
+
const zIndex = 10;
|
|
122
50
|
|
|
51
|
+
export enum HorizontalDirection {
|
|
52
|
+
Left = "left",
|
|
53
|
+
Right = "right",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export enum VerticalDirection {
|
|
57
|
+
Top = "top",
|
|
58
|
+
Bottom = "bottom",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type TriangleProps = {
|
|
62
|
+
color: string;
|
|
63
|
+
left: number;
|
|
64
|
+
top: number;
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
horizontalDirection: HorizontalDirection;
|
|
68
|
+
verticalDirection: VerticalDirection;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const Triangle = (props: TriangleProps) => {
|
|
72
|
+
let borderLeft;
|
|
73
|
+
let borderRight;
|
|
74
|
+
let borderTop;
|
|
75
|
+
let borderBottom;
|
|
76
|
+
|
|
77
|
+
const hBorder = `${props.width}px solid transparent`;
|
|
78
|
+
if (props.horizontalDirection === "right") {
|
|
79
|
+
borderLeft = hBorder;
|
|
80
|
+
} else {
|
|
81
|
+
borderRight = hBorder;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const vBorder = `${props.height}px solid ${props.color}`;
|
|
85
|
+
if (props.verticalDirection === "top") {
|
|
86
|
+
borderTop = vBorder;
|
|
87
|
+
} else {
|
|
88
|
+
borderBottom = vBorder;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
style={{
|
|
94
|
+
display: "block",
|
|
95
|
+
height: 0,
|
|
96
|
+
width: 0,
|
|
97
|
+
position: "absolute",
|
|
98
|
+
left: props.left,
|
|
99
|
+
top: props["top"],
|
|
100
|
+
borderLeft: borderLeft,
|
|
101
|
+
borderRight: borderRight,
|
|
102
|
+
borderTop: borderTop,
|
|
103
|
+
borderBottom: borderBottom,
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
type TooltipArrowProps = {
|
|
110
|
+
position: Property.Position;
|
|
111
|
+
visibility: Property.Visibility;
|
|
112
|
+
left: number;
|
|
113
|
+
top: number;
|
|
114
|
+
color: string; // a css color
|
|
115
|
+
border: string; // a css color
|
|
116
|
+
width: number;
|
|
117
|
+
height: number;
|
|
118
|
+
horizontalDirection: HorizontalDirection;
|
|
119
|
+
verticalDirection: VerticalDirection;
|
|
120
|
+
zIndex?: number;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const TooltipArrow = (props: TooltipArrowProps) => {
|
|
123
124
|
// TODO(aria): Think about adding a box-shadow to the triangle here
|
|
124
125
|
// See http://css-tricks.com/triangle-with-shadow/
|
|
125
|
-
render: function () {
|
|
126
|
-
//const isRight = (this.props.horizontalDirection === "right");
|
|
127
|
-
const isTop = this.props.verticalDirection === "top";
|
|
128
|
-
|
|
129
|
-
const frontTopOffset = isTop ? 0 : 1;
|
|
130
|
-
const borderTopOffset = isTop ? 0 : -1;
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
127
|
+
//const isRight = (this.props.horizontalDirection === "right");
|
|
128
|
+
const isTop = props.verticalDirection === "top";
|
|
129
|
+
|
|
130
|
+
const frontTopOffset = isTop ? 0 : 1;
|
|
131
|
+
const borderTopOffset = isTop ? 0 : -1;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div
|
|
135
|
+
style={{
|
|
136
|
+
display: "block",
|
|
137
|
+
position: props.position,
|
|
138
|
+
visibility: props.visibility,
|
|
139
|
+
left: props.left,
|
|
140
|
+
top: props["top"],
|
|
141
|
+
width: props.width + 2,
|
|
142
|
+
height: props.height + 1,
|
|
143
|
+
marginTop: -1,
|
|
144
|
+
marginBottom: -2,
|
|
145
|
+
zIndex: zIndex,
|
|
146
|
+
}}
|
|
147
|
+
>
|
|
148
|
+
{/* The background triangle used to create the effect of a
|
|
148
149
|
border around the foreground triangle*/}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
<Triangle
|
|
151
|
+
horizontalDirection={props.horizontalDirection}
|
|
152
|
+
verticalDirection={props.verticalDirection}
|
|
153
|
+
color={props.border}
|
|
154
|
+
left={0}
|
|
155
|
+
top={borderTopOffset}
|
|
156
|
+
width={props.width + 2} // one extra for the diagonal
|
|
157
|
+
height={props.height + 2}
|
|
158
|
+
/>
|
|
159
|
+
{/* The foreground triangle covers all but the left/right edges
|
|
159
160
|
of the background triangle */}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
161
|
+
<Triangle
|
|
162
|
+
horizontalDirection={props.horizontalDirection}
|
|
163
|
+
verticalDirection={props.verticalDirection}
|
|
164
|
+
color={props.color}
|
|
165
|
+
left={1}
|
|
166
|
+
top={frontTopOffset}
|
|
167
|
+
width={props.width}
|
|
168
|
+
height={props.height}
|
|
169
|
+
/>
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
TooltipArrow.defaultProps = {
|
|
175
|
+
position: "relative",
|
|
176
|
+
visibility: "visible",
|
|
177
|
+
left: 0,
|
|
178
|
+
top: 0,
|
|
179
|
+
};
|
|
173
180
|
|
|
174
181
|
const VERTICAL_CORNERS = {
|
|
175
182
|
top: {
|
|
@@ -201,52 +208,61 @@ const HORIZONTAL_ALIGNMNENTS = {
|
|
|
201
208
|
},
|
|
202
209
|
} as const;
|
|
203
210
|
|
|
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
|
-
|
|
211
|
+
type Props = {
|
|
212
|
+
show: boolean;
|
|
213
|
+
className: string;
|
|
214
|
+
arrowSize: number;
|
|
215
|
+
borderColor: string;
|
|
216
|
+
verticalPosition: VerticalDirection;
|
|
217
|
+
horizontalPosition: HorizontalDirection;
|
|
218
|
+
horizontalAlign: HorizontalDirection.Left;
|
|
219
|
+
children: React.ReactNode;
|
|
220
|
+
targetContainerStyle: any; // style object
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
type DefaultProps = {
|
|
224
|
+
className: Props["className"];
|
|
225
|
+
arrowSize: Props["arrowSize"];
|
|
226
|
+
borderColor: Props["borderColor"];
|
|
227
|
+
verticalPosition: Props["verticalPosition"];
|
|
228
|
+
horizontalPosition: Props["horizontalPosition"];
|
|
229
|
+
horizontalAlign: Props["horizontalAlign"];
|
|
230
|
+
targetContainerStyle: Props["targetContainerStyle"];
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
type State = {
|
|
234
|
+
height: number | null;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
class Tooltip extends React.Component<Props, State> {
|
|
238
|
+
static defaultProps: DefaultProps = {
|
|
239
|
+
className: "",
|
|
240
|
+
arrowSize: 10,
|
|
241
|
+
borderColor: "#ccc",
|
|
242
|
+
verticalPosition: VerticalDirection.Bottom,
|
|
243
|
+
horizontalPosition: HorizontalDirection.Left,
|
|
244
|
+
horizontalAlign: HorizontalDirection.Left,
|
|
245
|
+
targetContainerStyle: {},
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
state: State = {
|
|
249
|
+
height: null, // used for offsetting "top" positioned tooltips
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
componentDidMount() {
|
|
237
253
|
this._updateHeight();
|
|
238
|
-
}
|
|
254
|
+
}
|
|
239
255
|
|
|
240
|
-
UNSAFE_componentWillReceiveProps
|
|
256
|
+
UNSAFE_componentWillReceiveProps() {
|
|
241
257
|
// If the contents have changed, reset our measure of the height
|
|
242
258
|
this.setState({height: null});
|
|
243
|
-
}
|
|
259
|
+
}
|
|
244
260
|
|
|
245
|
-
componentDidUpdate
|
|
261
|
+
componentDidUpdate() {
|
|
246
262
|
this._updateHeight();
|
|
247
|
-
}
|
|
263
|
+
}
|
|
248
264
|
|
|
249
|
-
_renderToolTipDiv
|
|
265
|
+
_renderToolTipDiv(isTooltipAbove?: boolean) {
|
|
250
266
|
const settings = Object.assign(
|
|
251
267
|
{},
|
|
252
268
|
HORIZONTAL_CORNERS[this.props.horizontalPosition],
|
|
@@ -261,7 +277,7 @@ const Tooltip = createReactClass({
|
|
|
261
277
|
// We put an absolutely positioned arrow in the correct place
|
|
262
278
|
arrowAbove = (
|
|
263
279
|
<TooltipArrow
|
|
264
|
-
verticalDirection=
|
|
280
|
+
verticalDirection={VerticalDirection.Top}
|
|
265
281
|
horizontalDirection={this.props.horizontalAlign}
|
|
266
282
|
position="absolute"
|
|
267
283
|
color="white"
|
|
@@ -278,7 +294,7 @@ const Tooltip = createReactClass({
|
|
|
278
294
|
// content by the correct amount
|
|
279
295
|
arrowBelow = (
|
|
280
296
|
<TooltipArrow
|
|
281
|
-
verticalDirection=
|
|
297
|
+
verticalDirection={VerticalDirection.Top}
|
|
282
298
|
horizontalDirection={this.props.horizontalAlign}
|
|
283
299
|
visibility="hidden"
|
|
284
300
|
color="white"
|
|
@@ -293,7 +309,7 @@ const Tooltip = createReactClass({
|
|
|
293
309
|
} else {
|
|
294
310
|
arrowAbove = (
|
|
295
311
|
<TooltipArrow
|
|
296
|
-
verticalDirection=
|
|
312
|
+
verticalDirection={VerticalDirection.Bottom}
|
|
297
313
|
horizontalDirection={this.props.horizontalAlign}
|
|
298
314
|
color="white"
|
|
299
315
|
border={this.props.borderColor}
|
|
@@ -348,6 +364,7 @@ const Tooltip = createReactClass({
|
|
|
348
364
|
zIndex: zIndex - 1,
|
|
349
365
|
}}
|
|
350
366
|
>
|
|
367
|
+
{/* @ts-expect-error TS2533 - First child is target, rest is tooltip content */}
|
|
351
368
|
{this.props.children.slice(1)}
|
|
352
369
|
</div>
|
|
353
370
|
|
|
@@ -355,9 +372,9 @@ const Tooltip = createReactClass({
|
|
|
355
372
|
</div>
|
|
356
373
|
</div>
|
|
357
374
|
);
|
|
358
|
-
}
|
|
375
|
+
}
|
|
359
376
|
|
|
360
|
-
_updateHeight
|
|
377
|
+
_updateHeight() {
|
|
361
378
|
const tooltipContainer = ReactDOM.findDOMNode(
|
|
362
379
|
// eslint-disable-next-line react/no-string-refs
|
|
363
380
|
this.refs.tooltipContainer,
|
|
@@ -366,9 +383,9 @@ const Tooltip = createReactClass({
|
|
|
366
383
|
if (height !== this.state.height) {
|
|
367
384
|
this.setState({height});
|
|
368
385
|
}
|
|
369
|
-
}
|
|
386
|
+
}
|
|
370
387
|
|
|
371
|
-
render
|
|
388
|
+
render() {
|
|
372
389
|
const isTooltipAbove = this.props.verticalPosition === "top";
|
|
373
390
|
|
|
374
391
|
/* We wrap the entire output in a span so that it displays inline */
|
|
@@ -379,14 +396,15 @@ const Tooltip = createReactClass({
|
|
|
379
396
|
{/* We wrap our input in a div so that we can put the tooltip in a
|
|
380
397
|
div above/below it */}
|
|
381
398
|
<div style={this.props.targetContainerStyle}>
|
|
399
|
+
{/* @ts-expect-error TS2533 - First child is target, rest is tooltip content */}
|
|
382
400
|
{this.props.children[0]}
|
|
383
401
|
</div>
|
|
384
402
|
|
|
385
403
|
{!isTooltipAbove && this._renderToolTipDiv()}
|
|
386
404
|
</span>
|
|
387
405
|
);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
390
408
|
|
|
391
409
|
// Sorry. // Apology-Oriented-Programming
|
|
392
410
|
export default Tooltip;
|
|
@@ -136,8 +136,6 @@ class VisibilityTest extends React.Component<Props, State> {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
export const AlertWhenNotVisible: React.
|
|
140
|
-
args,
|
|
141
|
-
): React.ReactElement => {
|
|
139
|
+
export const AlertWhenNotVisible = (args: StoryArgs): React.ReactElement => {
|
|
142
140
|
return <VisibilityTest />;
|
|
143
141
|
};
|
package/src/error-boundary.tsx
CHANGED
|
@@ -2,18 +2,15 @@ import * as React from "react";
|
|
|
2
2
|
|
|
3
3
|
import {Errors, Log} from "./logging/log";
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type Props = {
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
};
|
|
8
|
-
type
|
|
8
|
+
type State = {
|
|
9
9
|
error: string;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
class ErrorBoundary extends React.Component<
|
|
13
|
-
|
|
14
|
-
ErrorBoundaryState
|
|
15
|
-
> {
|
|
16
|
-
constructor(props: ErrorBoundaryProps) {
|
|
12
|
+
class ErrorBoundary extends React.Component<Props, State> {
|
|
13
|
+
constructor(props: Props) {
|
|
17
14
|
super(props);
|
|
18
15
|
this.state = {error: ""};
|
|
19
16
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type Coord = [number, number];
|
|
2
|
-
export type Line = [Coord, Coord];
|
|
1
|
+
export type Coord = [number, number]; // x, y
|
|
2
|
+
export type Line = [Coord, Coord]; // start, end
|