@khanacademy/wonder-blocks-icon 3.0.0 → 4.0.1

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @khanacademy/wonder-blocks-icon
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 23ab9f8c: Added `role="img"` docs to PhosphorIcon. Fixed a11y issue to banners by adding the img role to the icons in each banner"
8
+ - Updated dependencies [6df21f71]
9
+ - @khanacademy/wonder-blocks-core@6.3.1
10
+
11
+ ## 4.0.0
12
+
13
+ ### Major Changes
14
+
15
+ - 171e3b01: Delete Icon component in favor of PhosphorIcon
16
+
3
17
  ## 3.0.0
4
18
 
5
19
  ### Major Changes
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
3
- import { PhosphorIconAsset } from "../types";
3
+ import { IconSize, PhosphorIconAsset } from "../types";
4
4
  /**
5
5
  * A `PhosphorIcon` displays a small informational or decorative image as an
6
6
  * HTML element that renders a Phosphor Icon SVG available from the
@@ -40,11 +40,20 @@ export declare const PhosphorIcon: React.ForwardRefExoticComponent<Pick<AriaProp
40
40
  * Adds CSS classes to the Icon.
41
41
  */
42
42
  className?: string | undefined;
43
+ /**
44
+ * The role of the icon.
45
+ * @see https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA24
46
+ */
47
+ role?: "img" | undefined;
48
+ /**
49
+ * Size of the icon. One of `small` (16), `medium` (24), `large` (48), or
50
+ * `xlarge` (96). Defaults to `small`.
51
+ */
52
+ size?: IconSize | undefined;
43
53
  /**
44
54
  * Test ID used for e2e testing.
45
55
  */
46
56
  testId?: string | undefined;
47
- size?: "medium" | "large" | "small" | "xlarge" | undefined;
48
57
  /**
49
58
  * The icon to display. This is a reference to the icon asset (imported as a
50
59
  * static SVG file).
package/dist/es/index.js CHANGED
@@ -36,164 +36,6 @@ const viewportPixelsForSize = size => ({
36
36
  large: 48,
37
37
  xlarge: 96
38
38
  })[size];
39
- const getPathForIcon = (icon, size) => {
40
- if (typeof icon[size] === "number") {
41
- return {
42
- assetSize: size,
43
- path: icon[size]
44
- };
45
- } else {
46
- const desiredPixelSize = viewportPixelsForSize(size);
47
- const availableSizes = Object.keys(icon);
48
- const sortFn = availableSize => {
49
- const availablePixelSize = viewportPixelsForSize(availableSize);
50
- const tooLargeByPixels = availablePixelSize - desiredPixelSize;
51
- return tooLargeByPixels > 0 ? Number.POSITIVE_INFINITY : Math.abs(tooLargeByPixels);
52
- };
53
- const assetSizes = availableSizes.sort((a, b) => sortFn(a) - sortFn(b));
54
- const bestAssetSize = assetSizes[0];
55
- if (bestAssetSize && icon[bestAssetSize]) {
56
- return {
57
- assetSize: bestAssetSize,
58
- path: icon[bestAssetSize]
59
- };
60
- } else {
61
- throw new Error("Icon does not contain any valid asset sizes!");
62
- }
63
- }
64
- };
65
-
66
- const _excluded$1 = ["color", "icon", "size", "style", "testId"];
67
- const StyledSVG = addStyle("svg");
68
- const Icon = React.forwardRef(function Icon(props, ref) {
69
- const {
70
- color = "currentColor",
71
- icon,
72
- size = "small",
73
- style,
74
- testId
75
- } = props,
76
- sharedProps = _objectWithoutPropertiesLoose(props, _excluded$1);
77
- const {
78
- assetSize,
79
- path
80
- } = getPathForIcon(icon, size);
81
- const pixelSize = viewportPixelsForSize(size);
82
- const viewboxPixelSize = viewportPixelsForSize(assetSize);
83
- return React.createElement(StyledSVG, _extends({}, sharedProps, {
84
- style: [styles$1.svg, style],
85
- width: pixelSize,
86
- height: pixelSize,
87
- viewBox: `0 0 ${viewboxPixelSize} ${viewboxPixelSize}`,
88
- "data-test-id": testId,
89
- ref: ref
90
- }), React.createElement("path", {
91
- fill: color,
92
- d: path
93
- }));
94
- });
95
- const styles$1 = StyleSheet.create({
96
- svg: {
97
- display: "inline-block",
98
- verticalAlign: "text-bottom",
99
- flexShrink: 0,
100
- flexGrow: 0
101
- }
102
- });
103
-
104
- const add = {
105
- 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"
106
- };
107
- const caretDown = {
108
- 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",
109
- 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"
110
- };
111
- const caretLeft = {
112
- 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",
113
- 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"
114
- };
115
- const caretRight = {
116
- 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",
117
- 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"
118
- };
119
- const caretUp = {
120
- 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",
121
- 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"
122
- };
123
- const check = {
124
- 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"
125
- };
126
- const contentArticle = {
127
- 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",
128
- 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"
129
- };
130
- const contentExercise = {
131
- 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",
132
- 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"
133
- };
134
- const contentVideo = {
135
- 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",
136
- 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"
137
- };
138
- const correct = {
139
- 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"
140
- };
141
- const _delete = {
142
- 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"
143
- };
144
- const dismiss = {
145
- 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",
146
- 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"
147
- };
148
- const hint = {
149
- 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"
150
- };
151
- const incorrect = {
152
- 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"
153
- };
154
- const info = {
155
- 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"
156
- };
157
- const search = {
158
- 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",
159
- 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"
160
- };
161
- const sortableArrowDown = {
162
- 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"
163
- };
164
- const sortableArrowUp = {
165
- 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"
166
- };
167
- const zoomIn = {
168
- 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"
169
- };
170
- const zoomOut = {
171
- 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"
172
- };
173
-
174
- var iconAssets = /*#__PURE__*/Object.freeze({
175
- __proto__: null,
176
- add: add,
177
- caretDown: caretDown,
178
- caretLeft: caretLeft,
179
- caretRight: caretRight,
180
- caretUp: caretUp,
181
- check: check,
182
- contentArticle: contentArticle,
183
- contentExercise: contentExercise,
184
- contentVideo: contentVideo,
185
- correct: correct,
186
- 'delete': _delete,
187
- dismiss: dismiss,
188
- hint: hint,
189
- incorrect: incorrect,
190
- info: info,
191
- search: search,
192
- sortableArrowDown: sortableArrowDown,
193
- sortableArrowUp: sortableArrowUp,
194
- zoomIn: zoomIn,
195
- zoomOut: zoomOut
196
- });
197
39
 
198
40
  const _excluded = ["color", "icon", "size", "style", "testId", "className"];
199
41
  const StyledIcon = addStyle("span");
@@ -248,4 +90,4 @@ const styles = StyleSheet.create({
248
90
  });
249
91
  PhosphorIcon.displayName = "PhosphorIcon";
250
92
 
251
- export { PhosphorIcon, Icon as default, iconAssets as icons };
93
+ export { PhosphorIcon };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,2 @@
1
- import Icon from "./components/icon";
2
- import type { IconAsset, IconSize } from "./util/icon-assets";
3
- export * as icons from "./util/icon-assets";
4
1
  export { PhosphorIcon } from "./components/phosphor-icon";
5
- export type { PhosphorIconAsset } from "./types";
6
- export type { IconAsset, IconSize };
7
- export default Icon;
2
+ export type { IconSize, PhosphorIconAsset } from "./types";
package/dist/index.js CHANGED
@@ -60,164 +60,6 @@ const viewportPixelsForSize = size => ({
60
60
  large: 48,
61
61
  xlarge: 96
62
62
  })[size];
63
- const getPathForIcon = (icon, size) => {
64
- if (typeof icon[size] === "number") {
65
- return {
66
- assetSize: size,
67
- path: icon[size]
68
- };
69
- } else {
70
- const desiredPixelSize = viewportPixelsForSize(size);
71
- const availableSizes = Object.keys(icon);
72
- const sortFn = availableSize => {
73
- const availablePixelSize = viewportPixelsForSize(availableSize);
74
- const tooLargeByPixels = availablePixelSize - desiredPixelSize;
75
- return tooLargeByPixels > 0 ? Number.POSITIVE_INFINITY : Math.abs(tooLargeByPixels);
76
- };
77
- const assetSizes = availableSizes.sort((a, b) => sortFn(a) - sortFn(b));
78
- const bestAssetSize = assetSizes[0];
79
- if (bestAssetSize && icon[bestAssetSize]) {
80
- return {
81
- assetSize: bestAssetSize,
82
- path: icon[bestAssetSize]
83
- };
84
- } else {
85
- throw new Error("Icon does not contain any valid asset sizes!");
86
- }
87
- }
88
- };
89
-
90
- const _excluded$1 = ["color", "icon", "size", "style", "testId"];
91
- const StyledSVG = wonderBlocksCore.addStyle("svg");
92
- const Icon = React__namespace.forwardRef(function Icon(props, ref) {
93
- const {
94
- color = "currentColor",
95
- icon,
96
- size = "small",
97
- style,
98
- testId
99
- } = props,
100
- sharedProps = _objectWithoutPropertiesLoose(props, _excluded$1);
101
- const {
102
- assetSize,
103
- path
104
- } = getPathForIcon(icon, size);
105
- const pixelSize = viewportPixelsForSize(size);
106
- const viewboxPixelSize = viewportPixelsForSize(assetSize);
107
- return React__namespace.createElement(StyledSVG, _extends({}, sharedProps, {
108
- style: [styles$1.svg, style],
109
- width: pixelSize,
110
- height: pixelSize,
111
- viewBox: `0 0 ${viewboxPixelSize} ${viewboxPixelSize}`,
112
- "data-test-id": testId,
113
- ref: ref
114
- }), React__namespace.createElement("path", {
115
- fill: color,
116
- d: path
117
- }));
118
- });
119
- const styles$1 = aphrodite.StyleSheet.create({
120
- svg: {
121
- display: "inline-block",
122
- verticalAlign: "text-bottom",
123
- flexShrink: 0,
124
- flexGrow: 0
125
- }
126
- });
127
-
128
- const add = {
129
- 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"
130
- };
131
- const caretDown = {
132
- 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",
133
- 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"
134
- };
135
- const caretLeft = {
136
- 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",
137
- 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"
138
- };
139
- const caretRight = {
140
- 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",
141
- 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"
142
- };
143
- const caretUp = {
144
- 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",
145
- 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"
146
- };
147
- const check = {
148
- 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"
149
- };
150
- const contentArticle = {
151
- 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",
152
- 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"
153
- };
154
- const contentExercise = {
155
- 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",
156
- 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"
157
- };
158
- const contentVideo = {
159
- 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",
160
- 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"
161
- };
162
- const correct = {
163
- 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"
164
- };
165
- const _delete = {
166
- 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"
167
- };
168
- const dismiss = {
169
- 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",
170
- 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"
171
- };
172
- const hint = {
173
- 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"
174
- };
175
- const incorrect = {
176
- 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"
177
- };
178
- const info = {
179
- 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"
180
- };
181
- const search = {
182
- 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",
183
- 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"
184
- };
185
- const sortableArrowDown = {
186
- 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"
187
- };
188
- const sortableArrowUp = {
189
- 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"
190
- };
191
- const zoomIn = {
192
- 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"
193
- };
194
- const zoomOut = {
195
- 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"
196
- };
197
-
198
- var iconAssets = /*#__PURE__*/Object.freeze({
199
- __proto__: null,
200
- add: add,
201
- caretDown: caretDown,
202
- caretLeft: caretLeft,
203
- caretRight: caretRight,
204
- caretUp: caretUp,
205
- check: check,
206
- contentArticle: contentArticle,
207
- contentExercise: contentExercise,
208
- contentVideo: contentVideo,
209
- correct: correct,
210
- 'delete': _delete,
211
- dismiss: dismiss,
212
- hint: hint,
213
- incorrect: incorrect,
214
- info: info,
215
- search: search,
216
- sortableArrowDown: sortableArrowDown,
217
- sortableArrowUp: sortableArrowUp,
218
- zoomIn: zoomIn,
219
- zoomOut: zoomOut
220
- });
221
63
 
222
64
  const _excluded = ["color", "icon", "size", "style", "testId", "className"];
223
65
  const StyledIcon = wonderBlocksCore.addStyle("span");
@@ -273,5 +115,3 @@ const styles = aphrodite.StyleSheet.create({
273
115
  PhosphorIcon.displayName = "PhosphorIcon";
274
116
 
275
117
  exports.PhosphorIcon = PhosphorIcon;
276
- exports["default"] = Icon;
277
- exports.icons = iconAssets;
package/dist/types.d.ts CHANGED
@@ -2,3 +2,7 @@
2
2
  * All the possible icon weights.
3
3
  */
4
4
  export type PhosphorIconAsset = PhosphorRegular | PhosphorBold | PhosphorFill;
5
+ /**
6
+ * All the possible icon weights.
7
+ */
8
+ export type IconSize = "small" | "medium" | "large" | "xlarge";
@@ -1,21 +1,6 @@
1
- import type { IconAsset, IconSize } from "./icon-assets";
1
+ import { IconSize } from "../types";
2
2
  /**
3
3
  * A simple function that tells us how many viewport pixels each icon size
4
4
  * corresponds to.
5
5
  */
6
6
  export declare const viewportPixelsForSize: (size: IconSize) => number;
7
- /**
8
- * A utility to find the right asset from an IconAsset to display in an icon
9
- * at a given IconSize. We're looking for, in the following order:
10
- * 1. The path for the IconSize (e.g. small, medium) requested
11
- * 2. A path that's _smaller_ than the size we requested
12
- * 3. Any path (what remains is one for a larger IconSize)
13
- *
14
- * The goal here is to provide a path that looks good at the given size...
15
- * obviously, if the size that we want is provided, we'll use it. Otherwise we'd
16
- * rather blow up a smaller, simpler icon than scrunch down a more complex one.
17
- */
18
- export declare const getPathForIcon: (icon: IconAsset, size: IconSize) => {
19
- assetSize: IconSize;
20
- path: string;
21
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-icon",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,7 +16,7 @@
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-core": "^6.3.0"
19
+ "@khanacademy/wonder-blocks-core": "^6.3.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@khanacademy/wonder-stuff-core": "^1.4.2",
@@ -25,20 +25,24 @@ describe("PhosphorIcon", () => {
25
25
  expect(ref.current).toBeInstanceOf(HTMLSpanElement);
26
26
  });
27
27
 
28
+ it("applies role to icon", async () => {
29
+ // Arrange
30
+
31
+ // Act
32
+ render(<PhosphorIcon icon={Plus} role="img" />);
33
+
34
+ // Assert
35
+ expect(screen.getByRole("img")).toBeInTheDocument();
36
+ });
37
+
28
38
  it("applies aria-label to icon", async () => {
29
39
  // Arrange
30
40
 
31
41
  // Act
32
- render(
33
- <PhosphorIcon
34
- icon={Plus}
35
- aria-label="something"
36
- testId="phosphor-icon"
37
- />,
38
- );
42
+ render(<PhosphorIcon icon={Plus} aria-label="something" role="img" />);
39
43
 
40
44
  // Assert
41
- expect(screen.getByTestId("phosphor-icon")).toHaveAttribute(
45
+ expect(screen.getByRole("img")).toHaveAttribute(
42
46
  "aria-label",
43
47
  "something",
44
48
  );
@@ -4,7 +4,7 @@ import {StyleSheet} from "aphrodite";
4
4
  import {addStyle, AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
5
5
 
6
6
  import {viewportPixelsForSize} from "../util/icon-util";
7
- import {PhosphorIconAsset} from "../types";
7
+ import {IconSize, PhosphorIconAsset} from "../types";
8
8
 
9
9
  // We use a span instead of an img because we want to use the mask-image CSS
10
10
  // property.
@@ -24,13 +24,24 @@ type Props = Pick<AriaProps, "aria-hidden" | "aria-label" | "role"> & {
24
24
  * Adds CSS classes to the Icon.
25
25
  */
26
26
  className?: string;
27
+
28
+ /**
29
+ * The role of the icon.
30
+ * @see https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA24
31
+ */
32
+ role?: "img";
33
+
34
+ /**
35
+ * Size of the icon. One of `small` (16), `medium` (24), `large` (48), or
36
+ * `xlarge` (96). Defaults to `small`.
37
+ */
38
+ size?: IconSize;
39
+
27
40
  /**
28
41
  * Test ID used for e2e testing.
29
42
  */
30
43
  testId?: string;
31
44
 
32
- size?: "small" | "medium" | "large" | "xlarge";
33
-
34
45
  /**
35
46
  * The icon to display. This is a reference to the icon asset (imported as a
36
47
  * static SVG file).
package/src/index.ts CHANGED
@@ -1,8 +1,2 @@
1
- import Icon from "./components/icon";
2
- import type {IconAsset, IconSize} from "./util/icon-assets";
3
-
4
- export * as icons from "./util/icon-assets";
5
1
  export {PhosphorIcon} from "./components/phosphor-icon";
6
- export type {PhosphorIconAsset} from "./types";
7
- export type {IconAsset, IconSize};
8
- export default Icon;
2
+ export type {IconSize, PhosphorIconAsset} from "./types";
package/src/types.ts CHANGED
@@ -2,3 +2,8 @@
2
2
  * All the possible icon weights.
3
3
  */
4
4
  export type PhosphorIconAsset = PhosphorRegular | PhosphorBold | PhosphorFill;
5
+
6
+ /**
7
+ * All the possible icon weights.
8
+ */
9
+ export type IconSize = "small" | "medium" | "large" | "xlarge";
@@ -1,83 +1,4 @@
1
- import {getPathForIcon, viewportPixelsForSize} from "./icon-util";
2
-
3
- import type {IconSize, IconAsset} from "./icon-assets";
4
-
5
- const SIZES = ["small", "medium", "large", "xlarge"];
6
-
7
- const DUMMY_ICON_MEDIUM_ONLY = {
8
- medium: "[MEDIUM SVG PATH]",
9
- } as const;
10
-
11
- const DUMMY_ICON_WITH_EVERYTHING_ON_IT: IconAsset = {
12
- small: "[SMALL SVG PATH]",
13
- medium: "[MEDIUM SVG PATH]",
14
- large: "[LARGE SVG PATH]",
15
- xlarge: "[XLARGE SVG PATH]",
16
- };
17
-
18
- describe("getPathForIcon", () => {
19
- test("return the path for the correct size, if available", () => {
20
- SIZES.forEach((size: any) => {
21
- const {path, assetSize} = getPathForIcon(
22
- DUMMY_ICON_WITH_EVERYTHING_ON_IT,
23
- size,
24
- );
25
- expect(
26
- // @ts-expect-error [FEI-5019] - TS7053 - Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'IconAsset'.
27
- path === DUMMY_ICON_WITH_EVERYTHING_ON_IT[size] &&
28
- assetSize === size,
29
- ).toBeTruthy();
30
- });
31
- });
32
-
33
- test("scale up a small asset rather than scaling down a large one", () => {
34
- const expectValueForSize = (
35
- requestedSize: IconSize,
36
- returnedSize: IconSize,
37
- ) => {
38
- const iconMissingRequestedSize = {
39
- ...DUMMY_ICON_WITH_EVERYTHING_ON_IT,
40
- } as const;
41
- delete iconMissingRequestedSize[requestedSize];
42
- expect(
43
- getPathForIcon(iconMissingRequestedSize, requestedSize),
44
- ).toMatchObject({
45
- assetSize: returnedSize,
46
- path: DUMMY_ICON_WITH_EVERYTHING_ON_IT[returnedSize],
47
- });
48
- };
49
- expectValueForSize("small", "medium");
50
- expectValueForSize("medium", "small");
51
- expectValueForSize("large", "medium");
52
- expectValueForSize("xlarge", "large");
53
- });
54
-
55
- test("return a path as long as at least one size is available", () => {
56
- SIZES.forEach((size: any) => {
57
- const {path, assetSize} = getPathForIcon(
58
- DUMMY_ICON_MEDIUM_ONLY,
59
- size,
60
- );
61
- expect(
62
- path === DUMMY_ICON_MEDIUM_ONLY["medium"] &&
63
- assetSize === "medium",
64
- ).toBeTruthy();
65
- });
66
- });
67
-
68
- test("no valid asset sizes, throws", () => {
69
- // Arrange
70
- const iconAsset: IconAsset = {} as any;
71
-
72
- // Act
73
- const underTest = () => getPathForIcon(iconAsset, "medium");
74
-
75
- // Assert
76
- expect(underTest).toThrowErrorMatchingInlineSnapshot(
77
- `"Icon does not contain any valid asset sizes!"`,
78
- );
79
- });
80
- });
1
+ import {viewportPixelsForSize} from "./icon-util";
81
2
 
82
3
  describe("viewportPixelsForSize", () => {
83
4
  test("return the correct values", () => {