@dxos/react-ui 0.7.2 → 0.7.3-staging.0905f03
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/lib/browser/index.mjs +376 -274
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +464 -364
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +376 -274
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Clipboard/ClipboardProvider.d.ts +9 -0
- package/dist/types/src/components/Clipboard/ClipboardProvider.d.ts.map +1 -0
- package/dist/types/src/components/Clipboard/CopyButton.d.ts +10 -0
- package/dist/types/src/components/Clipboard/CopyButton.d.ts.map +1 -0
- package/dist/types/src/components/Clipboard/index.d.ts +7 -0
- package/dist/types/src/components/Clipboard/index.d.ts.map +1 -0
- package/dist/types/src/components/Dialogs/AlertDialog.d.ts +3 -1
- package/dist/types/src/components/Dialogs/AlertDialog.d.ts.map +1 -1
- package/dist/types/src/components/Icon/Icon.d.ts.map +1 -1
- package/dist/types/src/components/ThemeProvider/ThemeProvider.d.ts +2 -1
- package/dist/types/src/components/ThemeProvider/ThemeProvider.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/components/Clipboard/ClipboardProvider.tsx +26 -0
- package/src/components/Clipboard/CopyButton.tsx +74 -0
- package/src/components/Clipboard/index.ts +14 -0
- package/src/components/Dialogs/AlertDialog.tsx +12 -3
- package/src/components/Icon/Icon.tsx +5 -2
- package/src/components/ThemeProvider/ThemeProvider.tsx +3 -1
- package/src/components/index.ts +1 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type IconProps } from '@phosphor-icons/react';
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
9
|
+
|
|
10
|
+
import { useClipboard } from './ClipboardProvider';
|
|
11
|
+
import { Button, type ButtonProps } from '../Buttons';
|
|
12
|
+
import { Icon } from '../Icon';
|
|
13
|
+
import { useTranslation } from '../ThemeProvider';
|
|
14
|
+
import { Tooltip } from '../Tooltip';
|
|
15
|
+
|
|
16
|
+
export type CopyButtonProps = ButtonProps & {
|
|
17
|
+
value: string;
|
|
18
|
+
iconProps?: IconProps;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const inactiveLabelStyles = 'invisible bs-px -mbe-px overflow-hidden';
|
|
22
|
+
|
|
23
|
+
export const CopyButton = ({ value, classNames, iconProps, ...props }: CopyButtonProps) => {
|
|
24
|
+
const { t } = useTranslation('os');
|
|
25
|
+
const { textValue, setTextValue } = useClipboard();
|
|
26
|
+
const isCopied = textValue === value;
|
|
27
|
+
return (
|
|
28
|
+
<Button
|
|
29
|
+
{...props}
|
|
30
|
+
classNames={['inline-flex flex-col justify-center', classNames]}
|
|
31
|
+
onClick={() => setTextValue(value)}
|
|
32
|
+
data-testid='copy-invitation'
|
|
33
|
+
>
|
|
34
|
+
<div role='none' className={mx('flex gap-1 items-center', isCopied && inactiveLabelStyles)}>
|
|
35
|
+
<span className='pli-1'>{t('copy label')}</span>
|
|
36
|
+
{/* TODO(wittjosiah): Why do these need as any? */}
|
|
37
|
+
<Icon icon='ph--copy--regular' size={5 as any} {...iconProps} />
|
|
38
|
+
</div>
|
|
39
|
+
<div role='none' className={mx('flex gap-1 items-center', !isCopied && inactiveLabelStyles)}>
|
|
40
|
+
<span className='pli-1'>{t('copy success label')}</span>
|
|
41
|
+
<Icon icon='ph--check--regular' size={5 as any} {...iconProps} />
|
|
42
|
+
</div>
|
|
43
|
+
</Button>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const CopyButtonIconOnly = ({ value, classNames, iconProps, variant, ...props }: CopyButtonProps) => {
|
|
48
|
+
const { t } = useTranslation('os');
|
|
49
|
+
const { textValue, setTextValue } = useClipboard();
|
|
50
|
+
const isCopied = textValue === value;
|
|
51
|
+
const label = isCopied ? t('copy success label') : t('copy label');
|
|
52
|
+
const [open, setOpen] = useState(false);
|
|
53
|
+
return (
|
|
54
|
+
<Tooltip.Root delayDuration={1500} open={open} onOpenChange={setOpen}>
|
|
55
|
+
<Tooltip.Portal>
|
|
56
|
+
<Tooltip.Content side='bottom' sideOffset={12} classNames='z-30'>
|
|
57
|
+
<span>{label}</span>
|
|
58
|
+
<Tooltip.Arrow />
|
|
59
|
+
</Tooltip.Content>
|
|
60
|
+
</Tooltip.Portal>
|
|
61
|
+
<Tooltip.Trigger
|
|
62
|
+
aria-label={label}
|
|
63
|
+
{...props}
|
|
64
|
+
onClick={() => setTextValue(value).then(() => setOpen(true))}
|
|
65
|
+
data-testid='copy-invitation'
|
|
66
|
+
asChild
|
|
67
|
+
>
|
|
68
|
+
<Button variant={variant} classNames={['inline-flex flex-col justify-center', classNames]}>
|
|
69
|
+
<Icon icon='ph--copy--regular' size={5 as any} {...iconProps} />
|
|
70
|
+
</Button>
|
|
71
|
+
</Tooltip.Trigger>
|
|
72
|
+
</Tooltip.Root>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { ClipboardProvider } from './ClipboardProvider';
|
|
6
|
+
import { CopyButton, CopyButtonIconOnly } from './CopyButton';
|
|
7
|
+
|
|
8
|
+
export const Clipboard = {
|
|
9
|
+
Button: CopyButton,
|
|
10
|
+
IconButton: CopyButtonIconOnly,
|
|
11
|
+
Provider: ClipboardProvider,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useClipboard } from './ClipboardProvider';
|
|
@@ -91,18 +91,27 @@ const [OverlayLayoutProvider, useOverlayLayoutContext] = createContext<OverlayLa
|
|
|
91
91
|
},
|
|
92
92
|
);
|
|
93
93
|
|
|
94
|
-
type AlertDialogOverlayProps = ThemedClassName<AlertDialogOverlayPrimitiveProps
|
|
94
|
+
type AlertDialogOverlayProps = ThemedClassName<AlertDialogOverlayPrimitiveProps> & { blockAlign?: 'center' | 'start' };
|
|
95
95
|
|
|
96
96
|
const AlertDialogOverlay: ForwardRefExoticComponent<AlertDialogOverlayProps> = forwardRef<
|
|
97
97
|
HTMLDivElement,
|
|
98
98
|
AlertDialogOverlayProps
|
|
99
|
-
>(({ classNames, children, ...props }, forwardedRef) => {
|
|
99
|
+
>(({ classNames, children, blockAlign, ...props }, forwardedRef) => {
|
|
100
100
|
const { tx } = useThemeContext();
|
|
101
101
|
return (
|
|
102
102
|
<AlertDialogOverlayPrimitive
|
|
103
103
|
{...props}
|
|
104
|
-
className={tx(
|
|
104
|
+
className={tx(
|
|
105
|
+
'dialog.overlay',
|
|
106
|
+
'dialog--alert__overlay',
|
|
107
|
+
{},
|
|
108
|
+
classNames,
|
|
109
|
+
'data-[block-align=start]:justify-center',
|
|
110
|
+
'data-[block-align=start]:items-start',
|
|
111
|
+
'data-[block-align=center]:place-content-center',
|
|
112
|
+
)}
|
|
105
113
|
ref={forwardedRef}
|
|
114
|
+
data-block-align={blockAlign}
|
|
106
115
|
>
|
|
107
116
|
<OverlayLayoutProvider inOverlayLayout>{children}</OverlayLayoutProvider>
|
|
108
117
|
</AlertDialogOverlayPrimitive>
|
|
@@ -10,14 +10,17 @@ import { type Size } from '@dxos/react-ui-types';
|
|
|
10
10
|
import { useThemeContext } from '../../hooks';
|
|
11
11
|
import { type ThemedClassName } from '../../util';
|
|
12
12
|
|
|
13
|
+
const ICONS_URL = '/icons.svg';
|
|
14
|
+
|
|
13
15
|
export type IconProps = ThemedClassName<ComponentPropsWithRef<typeof Primitive.svg>> & { icon: string; size?: Size };
|
|
14
16
|
|
|
15
17
|
export const Icon = memo(
|
|
16
18
|
forwardRef<SVGSVGElement, IconProps>(({ icon, classNames, size, ...props }, forwardedRef) => {
|
|
17
|
-
const { tx } = useThemeContext();
|
|
19
|
+
const { tx, noCache } = useThemeContext();
|
|
20
|
+
const url = noCache ? `${ICONS_URL}?nocache=${new Date().getMinutes()}` : ICONS_URL;
|
|
18
21
|
return (
|
|
19
22
|
<svg {...props} className={tx('icon.root', 'icon', { size }, classNames)} ref={forwardedRef}>
|
|
20
|
-
<use href={
|
|
23
|
+
<use href={`${url}#${icon}`} />
|
|
21
24
|
</svg>
|
|
22
25
|
);
|
|
23
26
|
}),
|
|
@@ -18,6 +18,7 @@ export type ThemeContextValue = {
|
|
|
18
18
|
tx: ThemeFunction<any>;
|
|
19
19
|
themeMode: ThemeMode;
|
|
20
20
|
hasIosKeyboard: boolean;
|
|
21
|
+
noCache?: boolean;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -41,6 +42,7 @@ export const ThemeProvider = ({
|
|
|
41
42
|
themeMode = 'dark',
|
|
42
43
|
rootDensity = 'fine',
|
|
43
44
|
rootElevation = 'base',
|
|
45
|
+
...rest
|
|
44
46
|
}: ThemeProviderProps) => {
|
|
45
47
|
useEffect(() => {
|
|
46
48
|
if (document.defaultView) {
|
|
@@ -51,7 +53,7 @@ export const ThemeProvider = ({
|
|
|
51
53
|
}, []);
|
|
52
54
|
|
|
53
55
|
return (
|
|
54
|
-
<ThemeContext.Provider value={{ tx, themeMode, hasIosKeyboard: hasIosKeyboard() }}>
|
|
56
|
+
<ThemeContext.Provider value={{ tx, themeMode, hasIosKeyboard: hasIosKeyboard(), ...rest }}>
|
|
55
57
|
<TranslationsProvider
|
|
56
58
|
{...{
|
|
57
59
|
fallback,
|
package/src/components/index.ts
CHANGED