@xyo-network/react-share 7.5.8 → 7.5.11

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.
Files changed (39) hide show
  1. package/dist/browser/button/ShareButton.d.ts.map +1 -1
  2. package/dist/browser/index.mjs +361 -338
  3. package/dist/browser/index.mjs.map +1 -1
  4. package/dist/browser/out/CopyLinkStack.d.ts.map +1 -1
  5. package/dist/browser/out/lib/AnimatedGradientTypography.d.ts +4 -2
  6. package/dist/browser/out/lib/AnimatedGradientTypography.d.ts.map +1 -1
  7. package/package.json +70 -29
  8. package/src/button/ShareButton.stories.tsx +0 -23
  9. package/src/button/ShareButton.tsx +0 -75
  10. package/src/button/index.ts +0 -1
  11. package/src/global.d.ts +0 -1
  12. package/src/icons/index.ts +0 -1
  13. package/src/icons/social/Facebook.tsx +0 -11
  14. package/src/icons/social/XTwitter.tsx +0 -10
  15. package/src/icons/social/index.ts +0 -2
  16. package/src/index.ts +0 -4
  17. package/src/meta-server/dynamic-share/DynamicShareImage.tsx +0 -23
  18. package/src/meta-server/dynamic-share/index.ts +0 -1
  19. package/src/meta-server/index.ts +0 -2
  20. package/src/meta-server/live-share/HideParentsFlexbox.tsx +0 -40
  21. package/src/meta-server/live-share/index.ts +0 -1
  22. package/src/out/CopyIconButton.tsx +0 -58
  23. package/src/out/CopyLinkStack.stories.tsx +0 -69
  24. package/src/out/CopyLinkStack.tsx +0 -77
  25. package/src/out/CopyLinkTextField.stories.tsx +0 -18
  26. package/src/out/CopyLinkTextField.tsx +0 -41
  27. package/src/out/Dialog.stories.tsx +0 -78
  28. package/src/out/Dialog.tsx +0 -48
  29. package/src/out/Explanation.tsx +0 -29
  30. package/src/out/GenerateShareLinkButton.stories.tsx +0 -18
  31. package/src/out/GenerateShareLinkButton.tsx +0 -31
  32. package/src/out/HeadingFlexbox.tsx +0 -27
  33. package/src/out/SocialButtonsFlexbox.stories.tsx +0 -41
  34. package/src/out/SocialButtonsFlexbox.tsx +0 -79
  35. package/src/out/index.ts +0 -7
  36. package/src/out/lib/AnimatedGradientTypography.tsx +0 -54
  37. package/src/out/lib/ShareLinkProps.ts +0 -8
  38. package/src/out/lib/index.ts +0 -3
  39. package/src/out/lib/splitAroundSubstring.ts +0 -19
@@ -1,58 +0,0 @@
1
- import { CopyAllRounded } from '@mui/icons-material'
2
- import {
3
- type ButtonProps, CircularProgress, IconButton, Tooltip,
4
- } from '@mui/material'
5
- import { forget } from '@xylabs/sdk-js'
6
- import React, { useState } from 'react'
7
-
8
- import type { ShareLinkProps } from './lib/index.ts'
9
-
10
- export interface CopyIconButtonProps extends ButtonProps, ShareLinkProps {
11
- onClickError?: (error: Error) => void
12
- }
13
-
14
- export const CopyIconButton: React.FC<CopyIconButtonProps> = ({
15
- copyLinkText, copiedLinkText, onClickError, shareLinkName, shareUrl, uploadPayloads, ...props
16
- }) => {
17
- const CopyLink = copyLinkText ?? 'Copy Link'
18
- const Copied = copiedLinkText ?? 'Copied!'
19
-
20
- const [copyTooltipTitle, setCopyToolTipTitle] = useState(CopyLink)
21
- const [loading, setLoading] = useState(false)
22
-
23
- const copyToClipboard = async (link?: string) => {
24
- if (link) {
25
- try {
26
- setLoading(true)
27
- await uploadPayloads?.()
28
- await navigator.clipboard.writeText(link)
29
- setCopyToolTipTitle(Copied)
30
- setTimeout(() => setCopyToolTipTitle(CopyLink), 2000)
31
- setLoading(false)
32
- } catch (e) {
33
- setLoading(false)
34
- const message = 'Error copying shareUrl to clipboard'
35
- console.error(message, e, link)
36
- onClickError?.(new Error(message))
37
- }
38
- } else {
39
- console.warn('tried to copy shareUrl before it was generated')
40
- }
41
- }
42
-
43
- return (
44
- <Tooltip title={copyTooltipTitle}>
45
- {loading
46
- ? (
47
- <IconButton>
48
- <CircularProgress size="24px" />
49
- </IconButton>
50
- )
51
- : (
52
- <IconButton aria-label={`copy ${shareLinkName} link`} onClick={() => forget(copyToClipboard(shareUrl))} edge="end" {...props}>
53
- <CopyAllRounded />
54
- </IconButton>
55
- )}
56
- </Tooltip>
57
- )
58
- }
@@ -1,69 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { CopyLinkStack } from './CopyLinkStack.tsx'
5
-
6
- export default { title: 'modules/ShareOut/CopyLinkStack' } as Meta<typeof CopyLinkStack>
7
-
8
- const Template: StoryFn<typeof CopyLinkStack> = (props) => {
9
- return <CopyLinkStack {...props} />
10
- }
11
-
12
- const Default = Template.bind({})
13
- Default.args = {}
14
-
15
- const WithShareUrl = Template.bind({})
16
- WithShareUrl.args = { shareUrl: 'https://google.com' }
17
-
18
- const WithXnsName = Template.bind({})
19
- WithXnsName.args = {
20
- shareUrl: 'https://beta.node.xyo.network.com/view/arietrouw.xyo/profile', xnsName: 'arietrouw.xyo', addToXnsName: true,
21
- }
22
-
23
- const WithNoAddToXnsName = Template.bind({})
24
- WithNoAddToXnsName.args = {
25
- shareUrl: 'https://beta.node.xyo.network.com/view/somehash1234567/profile', xnsName: 'arietrouw.xyo', addToXnsName: false,
26
- }
27
-
28
- const WithXnsNameShortened = Template.bind({})
29
- WithXnsNameShortened.args = {
30
- shareUrl: 'https://beta.node.xyo.network.com/view/arietrouw.xyo/profile', xnsName: 'arietrouw.xyo', addToXnsName: true, sx: { maxWidth: '200px' },
31
- }
32
-
33
- const WithXnsNameInSubdomain = Template.bind({})
34
- WithXnsNameInSubdomain.args = {
35
- shareUrl: 'https://arietrouw.xyo.network', xnsName: 'arietrouw.xyo', addToXnsName: true,
36
- }
37
-
38
- const WithXnsNameCustomColors = Template.bind({})
39
- WithXnsNameCustomColors.args = {
40
- shareUrl: 'https://arietrouw.xyo.network', xnsName: 'arietrouw.xyo', xnsStartColor: 'blue', xnsEndColor: 'red', addToXnsName: true,
41
- }
42
-
43
- const WithError = Template.bind({})
44
- WithError.args = {
45
- shareUrl: 'https://google.com', xnsName: 'foo.xyo', addToXnsName: true,
46
- }
47
-
48
- const WithUploadPayloads = Template.bind({})
49
- WithUploadPayloads.args = {
50
- shareUrl: 'https://beta.node.xyo.network.com/view/arietrouw.xyo/profile',
51
- xnsName: 'arietrouw.xyo',
52
- addToXnsName: true,
53
- copiedLinkText: 'Copied and data uploaded!',
54
- copyLinkText: 'Copy link and upload data',
55
- uploadPayloads: () => new Promise((resolve) => {
56
- setTimeout(() => {
57
- alert('uploaded payloads')
58
- resolve()
59
- }, 1000)
60
- }),
61
- }
62
-
63
- export {
64
- Default, WithError,
65
- WithNoAddToXnsName,
66
- WithShareUrl, WithUploadPayloads,
67
- WithXnsName, WithXnsNameCustomColors,
68
- WithXnsNameInSubdomain, WithXnsNameShortened,
69
- }
@@ -1,77 +0,0 @@
1
- import { Cancel } from '@mui/icons-material'
2
- import type { StackProps } from '@mui/material'
3
- import {
4
- Stack,
5
- Tooltip,
6
- Typography,
7
- } from '@mui/material'
8
- import React, {
9
- useCallback, useMemo, useState,
10
- } from 'react'
11
-
12
- import { CopyIconButton } from './CopyIconButton.tsx'
13
- import {
14
- AnimatedGradientTypography, type ShareLinkProps, splitAroundSubstring,
15
- } from './lib/index.ts'
16
-
17
- export interface CopyLinkStackProps extends ShareLinkProps, StackProps {
18
- addToXnsName?: boolean
19
- copiedLinkText?: string
20
- copyLinkText?: string
21
- xnsEndColor?: string
22
- xnsStartColor?: string
23
- }
24
-
25
- export const CopyLinkStack: React.FC<CopyLinkStackProps> = ({
26
- addToXnsName, copiedLinkText, copyLinkText, shareLinkName, shareUrl, xnsName: xnsNameProp, xnsEndColor, uploadPayloads, xnsStartColor, ...props
27
- }) => {
28
- const [error, setError] = useState<Error>()
29
-
30
- const onClickError = useCallback((error: Error) => {
31
- setError(error)
32
- }, [])
33
-
34
- const parsedXnsName = useMemo(() => {
35
- if (shareUrl && xnsNameProp && addToXnsName) {
36
- try {
37
- const parts = splitAroundSubstring(shareUrl, xnsNameProp)
38
- return parts
39
- } catch (e) {
40
- setError(e as Error)
41
- }
42
- }
43
- }, [addToXnsName, shareUrl, xnsNameProp])
44
-
45
- const [part1, xnsName, part3] = parsedXnsName || []
46
-
47
- return (
48
- <Stack direction="row" alignItems="center" gap={0.25} {...props}>
49
- {xnsName && addToXnsName
50
- ? (
51
- <Stack direction="row" maxWidth="100%" sx={{ overflowX: 'auto' }}>
52
- <Typography sx={{ display: 'inline-flex' }}>{part1}</Typography>
53
- <AnimatedGradientTypography color1={xnsStartColor} color2={xnsEndColor} sx={{ display: 'inline-flex' }}>{xnsName}</AnimatedGradientTypography>
54
- <Typography sx={{ display: 'inline-flex' }}>{part3}</Typography>
55
- </Stack>
56
- )
57
- : (
58
- <Typography sx={{
59
- display: 'inline-flex', maxWidth: '100%', overflow: 'auto',
60
- }}
61
- >
62
- {shareUrl}
63
- </Typography>
64
- )}
65
- <CopyIconButton
66
- copiedLinkText={copiedLinkText}
67
- copyLinkText={copyLinkText}
68
- onClickError={onClickError}
69
- shareLinkName={shareLinkName}
70
- shareUrl={shareUrl}
71
- sx={{ display: 'inline-flex' }}
72
- uploadPayloads={uploadPayloads}
73
- />
74
- {error ? <Tooltip title={error.message}><Cancel color="error" sx={{ display: 'inline-flex' }} /></Tooltip> : null}
75
- </Stack>
76
- )
77
- }
@@ -1,18 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { CopyLinkTextField } from './CopyLinkTextField.tsx'
5
-
6
- export default { title: 'modules/ShareOut/CopyLinkTextField' } as Meta<typeof CopyLinkTextField>
7
-
8
- const Template: StoryFn<typeof CopyLinkTextField> = (props) => {
9
- return <CopyLinkTextField {...props} />
10
- }
11
-
12
- const Default = Template.bind({})
13
- Default.args = {}
14
-
15
- const WithShareUrl = Template.bind({})
16
- WithShareUrl.args = { shareUrl: 'https://google.com' }
17
-
18
- export { Default, WithShareUrl }
@@ -1,41 +0,0 @@
1
- import type { StandardTextFieldProps } from '@mui/material'
2
- import { InputAdornment, TextField } from '@mui/material'
3
- import React, { useCallback, useState } from 'react'
4
-
5
- import { CopyIconButton } from './CopyIconButton.tsx'
6
-
7
- export interface CopyLinkTextFieldProps extends StandardTextFieldProps {
8
- shareLinkName?: string
9
- shareUrl?: string
10
- }
11
-
12
- export const CopyLinkTextField: React.FC<CopyLinkTextFieldProps> = ({
13
- shareLinkName, shareUrl, ...props
14
- }) => {
15
- const [error, setError] = useState<Error>()
16
-
17
- const onClickError = useCallback((error?: Error) => {
18
- setError(error)
19
- }, [])
20
-
21
- return (
22
- <TextField
23
- disabled
24
- error={!!error}
25
- helperText={error?.message}
26
- // to override the color that appears when it's a text field, only on dark mode
27
- sx={{ input: { WebkitTextFillColor: 'lightgray !important' } }}
28
- value={shareUrl}
29
- {...props}
30
- slotProps={{
31
- input: {
32
- endAdornment: (
33
- <InputAdornment position="end">
34
- <CopyIconButton shareLinkName={shareLinkName} shareUrl={shareUrl} onClickError={onClickError} />
35
- </InputAdornment>
36
- ),
37
- },
38
- }}
39
- />
40
- )
41
- }
@@ -1,78 +0,0 @@
1
- import { Button } from '@mui/material'
2
- import type { Meta, StoryFn } from '@storybook/react-vite'
3
- import { FlexGrowCol } from '@xylabs/react-flexbox'
4
- import React, { useMemo, useState } from 'react'
5
-
6
- import { CopyLinkTextField } from './CopyLinkTextField.tsx'
7
- import { ShareOutDialog } from './Dialog.tsx'
8
- import { ShareOutExplanation } from './Explanation.tsx'
9
- import { GenerateShareLinkButton } from './GenerateShareLinkButton.tsx'
10
- import { ShareOutHeadingFlexbox } from './HeadingFlexbox.tsx'
11
- import { SocialButtonsFlexbox } from './SocialButtonsFlexbox.tsx'
12
-
13
- export default { title: 'modules/ShareOut/Dialog' } as Meta<typeof ShareOutDialog>
14
-
15
- const Template: StoryFn<typeof ShareOutDialog> = (props) => {
16
- return <ShareOutDialog {...props} />
17
- }
18
-
19
- const TemplateWithContent: StoryFn<typeof ShareOutDialog> = (props) => {
20
- const [open, setOpen] = useState(false)
21
- const onClose = () => setOpen(false)
22
- const [shareUrl, setShareUrl] = useState('')
23
- const [loading, setLoading] = useState(false)
24
-
25
- const { open: unused, ...restProps } = props
26
-
27
- const cardImg = <img src="https://picsum.photos/100/100" height="100px" width="100px" />
28
- const shareLinkName = 'My Share Link'
29
-
30
- const generateLink = async () => {
31
- setLoading(true)
32
- await new Promise(resolve => setTimeout(() => {
33
- setShareUrl('https://example.com')
34
- setLoading(false)
35
- resolve(null)
36
- }, 2000))
37
- }
38
-
39
- const shareOutDialogContent = useMemo(() => (
40
- <FlexGrowCol gap={2}>
41
- <ShareOutHeadingFlexbox shareLinkName={shareLinkName} shareUrl={shareUrl} />
42
- {shareUrl
43
- ? (
44
- <>
45
- <CopyLinkTextField shareLinkName={shareLinkName} shareUrl={shareUrl} />
46
- <SocialButtonsFlexbox shareUrl={shareUrl} />
47
- </>
48
- )
49
- : <GenerateShareLinkButton loading={loading} onClick={generateLink} />}
50
- <ShareOutExplanation />
51
- </FlexGrowCol>
52
- ), [loading, generateLink, shareLinkName, shareUrl])
53
-
54
- const shareOutDialogActions = ({ onClose }: { onClose?: () => void }) => <Button onClick={onClose} variant="outlined">Close</Button>
55
-
56
- return (
57
- <>
58
- <Button onClick={() => setOpen(true)} variant="contained">Open</Button>
59
- <ShareOutDialog
60
- cardImg={cardImg}
61
- onClose={onClose}
62
- ShareOutDialogActions={shareOutDialogActions}
63
- shareOutDialogContent={shareOutDialogContent}
64
- open={open}
65
- title="Share Out Dialog"
66
- subtitle="With a subtitle"
67
- {...restProps}
68
- />
69
- </>
70
- )
71
- }
72
-
73
- const Default = Template.bind({})
74
-
75
- const WithContent = TemplateWithContent.bind({})
76
- WithContent.args = {}
77
-
78
- export { Default, WithContent }
@@ -1,48 +0,0 @@
1
- import type { DialogProps } from '@mui/material'
2
- import {
3
- Dialog, DialogActions, DialogContent, DialogTitle, Stack, Typography,
4
- } from '@mui/material'
5
- import { FlexCol, FlexGrowCol } from '@xylabs/react-flexbox'
6
- import type { ComponentType, ReactNode } from 'react'
7
- import React from 'react'
8
-
9
- export interface ShareOutDialogProps extends DialogProps {
10
- ShareOutDialogActions?: ComponentType<{ onClose?: () => void }>
11
- cardImg?: ReactNode
12
- shareOutDialogContent?: ReactNode
13
- subtitle?: string
14
- title?: string
15
- }
16
-
17
- export const ShareOutDialog: React.FC<ShareOutDialogProps> = ({
18
- ShareOutDialogActions, cardImg, open, onClose, shareOutDialogContent, subtitle, title, ...props
19
- }) => {
20
- const handleClose = () => {
21
- onClose?.('', 'backdropClick')
22
- }
23
-
24
- return (
25
- <Dialog onClose={onClose} open={open} {...props}>
26
- <DialogTitle>
27
- <Stack direction="row" spacing={2}>
28
- <FlexGrowCol alignItems="flex-start" width="60%">
29
- <Typography variant="h5">{title}</Typography>
30
- <Typography variant="body1">
31
- {' '}
32
- {subtitle}
33
- </Typography>
34
- </FlexGrowCol>
35
- <FlexGrowCol alignItems="flex-end" width="40%">
36
- {cardImg}
37
- </FlexGrowCol>
38
- </Stack>
39
- </DialogTitle>
40
- <DialogContent>
41
- {shareOutDialogContent}
42
- <FlexCol alignItems="stretch">
43
- </FlexCol>
44
- </DialogContent>
45
- {ShareOutDialogActions ? <DialogActions><ShareOutDialogActions onClose={handleClose} /></DialogActions> : null}
46
- </Dialog>
47
- )
48
- }
@@ -1,29 +0,0 @@
1
- import { InfoOutlined } from '@mui/icons-material'
2
- import {
3
- Tooltip, Typography, useTheme,
4
- } from '@mui/material'
5
- import { FlexGrowRow } from '@xylabs/react-flexbox'
6
- import React from 'react'
7
-
8
- export interface ShareOutExplanationProps {
9
- toolTipTitle?: string
10
- }
11
-
12
- export const ShareOutExplanation: React.FC<ShareOutExplanationProps> = ({ toolTipTitle }) => {
13
- const theme = useTheme()
14
- // eslint-disable-next-line @stylistic/max-len
15
- const title = toolTipTitle ?? 'In order for your data to be publicly viewable, it needs to be saved to the XYO Network Public Archivist. Public data can be seen by your friends, and XYO can generate preview images for easier sharing on social media.'
16
- return (
17
- <FlexGrowRow alignItems="center">
18
- <Typography variant="body2" paddingRight={0.5}>
19
- What am I sharing?
20
- </Typography>
21
- <Tooltip
22
- title={title}
23
- placement="bottom"
24
- >
25
- <InfoOutlined fontSize="small" sx={{ fontSize: theme.typography.caption.fontSize }} />
26
- </Tooltip>
27
- </FlexGrowRow>
28
- )
29
- }
@@ -1,18 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { GenerateShareLinkButton } from './GenerateShareLinkButton.tsx'
5
-
6
- export default { title: 'modules/ShareOut/GenerateShareLinkButton' } as Meta<typeof GenerateShareLinkButton>
7
-
8
- const Template: StoryFn<typeof GenerateShareLinkButton> = (props) => {
9
- return <GenerateShareLinkButton {...props} />
10
- }
11
-
12
- const Default = Template.bind({})
13
- Default.args = {}
14
-
15
- const WithLoading = Template.bind({})
16
- WithLoading.args = { loading: true }
17
-
18
- export { Default, WithLoading }
@@ -1,31 +0,0 @@
1
- import type { ButtonProps } from '@mui/material'
2
- import {
3
- Button, CircularProgress, styled,
4
- } from '@mui/material'
5
- import React from 'react'
6
-
7
- export interface GenerateShareLinkButtonProps extends ButtonProps {
8
- loading?: boolean
9
- }
10
-
11
- export const GenerateShareLinkButton: React.FC<GenerateShareLinkButtonProps> = ({
12
- children = 'Generate My Share Link', loading, ...props
13
- }) => {
14
- return (
15
- <Button
16
- variant="contained"
17
- startIcon={loading ? <StyledCircularProgress size="small" /> : null}
18
- {...props}
19
- >
20
- {children}
21
- </Button>
22
- )
23
- }
24
-
25
- const StyledCircularProgress = styled(CircularProgress, { name: 'StyledCircularProgress' })(({ theme }) => ({
26
- // ensure the color of the spinner is the same as the button color
27
- color: theme.vars.palette.primary.contrastText,
28
- height: '20px',
29
- opacity: '.87',
30
- width: '20px',
31
- }))
@@ -1,27 +0,0 @@
1
- import { Typography } from '@mui/material'
2
- import type { FlexBoxProps } from '@xylabs/react-flexbox'
3
- import { FlexGrowCol } from '@xylabs/react-flexbox'
4
- import React from 'react'
5
-
6
- export interface ShareOutHeadingFlexboxProps extends FlexBoxProps {
7
- shareLinkName?: string
8
- shareUrl?: string
9
- }
10
-
11
- export const ShareOutHeadingFlexbox: React.FC<ShareOutHeadingFlexboxProps> = ({
12
- children, shareLinkName, shareUrl, ...props
13
- }) => {
14
- const GenerateShareLinkExplanation = "When you generate your share link, we'll make a small amount of your data public so friends can check it out!"
15
-
16
- return (
17
- <FlexGrowCol alignItems="flex-start" paddingBottom={1} {...props}>
18
- <Typography variant="body1" gutterBottom>
19
- <strong>Your Share Link</strong>
20
- </Typography>
21
- <Typography variant="body1">
22
- {shareUrl ? `Use this link or the buttons below to share ${shareLinkName}` : GenerateShareLinkExplanation}
23
- </Typography>
24
- {children}
25
- </FlexGrowCol>
26
- )
27
- }
@@ -1,41 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { SocialButtonsFlexbox } from './SocialButtonsFlexbox.tsx'
5
-
6
- export default { title: 'modules/ShareOut/SocialButtonsFlexbox' } as Meta<typeof SocialButtonsFlexbox>
7
-
8
- const Template: StoryFn<typeof SocialButtonsFlexbox> = (props) => {
9
- return <SocialButtonsFlexbox {...props} />
10
- }
11
-
12
- const Default = Template.bind({})
13
- Default.args = {}
14
-
15
- const WithShareUrl = Template.bind({})
16
- WithShareUrl.args = { shareUrl: 'https://google.com' }
17
-
18
- const WithUploadPayloads = Template.bind({})
19
- WithUploadPayloads.args = {
20
- shareUrl: 'https://google.com',
21
- uploadPayloads: () => new Promise((resolve) => {
22
- setTimeout(() => {
23
- alert('uploaded payloads')
24
- resolve()
25
- }, 1000)
26
- }),
27
- }
28
-
29
- const WithUploadPayloadsError = Template.bind({})
30
- WithUploadPayloadsError.args = {
31
- shareUrl: 'https://google.com',
32
- uploadPayloads: () => new Promise((_resolve, reject) => {
33
- setTimeout(() => {
34
- reject(new Error('Error uploading payloads'))
35
- }, 1000)
36
- }),
37
- }
38
-
39
- export {
40
- Default, WithShareUrl, WithUploadPayloads, WithUploadPayloadsError,
41
- }
@@ -1,79 +0,0 @@
1
- import { Typography } from '@mui/material'
2
- import { ButtonEx } from '@xylabs/react-button'
3
- import { ErrorRender } from '@xylabs/react-error'
4
- import type { FlexBoxProps } from '@xylabs/react-flexbox'
5
- import { FlexGrowCol, FlexRow } from '@xylabs/react-flexbox'
6
- import React, { useState } from 'react'
7
-
8
- import { FacebookSvgIcon, XTwitterSvgIcon } from '../icons/index.ts'
9
-
10
- export interface SocialButtonsFlexboxProps extends FlexBoxProps {
11
- shareUrl?: string
12
- uploadPayloads?: () => Promise<void>
13
- }
14
-
15
- export const SocialButtonsFlexbox: React.FC<SocialButtonsFlexboxProps> = ({
16
- shareUrl, uploadPayloads, ...props
17
- }) => {
18
- const [error, setError] = useState<Error>()
19
- const [xLoading, setXLoading] = useState(false)
20
- const [fbLoading, setFbLoading] = useState(false)
21
-
22
- const handleClick = async (openUrl: () => void, buttonName: 'x' | 'fb') => {
23
- const setLoading = buttonName === 'x' ? setXLoading : setFbLoading
24
- try {
25
- setLoading(true)
26
- await uploadPayloads?.()
27
- setLoading(false)
28
- openUrl()
29
- } catch (e) {
30
- setLoading(false)
31
- console.error('Error uploading payloads', e)
32
- setError(e as Error)
33
- }
34
- }
35
-
36
- return (
37
- <FlexGrowCol alignItems="stretch" paddingTop={2} {...props}>
38
- <Typography variant="body1" gutterBottom>
39
- <strong>Share on Social Media</strong>
40
- </Typography>
41
- <FlexRow
42
- gap={0.5}
43
- sx={{ flexDirection: { md: 'row', xs: 'column' } }}
44
- >
45
- {shareUrl
46
- ? (
47
- <>
48
- <ButtonEx
49
- variant="contained"
50
- style={{ backgroundColor: '#000', color: '#fff' }}
51
- busy={xLoading}
52
- onClick={async () => {
53
- const openUrl = () => window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(shareUrl)}`)
54
- await handleClick(openUrl, 'x')
55
- }}
56
- startIcon={<XTwitterSvgIcon width="20px" />}
57
- >
58
- Share on X (Twitter)
59
- </ButtonEx>
60
- <ButtonEx
61
- busy={fbLoading}
62
- variant="contained"
63
- style={{ backgroundColor: '#4267b2', color: '#fff' }}
64
- onClick={async () => {
65
- const openUrl = () => window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(shareUrl)}`)
66
- await handleClick(openUrl, 'fb')
67
- }}
68
- startIcon={<FacebookSvgIcon />}
69
- >
70
- Share on Facebook
71
- </ButtonEx>
72
- </>
73
- )
74
- : null}
75
- </FlexRow>
76
- <ErrorRender error={error} scope="SocialButtonsFlexbox" />
77
- </FlexGrowCol>
78
- )
79
- }
package/src/out/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './CopyLinkStack.tsx'
2
- export * from './CopyLinkTextField.tsx'
3
- export * from './Dialog.tsx'
4
- export * from './Explanation.tsx'
5
- export * from './GenerateShareLinkButton.tsx'
6
- export * from './HeadingFlexbox.tsx'
7
- export * from './SocialButtonsFlexbox.tsx'