@khanacademy/wonder-blocks-icon-button 4.2.2 → 5.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @khanacademy/wonder-blocks-icon-button
2
2
 
3
+ ## 5.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - cc6b1950: Change `icon` type to use `PhosphorIcon` (instead of `Icon`).
8
+
3
9
  ## 4.2.2
4
10
 
5
11
  ### Patch Changes
@@ -1,14 +1,13 @@
1
1
  import * as React from "react";
2
- import type { IconAsset } from "@khanacademy/wonder-blocks-icon";
2
+ import type { PhosphorIconAsset } from "@khanacademy/wonder-blocks-icon";
3
3
  import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
4
4
  import { Link } from "react-router-dom";
5
5
  export type IconButtonSize = "xsmall" | "small" | "medium";
6
6
  export type SharedProps = Partial<Omit<AriaProps, "aria-disabled">> & {
7
7
  /**
8
- * A Wonder Blocks icon asset, an object specifing paths for one or more of
9
- * the following sizes: small, medium, large, xlarge.
8
+ * A Phosphor icon asset (imported as a static SVG file).
10
9
  */
11
- icon: IconAsset;
10
+ icon: PhosphorIconAsset;
12
11
  /**
13
12
  * The color of the icon button, either blue or red.
14
13
  */
@@ -99,41 +98,42 @@ export type SharedProps = Partial<Omit<AriaProps, "aria-disabled">> & {
99
98
  onClick?: (e: React.SyntheticEvent) => unknown;
100
99
  };
101
100
  /**
102
- * An IconButton is a button whose contents are an SVG image.
101
+ * An `IconButton` is a button whose contents are an SVG image.
103
102
  *
104
- * To use, supply an onClick function, a wonder-blocks icon asset (see
105
- * the Icon section) and an aria-label to describe the button functionality.
106
- * Optionally specify href (URL), clientSideNav, color
107
- * (Wonder Blocks Blue or Red), kind ("primary", "secondary", or "tertiary"),
108
- * light (whether the IconButton will be rendered on a dark background),
109
- * disabled , test ID, and custom styling.
103
+ * To use, supply an `onClick` function, a Phosphor icon asset (see the
104
+ * `Icon>PhosphorIcon` section) and an `aria-label` to describe the button
105
+ * functionality. Optionally specify href (URL), clientSideNav, color (Wonder
106
+ * Blocks Blue or Red), kind ("primary", "secondary", or "tertiary"), light
107
+ * (whether the IconButton will be rendered on a dark background), disabled ,
108
+ * test ID, and custom styling.
110
109
  *
111
- * The size of an IconButton matches the size of icon it wraps which is 24x24
112
- * pixels. The focus ring which is displayed on hover and focus is much
113
- * larger but does not affect its size. This matches the behavior of Button.
110
+ * The size of an `IconButton` is based on how the `size` prop is defined (see
111
+ * `Sizes` below for more details). The focus ring which is displayed on hover
112
+ * and focus is much larger but does not affect its size. This matches the
113
+ * behavior of Button.
114
114
  *
115
115
  * IconButtons require a certain amount of space between them to ensure the
116
- * focus rings don't overlap. The minimum amount of spacing is 16px, but
117
- * you should refer to the mocks provided by design. Using a Strut in between
116
+ * focus rings don't overlap. The minimum amount of spacing is 16px, but you
117
+ * should refer to the mocks provided by design. Using a Strut in between
118
118
  * IconButtons is the preferred way to for adding this spacing.
119
119
  *
120
120
  * Many layouts require alignment of visual left (or right) side of an
121
- * IconButton. This requires a little bit of pixel nudging since each icon
122
- * as a different amount of internal padding.
121
+ * `IconButton`. This requires a little bit of pixel nudging since each icon as
122
+ * a different amount of internal padding.
123
123
  *
124
- * See the Toolbar documentation for examples of IconButton use that follow
124
+ * See the Toolbar documentation for examples of `IconButton` use that follow
125
125
  * the best practices described above.
126
126
  *
127
127
  * ```js
128
- * import {icons} from "@khanacademy/wonder-blocks-icon";
128
+ * import magnifyingGlassIcon from "@phosphor-icons/core/regular/magnifying-glass.svg";
129
129
  * import IconButton from "@khanacademy/wonder-blocks-icon-button";
130
130
  *
131
131
  * <IconButton
132
- * icon={icons.anIcon}
132
+ * icon={magnifyingGlassIcon}
133
133
  * aria-label="An Icon"
134
134
  * onClick={(e) => console.log("Hello, world!")}
135
+ * size="medium"
135
136
  * />
136
137
  * ```
137
138
  */
138
- declare const IconButton: React.ForwardRefExoticComponent<SharedProps & React.RefAttributes<typeof Link | HTMLButtonElement | HTMLAnchorElement>>;
139
- export default IconButton;
139
+ export declare const IconButton: React.ForwardRefExoticComponent<SharedProps & React.RefAttributes<typeof Link | HTMLButtonElement | HTMLAnchorElement>>;
package/dist/es/index.js CHANGED
@@ -5,7 +5,7 @@ import { StyleSheet } from 'aphrodite';
5
5
  import { Link } from 'react-router-dom';
6
6
  import Color, { SemanticColor, mix, fade } from '@khanacademy/wonder-blocks-color';
7
7
  import { addStyle } from '@khanacademy/wonder-blocks-core';
8
- import Icon from '@khanacademy/wonder-blocks-icon';
8
+ import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
9
9
 
10
10
  function _objectDestructuringEmpty(obj) {
11
11
  if (obj == null) throw new TypeError("Cannot destructure " + obj);
@@ -56,6 +56,27 @@ const targetPixelsForSize = size => ({
56
56
  })[size];
57
57
 
58
58
  const _excluded$1 = ["color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "size", "skipClientNav", "style", "testId", "waiting"];
59
+ function IconChooser({
60
+ icon,
61
+ size
62
+ }) {
63
+ const iconSize = iconSizeForButtonSize(size);
64
+ switch (iconSize) {
65
+ case "small":
66
+ return React.createElement(PhosphorIcon, {
67
+ size: "small",
68
+ color: "currentColor",
69
+ icon: icon
70
+ });
71
+ case "medium":
72
+ default:
73
+ return React.createElement(PhosphorIcon, {
74
+ size: "medium",
75
+ color: "currentColor",
76
+ icon: icon
77
+ });
78
+ }
79
+ }
59
80
  const StyledAnchor = addStyle("a");
60
81
  const StyledButton = addStyle("button");
61
82
  const StyledLink = addStyle(Link);
@@ -80,9 +101,8 @@ const IconButtonCore = React.forwardRef(function IconButtonCore(props, ref) {
80
101
  const buttonColor = color === "destructive" ? SemanticColor.controlDestructive : SemanticColor.controlDefault;
81
102
  const buttonStyles = _generateStyles(buttonColor, kind, light, size);
82
103
  const defaultStyle = [sharedStyles.shared, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
83
- const child = React.createElement(Icon, {
84
- size: iconSizeForButtonSize(size),
85
- color: "currentColor",
104
+ const child = React.createElement(IconChooser, {
105
+ size: size,
86
106
  icon: icon
87
107
  });
88
108
  const commonProps = _extends({
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- import IconButton from "./components/icon-button";
2
- export { IconButton as default };
1
+ export { IconButton as default } from "./components/icon-button";
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var aphrodite = require('aphrodite');
7
7
  var reactRouterDom = require('react-router-dom');
8
8
  var Color = require('@khanacademy/wonder-blocks-color');
9
9
  var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
10
- var Icon = require('@khanacademy/wonder-blocks-icon');
10
+ var wonderBlocksIcon = require('@khanacademy/wonder-blocks-icon');
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
@@ -31,7 +31,6 @@ function _interopNamespace(e) {
31
31
 
32
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
33
  var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
34
- var Icon__default = /*#__PURE__*/_interopDefaultLegacy(Icon);
35
34
 
36
35
  function _objectDestructuringEmpty(obj) {
37
36
  if (obj == null) throw new TypeError("Cannot destructure " + obj);
@@ -82,6 +81,27 @@ const targetPixelsForSize = size => ({
82
81
  })[size];
83
82
 
84
83
  const _excluded$1 = ["color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "size", "skipClientNav", "style", "testId", "waiting"];
84
+ function IconChooser({
85
+ icon,
86
+ size
87
+ }) {
88
+ const iconSize = iconSizeForButtonSize(size);
89
+ switch (iconSize) {
90
+ case "small":
91
+ return React__namespace.createElement(wonderBlocksIcon.PhosphorIcon, {
92
+ size: "small",
93
+ color: "currentColor",
94
+ icon: icon
95
+ });
96
+ case "medium":
97
+ default:
98
+ return React__namespace.createElement(wonderBlocksIcon.PhosphorIcon, {
99
+ size: "medium",
100
+ color: "currentColor",
101
+ icon: icon
102
+ });
103
+ }
104
+ }
85
105
  const StyledAnchor = wonderBlocksCore.addStyle("a");
86
106
  const StyledButton = wonderBlocksCore.addStyle("button");
87
107
  const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
@@ -106,9 +126,8 @@ const IconButtonCore = React__namespace.forwardRef(function IconButtonCore(props
106
126
  const buttonColor = color === "destructive" ? Color.SemanticColor.controlDestructive : Color.SemanticColor.controlDefault;
107
127
  const buttonStyles = _generateStyles(buttonColor, kind, light, size);
108
128
  const defaultStyle = [sharedStyles.shared, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
109
- const child = React__namespace.createElement(Icon__default["default"], {
110
- size: iconSizeForButtonSize(size),
111
- color: "currentColor",
129
+ const child = React__namespace.createElement(IconChooser, {
130
+ size: size,
112
131
  icon: icon
113
132
  });
114
133
  const commonProps = _extends({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-icon-button",
3
- "version": "4.2.2",
3
+ "version": "5.0.0",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"