@planningcenter/tapestry-react 2.4.0 → 2.5.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.
@@ -54,8 +54,10 @@ function Button(_ref) {
54
54
  title = _ref.title,
55
55
  to = _ref.to,
56
56
  tooltip = _ref.tooltip,
57
+ _ref$type = _ref.type,
58
+ type = _ref$type === void 0 ? 'button' : _ref$type,
57
59
  variant = _ref.variant,
58
- restProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["children", "disabled", "external", "icon", "iconLeft", "iconRight", "onClick", "onKeyDown", "size", "spinner", "square", "theme", "title", "to", "tooltip", "variant"]);
60
+ restProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["children", "disabled", "external", "icon", "iconLeft", "iconRight", "onClick", "onKeyDown", "size", "spinner", "square", "theme", "title", "to", "tooltip", "type", "variant"]);
59
61
  var buttonThemes = (0, _system.useThemeValue)('button.themes');
60
62
 
61
63
  var _useBoxSize = (0, _system.useBoxSize)(size),
@@ -80,7 +82,8 @@ function Button(_ref) {
80
82
  strokeAlign: 'inside',
81
83
  strokeWeight: 1,
82
84
  userSelect: 'none',
83
- zIndex: 1
85
+ zIndex: 1,
86
+ type: type
84
87
  };
85
88
  var spinnerColor;
86
89
 
@@ -229,12 +232,13 @@ function Button(_ref) {
229
232
 
230
233
 
231
234
  if (restProps.as) {
232
- buttonProps.to = to;
233
- } // set button type to prevent nested buttons from unintentionally submiting forms
235
+ buttonProps.to = to; // remove type if it is not a button
234
236
 
235
-
236
- if (buttonProps.as === "button") {
237
- buttonProps.type = "button";
237
+ if (restProps.as !== "button") {
238
+ buttonProps = _objectSpread(_objectSpread({}, buttonProps), {}, {
239
+ type: null
240
+ });
241
+ }
238
242
  }
239
243
 
240
244
  if (process.env.NODE_ENV !== 'production') {
@@ -255,8 +259,8 @@ function Button(_ref) {
255
259
  restProps = (0, _utils.mergeProps)(restProps, wrapperProps);
256
260
  }
257
261
 
258
- if (restProps['type'] === 'submit') {
259
- throw Error("Tapestry-React: <Button/> does not support type=\"submit\" please add an explicit onClick handler.");
262
+ if (type && restProps.as && restProps.as !== "button") {
263
+ throw Error("Tapestry-React: <Button/> type prop is only supported by <button> and not <" + restProps.as + ">.");
260
264
  }
261
265
  }
262
266
 
@@ -46,8 +46,10 @@ export function Button(_ref) {
46
46
  title = _ref.title,
47
47
  to = _ref.to,
48
48
  tooltip = _ref.tooltip,
49
+ _ref$type = _ref.type,
50
+ type = _ref$type === void 0 ? 'button' : _ref$type,
49
51
  variant = _ref.variant,
50
- restProps = _objectWithoutPropertiesLoose(_ref, ["children", "disabled", "external", "icon", "iconLeft", "iconRight", "onClick", "onKeyDown", "size", "spinner", "square", "theme", "title", "to", "tooltip", "variant"]);
52
+ restProps = _objectWithoutPropertiesLoose(_ref, ["children", "disabled", "external", "icon", "iconLeft", "iconRight", "onClick", "onKeyDown", "size", "spinner", "square", "theme", "title", "to", "tooltip", "type", "variant"]);
51
53
 
52
54
  var buttonThemes = useThemeValue('button.themes');
53
55
 
@@ -73,7 +75,8 @@ export function Button(_ref) {
73
75
  strokeAlign: 'inside',
74
76
  strokeWeight: 1,
75
77
  userSelect: 'none',
76
- zIndex: 1
78
+ zIndex: 1,
79
+ type: type
77
80
  };
78
81
  var spinnerColor;
79
82
 
@@ -222,12 +225,13 @@ export function Button(_ref) {
222
225
 
223
226
 
224
227
  if (restProps.as) {
225
- buttonProps.to = to;
226
- } // set button type to prevent nested buttons from unintentionally submiting forms
228
+ buttonProps.to = to; // remove type if it is not a button
227
229
 
228
-
229
- if (buttonProps.as === "button") {
230
- buttonProps.type = "button";
230
+ if (restProps.as !== "button") {
231
+ buttonProps = _objectSpread(_objectSpread({}, buttonProps), {}, {
232
+ type: null
233
+ });
234
+ }
231
235
  }
232
236
 
233
237
  if (process.env.NODE_ENV !== 'production') {
@@ -240,8 +244,8 @@ export function Button(_ref) {
240
244
  restProps = mergeProps(restProps, wrapperProps);
241
245
  }
242
246
 
243
- if (restProps['type'] === 'submit') {
244
- throw Error("Tapestry-React: <Button/> does not support type=\"submit\" please add an explicit onClick handler.");
247
+ if (type && restProps.as && restProps.as !== "button") {
248
+ throw Error("Tapestry-React: <Button/> type prop is only supported by <button> and not <" + restProps.as + ">.");
245
249
  }
246
250
  }
247
251
 
@@ -64,6 +64,10 @@ declare type ButtonProps = {
64
64
  * Wraps button in a [`<Tooltip />`](./tooltip). Accepts any valid Tooltip props.
65
65
  */
66
66
  tooltip?: string | Object;
67
+ /**
68
+ * Sets the button type to `button`, `submit`, or `reset`. Default is `button`. Type is only valid for `<button>`s.
69
+ */
70
+ type?: 'button' | 'submit' | 'reset';
67
71
  /**
68
72
  * Determines the modified style of the button.
69
73
  */
@@ -74,7 +78,7 @@ declare type ButtonProps = {
74
78
  mediaQueries?: object;
75
79
  } & StackViewProps;
76
80
  declare type Props = React.RefAttributes<any> & React.HTMLAttributes<any> & ButtonProps & MediaQueries<ButtonProps>;
77
- export declare function Button({ children, disabled, external, icon, iconLeft, iconRight, onClick, onKeyDown, size, spinner, square, theme, title, to, tooltip, variant, ...restProps }: Props): JSX.Element;
81
+ export declare function Button({ children, disabled, external, icon, iconLeft, iconRight, onClick, onKeyDown, size, spinner, square, theme, title, to, tooltip, type, variant, ...restProps }: Props): JSX.Element;
78
82
  export declare namespace Button {
79
83
  var Input: React.ForwardRefExoticComponent<Pick<React.RefAttributes<any> & React.HTMLAttributes<any> & {
80
84
  children: React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any>) | (new (props: any) => React.Component<any, any, any>)> | ((inputProps: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/tapestry-react",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "A collection of flexible React components to help you build resilient, accessible user interfaces quickly and effectively.",
5
5
  "author": "Front End Systems Engineering <frontend@pco.bz>",
6
6
  "main": "dist/cjs/index.js",
@@ -91,6 +91,11 @@ type ButtonProps = {
91
91
  */
92
92
  tooltip?: string | Object
93
93
 
94
+ /**
95
+ * Sets the button type to `button`, `submit`, or `reset`. Default is `button`. Type is only valid for `<button>`s.
96
+ */
97
+ type?: 'button' | 'submit' | 'reset'
98
+
94
99
  /**
95
100
  * Determines the modified style of the button.
96
101
  */
@@ -125,6 +130,7 @@ export function Button({
125
130
  title,
126
131
  to,
127
132
  tooltip,
133
+ type = 'button',
128
134
  variant,
129
135
  ...restProps
130
136
  }: Props) {
@@ -153,6 +159,7 @@ export function Button({
153
159
  strokeWeight: 1,
154
160
  userSelect: 'none',
155
161
  zIndex: 1,
162
+ type,
156
163
  }
157
164
 
158
165
  let spinnerColor
@@ -296,11 +303,14 @@ export function Button({
296
303
  // pass to if as is defined
297
304
  if ((restProps as any).as) {
298
305
  buttonProps.to = to
299
- }
300
306
 
301
- // set button type to prevent nested buttons from unintentionally submiting forms
302
- if (buttonProps.as === "button") {
303
- buttonProps.type = "button"
307
+ // remove type if it is not a button
308
+ if ((restProps as any).as !== "button") {
309
+ buttonProps = {
310
+ ...buttonProps,
311
+ type: null,
312
+ }
313
+ }
304
314
  }
305
315
 
306
316
  if (process.env.NODE_ENV !== 'production') {
@@ -330,9 +340,14 @@ export function Button({
330
340
  tooltip = tooltipProps
331
341
  restProps = mergeProps(restProps, wrapperProps)
332
342
  }
333
- if (restProps['type'] === 'submit') {
343
+
344
+ if (
345
+ type &&
346
+ (restProps as any).as &&
347
+ (restProps as any).as !== "button"
348
+ ) {
334
349
  throw Error(
335
- `Tapestry-React: <Button/> does not support type="submit" please add an explicit onClick handler.`
350
+ `Tapestry-React: <Button/> type prop is only supported by <button> and not <${(restProps as any).as}>.`
336
351
  )
337
352
  }
338
353
  }