@khanacademy/wonder-blocks-icon 5.1.3 → 5.2.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 +24 -0
- package/dist/components/custom-icon-components/gem-icon.d.ts +18 -0
- package/dist/components/custom-icon-components/streak-icon.d.ts +18 -0
- package/dist/components/icon.d.ts +39 -0
- package/dist/es/index.js +14 -64
- package/dist/hooks/use-image-role-attributes.d.ts +16 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -67
- package/dist/types.d.ts +29 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-icon
|
|
2
2
|
|
|
3
|
+
## 5.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 308696e: - Rename `useSvgAttributes` hook to `useImageRoleAttributes`
|
|
8
|
+
- Make the `useImageRoleAttributes` utility public
|
|
9
|
+
- dc34e0c: Adds `StreakIcon` custom icon component
|
|
10
|
+
- 2cace08: Add `Icon` component to support custom icons.
|
|
11
|
+
- f714517: Adds `GemIcon` custom icon component
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 8468d8d: Use `semanticColor` tokens for `GemIcon` and `StreakIcon` custom icon components
|
|
16
|
+
- Updated dependencies [8468d8d]
|
|
17
|
+
- @khanacademy/wonder-blocks-tokens@10.5.0
|
|
18
|
+
|
|
19
|
+
## 5.1.4
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [28fa0c0]
|
|
24
|
+
- Updated dependencies [28fa0c0]
|
|
25
|
+
- @khanacademy/wonder-blocks-core@12.3.0
|
|
26
|
+
|
|
3
27
|
## 5.1.3
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A custom icon component that renders a gem icon using an inline svg. Use
|
|
4
|
+
* with the `Icon` component to display the icon.
|
|
5
|
+
*
|
|
6
|
+
* The icon uses semantic color tokens for the different parts of the icon so
|
|
7
|
+
* it will respond to the current theme.
|
|
8
|
+
*/
|
|
9
|
+
declare const GemIcon: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
|
|
10
|
+
role?: import("@khanacademy/wonder-blocks-core").AriaRole;
|
|
11
|
+
}> & {
|
|
12
|
+
"aria-label"?: string;
|
|
13
|
+
"aria-labelledby"?: string;
|
|
14
|
+
id?: string;
|
|
15
|
+
testId?: string;
|
|
16
|
+
style?: import("@khanacademy/wonder-blocks-core").StyleType;
|
|
17
|
+
} & React.RefAttributes<SVGSVGElement>>;
|
|
18
|
+
export { GemIcon };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A custom icon component that renders a streak icon using an inline svg. Use
|
|
4
|
+
* with the `Icon` component to display the icon.
|
|
5
|
+
*
|
|
6
|
+
* The icon uses semantic color tokens for the different parts of the icon so
|
|
7
|
+
* it will respond to the current theme.
|
|
8
|
+
*/
|
|
9
|
+
declare const StreakIcon: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
|
|
10
|
+
role?: import("@khanacademy/wonder-blocks-core").AriaRole;
|
|
11
|
+
}> & {
|
|
12
|
+
"aria-label"?: string;
|
|
13
|
+
"aria-labelledby"?: string;
|
|
14
|
+
id?: string;
|
|
15
|
+
testId?: string;
|
|
16
|
+
style?: import("@khanacademy/wonder-blocks-core").StyleType;
|
|
17
|
+
} & React.RefAttributes<SVGSVGElement>>;
|
|
18
|
+
export { StreakIcon };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import { IconSize } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* A component for displaying a custom icon. The Icon component supports custom
|
|
6
|
+
* icons that are `img` elements or inline svg assets with their own fill.
|
|
7
|
+
*
|
|
8
|
+
* Related components:
|
|
9
|
+
* - For Phosphor icons, use the `PhosphorIcon` component.
|
|
10
|
+
* - For custom icons that are single colored svg assets, use the `PhosphorIcon`
|
|
11
|
+
* component, which supports changing the color of the icon.
|
|
12
|
+
* - If the icon is interactive, use `IconButton` instead.
|
|
13
|
+
*/
|
|
14
|
+
declare const Icon: React.ForwardRefExoticComponent<Readonly<import("@khanacademy/wonder-blocks-core").AriaAttributes> & Readonly<{
|
|
15
|
+
role?: import("@khanacademy/wonder-blocks-core").AriaRole;
|
|
16
|
+
}> & {
|
|
17
|
+
/**
|
|
18
|
+
* The id for the icon component.
|
|
19
|
+
*/
|
|
20
|
+
id?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The test id for the icon component.
|
|
23
|
+
*/
|
|
24
|
+
testId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Custom styles to apply to the icon component.
|
|
27
|
+
*/
|
|
28
|
+
style?: StyleType;
|
|
29
|
+
/**
|
|
30
|
+
* Size of the icon. One of `small` (16), `medium` (24), `large` (48), or
|
|
31
|
+
* `xlarge` (96). Defaults to `small`.
|
|
32
|
+
*/
|
|
33
|
+
size?: IconSize;
|
|
34
|
+
/**
|
|
35
|
+
* The icon to display. This can be an inline svg or an image.
|
|
36
|
+
*/
|
|
37
|
+
children: React.ReactElement;
|
|
38
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
39
|
+
export { Icon };
|
package/dist/es/index.js
CHANGED
|
@@ -1,69 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
2
|
import * as React from 'react';
|
|
4
|
-
import { StyleSheet } from 'aphrodite';
|
|
5
3
|
import { addStyle } from '@khanacademy/wonder-blocks-core';
|
|
4
|
+
import { StyleSheet } from 'aphrodite';
|
|
5
|
+
import { sizing, semanticColor } from '@khanacademy/wonder-blocks-tokens';
|
|
6
|
+
|
|
7
|
+
function getSize(size){switch(size){case"small":default:{return styles$1.small}case"medium":{return styles$1.medium}case"large":{return styles$1.large}case"xlarge":{return styles$1.xlarge}}}const StyledDiv=addStyle("div");const Icon=React.forwardRef((props,ref)=>{const{size="small",id,testId,style,children,...otherProps}=props;const childrenElement=React.cloneElement(children,{style:{width:"100%",height:"100%"}});return jsx(StyledDiv,{style:[getSize(size),style],id:id,"data-testid":testId,ref:ref,...otherProps,children:childrenElement})});const styles$1=StyleSheet.create({small:{width:sizing.size_160,height:sizing.size_160},medium:{width:sizing.size_240,height:sizing.size_240},large:{width:sizing.size_480,height:sizing.size_480},xlarge:{width:sizing.size_960,height:sizing.size_960}});
|
|
8
|
+
|
|
9
|
+
const viewportPixelsForSize=size=>({small:16,medium:24,large:48,xlarge:96})[size];
|
|
10
|
+
|
|
11
|
+
const StyledSpan=addStyle("span");const PhosphorIcon=React.forwardRef(function PhosphorIcon(props,ref){const{color="currentColor",icon,size="small",style,testId,className,role,...sharedProps}=props;const pixelSize=viewportPixelsForSize(size);const classNames=`${className??""}`;const iconStyles=_generateStyles(color,pixelSize);return jsx(StyledSpan,{...sharedProps,className:classNames,style:[styles.svg,iconStyles.icon,{maskImage:`url(${icon})`},style],"data-testid":testId,ref:ref,role:role??sharedProps["aria-label"]?"img":undefined})});const dynamicStyles={};const _generateStyles=(color,size)=>{const iconStyle=`${color}-${size}`;if(styles[iconStyle]){return styles[iconStyle]}const newStyles={icon:{backgroundColor:color,width:size,height:size}};dynamicStyles[iconStyle]=StyleSheet.create(newStyles);return dynamicStyles[iconStyle]};const styles=StyleSheet.create({svg:{display:"inline-block",verticalAlign:"text-bottom",flexShrink:0,flexGrow:0,maskSize:"100%",maskRepeat:"no-repeat",maskPosition:"center"}});PhosphorIcon.displayName="PhosphorIcon";
|
|
12
|
+
|
|
13
|
+
function useImageRoleAttributes(props){const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy}=props;const presentationOnlyAttributes={"aria-hidden":true};const iconMeaningAttributes={"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,role:"img"};const attributes=ariaLabel||ariaLabelledBy?iconMeaningAttributes:presentationOnlyAttributes;return attributes}
|
|
6
14
|
|
|
7
|
-
const
|
|
8
|
-
small: 16,
|
|
9
|
-
medium: 24,
|
|
10
|
-
large: 48,
|
|
11
|
-
xlarge: 96
|
|
12
|
-
})[size];
|
|
15
|
+
const StyledSvg$1=addStyle("svg");const GemIcon=React.forwardRef((props,ref)=>{const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,id,testId,style,...otherProps}=props;const attributes=useImageRoleAttributes({"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy});return jsxs(StyledSvg$1,{id:id,"data-testid":testId,style:style,ref:ref,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...attributes,...otherProps,children:[jsx("path",{d:"M1.246 5.38105L2.36444 3.66654C2.63609 3.25012 3.0934 3 3.58311 3H12.4169C12.9066 3 13.3639 3.25012 13.6356 3.66654L14.754 5.38105C15.1278 5.95411 15.0708 6.71389 14.6158 7.22195L9.08044 13.4027C8.49982 14.051 7.50018 14.051 6.91956 13.4027L1.38423 7.22195C0.929229 6.71389 0.872177 5.95411 1.246 5.38105Z",fill:semanticColor.core.foreground.gems.default}),jsx("path",{d:"M9.45654 7.01492L8.34027 10.0102C8.07911 10.711 8.97464 11.2595 9.48018 10.7084L12.6345 7.26989C13.0351 6.83317 12.7253 6.12858 12.1327 6.12858H10.7327C10.164 6.12858 9.65515 6.48199 9.45654 7.01492Z",fill:semanticColor.core.foreground.gems.subtle})]})});
|
|
13
16
|
|
|
14
|
-
const
|
|
15
|
-
const StyledSpan = addStyle("span");
|
|
16
|
-
const PhosphorIcon = React.forwardRef(function PhosphorIcon(props, ref) {
|
|
17
|
-
const {
|
|
18
|
-
color = "currentColor",
|
|
19
|
-
icon,
|
|
20
|
-
size = "small",
|
|
21
|
-
style,
|
|
22
|
-
testId,
|
|
23
|
-
className,
|
|
24
|
-
role
|
|
25
|
-
} = props,
|
|
26
|
-
sharedProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
27
|
-
const pixelSize = viewportPixelsForSize(size);
|
|
28
|
-
const classNames = `${className != null ? className : ""}`;
|
|
29
|
-
const iconStyles = _generateStyles(color, pixelSize);
|
|
30
|
-
return React.createElement(StyledSpan, _extends({}, sharedProps, {
|
|
31
|
-
className: classNames,
|
|
32
|
-
style: [styles.svg, iconStyles.icon, {
|
|
33
|
-
maskImage: `url(${icon})`
|
|
34
|
-
}, style],
|
|
35
|
-
"data-testid": testId,
|
|
36
|
-
ref: ref,
|
|
37
|
-
role: (role != null ? role : sharedProps["aria-label"]) ? "img" : undefined
|
|
38
|
-
}));
|
|
39
|
-
});
|
|
40
|
-
const dynamicStyles = {};
|
|
41
|
-
const _generateStyles = (color, size) => {
|
|
42
|
-
const iconStyle = `${color}-${size}`;
|
|
43
|
-
if (styles[iconStyle]) {
|
|
44
|
-
return styles[iconStyle];
|
|
45
|
-
}
|
|
46
|
-
const newStyles = {
|
|
47
|
-
icon: {
|
|
48
|
-
backgroundColor: color,
|
|
49
|
-
width: size,
|
|
50
|
-
height: size
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
dynamicStyles[iconStyle] = StyleSheet.create(newStyles);
|
|
54
|
-
return dynamicStyles[iconStyle];
|
|
55
|
-
};
|
|
56
|
-
const styles = StyleSheet.create({
|
|
57
|
-
svg: {
|
|
58
|
-
display: "inline-block",
|
|
59
|
-
verticalAlign: "text-bottom",
|
|
60
|
-
flexShrink: 0,
|
|
61
|
-
flexGrow: 0,
|
|
62
|
-
maskSize: "100%",
|
|
63
|
-
maskRepeat: "no-repeat",
|
|
64
|
-
maskPosition: "center"
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
PhosphorIcon.displayName = "PhosphorIcon";
|
|
17
|
+
const StyledSvg=addStyle("svg");const StreakIcon=React.forwardRef((props,ref)=>{const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,id,testId,style,...otherProps}=props;const attributes=useImageRoleAttributes({"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy});return jsxs(StyledSvg,{id:id,"data-testid":testId,style:style,ref:ref,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...attributes,...otherProps,children:[jsx("path",{d:"M9.14653 0.628361C9.07012 0.571421 8.97956 0.531782 8.88248 0.512785C8.78539 0.493787 8.68464 0.49599 8.5887 0.519205C8.49277 0.542421 8.40447 0.585969 8.33125 0.64618C8.25802 0.70639 8.20202 0.781496 8.16797 0.865168L5.47556 5.06034L4.59152 3.43463C4.52866 3.37998 4.45359 3.33789 4.37125 3.31114C4.28892 3.28438 4.2012 3.27357 4.11387 3.27941C4.02653 3.28525 3.94157 3.30761 3.86458 3.34502C3.78759 3.38243 3.72032 3.43403 3.66719 3.49644C1.98899 5.46729 1.13672 7.44994 1.13672 9.38884C1.13672 11.0096 1.85506 12.564 3.13372 13.7101C4.41238 14.8561 6.14661 15.5 7.9549 15.5C9.7632 15.5 11.4974 14.8561 12.7761 13.7101C14.0547 12.564 14.7731 11.0096 14.7731 9.38884C14.7731 5.26034 10.8379 1.88879 9.14653 0.628361Z",fill:semanticColor.core.foreground.streak.default}),jsx("path",{d:"M10.8067 10.5315C10.8067 12.0965 9.53809 13.3651 7.97318 13.3651C6.40826 13.3651 5.13965 12.0965 5.13965 10.5315C5.13965 8.96663 7.2648 6.28125 7.97318 6.28125C8.68156 6.28125 10.8067 8.96663 10.8067 10.5315Z",fill:semanticColor.core.foreground.streak.subtle})]})});
|
|
68
18
|
|
|
69
|
-
export { PhosphorIcon };
|
|
19
|
+
export { GemIcon, Icon, PhosphorIcon, StreakIcon, useImageRoleAttributes };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines what attributes should be applied to an icon based on if there is
|
|
3
|
+
* an accessible label for the icon.
|
|
4
|
+
*
|
|
5
|
+
* @returns The attributes to apply to an svg element.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useImageRoleAttributes(props: {
|
|
8
|
+
"aria-label"?: string;
|
|
9
|
+
"aria-labelledby"?: string;
|
|
10
|
+
}): {
|
|
11
|
+
"aria-hidden": boolean;
|
|
12
|
+
} | {
|
|
13
|
+
"aria-label": string | undefined;
|
|
14
|
+
"aria-labelledby": string | undefined;
|
|
15
|
+
role: string;
|
|
16
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
export { Icon } from "./components/icon";
|
|
1
2
|
export { PhosphorIcon } from "./components/phosphor-icon";
|
|
2
3
|
export type { IconSize, PhosphorIconAsset } from "./types";
|
|
4
|
+
export { GemIcon } from "./components/custom-icon-components/gem-icon";
|
|
5
|
+
export { StreakIcon } from "./components/custom-icon-components/streak-icon";
|
|
6
|
+
export { useImageRoleAttributes } from "./hooks/use-image-role-attributes";
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
6
|
var React = require('react');
|
|
8
|
-
var aphrodite = require('aphrodite');
|
|
9
7
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
var aphrodite = require('aphrodite');
|
|
9
|
+
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
12
10
|
|
|
13
11
|
function _interopNamespace(e) {
|
|
14
12
|
if (e && e.__esModule) return e;
|
|
@@ -28,70 +26,22 @@ function _interopNamespace(e) {
|
|
|
28
26
|
return Object.freeze(n);
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
32
|
-
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
33
29
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
34
30
|
|
|
35
|
-
const
|
|
36
|
-
small: 16,
|
|
37
|
-
medium: 24,
|
|
38
|
-
large: 48,
|
|
39
|
-
xlarge: 96
|
|
40
|
-
})[size];
|
|
31
|
+
function getSize(size){switch(size){case"small":default:{return styles$1.small}case"medium":{return styles$1.medium}case"large":{return styles$1.large}case"xlarge":{return styles$1.xlarge}}}const StyledDiv=wonderBlocksCore.addStyle("div");const Icon=React__namespace.forwardRef((props,ref)=>{const{size="small",id,testId,style,children,...otherProps}=props;const childrenElement=React__namespace.cloneElement(children,{style:{width:"100%",height:"100%"}});return jsxRuntime.jsx(StyledDiv,{style:[getSize(size),style],id:id,"data-testid":testId,ref:ref,...otherProps,children:childrenElement})});const styles$1=aphrodite.StyleSheet.create({small:{width:wonderBlocksTokens.sizing.size_160,height:wonderBlocksTokens.sizing.size_160},medium:{width:wonderBlocksTokens.sizing.size_240,height:wonderBlocksTokens.sizing.size_240},large:{width:wonderBlocksTokens.sizing.size_480,height:wonderBlocksTokens.sizing.size_480},xlarge:{width:wonderBlocksTokens.sizing.size_960,height:wonderBlocksTokens.sizing.size_960}});
|
|
41
32
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const PhosphorIcon
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
className,
|
|
52
|
-
role
|
|
53
|
-
} = props,
|
|
54
|
-
sharedProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded);
|
|
55
|
-
const pixelSize = viewportPixelsForSize(size);
|
|
56
|
-
const classNames = `${className != null ? className : ""}`;
|
|
57
|
-
const iconStyles = _generateStyles(color, pixelSize);
|
|
58
|
-
return React__namespace.createElement(StyledSpan, _extends__default["default"]({}, sharedProps, {
|
|
59
|
-
className: classNames,
|
|
60
|
-
style: [styles.svg, iconStyles.icon, {
|
|
61
|
-
maskImage: `url(${icon})`
|
|
62
|
-
}, style],
|
|
63
|
-
"data-testid": testId,
|
|
64
|
-
ref: ref,
|
|
65
|
-
role: (role != null ? role : sharedProps["aria-label"]) ? "img" : undefined
|
|
66
|
-
}));
|
|
67
|
-
});
|
|
68
|
-
const dynamicStyles = {};
|
|
69
|
-
const _generateStyles = (color, size) => {
|
|
70
|
-
const iconStyle = `${color}-${size}`;
|
|
71
|
-
if (styles[iconStyle]) {
|
|
72
|
-
return styles[iconStyle];
|
|
73
|
-
}
|
|
74
|
-
const newStyles = {
|
|
75
|
-
icon: {
|
|
76
|
-
backgroundColor: color,
|
|
77
|
-
width: size,
|
|
78
|
-
height: size
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
dynamicStyles[iconStyle] = aphrodite.StyleSheet.create(newStyles);
|
|
82
|
-
return dynamicStyles[iconStyle];
|
|
83
|
-
};
|
|
84
|
-
const styles = aphrodite.StyleSheet.create({
|
|
85
|
-
svg: {
|
|
86
|
-
display: "inline-block",
|
|
87
|
-
verticalAlign: "text-bottom",
|
|
88
|
-
flexShrink: 0,
|
|
89
|
-
flexGrow: 0,
|
|
90
|
-
maskSize: "100%",
|
|
91
|
-
maskRepeat: "no-repeat",
|
|
92
|
-
maskPosition: "center"
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
PhosphorIcon.displayName = "PhosphorIcon";
|
|
33
|
+
const viewportPixelsForSize=size=>({small:16,medium:24,large:48,xlarge:96})[size];
|
|
34
|
+
|
|
35
|
+
const StyledSpan=wonderBlocksCore.addStyle("span");const PhosphorIcon=React__namespace.forwardRef(function PhosphorIcon(props,ref){const{color="currentColor",icon,size="small",style,testId,className,role,...sharedProps}=props;const pixelSize=viewportPixelsForSize(size);const classNames=`${className??""}`;const iconStyles=_generateStyles(color,pixelSize);return jsxRuntime.jsx(StyledSpan,{...sharedProps,className:classNames,style:[styles.svg,iconStyles.icon,{maskImage:`url(${icon})`},style],"data-testid":testId,ref:ref,role:role??sharedProps["aria-label"]?"img":undefined})});const dynamicStyles={};const _generateStyles=(color,size)=>{const iconStyle=`${color}-${size}`;if(styles[iconStyle]){return styles[iconStyle]}const newStyles={icon:{backgroundColor:color,width:size,height:size}};dynamicStyles[iconStyle]=aphrodite.StyleSheet.create(newStyles);return dynamicStyles[iconStyle]};const styles=aphrodite.StyleSheet.create({svg:{display:"inline-block",verticalAlign:"text-bottom",flexShrink:0,flexGrow:0,maskSize:"100%",maskRepeat:"no-repeat",maskPosition:"center"}});PhosphorIcon.displayName="PhosphorIcon";
|
|
36
|
+
|
|
37
|
+
function useImageRoleAttributes(props){const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy}=props;const presentationOnlyAttributes={"aria-hidden":true};const iconMeaningAttributes={"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,role:"img"};const attributes=ariaLabel||ariaLabelledBy?iconMeaningAttributes:presentationOnlyAttributes;return attributes}
|
|
38
|
+
|
|
39
|
+
const StyledSvg$1=wonderBlocksCore.addStyle("svg");const GemIcon=React__namespace.forwardRef((props,ref)=>{const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,id,testId,style,...otherProps}=props;const attributes=useImageRoleAttributes({"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy});return jsxRuntime.jsxs(StyledSvg$1,{id:id,"data-testid":testId,style:style,ref:ref,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...attributes,...otherProps,children:[jsxRuntime.jsx("path",{d:"M1.246 5.38105L2.36444 3.66654C2.63609 3.25012 3.0934 3 3.58311 3H12.4169C12.9066 3 13.3639 3.25012 13.6356 3.66654L14.754 5.38105C15.1278 5.95411 15.0708 6.71389 14.6158 7.22195L9.08044 13.4027C8.49982 14.051 7.50018 14.051 6.91956 13.4027L1.38423 7.22195C0.929229 6.71389 0.872177 5.95411 1.246 5.38105Z",fill:wonderBlocksTokens.semanticColor.core.foreground.gems.default}),jsxRuntime.jsx("path",{d:"M9.45654 7.01492L8.34027 10.0102C8.07911 10.711 8.97464 11.2595 9.48018 10.7084L12.6345 7.26989C13.0351 6.83317 12.7253 6.12858 12.1327 6.12858H10.7327C10.164 6.12858 9.65515 6.48199 9.45654 7.01492Z",fill:wonderBlocksTokens.semanticColor.core.foreground.gems.subtle})]})});
|
|
40
|
+
|
|
41
|
+
const StyledSvg=wonderBlocksCore.addStyle("svg");const StreakIcon=React__namespace.forwardRef((props,ref)=>{const{"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,id,testId,style,...otherProps}=props;const attributes=useImageRoleAttributes({"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy});return jsxRuntime.jsxs(StyledSvg,{id:id,"data-testid":testId,style:style,ref:ref,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...attributes,...otherProps,children:[jsxRuntime.jsx("path",{d:"M9.14653 0.628361C9.07012 0.571421 8.97956 0.531782 8.88248 0.512785C8.78539 0.493787 8.68464 0.49599 8.5887 0.519205C8.49277 0.542421 8.40447 0.585969 8.33125 0.64618C8.25802 0.70639 8.20202 0.781496 8.16797 0.865168L5.47556 5.06034L4.59152 3.43463C4.52866 3.37998 4.45359 3.33789 4.37125 3.31114C4.28892 3.28438 4.2012 3.27357 4.11387 3.27941C4.02653 3.28525 3.94157 3.30761 3.86458 3.34502C3.78759 3.38243 3.72032 3.43403 3.66719 3.49644C1.98899 5.46729 1.13672 7.44994 1.13672 9.38884C1.13672 11.0096 1.85506 12.564 3.13372 13.7101C4.41238 14.8561 6.14661 15.5 7.9549 15.5C9.7632 15.5 11.4974 14.8561 12.7761 13.7101C14.0547 12.564 14.7731 11.0096 14.7731 9.38884C14.7731 5.26034 10.8379 1.88879 9.14653 0.628361Z",fill:wonderBlocksTokens.semanticColor.core.foreground.streak.default}),jsxRuntime.jsx("path",{d:"M10.8067 10.5315C10.8067 12.0965 9.53809 13.3651 7.97318 13.3651C6.40826 13.3651 5.13965 12.0965 5.13965 10.5315C5.13965 8.96663 7.2648 6.28125 7.97318 6.28125C8.68156 6.28125 10.8067 8.96663 10.8067 10.5315Z",fill:wonderBlocksTokens.semanticColor.core.foreground.streak.subtle})]})});
|
|
96
42
|
|
|
43
|
+
exports.GemIcon = GemIcon;
|
|
44
|
+
exports.Icon = Icon;
|
|
97
45
|
exports.PhosphorIcon = PhosphorIcon;
|
|
46
|
+
exports.StreakIcon = StreakIcon;
|
|
47
|
+
exports.useImageRoleAttributes = useImageRoleAttributes;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
1
2
|
/**
|
|
2
3
|
* All the possible icon weights.
|
|
3
4
|
*/
|
|
@@ -6,3 +7,31 @@ export type PhosphorIconAsset = PhosphorRegular | PhosphorBold | PhosphorFill;
|
|
|
6
7
|
* All the possible icon weights.
|
|
7
8
|
*/
|
|
8
9
|
export type IconSize = "small" | "medium" | "large" | "xlarge";
|
|
10
|
+
/**
|
|
11
|
+
* Common props for custom icon components.
|
|
12
|
+
*/
|
|
13
|
+
export type CustomIconProps = AriaProps & {
|
|
14
|
+
/**
|
|
15
|
+
* The alternative text for the icon. If `aria-label` or `aria-labelledby`
|
|
16
|
+
* is not provided, the icon will be marked with `aria-hidden=true`..
|
|
17
|
+
*/
|
|
18
|
+
"aria-label"?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The id of the element that provides the alternative text for the icon.
|
|
21
|
+
* If `aria-label` is not provided, the icon will be marked with
|
|
22
|
+
* `aria-hidden=true`.
|
|
23
|
+
*/
|
|
24
|
+
"aria-labelledby"?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The id for the element.
|
|
27
|
+
*/
|
|
28
|
+
id?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The test id for the element.
|
|
31
|
+
*/
|
|
32
|
+
testId?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The style for the element.
|
|
35
|
+
*/
|
|
36
|
+
style?: StyleType;
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-icon",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"author": "",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@
|
|
16
|
-
"@khanacademy/wonder-blocks-
|
|
15
|
+
"@khanacademy/wonder-blocks-core": "12.3.0",
|
|
16
|
+
"@khanacademy/wonder-blocks-tokens": "10.5.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@khanacademy/wb-dev-build-settings": "2.
|
|
19
|
+
"@khanacademy/wb-dev-build-settings": "3.2.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@phosphor-icons/core": "^2.0.2",
|