@khanacademy/wonder-blocks-core 12.1.0 → 12.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @khanacademy/wonder-blocks-core
2
2
 
3
+ ## 12.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ed26d66: Enables View to accept all tag names
8
+
9
+ ## 12.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - ee8d95a: Rollback rollup version from v4 to v2 to prevent an issue with CJS builds in unit tests
14
+
3
15
  ## 12.1.0
4
16
 
5
17
  ### Minor Changes
@@ -1,11 +1,10 @@
1
1
  import * as React from "react";
2
2
  import type { TextViewSharedProps } from "../util/types";
3
- type ValidViewTags = "div" | "article" | "aside" | "nav" | "section";
4
3
  type Props = TextViewSharedProps & {
5
4
  /**
6
5
  * The HTML tag to render.
7
6
  */
8
- tag?: ValidViewTags;
7
+ tag?: keyof JSX.IntrinsicElements;
9
8
  };
10
9
  /**
11
10
  * View is a building block for constructing other components. `View` roughly
package/dist/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import _extends from '@babel/runtime/helpers/extends';
2
2
  import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
3
3
  import * as React from 'react';
4
- import { useId, useEffect as useEffect$1, useContext as useContext$1 } from 'react';
4
+ import { useMemo, useId, useEffect as useEffect$1, useContext as useContext$1 } from 'react';
5
5
  import { StyleSheet, css } from 'aphrodite';
6
6
 
7
7
  function flatten(list) {
@@ -135,11 +135,6 @@ const styles = StyleSheet.create({
135
135
  minWidth: 0
136
136
  }
137
137
  });
138
- const StyledDiv = addStyle("div", styles.default);
139
- const StyledArticle = addStyle("article", styles.default);
140
- const StyledAside = addStyle("aside", styles.default);
141
- const StyledNav = addStyle("nav", styles.default);
142
- const StyledSection = addStyle("section", styles.default);
143
138
  const View = React.forwardRef(function View(props, ref) {
144
139
  const {
145
140
  testId,
@@ -149,30 +144,10 @@ const View = React.forwardRef(function View(props, ref) {
149
144
  const commonProps = _extends({}, restProps, {
150
145
  "data-testid": testId
151
146
  });
152
- switch (tag) {
153
- case "article":
154
- return React.createElement(StyledArticle, _extends({}, commonProps, {
155
- ref: ref
156
- }));
157
- case "aside":
158
- return React.createElement(StyledAside, _extends({}, commonProps, {
159
- ref: ref
160
- }));
161
- case "nav":
162
- return React.createElement(StyledNav, _extends({}, commonProps, {
163
- ref: ref
164
- }));
165
- case "section":
166
- return React.createElement(StyledSection, _extends({}, commonProps, {
167
- ref: ref
168
- }));
169
- case "div":
170
- return React.createElement(StyledDiv, _extends({}, commonProps, {
171
- ref: ref
172
- }));
173
- default:
174
- throw Error(`${tag} is not an allowed value for the 'tag' prop`);
175
- }
147
+ const StyledTag = useMemo(() => addStyle(tag, styles.default), [tag]);
148
+ return React.createElement(StyledTag, _extends({}, commonProps, {
149
+ ref: ref
150
+ }));
176
151
  });
177
152
 
178
153
  let RenderState = function (RenderState) {
package/dist/index.js CHANGED
@@ -1,11 +1,16 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var _extends = require('@babel/runtime/helpers/extends');
4
6
  var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
5
7
  var React = require('react');
6
8
  var aphrodite = require('aphrodite');
7
9
 
8
- function _interopNamespaceDefault(e) {
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
9
14
  var n = Object.create(null);
10
15
  if (e) {
11
16
  Object.keys(e).forEach(function (k) {
@@ -18,11 +23,13 @@ function _interopNamespaceDefault(e) {
18
23
  }
19
24
  });
20
25
  }
21
- n.default = e;
26
+ n["default"] = e;
22
27
  return Object.freeze(n);
23
28
  }
24
29
 
25
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
30
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
31
+ var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
32
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
33
 
27
34
  function flatten(list) {
28
35
  const result = [];
@@ -95,11 +102,11 @@ const Text = React__namespace.forwardRef(function Text(_ref, ref) {
95
102
  tag: Tag = "span",
96
103
  testId
97
104
  } = _ref,
98
- otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$2);
105
+ otherProps = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
99
106
  const isHeader = isHeaderRegex.test(Tag);
100
107
  const styleAttributes = processStyleList([styles$1.text, isHeader && styles$1.header, style]);
101
108
  const classNames = otherProps.className ? [otherProps.className, styleAttributes.className].join(" ") : styleAttributes.className;
102
- return (React__namespace.createElement(Tag, _extends({}, otherProps, {
109
+ return (React__namespace.createElement(Tag, _extends__default["default"]({}, otherProps, {
103
110
  style: styleAttributes.style,
104
111
  className: classNames,
105
112
  "data-testid": testId,
@@ -116,13 +123,13 @@ function addStyle(Component, defaultStyle) {
116
123
  className,
117
124
  style
118
125
  } = _ref,
119
- otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$1);
126
+ otherProps = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$1);
120
127
  const reset = typeof Component === "string" ? overrides[Component] : null;
121
128
  const {
122
129
  className: aphroditeClassName,
123
130
  style: inlineStyles
124
131
  } = processStyleList([reset, defaultStyle, style]);
125
- return React__namespace.createElement(Component, _extends({}, otherProps, {
132
+ return React__namespace.createElement(Component, _extends__default["default"]({}, otherProps, {
126
133
  ref: ref,
127
134
  className: [aphroditeClassName, className].filter(Boolean).join(" "),
128
135
  style: inlineStyles
@@ -155,44 +162,19 @@ const styles = aphrodite.StyleSheet.create({
155
162
  minWidth: 0
156
163
  }
157
164
  });
158
- const StyledDiv = addStyle("div", styles.default);
159
- const StyledArticle = addStyle("article", styles.default);
160
- const StyledAside = addStyle("aside", styles.default);
161
- const StyledNav = addStyle("nav", styles.default);
162
- const StyledSection = addStyle("section", styles.default);
163
165
  const View = React__namespace.forwardRef(function View(props, ref) {
164
166
  const {
165
167
  testId,
166
168
  tag = "div"
167
169
  } = props,
168
- restProps = _objectWithoutPropertiesLoose(props, _excluded);
169
- const commonProps = _extends({}, restProps, {
170
+ restProps = _objectWithoutPropertiesLoose__default["default"](props, _excluded);
171
+ const commonProps = _extends__default["default"]({}, restProps, {
170
172
  "data-testid": testId
171
173
  });
172
- switch (tag) {
173
- case "article":
174
- return React__namespace.createElement(StyledArticle, _extends({}, commonProps, {
175
- ref: ref
176
- }));
177
- case "aside":
178
- return React__namespace.createElement(StyledAside, _extends({}, commonProps, {
179
- ref: ref
180
- }));
181
- case "nav":
182
- return React__namespace.createElement(StyledNav, _extends({}, commonProps, {
183
- ref: ref
184
- }));
185
- case "section":
186
- return React__namespace.createElement(StyledSection, _extends({}, commonProps, {
187
- ref: ref
188
- }));
189
- case "div":
190
- return React__namespace.createElement(StyledDiv, _extends({}, commonProps, {
191
- ref: ref
192
- }));
193
- default:
194
- throw Error(`${tag} is not an allowed value for the 'tag' prop`);
195
- }
174
+ const StyledTag = React.useMemo(() => addStyle(tag, styles.default), [tag]);
175
+ return React__namespace.createElement(StyledTag, _extends__default["default"]({}, commonProps, {
176
+ ref: ref
177
+ }));
196
178
  });
197
179
 
198
180
  let RenderState = function (RenderState) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-core",
3
- "version": "12.1.0",
3
+ "version": "12.2.0",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,8 +20,8 @@
20
20
  "react-router-dom": "5.3.4"
21
21
  },
22
22
  "devDependencies": {
23
- "@khanacademy/wb-dev-build-settings": "2.1.0",
24
- "@khanacademy/wonder-blocks-testing-core": "2.1.0"
23
+ "@khanacademy/wb-dev-build-settings": "2.1.1",
24
+ "@khanacademy/wonder-blocks-testing-core": "2.2.0"
25
25
  },
26
26
  "author": "",
27
27
  "license": "MIT",