@xylabs/react-button 5.2.0 → 5.2.2
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/dist/browser/components/ButtonExProps.d.ts +22 -15
- package/dist/browser/components/ButtonExProps.d.ts.map +1 -1
- package/dist/browser/index.mjs +15 -1
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/components/ButtonEx.stories.tsx +31 -1
- package/src/components/ButtonExProps.tsx +30 -15
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import type { ButtonProps } from '@mui/material';
|
|
2
2
|
import type { BoxlikeComponentProps, BusyProps } from '@xylabs/react-shared';
|
|
3
3
|
import type { NavigateOptions, To } from 'react-router-dom';
|
|
4
|
-
export interface
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
placement?: string;
|
|
9
|
-
target?: string;
|
|
4
|
+
export interface ButtonOnlyHrefProps {
|
|
5
|
+
href?: string;
|
|
6
|
+
to?: never;
|
|
7
|
+
toOptions?: never;
|
|
10
8
|
}
|
|
11
|
-
export interface
|
|
9
|
+
export interface ButtonOnlyToProps {
|
|
12
10
|
href?: never;
|
|
13
|
-
to
|
|
11
|
+
to?: To;
|
|
14
12
|
toOptions?: NavigateOptions;
|
|
15
13
|
}
|
|
16
|
-
export interface
|
|
17
|
-
href: string;
|
|
18
|
-
to?: never;
|
|
19
|
-
toOptions?: never;
|
|
20
|
-
}
|
|
21
|
-
export interface ButtonClickExProps extends ButtonBaseExProps {
|
|
14
|
+
export interface ButtonNoToOrHrefProps {
|
|
22
15
|
href?: never;
|
|
23
16
|
to?: never;
|
|
24
17
|
toOptions?: never;
|
|
25
18
|
}
|
|
26
|
-
export type
|
|
19
|
+
export type ButtonHrefOrToOrNoProps = ButtonOnlyHrefProps | ButtonOnlyToProps | ButtonNoToOrHrefProps;
|
|
20
|
+
export interface ButtonHrefAndToProps {
|
|
21
|
+
href?: string;
|
|
22
|
+
to?: To;
|
|
23
|
+
toOptions?: NavigateOptions;
|
|
24
|
+
}
|
|
25
|
+
export declare const asButtonHrefOrToProps: (props: ButtonHrefAndToProps) => ButtonHrefOrToOrNoProps;
|
|
26
|
+
export interface ButtonBaseExProps extends Omit<ButtonProps, 'ref' | 'href'>, BoxlikeComponentProps, BusyProps {
|
|
27
|
+
disableUserEvents?: boolean;
|
|
28
|
+
funnel?: string;
|
|
29
|
+
intent?: string;
|
|
30
|
+
placement?: string;
|
|
31
|
+
target?: string;
|
|
32
|
+
}
|
|
33
|
+
export type ButtonExProps = ButtonBaseExProps & ButtonHrefOrToOrNoProps;
|
|
27
34
|
//# sourceMappingURL=ButtonExProps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonExProps.d.ts","sourceRoot":"","sources":["../../../src/components/ButtonExProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAE3D,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"ButtonExProps.d.ts","sourceRoot":"","sources":["../../../src/components/ButtonExProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAE3D,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,SAAS,CAAC,EAAE,KAAK,CAAA;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,EAAE,CAAC,EAAE,EAAE,CAAA;IACP,SAAS,CAAC,EAAE,eAAe,CAAA;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,SAAS,CAAC,EAAE,KAAK,CAAA;CAClB;AAED,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,qBAAqB,CAAA;AAErG,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,EAAE,CAAA;IACP,SAAS,CAAC,EAAE,eAAe,CAAA;CAC5B;AAED,eAAO,MAAM,qBAAqB,UAAW,oBAAoB,KAAG,uBAKnE,CAAA;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,WAAW,EAAE,KAAK,GAAG,MAAM,CAAC,EAAE,qBAAqB,EAAE,SAAS;IAC5G,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,uBAAuB,CAAA"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -97,7 +97,21 @@ var ButtonEx = /* @__PURE__ */ forwardRef3((props, ref) => {
|
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
ButtonEx.displayName = "ButtonExXYLabs";
|
|
100
|
+
|
|
101
|
+
// src/components/ButtonExProps.tsx
|
|
102
|
+
var asButtonHrefOrToProps = /* @__PURE__ */ __name((props) => {
|
|
103
|
+
if (props.href && (props.to || props.toOptions)) {
|
|
104
|
+
throw new Error("ButtonExProps: cannot have both href and to");
|
|
105
|
+
}
|
|
106
|
+
return props.href ? {
|
|
107
|
+
href: props.href
|
|
108
|
+
} : props.to ? {
|
|
109
|
+
to: props.to,
|
|
110
|
+
toOptions: props.toOptions
|
|
111
|
+
} : {};
|
|
112
|
+
}, "asButtonHrefOrToProps");
|
|
100
113
|
export {
|
|
101
|
-
ButtonEx
|
|
114
|
+
ButtonEx,
|
|
115
|
+
asButtonHrefOrToProps
|
|
102
116
|
};
|
|
103
117
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -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>((props, ref) => {\n if (props.to) {\n const { to, ...additionalProps } = props\n return <ButtonToEx to={to} ref={ref} {...additionalProps} />\n } else {\n return <ButtonExBase {...props} />\n }\n})\n\nButtonEx.displayName = 'ButtonExXYLabs'\n\nexport { ButtonEx }\n","import { Button, useTheme } from '@mui/material'\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 funnel, intent, target, placement, disableUserEvents, href, ...props\n}, ref) => {\n const theme = useTheme()\n const userEvents = useUserEvents()\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 elementName = props['aria-label'] ?? event.currentTarget.textContent\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) ?? globalThis : globalThis\n const callOnClickAndFollowHref = (windowToNav = windowToNavigate()) => {\n onClick?.(event)\n if (href) {\n windowToNav.location.href = href\n }\n }\n if (!disableUserEvents && userEvents) {\n event.preventDefault()\n const windowToNav = windowToNavigate()\n if (href) {\n userEvents.userClick({\n elementName, intent, funnel, placement,\n }).then(() => {\n callOnClickAndFollowHref(windowToNav)\n }).catch((ex) => {\n console.error('User event failed', elementName, funnel, placement, ex)\n callOnClickAndFollowHref(windowToNav)\n })\n }\n onClick?.(event)\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,qBAAqB;AAC9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KACtEL,QAAQC,gBAAgB,WACrB,sBAAA,cAAC0B,oBAAAA;IAAmBC,SAAAA;IAAQC,SAAS3B,eAAe;OACpD,MACHF,QAAQC,gBAAgB,aACrB,sBAAA,cAAC6B,sBAAAA;IAAqBF,SAAAA;IAAQG,MAAM;IAAIF,SAAS3B,eAAe;OAChE,MACHE,QAAAA;AAGP,CAAA;AAEAlB,aAAa8C,cAAc;;;ACjE3B,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,CAACC,OAAOC,QAAAA;AACpE,MAAID,MAAME,IAAI;AACZ,UAAM,EAAEA,IAAI,GAAGC,gBAAAA,IAAoBH;AACnC,WAAO,gBAAAI,OAAA,cAACC,YAAAA;MAAWH;MAAQD;MAAW,GAAGE;;EAC3C,OAAO;AACL,WAAO,gBAAAC,OAAA,cAACE,cAAiBN,KAAAA;EAC3B;AACF,CAAA;AAEAF,SAASS,cAAc;","names":["React","forwardRef","Button","useTheme","useUserEvents","BusyCircularProgress","BusyLinearProgress","mergeBoxlikeStyles","React","forwardRef","ButtonExBase","forwardRef","funnel","intent","target","placement","disableUserEvents","href","props","ref","theme","useTheme","userEvents","useUserEvents","busy","busyVariant","busyOpacity","onClick","children","rootProps","mergeBoxlikeStyles","localOnClick","event","preventDefault","elementName","currentTarget","textContent","windowToNavigate","window","open","globalThis","callOnClickAndFollowHref","windowToNav","location","userClick","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","props","ref","to","additionalProps","React","ButtonToEx","ButtonExBase","displayName"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/ButtonEx.tsx","../../src/components/ButtonExBase.tsx","../../src/components/ButtonExTo.tsx","../../src/components/ButtonExProps.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>((props, ref) => {\n if (props.to) {\n const { to, ...additionalProps } = props\n return <ButtonToEx to={to} ref={ref} {...additionalProps} />\n } else {\n return <ButtonExBase {...props} />\n }\n})\n\nButtonEx.displayName = 'ButtonExXYLabs'\n\nexport { ButtonEx }\n","import { Button, useTheme } from '@mui/material'\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 funnel, intent, target, placement, disableUserEvents, href, ...props\n}, ref) => {\n const theme = useTheme()\n const userEvents = useUserEvents()\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 elementName = props['aria-label'] ?? event.currentTarget.textContent\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) ?? globalThis : globalThis\n const callOnClickAndFollowHref = (windowToNav = windowToNavigate()) => {\n onClick?.(event)\n if (href) {\n windowToNav.location.href = href\n }\n }\n if (!disableUserEvents && userEvents) {\n event.preventDefault()\n const windowToNav = windowToNavigate()\n if (href) {\n userEvents.userClick({\n elementName, intent, funnel, placement,\n }).then(() => {\n callOnClickAndFollowHref(windowToNav)\n }).catch((ex) => {\n console.error('User event failed', elementName, funnel, placement, ex)\n callOnClickAndFollowHref(windowToNav)\n })\n }\n onClick?.(event)\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","import type { ButtonProps } from '@mui/material'\nimport type { BoxlikeComponentProps, BusyProps } from '@xylabs/react-shared'\nimport type { NavigateOptions, To } from 'react-router-dom'\n\nexport interface ButtonOnlyHrefProps {\n href?: string\n to?: never\n toOptions?: never\n}\n\nexport interface ButtonOnlyToProps {\n href?: never\n to?: To\n toOptions?: NavigateOptions\n}\n\nexport interface ButtonNoToOrHrefProps {\n href?: never\n to?: never\n toOptions?: never\n}\n\nexport type ButtonHrefOrToOrNoProps = ButtonOnlyHrefProps | ButtonOnlyToProps | ButtonNoToOrHrefProps\n\nexport interface ButtonHrefAndToProps {\n href?: string\n to?: To\n toOptions?: NavigateOptions\n}\n\nexport const asButtonHrefOrToProps = (props: ButtonHrefAndToProps): ButtonHrefOrToOrNoProps => {\n if (props.href && (props.to || props.toOptions)) {\n throw new Error('ButtonExProps: cannot have both href and to')\n }\n return props.href ? { href: props.href } : props.to ? { to: props.to, toOptions: props.toOptions } : {}\n}\n\nexport interface ButtonBaseExProps extends Omit<ButtonProps, 'ref' | 'href'>, BoxlikeComponentProps, BusyProps {\n disableUserEvents?: boolean\n funnel?: string\n intent?: string\n placement?: string\n target?: string\n}\n\nexport type ButtonExProps = ButtonBaseExProps & ButtonHrefOrToOrNoProps\n"],"mappings":";;;;AAAA,OAAOA,UAASC,cAAAA,mBAAkB;;;ACAlC,SAASC,QAAQC,gBAAgB;AACjC,SAASC,qBAAqB;AAC9B,SACEC,sBAAsBC,oBAAoBC,0BACrC;AAEP,OAAOC,SAASC,kBAAkB;AAIlC,IAAMC,eAAeC,2BAA6C,CAAC,EACjEC,QAAQC,QAAQC,QAAQC,WAAWC,mBAAmBC,MAAM,GAAGC,MAAAA,GAC9DC,QAAAA;AACD,QAAMC,QAAQC,SAAAA;AACd,QAAMC,aAAaC,cAAAA;AACnB,QAAM,EACJC,MAAMC,cAAc,UAAUC,aAAaC,SAASC,UAAU,GAAGC,UAAAA,IAC/DC,mBAAkCV,OAAOF,KAAAA;AAE7C,QAAMa,eAAe,wBAACC,UAAAA;AACpB,QAAIR,MAAM;AAERQ,YAAMC,eAAc;IACtB,OAAO;AACL,YAAMC,cAAchB,MAAM,YAAA,KAAiBc,MAAMG,cAAcC;AAE/D,YAAMC,mBA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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,CAACC,OAAOC,QAAAA;AACpE,MAAID,MAAME,IAAI;AACZ,UAAM,EAAEA,IAAI,GAAGC,gBAAAA,IAAoBH;AACnC,WAAO,gBAAAI,OAAA,cAACC,YAAAA;MAAWH;MAAQD;MAAW,GAAGE;;EAC3C,OAAO;AACL,WAAO,gBAAAC,OAAA,cAACE,cAAiBN,KAAAA;EAC3B;AACF,CAAA;AAEAF,SAASS,cAAc;;;AGehB,IAAMC,wBAAwB,wBAACC,UAAAA;AACpC,MAAIA,MAAMC,SAASD,MAAME,MAAMF,MAAMG,YAAY;AAC/C,UAAM,IAAIC,MAAM,6CAAA;EAClB;AACA,SAAOJ,MAAMC,OAAO;IAAEA,MAAMD,MAAMC;EAAK,IAAID,MAAME,KAAK;IAAEA,IAAIF,MAAME;IAAIC,WAAWH,MAAMG;EAAU,IAAI,CAAC;AACxG,GALqC;","names":["React","forwardRef","Button","useTheme","useUserEvents","BusyCircularProgress","BusyLinearProgress","mergeBoxlikeStyles","React","forwardRef","ButtonExBase","forwardRef","funnel","intent","target","placement","disableUserEvents","href","props","ref","theme","useTheme","userEvents","useUserEvents","busy","busyVariant","busyOpacity","onClick","children","rootProps","mergeBoxlikeStyles","localOnClick","event","preventDefault","elementName","currentTarget","textContent","windowToNavigate","window","open","globalThis","callOnClickAndFollowHref","windowToNav","location","userClick","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","props","ref","to","additionalProps","React","ButtonToEx","ButtonExBase","displayName","asButtonHrefOrToProps","props","href","to","toOptions","Error"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/react-button",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"description": "Common React library for all XY Labs projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"utility",
|
|
@@ -37,15 +37,16 @@
|
|
|
37
37
|
"packages/*"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@xylabs/react-pixel": "^5.2.
|
|
41
|
-
"@xylabs/react-shared": "^5.2.
|
|
40
|
+
"@xylabs/react-pixel": "^5.2.2",
|
|
41
|
+
"@xylabs/react-shared": "^5.2.2",
|
|
42
42
|
"react-router-dom": "^6.27.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@mui/material": "^6.1.
|
|
45
|
+
"@mui/material": "^6.1.4",
|
|
46
46
|
"@storybook/react": "^8.3.5",
|
|
47
47
|
"@types/react": "^18.3.11",
|
|
48
|
-
"@xylabs/react-flexbox": "^5.2.
|
|
48
|
+
"@xylabs/react-flexbox": "^5.2.2",
|
|
49
|
+
"@xylabs/react-pixel": "^5.2.2",
|
|
49
50
|
"@xylabs/ts-scripts-yarn3": "^4.2.1",
|
|
50
51
|
"@xylabs/tsconfig-react": "^4.2.1",
|
|
51
52
|
"react": "^18.3.1",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryFn } from '@storybook/react'
|
|
2
2
|
import { FlexCol, FlexRow } from '@xylabs/react-flexbox'
|
|
3
|
+
import { UserEventsProvider, XyoUserEventHandler } from '@xylabs/react-pixel'
|
|
3
4
|
import React from 'react'
|
|
4
5
|
|
|
5
6
|
import { ButtonEx } from './ButtonEx.tsx'
|
|
@@ -29,6 +30,26 @@ const DefaultTemplate: StoryFn<typeof ButtonEx> = args => (
|
|
|
29
30
|
</FlexRow>
|
|
30
31
|
)
|
|
31
32
|
|
|
33
|
+
const UserEventTemplate: StoryFn<typeof ButtonEx> = args => (
|
|
34
|
+
<UserEventsProvider userEvents={XyoUserEventHandler.get()}>
|
|
35
|
+
<FlexRow justifyContent="flex-start">
|
|
36
|
+
<FlexCol marginX={1}>
|
|
37
|
+
<ButtonEx {...args}>Default</ButtonEx>
|
|
38
|
+
</FlexCol>
|
|
39
|
+
<FlexCol marginX={1}>
|
|
40
|
+
<ButtonEx variant="outlined" {...args}>
|
|
41
|
+
Outlined
|
|
42
|
+
</ButtonEx>
|
|
43
|
+
</FlexCol>
|
|
44
|
+
<FlexCol marginX={1}>
|
|
45
|
+
<ButtonEx variant="contained" {...args}>
|
|
46
|
+
Contained
|
|
47
|
+
</ButtonEx>
|
|
48
|
+
</FlexCol>
|
|
49
|
+
</FlexRow>
|
|
50
|
+
</UserEventsProvider>
|
|
51
|
+
)
|
|
52
|
+
|
|
32
53
|
const Default = DefaultTemplate.bind({})
|
|
33
54
|
Default.args = {}
|
|
34
55
|
|
|
@@ -49,8 +70,17 @@ HrefTargetOnClick.args = {
|
|
|
49
70
|
href: 'https://xylabs.com', target: '_blank', onClick: () => console.log('Clicked'),
|
|
50
71
|
}
|
|
51
72
|
|
|
73
|
+
const HrefTargetWithEvents = UserEventTemplate.bind({})
|
|
74
|
+
HrefTargetWithEvents.args = { href: 'https://xylabs.com', target: '_blank' }
|
|
75
|
+
|
|
76
|
+
const HrefTargetOnClickWithEvents = UserEventTemplate.bind({})
|
|
77
|
+
HrefTargetOnClickWithEvents.args = {
|
|
78
|
+
href: 'https://xylabs.com', target: '_blank', onClick: () => console.log('Clicked'),
|
|
79
|
+
}
|
|
80
|
+
|
|
52
81
|
export {
|
|
53
|
-
BusyCircular, BusyLinear, Default, Href, HrefTarget, HrefTargetOnClick,
|
|
82
|
+
BusyCircular, BusyLinear, Default, Href, HrefTarget, HrefTargetOnClick, HrefTargetOnClickWithEvents,
|
|
83
|
+
HrefTargetWithEvents,
|
|
54
84
|
}
|
|
55
85
|
|
|
56
86
|
export default StorybookEntry
|
|
@@ -2,30 +2,45 @@ import type { ButtonProps } from '@mui/material'
|
|
|
2
2
|
import type { BoxlikeComponentProps, BusyProps } from '@xylabs/react-shared'
|
|
3
3
|
import type { NavigateOptions, To } from 'react-router-dom'
|
|
4
4
|
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
placement?: string
|
|
10
|
-
target?: string
|
|
5
|
+
export interface ButtonOnlyHrefProps {
|
|
6
|
+
href?: string
|
|
7
|
+
to?: never
|
|
8
|
+
toOptions?: never
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
export interface
|
|
11
|
+
export interface ButtonOnlyToProps {
|
|
14
12
|
href?: never
|
|
15
|
-
to
|
|
13
|
+
to?: To
|
|
16
14
|
toOptions?: NavigateOptions
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
export interface
|
|
20
|
-
href
|
|
17
|
+
export interface ButtonNoToOrHrefProps {
|
|
18
|
+
href?: never
|
|
21
19
|
to?: never
|
|
22
20
|
toOptions?: never
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
export type ButtonHrefOrToOrNoProps = ButtonOnlyHrefProps | ButtonOnlyToProps | ButtonNoToOrHrefProps
|
|
24
|
+
|
|
25
|
+
export interface ButtonHrefAndToProps {
|
|
26
|
+
href?: string
|
|
27
|
+
to?: To
|
|
28
|
+
toOptions?: NavigateOptions
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const asButtonHrefOrToProps = (props: ButtonHrefAndToProps): ButtonHrefOrToOrNoProps => {
|
|
32
|
+
if (props.href && (props.to || props.toOptions)) {
|
|
33
|
+
throw new Error('ButtonExProps: cannot have both href and to')
|
|
34
|
+
}
|
|
35
|
+
return props.href ? { href: props.href } : props.to ? { to: props.to, toOptions: props.toOptions } : {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ButtonBaseExProps extends Omit<ButtonProps, 'ref' | 'href'>, BoxlikeComponentProps, BusyProps {
|
|
39
|
+
disableUserEvents?: boolean
|
|
40
|
+
funnel?: string
|
|
41
|
+
intent?: string
|
|
42
|
+
placement?: string
|
|
43
|
+
target?: string
|
|
29
44
|
}
|
|
30
45
|
|
|
31
|
-
export type ButtonExProps =
|
|
46
|
+
export type ButtonExProps = ButtonBaseExProps & ButtonHrefOrToOrNoProps
|