@xylabs/react-button 4.2.3 → 4.2.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ButtonExBase.d.ts","sourceRoot":"","sources":["../../../src/components/ButtonExBase.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,QAAA,MAAM,YAAY,yFAwDhB,CAAA;AAIF,OAAO,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"ButtonExBase.d.ts","sourceRoot":"","sources":["../../../src/components/ButtonExBase.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,QAAA,MAAM,YAAY,yFAuDhB,CAAA;AAIF,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -19,14 +19,11 @@ var ButtonExBase = /* @__PURE__ */ forwardRef(({ eventName = "Button Click", fun
19
19
  if (busy) {
20
20
  event.preventDefault();
21
21
  } else {
22
- const callOnClickAndFollowHref = /* @__PURE__ */ __name(() => {
22
+ const windowToNavigate = /* @__PURE__ */ __name(() => target && href ? window.open("", target) ?? window : window, "windowToNavigate");
23
+ const callOnClickAndFollowHref = /* @__PURE__ */ __name((windowToNav = windowToNavigate()) => {
23
24
  onClick?.(event);
24
25
  if (href) {
25
- if (target) {
26
- window.open(href, target);
27
- } else {
28
- window.location.href = href;
29
- }
26
+ windowToNav.location.href = href;
30
27
  }
31
28
  }, "callOnClickAndFollowHref");
32
29
  if (!disableMixpanel && mixpanel) {
@@ -37,14 +34,15 @@ var ButtonExBase = /* @__PURE__ */ forwardRef(({ eventName = "Button Click", fun
37
34
  }
38
35
  if (!disableUserEvents && userEvents) {
39
36
  event.preventDefault();
37
+ const windowToNav = windowToNavigate();
40
38
  userEvents.userClick({
41
39
  elementName: eventName,
42
40
  elementType: placement
43
41
  }).then(() => {
44
- callOnClickAndFollowHref();
42
+ callOnClickAndFollowHref(windowToNav);
45
43
  }).catch((ex) => {
46
44
  console.error("User event failed", eventName, ex);
47
- callOnClickAndFollowHref();
45
+ callOnClickAndFollowHref(windowToNav);
48
46
  });
49
47
  } else {
50
48
  callOnClickAndFollowHref();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/ButtonEx.tsx","../../src/components/ButtonExBase.tsx","../../src/components/ButtonExTo.tsx"],"sourcesContent":["import React, { forwardRef } from 'react'\n\nimport { ButtonExBase } from './ButtonExBase.tsx'\nimport type { ButtonExProps } from './ButtonExProps.tsx'\nimport { ButtonToEx } from './ButtonExTo.tsx'\n\nconst ButtonEx = forwardRef<HTMLButtonElement, ButtonExProps>(({ to, ...props }, ref) => {\n return to ? <ButtonToEx to={to} ref={ref} {...props} /> : <ButtonExBase {...props} />\n})\n\nButtonEx.displayName = 'ButtonExXYLabs'\n\nexport { ButtonEx }\n","import { Button, useTheme } from '@mui/material'\nimport { useMixpanel } from '@xylabs/react-mixpanel'\nimport { useUserEvents } from '@xylabs/react-pixel'\nimport {\n BusyCircularProgress, BusyLinearProgress, mergeBoxlikeStyles,\n} from '@xylabs/react-shared'\nimport type { MouseEvent } from 'react'\nimport React, { forwardRef } from 'react'\n\nimport type { ButtonExProps } from './ButtonExProps.tsx'\n\nconst ButtonExBase = forwardRef<HTMLButtonElement, ButtonExProps>(({\n eventName = 'Button Click', funnel, target, placement, disableUserEvents, href, disableMixpanel, ...props\n}, ref) => {\n const theme = useTheme()\n const userEvents = useUserEvents()\n const mixpanel = useMixpanel(false)\n const {\n busy, busyVariant = 'linear', busyOpacity, onClick, children, ...rootProps\n } = mergeBoxlikeStyles<ButtonExProps>(theme, props)\n\n const localOnClick = (event: MouseEvent<HTMLButtonElement>) => {\n if (busy) {\n // If it is busy, do not allow href clicks\n event.preventDefault()\n } else {\n const callOnClickAndFollowHref = () => {\n onClick?.(event)\n if (href) {\n if (target) {\n window.open(href, target)\n } else {\n window.location.href = href\n }\n }\n }\n if (!disableMixpanel && mixpanel) {\n mixpanel.track(eventName, {\n funnel,\n placement: placement ?? rootProps['aria-label'] ?? event.currentTarget.textContent,\n })\n }\n if (!disableUserEvents && userEvents) {\n event.preventDefault()\n userEvents.userClick({ elementName: eventName, elementType: placement }).then(() => {\n callOnClickAndFollowHref()\n }).catch((ex) => {\n console.error('User event failed', eventName, ex)\n callOnClickAndFollowHref()\n })\n } else {\n callOnClickAndFollowHref()\n }\n }\n }\n\n return (\n <Button ref={ref} href={href} onClick={localOnClick} target={target} {...rootProps}>\n {busy && busyVariant === 'linear'\n ? <BusyLinearProgress rounded opacity={busyOpacity ?? 0} />\n : null}\n {busy && busyVariant === 'circular'\n ? <BusyCircularProgress rounded size={24} opacity={busyOpacity ?? 0.5} />\n : null}\n {children}\n </Button>\n )\n})\n\nButtonExBase.displayName = 'ButtonExBaseXYLabs'\n\nexport { ButtonExBase }\n","import type { MouseEvent } from 'react'\nimport React, { forwardRef } from 'react'\nimport { useNavigate } from 'react-router-dom'\n\nimport { ButtonExBase } from './ButtonExBase.tsx'\nimport type { ButtonExProps } from './ButtonExProps.tsx'\n\nconst ButtonToEx = forwardRef<HTMLButtonElement, ButtonExProps>(({\n to, toOptions, onClick, ...props\n}, ref) => {\n const navigate = useNavigate()\n const localOnClick = (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (to) {\n navigate(to, toOptions)\n }\n }\n\n return <ButtonExBase ref={ref} onClick={localOnClick} {...props} />\n})\n\nButtonToEx.displayName = 'ButtonToExXYLabs'\n\nexport { ButtonToEx }\n"],"mappings":";;;;AAAA,OAAOA,UAASC,cAAAA,mBAAkB;;;ACAlC,SAASC,QAAQC,gBAAgB;AACjC,SAASC,mBAAmB;AAC5B,SAASC,qBAAqB;AAC9B,SACEC,sBAAsBC,oBAAoBC,0BACrC;AAEP,OAAOC,SAAS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AAA;IAAQC,SAAS1B,eAAe;OACpD,MACHF,QAAQC,gBAAgB,aACrB,sBAAA,cAAC4B,sBAAAA;IAAqBF,SAAAA;IAAQG,MAAM;IAAIF,SAAS1B,eAAe;OAChE,MACHE,QAAAA;AAGP,CAAA;AAEArB,aAAagD,cAAc;;;ACpE3B,OAAOC,UAASC,cAAAA,mBAAkB;AAClC,SAASC,mBAAmB;AAK5B,IAAMC,aAAaC,gBAAAA,YAA6C,CAAC,EAC/DC,IAAIC,WAAWC,SAAS,GAAGC,MAAAA,GAC1BC,QAAAA;AACD,QAAMC,WAAWC,YAAAA;AACjB,QAAMC,eAAe,wBAACC,UAAAA;AACpBN,cAAUM,KAAAA;AACV,QAAIR,IAAI;AACNK,eAASL,IAAIC,SAAAA;IACf;EACF,GALqB;AAOrB,SAAO,gBAAAQ,OAAA,cAACC,cAAAA;IAAaN;IAAUF,SAASK;IAAe,GAAGJ;;AAC5D,CAAA;AAEAL,WAAWa,cAAc;;;AFfzB,IAAMC,WAAWC,gBAAAA,YAA6C,CAAC,EAAEC,IAAI,GAAGC,MAAAA,GAASC,QAAAA;AAC/E,SAAOF,KAAK,gBAAAG,OAAA,cAACC,YAAAA;IAAWJ;IAAQE;IAAW,GAAGD;OAAY,gBAAAE,OAAA,cAACE,cAAiBJ,KAAAA;AAC9E,CAAA;AAEAH,SAASQ,cAAc;","names":["React","forwardRef","Button","useTheme","useMixpanel","useUserEvents","BusyCircularProgress","BusyLinearProgress","mergeBoxlikeStyles","React","forwardRef","ButtonExBase","forwardRef","eventName","funnel","target","placement","disableUserEvents","href","disableMixpanel","props","ref","theme","useTheme","userEvents","useUserEvents","mixpanel","useMixpanel","busy","busyVariant","busyOpacity","onClick","children","rootProps","mergeBoxlikeStyles","localOnClick","event","preventDefault","callOnClickAndFollowHref","window","open","location","track","currentTarget","textContent","userClick","elementName","elementType","then","catch","ex","console","error","Button","BusyLinearProgress","rounded","opacity","BusyCircularProgress","size","displayName","React","forwardRef","useNavigate","ButtonToEx","forwardRef","to","toOptions","onClick","props","ref","navigate","useNavigate","localOnClick","event","React","ButtonExBase","displayName","ButtonEx","forwardRef","to","props","ref","React","ButtonToEx","ButtonExBase","displayName"]}
1
+ {"version":3,"sources":["../../src/components/ButtonEx.tsx","../../src/components/ButtonExBase.tsx","../../src/components/ButtonExTo.tsx"],"sourcesContent":["import React, { forwardRef } from 'react'\n\nimport { ButtonExBase } from './ButtonExBase.tsx'\nimport type { ButtonExProps } from './ButtonExProps.tsx'\nimport { ButtonToEx } from './ButtonExTo.tsx'\n\nconst ButtonEx = forwardRef<HTMLButtonElement, ButtonExProps>(({ to, ...props }, ref) => {\n return to ? <ButtonToEx to={to} ref={ref} {...props} /> : <ButtonExBase {...props} />\n})\n\nButtonEx.displayName = 'ButtonExXYLabs'\n\nexport { ButtonEx }\n","import { Button, useTheme } from '@mui/material'\nimport { useMixpanel } from '@xylabs/react-mixpanel'\nimport { useUserEvents } from '@xylabs/react-pixel'\nimport {\n BusyCircularProgress, BusyLinearProgress, mergeBoxlikeStyles,\n} from '@xylabs/react-shared'\nimport type { MouseEvent } from 'react'\nimport React, { forwardRef } from 'react'\n\nimport type { ButtonExProps } from './ButtonExProps.tsx'\n\nconst ButtonExBase = forwardRef<HTMLButtonElement, ButtonExProps>(({\n eventName = 'Button Click', funnel, target, placement, disableUserEvents, href, disableMixpanel, ...props\n}, ref) => {\n const theme = useTheme()\n const userEvents = useUserEvents()\n const mixpanel = useMixpanel(false)\n const {\n busy, busyVariant = 'linear', busyOpacity, onClick, children, ...rootProps\n } = mergeBoxlikeStyles<ButtonExProps>(theme, props)\n\n const localOnClick = (event: MouseEvent<HTMLButtonElement>) => {\n if (busy) {\n // If it is busy, do not allow href clicks\n event.preventDefault()\n } else {\n // we do this crazy navigate thing so that we can set it up outside the promise so that safari does not block it\n const windowToNavigate = () => (target && href) ? window.open('', target) ?? window : window\n const callOnClickAndFollowHref = (windowToNav = windowToNavigate()) => {\n onClick?.(event)\n if (href) {\n windowToNav.location.href = href\n }\n }\n if (!disableMixpanel && mixpanel) {\n mixpanel.track(eventName, {\n funnel,\n placement: placement ?? rootProps['aria-label'] ?? event.currentTarget.textContent,\n })\n }\n if (!disableUserEvents && userEvents) {\n event.preventDefault()\n const windowToNav = windowToNavigate()\n userEvents.userClick({ elementName: eventName, elementType: placement }).then(() => {\n callOnClickAndFollowHref(windowToNav)\n }).catch((ex) => {\n console.error('User event failed', eventName, ex)\n callOnClickAndFollowHref(windowToNav)\n })\n } else {\n callOnClickAndFollowHref()\n }\n }\n }\n\n return (\n <Button ref={ref} href={href} onClick={localOnClick} target={target} {...rootProps}>\n {busy && busyVariant === 'linear'\n ? <BusyLinearProgress rounded opacity={busyOpacity ?? 0} />\n : null}\n {busy && busyVariant === 'circular'\n ? <BusyCircularProgress rounded size={24} opacity={busyOpacity ?? 0.5} />\n : null}\n {children}\n </Button>\n )\n})\n\nButtonExBase.displayName = 'ButtonExBaseXYLabs'\n\nexport { ButtonExBase }\n","import type { MouseEvent } from 'react'\nimport React, { forwardRef } from 'react'\nimport { useNavigate } from 'react-router-dom'\n\nimport { ButtonExBase } from './ButtonExBase.tsx'\nimport type { ButtonExProps } from './ButtonExProps.tsx'\n\nconst ButtonToEx = forwardRef<HTMLButtonElement, ButtonExProps>(({\n to, toOptions, onClick, ...props\n}, ref) => {\n const navigate = useNavigate()\n const localOnClick = (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (to) {\n navigate(to, toOptions)\n }\n }\n\n return <ButtonExBase ref={ref} onClick={localOnClick} {...props} />\n})\n\nButtonToEx.displayName = 'ButtonToExXYLabs'\n\nexport { ButtonToEx }\n"],"mappings":";;;;AAAA,OAAOA,UAASC,cAAAA,mBAAkB;;;ACAlC,SAASC,QAAQC,gBAAgB;AACjC,SAASC,mBAAmB;AAC5B,SAASC,qBAAqB;AAC9B,SACEC,sBAAsBC,oBAAoBC,0BACrC;AAEP,OAAOC,SAASC,kBAAkB;AAIlC,IAAMC,eAAeC,2BAA6C,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QAAQC,gBAAgB,WACrB,sBAAA,cAAC2B,oBAAAA;IAAmBC,SAAAA;IAAQC,SAAS5B,eAAe;OACpD,MACHF,QAAQC,gBAAgB,aACrB,sBAAA,cAAC8B,sBAAAA;IAAqBF,SAAAA;IAAQG,MAAM;IAAIF,SAAS5B,eAAe;OAChE,MACHE,QAAAA;AAGP,CAAA;AAEArB,aAAakD,cAAc;;;ACnE3B,OAAOC,UAASC,cAAAA,mBAAkB;AAClC,SAASC,mBAAmB;AAK5B,IAAMC,aAAaC,gBAAAA,YAA6C,CAAC,EAC/DC,IAAIC,WAAWC,SAAS,GAAGC,MAAAA,GAC1BC,QAAAA;AACD,QAAMC,WAAWC,YAAAA;AACjB,QAAMC,eAAe,wBAACC,UAAAA;AACpBN,cAAUM,KAAAA;AACV,QAAIR,IAAI;AACNK,eAASL,IAAIC,SAAAA;IACf;EACF,GALqB;AAOrB,SAAO,gBAAAQ,OAAA,cAACC,cAAAA;IAAaN;IAAUF,SAASK;IAAe,GAAGJ;;AAC5D,CAAA;AAEAL,WAAWa,cAAc;;;AFfzB,IAAMC,WAAWC,gBAAAA,YAA6C,CAAC,EAAEC,IAAI,GAAGC,MAAAA,GAASC,QAAAA;AAC/E,SAAOF,KAAK,gBAAAG,OAAA,cAACC,YAAAA;IAAWJ;IAAQE;IAAW,GAAGD;OAAY,gBAAAE,OAAA,cAACE,cAAiBJ,KAAAA;AAC9E,CAAA;AAEAH,SAASQ,cAAc;","names":["React","forwardRef","Button","useTheme","useMixpanel","useUserEvents","BusyCircularProgress","BusyLinearProgress","mergeBoxlikeStyles","React","forwardRef","ButtonExBase","forwardRef","eventName","funnel","target","placement","disableUserEvents","href","disableMixpanel","props","ref","theme","useTheme","userEvents","useUserEvents","mixpanel","useMixpanel","busy","busyVariant","busyOpacity","onClick","children","rootProps","mergeBoxlikeStyles","localOnClick","event","preventDefault","windowToNavigate","window","open","callOnClickAndFollowHref","windowToNav","location","track","currentTarget","textContent","userClick","elementName","elementType","then","catch","ex","console","error","Button","BusyLinearProgress","rounded","opacity","BusyCircularProgress","size","displayName","React","forwardRef","useNavigate","ButtonToEx","forwardRef","to","toOptions","onClick","props","ref","navigate","useNavigate","localOnClick","event","React","ButtonExBase","displayName","ButtonEx","forwardRef","to","props","ref","React","ButtonToEx","ButtonExBase","displayName"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/react-button",
3
- "version": "4.2.3",
3
+ "version": "4.2.4",
4
4
  "description": "Common React library for all XY Labs projects that use React",
5
5
  "keywords": [
6
6
  "utility",
@@ -37,16 +37,16 @@
37
37
  "packages/*"
38
38
  ],
39
39
  "dependencies": {
40
- "@xylabs/react-mixpanel": "^4.2.3",
41
- "@xylabs/react-pixel": "^4.2.3",
42
- "@xylabs/react-shared": "^4.2.3",
40
+ "@xylabs/react-mixpanel": "^4.2.4",
41
+ "@xylabs/react-pixel": "^4.2.4",
42
+ "@xylabs/react-shared": "^4.2.4",
43
43
  "react-router-dom": "^6.26.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@mui/material": "^6.0.2",
47
47
  "@storybook/react": "^8.2.9",
48
48
  "@types/react": "^18.3.5",
49
- "@xylabs/react-flexbox": "^4.2.3",
49
+ "@xylabs/react-flexbox": "^4.2.4",
50
50
  "@xylabs/ts-scripts-yarn3": "^4.0.7",
51
51
  "@xylabs/tsconfig-react": "^4.0.7",
52
52
  "react": "^18.3.1",
@@ -38,8 +38,19 @@ BusyCircular.args = { busy: true, busyVariant: 'circular' }
38
38
  const BusyLinear = DefaultTemplate.bind({})
39
39
  BusyLinear.args = { busy: true, busyVariant: 'linear' }
40
40
 
41
+ const Href = DefaultTemplate.bind({})
42
+ Href.args = { href: 'https://xylabs.com' }
43
+
44
+ const HrefTarget = DefaultTemplate.bind({})
45
+ HrefTarget.args = { href: 'https://xylabs.com', target: '_blank' }
46
+
47
+ const HrefTargetOnClick = DefaultTemplate.bind({})
48
+ HrefTargetOnClick.args = {
49
+ href: 'https://xylabs.com', target: '_blank', onClick: () => console.log('Clicked'),
50
+ }
51
+
41
52
  export {
42
- BusyCircular, BusyLinear, Default,
53
+ BusyCircular, BusyLinear, Default, Href, HrefTarget, HrefTargetOnClick,
43
54
  }
44
55
 
45
56
  export default StorybookEntry
@@ -24,14 +24,12 @@ const ButtonExBase = forwardRef<HTMLButtonElement, ButtonExProps>(({
24
24
  // If it is busy, do not allow href clicks
25
25
  event.preventDefault()
26
26
  } else {
27
- const callOnClickAndFollowHref = () => {
27
+ // we do this crazy navigate thing so that we can set it up outside the promise so that safari does not block it
28
+ const windowToNavigate = () => (target && href) ? window.open('', target) ?? window : window
29
+ const callOnClickAndFollowHref = (windowToNav = windowToNavigate()) => {
28
30
  onClick?.(event)
29
31
  if (href) {
30
- if (target) {
31
- window.open(href, target)
32
- } else {
33
- window.location.href = href
34
- }
32
+ windowToNav.location.href = href
35
33
  }
36
34
  }
37
35
  if (!disableMixpanel && mixpanel) {
@@ -42,11 +40,12 @@ const ButtonExBase = forwardRef<HTMLButtonElement, ButtonExProps>(({
42
40
  }
43
41
  if (!disableUserEvents && userEvents) {
44
42
  event.preventDefault()
43
+ const windowToNav = windowToNavigate()
45
44
  userEvents.userClick({ elementName: eventName, elementType: placement }).then(() => {
46
- callOnClickAndFollowHref()
45
+ callOnClickAndFollowHref(windowToNav)
47
46
  }).catch((ex) => {
48
47
  console.error('User event failed', eventName, ex)
49
- callOnClickAndFollowHref()
48
+ callOnClickAndFollowHref(windowToNav)
50
49
  })
51
50
  } else {
52
51
  callOnClickAndFollowHref()