@khanacademy/wonder-blocks-icon 3.0.0 → 4.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 +6 -0
- package/dist/components/phosphor-icon.d.ts +6 -2
- package/dist/es/index.js +1 -159
- package/dist/index.d.ts +1 -6
- package/dist/index.js +0 -160
- package/dist/types.d.ts +4 -0
- package/dist/util/icon-util.d.ts +1 -16
- package/package.json +1 -1
- package/src/components/phosphor-icon.tsx +6 -2
- package/src/index.ts +1 -7
- package/src/types.ts +5 -0
- package/src/util/icon-util.test.ts +1 -80
- package/src/util/icon-util.ts +1 -49
- package/tsconfig-build.tsbuildinfo +1 -1
- package/dist/components/icon.d.ts +0 -70
- package/dist/util/icon-assets.d.ts +0 -31
- package/src/components/__tests__/icon.test.tsx +0 -152
- package/src/components/icon.tsx +0 -117
- package/src/util/icon-assets.test.ts +0 -35
- package/src/util/icon-assets.ts +0 -83
package/src/components/icon.tsx
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {StyleSheet} from "aphrodite";
|
|
3
|
-
|
|
4
|
-
import {addStyle} from "@khanacademy/wonder-blocks-core";
|
|
5
|
-
import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
|
|
6
|
-
import {getPathForIcon, viewportPixelsForSize} from "../util/icon-util";
|
|
7
|
-
|
|
8
|
-
import type {IconAsset, IconSize} from "../util/icon-assets";
|
|
9
|
-
|
|
10
|
-
type Props = AriaProps & {
|
|
11
|
-
/**
|
|
12
|
-
* The color of the icon. Will default to `currentColor`, which means that
|
|
13
|
-
* it will take on the CSS `color` value from the parent element.
|
|
14
|
-
*/
|
|
15
|
-
color?: string;
|
|
16
|
-
/**
|
|
17
|
-
* One of our named icons from icon-assets.js
|
|
18
|
-
*/
|
|
19
|
-
icon: IconAsset;
|
|
20
|
-
/**
|
|
21
|
-
* One of `small` (16px), `medium` (24px), `large` (48px),
|
|
22
|
-
* or `xlarge` (96px).
|
|
23
|
-
*/
|
|
24
|
-
size?: IconSize;
|
|
25
|
-
/**
|
|
26
|
-
* Styles that can be processed by `addStyle` — bare style objects,
|
|
27
|
-
* Aphrodite style objects, or arrays thereof.
|
|
28
|
-
*/
|
|
29
|
-
style?: StyleType;
|
|
30
|
-
/**
|
|
31
|
-
* Adds CSS classes to the Icon.
|
|
32
|
-
*/
|
|
33
|
-
className?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Test ID used for e2e testing.
|
|
36
|
-
*/
|
|
37
|
-
testId?: string;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const StyledSVG = addStyle("svg");
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* An Icon displays a small informational or decorative image as an SVG.
|
|
44
|
-
*
|
|
45
|
-
* ```js
|
|
46
|
-
* import Icon, {icons} from "@khanacademy/wonder-blocks-icon";
|
|
47
|
-
*
|
|
48
|
-
* <Icon
|
|
49
|
-
* icon={icons.search}
|
|
50
|
-
* color={Color.white}
|
|
51
|
-
* size="medium"
|
|
52
|
-
* style={{margin: 4}}
|
|
53
|
-
* />
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* Wonder Blocks comes with a fixed set of icons available by importing `icons`,
|
|
57
|
-
* but you can also provide your own `IconAsset`.
|
|
58
|
-
*
|
|
59
|
-
* ```js
|
|
60
|
-
* import Icon from "@khanacademy/wonder-blocks-icon";
|
|
61
|
-
* import type {IconAsset} from "@khanacademy/wonder-blocks-icon";
|
|
62
|
-
*
|
|
63
|
-
* // Easter egg: what shape am I?
|
|
64
|
-
* const customIcon: IconAsset = {
|
|
65
|
-
* small: "M6.92820 0L13.85640 4L13.85640 12L6.92820 16L0 12L0 4Z",
|
|
66
|
-
* };
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* `IconAsset` should be in the following format:
|
|
70
|
-
* ```js
|
|
71
|
-
* {small?: string, medium?: string, large?: string, xlarge?: string}
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* These icons should fit into a viewport of 16, 24, 48, and 96 pixels,
|
|
75
|
-
* respectively.
|
|
76
|
-
*/
|
|
77
|
-
const Icon = React.forwardRef(function Icon(
|
|
78
|
-
props: Props,
|
|
79
|
-
ref: React.ForwardedRef<SVGSVGElement>,
|
|
80
|
-
) {
|
|
81
|
-
const {
|
|
82
|
-
color = "currentColor",
|
|
83
|
-
icon,
|
|
84
|
-
size = "small",
|
|
85
|
-
style,
|
|
86
|
-
testId,
|
|
87
|
-
...sharedProps
|
|
88
|
-
} = props;
|
|
89
|
-
|
|
90
|
-
const {assetSize, path} = getPathForIcon(icon, size);
|
|
91
|
-
const pixelSize = viewportPixelsForSize(size);
|
|
92
|
-
const viewboxPixelSize = viewportPixelsForSize(assetSize);
|
|
93
|
-
return (
|
|
94
|
-
<StyledSVG
|
|
95
|
-
{...sharedProps}
|
|
96
|
-
style={[styles.svg, style]}
|
|
97
|
-
width={pixelSize}
|
|
98
|
-
height={pixelSize}
|
|
99
|
-
viewBox={`0 0 ${viewboxPixelSize} ${viewboxPixelSize}`}
|
|
100
|
-
data-test-id={testId}
|
|
101
|
-
ref={ref}
|
|
102
|
-
>
|
|
103
|
-
<path fill={color} d={path} />
|
|
104
|
-
</StyledSVG>
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const styles = StyleSheet.create({
|
|
109
|
-
svg: {
|
|
110
|
-
display: "inline-block",
|
|
111
|
-
verticalAlign: "text-bottom",
|
|
112
|
-
flexShrink: 0,
|
|
113
|
-
flexGrow: 0,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
export default Icon;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
describe("icons", () => {
|
|
2
|
-
test("default contains icons we expect", async () => {
|
|
3
|
-
// Arrange
|
|
4
|
-
|
|
5
|
-
// Act
|
|
6
|
-
// @ts-expect-error [FEI-5019] - TS2339 - Property '__esModule' does not exist on type 'typeof import("/Users/kevinbarabash/khan/wonder-blocks/packages/wonder-blocks-icon/src/util/icon-assets")'.
|
|
7
|
-
const {__esModule: _, ...icons} = await import("./icon-assets");
|
|
8
|
-
|
|
9
|
-
// Assert
|
|
10
|
-
expect(Object.keys(icons).sort()).toEqual(
|
|
11
|
-
[
|
|
12
|
-
"add",
|
|
13
|
-
"caretDown",
|
|
14
|
-
"caretLeft",
|
|
15
|
-
"caretRight",
|
|
16
|
-
"caretUp",
|
|
17
|
-
"check",
|
|
18
|
-
"contentArticle",
|
|
19
|
-
"contentExercise",
|
|
20
|
-
"contentVideo",
|
|
21
|
-
"correct",
|
|
22
|
-
"delete",
|
|
23
|
-
"dismiss",
|
|
24
|
-
"hint",
|
|
25
|
-
"incorrect",
|
|
26
|
-
"info",
|
|
27
|
-
"search",
|
|
28
|
-
"sortableArrowDown",
|
|
29
|
-
"sortableArrowUp",
|
|
30
|
-
"zoomIn",
|
|
31
|
-
"zoomOut",
|
|
32
|
-
].sort(),
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
});
|
package/src/util/icon-assets.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The source SVG paths for our icons at various sizes
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export type IconAsset = {
|
|
6
|
-
small?: string;
|
|
7
|
-
medium?: string;
|
|
8
|
-
large?: string;
|
|
9
|
-
xlarge?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type IconSize = keyof IconAsset;
|
|
13
|
-
|
|
14
|
-
export const add: IconAsset = {
|
|
15
|
-
medium: "M11 11V7a1 1 0 0 1 2 0v4h4a1 1 0 0 1 0 2h-4v4a1 1 0 0 1-2 0v-4H7a1 1 0 0 1 0-2h4zm1 13C5.373 24 0 18.627 0 12S5.373 0 12 0s12 5.373 12 12-5.373 12-12 12zm0-2c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z",
|
|
16
|
-
};
|
|
17
|
-
export const caretDown: IconAsset = {
|
|
18
|
-
small: "M8 8.586l3.293-3.293a1 1 0 0 1 1.414 1.414l-4 4a1 1 0 0 1-1.414 0l-4-4a1 1 0 0 1 1.414-1.414L8 8.586z",
|
|
19
|
-
medium: "M17.293 8.293a1 1 0 0 1 1.414 1.414l-6 6a1 1 0 0 1-1.414 0l-6-6a1 1 0 0 1 1.414-1.414L12 13.586l5.293-5.293z",
|
|
20
|
-
};
|
|
21
|
-
export const caretLeft: IconAsset = {
|
|
22
|
-
small: "M7.414 8l3.293 3.293a1 1 0 0 1-1.414 1.414l-4-4a1 1 0 0 1 0-1.414l4-4a1 1 0 0 1 1.414 1.414L7.414 8z",
|
|
23
|
-
medium: "M15.707 17.293a1 1 0 0 1-1.414 1.414l-6-6a1 1 0 0 1 0-1.414l6-6a1 1 0 0 1 1.414 1.414L10.414 12l5.293 5.293z",
|
|
24
|
-
};
|
|
25
|
-
export const caretRight: IconAsset = {
|
|
26
|
-
small: "M8.586 8L5.293 4.707a1 1 0 0 1 1.414-1.414l4 4a1 1 0 0 1 0 1.414l-4 4a1 1 0 0 1-1.414-1.414L8.586 8z",
|
|
27
|
-
medium: "M8.293 17.293a1 1 0 0 0 1.414 1.414l6-6a1 1 0 0 0 0-1.414l-6-6a1 1 0 0 0-1.414 1.414L13.586 12l-5.293 5.293z",
|
|
28
|
-
};
|
|
29
|
-
export const caretUp: IconAsset = {
|
|
30
|
-
small: "M8 7.414l-3.293 3.293a1 1 0 0 1-1.414-1.414l4-4a1 1 0 0 1 1.414 0l4 4a1 1 0 0 1-1.414 1.414L8 7.414z",
|
|
31
|
-
medium: "M17.293 15.707a1 1 0 0 0 1.414-1.414l-6-6a1 1 0 0 0-1.414 0l-6 6a1 1 0 0 0 1.414 1.414L12 10.414l5.293 5.293z",
|
|
32
|
-
};
|
|
33
|
-
export const check: IconAsset = {
|
|
34
|
-
small: "M6.072 10.4l6.175-7.058a1 1 0 1 1 1.506 1.317L6.769 12.64a1 1 0 0 1-1.55-.054L2.203 8.604a1 1 0 1 1 1.594-1.208L6.072 10.4z",
|
|
35
|
-
};
|
|
36
|
-
export const contentArticle: IconAsset = {
|
|
37
|
-
small: "M11 12V8h2v5a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1h3v2H5v8h6zM9.5 6a.5.5 0 0 1-.5-.5V2l4 4H9.5z",
|
|
38
|
-
medium: "M12 24C5.373 24 0 18.627 0 12S5.373 0 12 0s12 5.373 12 12-5.373 12-12 12zm0-2c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10zm3-6v-4h2v5a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h3v2H9v8h6zm-1.5-6a.5.5 0 0 1-.5-.5V6l4 4h-3.5z",
|
|
39
|
-
};
|
|
40
|
-
export const contentExercise: IconAsset = {
|
|
41
|
-
small: "M7.5 6.914L5 9.414V11h1.586l2.5-2.5L7.5 6.914zM8.914 5.5L10.5 7.086 11.586 6 10 4.414 8.914 5.5zM3 9a1 1 0 0 1 .293-.707l6-6a1 1 0 0 1 1.414 0l3 3a1 1 0 0 1 0 1.414l-6 6A1 1 0 0 1 7 13H4a1 1 0 0 1-1-1V9z",
|
|
42
|
-
medium: "M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10zm-.5-11.086l1.586 1.586-2.5 2.5H9v-1.586l2.5-2.5zM12.914 9.5L14 8.414 15.586 10 14.5 11.086 12.914 9.5zM12 24C5.373 24 0 18.627 0 12S5.373 0 12 0s12 5.373 12 12-5.373 12-12 12zM7 13v3a1 1 0 0 0 1 1h3a1 1 0 0 0 .707-.293l6-6a1 1 0 0 0 0-1.414l-3-3a1 1 0 0 0-1.414 0l-6 6A1 1 0 0 0 7 13z",
|
|
43
|
-
};
|
|
44
|
-
export const contentVideo: IconAsset = {
|
|
45
|
-
small: "M6 5.87v4.263l3.197-2.131L6 5.87zm-.445-2.7l6 4a1 1 0 0 1 0 1.664l-6 4A1 1 0 0 1 4 12.002v-8a1 1 0 0 1 1.555-.832z",
|
|
46
|
-
medium: "M12 24C5.373 24 0 18.627 0 12S5.373 0 12 0s12 5.373 12 12-5.373 12-12 12zm0-2c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10zM10.555 7.17l6 4a1 1 0 0 1 0 1.664l-6 4A1 1 0 0 1 9 16.002v-8a1 1 0 0 1 1.555-.832zM11 14.133l3.197-2.131L11 9.87v4.263z",
|
|
47
|
-
};
|
|
48
|
-
export const correct: IconAsset = {
|
|
49
|
-
medium: "M12 24C5.373 24 0 18.627 0 12S5.373 0 12 0s12 5.373 12 12-5.373 12-12 12zm0-2c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10zm-1.928-7.6l6.175-7.058a1 1 0 1 1 1.506 1.317l-6.984 7.981a1 1 0 0 1-1.55-.054l-3.016-3.982a1 1 0 0 1 1.594-1.208l2.275 3.003z",
|
|
50
|
-
};
|
|
51
|
-
const _delete: IconAsset = {
|
|
52
|
-
medium: "M12 24C5.373 24 0 18.627 0 12S5.373 0 12 0s12 5.373 12 12-5.373 12-12 12zm0-2c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10zm-5-9a1 1 0 0 1 0-2h10a1 1 0 0 1 0 2H7z",
|
|
53
|
-
};
|
|
54
|
-
export {_delete as delete};
|
|
55
|
-
export const dismiss: IconAsset = {
|
|
56
|
-
small: "M8 6.586l3.293-3.293a1 1 0 0 1 1.414 1.414L9.414 8l3.293 3.293a1 1 0 0 1-1.414 1.414L8 9.414l-3.293 3.293a1 1 0 1 1-1.414-1.414L6.586 8 3.293 4.707a1 1 0 0 1 1.414-1.414L8 6.586z",
|
|
57
|
-
medium: "M12 10.586L7.706 6.293a1 1 0 1 0-1.413 1.413L10.586 12l-4.293 4.294a1 1 0 0 0 1.413 1.413L12 13.414l4.294 4.293a1 1 0 0 0 1.413-1.413L13.414 12l4.293-4.294a1 1 0 1 0-1.413-1.413L12 10.586z",
|
|
58
|
-
};
|
|
59
|
-
export const hint: IconAsset = {
|
|
60
|
-
medium: "M10.835 15.993a1 1 0 0 1 1.008-.247 5.5 5.5 0 1 0-3.59-3.59 1 1 0 0 1-.246 1.009L6.172 15 9 17.828l1.835-1.835zm-.78 3.61a1.496 1.496 0 0 1-2.11 0l-3.548-3.549a1.496 1.496 0 0 1 0-2.108l1.787-1.787a7.5 7.5 0 1 1 5.657 5.657l-1.787 1.787zm-6.762.104a1 1 0 0 1 1.414-1.414l1 1a1 1 0 0 1-1.414 1.414l-1-1z",
|
|
61
|
-
};
|
|
62
|
-
export const incorrect: IconAsset = {
|
|
63
|
-
medium: "M12 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414L13.414 12l3.293 3.293a1 1 0 0 1-1.414 1.414L12 13.414l-3.293 3.293a1 1 0 1 1-1.414-1.414L10.586 12 7.293 8.707a1 1 0 0 1 1.414-1.414L12 10.586zM12 24C5.373 24 0 18.627 0 12S5.373 0 12 0s12 5.373 12 12-5.373 12-12 12zm0-2c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z",
|
|
64
|
-
};
|
|
65
|
-
export const info: IconAsset = {
|
|
66
|
-
small: "M8 16A8 8 0 1 1 8 0a8 8 0 0 1 0 16zm0-2A6 6 0 1 0 8 2a6 6 0 0 0 0 12zM7 8a1 1 0 1 1 2 0v3a1 1 0 0 1-2 0V8zm1-2a1 1 0 1 1 0-2 1 1 0 0 1 0 2z",
|
|
67
|
-
};
|
|
68
|
-
export const search: IconAsset = {
|
|
69
|
-
small: "M11.172 9.757l2.535 2.536a1 1 0 0 1-1.414 1.414l-2.536-2.535a5 5 0 1 1 1.414-1.414zM7 10a3 3 0 1 0 0-6 3 3 0 0 0 0 6z",
|
|
70
|
-
medium: "M11 17a6 6 0 1 0 0-12 6 6 0 0 0 0 12zm6.32-1.094l3.387 3.387a1 1 0 0 1-1.414 1.414l-3.387-3.387a8 8 0 1 1 1.414-1.414z",
|
|
71
|
-
};
|
|
72
|
-
export const sortableArrowDown: IconAsset = {
|
|
73
|
-
small: "M7 9.586V4a1 1 0 1 1 2 0v5.586l2.293-2.293a1 1 0 0 1 1.414 1.414l-4 4a1 1 0 0 1-1.414 0l-4-4a1 1 0 0 1 1.414-1.414L7 9.586z",
|
|
74
|
-
};
|
|
75
|
-
export const sortableArrowUp: IconAsset = {
|
|
76
|
-
small: "M9 6.414l2.293 2.293a1 1 0 0 0 1.414-1.414l-4-4a1 1 0 0 0-1.414 0l-4 4a1 1 0 0 0 1.414 1.414L7 6.414V12a1 1 0 1 0 2 0V6.414z",
|
|
77
|
-
};
|
|
78
|
-
export const zoomIn: IconAsset = {
|
|
79
|
-
medium: "M17.32 15.906l3.387 3.387a1 1 0 0 1-1.414 1.414l-3.387-3.387a8 8 0 1 1 1.414-1.414zM12 10h2a1 1 0 0 1 0 2h-2v2a1 1 0 0 1-2 0v-2H8a1 1 0 0 1 0-2h2V8a1 1 0 0 1 2 0v2zm-1 7a6 6 0 1 0 0-12 6 6 0 0 0 0 12z",
|
|
80
|
-
};
|
|
81
|
-
export const zoomOut: IconAsset = {
|
|
82
|
-
medium: "M17.32 15.906l3.387 3.387a1 1 0 0 1-1.414 1.414l-3.387-3.387a8 8 0 1 1 1.414-1.414zM11 17a6 6 0 1 0 0-12 6 6 0 0 0 0 12zm-3-5a1 1 0 0 1 0-2h6a1 1 0 0 1 0 2H8z",
|
|
83
|
-
};
|