@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.
Files changed (30) hide show
  1. package/dist/lib/browser/index.mjs +376 -274
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +464 -364
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +376 -274
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/Clipboard/ClipboardProvider.d.ts +9 -0
  11. package/dist/types/src/components/Clipboard/ClipboardProvider.d.ts.map +1 -0
  12. package/dist/types/src/components/Clipboard/CopyButton.d.ts +10 -0
  13. package/dist/types/src/components/Clipboard/CopyButton.d.ts.map +1 -0
  14. package/dist/types/src/components/Clipboard/index.d.ts +7 -0
  15. package/dist/types/src/components/Clipboard/index.d.ts.map +1 -0
  16. package/dist/types/src/components/Dialogs/AlertDialog.d.ts +3 -1
  17. package/dist/types/src/components/Dialogs/AlertDialog.d.ts.map +1 -1
  18. package/dist/types/src/components/Icon/Icon.d.ts.map +1 -1
  19. package/dist/types/src/components/ThemeProvider/ThemeProvider.d.ts +2 -1
  20. package/dist/types/src/components/ThemeProvider/ThemeProvider.d.ts.map +1 -1
  21. package/dist/types/src/components/index.d.ts +1 -0
  22. package/dist/types/src/components/index.d.ts.map +1 -1
  23. package/package.json +12 -12
  24. package/src/components/Clipboard/ClipboardProvider.tsx +26 -0
  25. package/src/components/Clipboard/CopyButton.tsx +74 -0
  26. package/src/components/Clipboard/index.ts +14 -0
  27. package/src/components/Dialogs/AlertDialog.tsx +12 -3
  28. package/src/components/Icon/Icon.tsx +5 -2
  29. package/src/components/ThemeProvider/ThemeProvider.tsx +3 -1
  30. 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('dialog.overlay', 'dialog--alert__overlay', {}, classNames)}
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={`/icons.svg#${icon}`} />
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,
@@ -6,6 +6,7 @@ export * from './AnchoredOverflow';
6
6
  export * from './Avatars';
7
7
  export * from './Breadcrumb';
8
8
  export * from './Buttons';
9
+ export * from './Clipboard';
9
10
  export * from './Dialogs';
10
11
  export * from './Menus';
11
12
  export * from './Icon';