@dxos/react-ui 0.7.5-main.499c70c → 0.7.5-main.937ce75
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 +60 -26
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +48 -14
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +60 -26
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Buttons/IconButton.d.ts +4 -2
- package/dist/types/src/components/Buttons/IconButton.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +11 -5
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +3 -2
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/components/Buttons/IconButton.tsx +19 -5
- package/src/components/Toolbar/Toolbar.tsx +35 -7
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { forwardRef } from 'react';
|
|
5
|
+
import React, { forwardRef, type ReactNode, type MutableRefObject, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { Button, type ButtonProps } from './Button';
|
|
8
8
|
import { useThemeContext } from '../../hooks';
|
|
@@ -12,16 +12,19 @@ import { Tooltip } from '../Tooltip';
|
|
|
12
12
|
|
|
13
13
|
type IconButtonProps = Omit<ButtonProps, 'children'> &
|
|
14
14
|
Pick<IconProps, 'icon' | 'size'> & {
|
|
15
|
-
label:
|
|
15
|
+
label: NonNullable<ReactNode>;
|
|
16
16
|
iconOnly?: boolean;
|
|
17
|
+
caretDown?: boolean;
|
|
17
18
|
// TODO(burdon): Create slots abstraction?
|
|
18
19
|
iconClassNames?: ThemedClassName<any>['classNames'];
|
|
19
20
|
tooltipPortal?: boolean;
|
|
20
21
|
tooltipZIndex?: string;
|
|
22
|
+
suppressNextTooltip?: MutableRefObject<boolean>;
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
const IconOnlyButton = forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
24
|
-
({ tooltipPortal = true, tooltipZIndex: zIndex, ...props }, forwardedRef) => {
|
|
26
|
+
({ tooltipPortal = true, tooltipZIndex: zIndex, suppressNextTooltip, ...props }, forwardedRef) => {
|
|
27
|
+
const [triggerTooltipOpen, setTriggerTooltipOpen] = useState(false);
|
|
25
28
|
const content = (
|
|
26
29
|
<Tooltip.Content {...(zIndex && { style: { zIndex } })}>
|
|
27
30
|
{props.label}
|
|
@@ -29,7 +32,17 @@ const IconOnlyButton = forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
|
29
32
|
</Tooltip.Content>
|
|
30
33
|
);
|
|
31
34
|
return (
|
|
32
|
-
<Tooltip.Root
|
|
35
|
+
<Tooltip.Root
|
|
36
|
+
open={triggerTooltipOpen}
|
|
37
|
+
onOpenChange={(nextOpen) => {
|
|
38
|
+
if (suppressNextTooltip?.current) {
|
|
39
|
+
setTriggerTooltipOpen(false);
|
|
40
|
+
suppressNextTooltip.current = false;
|
|
41
|
+
} else {
|
|
42
|
+
setTriggerTooltipOpen(nextOpen);
|
|
43
|
+
}
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
33
46
|
<Tooltip.Trigger asChild>
|
|
34
47
|
<LabelledIconButton {...props} ref={forwardedRef} />
|
|
35
48
|
</Tooltip.Trigger>
|
|
@@ -40,12 +53,13 @@ const IconOnlyButton = forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
|
40
53
|
);
|
|
41
54
|
|
|
42
55
|
const LabelledIconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
43
|
-
({ icon, size, iconOnly, label, classNames, iconClassNames, ...props }, forwardedRef) => {
|
|
56
|
+
({ icon, size, iconOnly, label, classNames, iconClassNames, caretDown, ...props }, forwardedRef) => {
|
|
44
57
|
const { tx } = useThemeContext();
|
|
45
58
|
return (
|
|
46
59
|
<Button {...props} classNames={tx('iconButton.root', 'iconButton', {}, classNames)} ref={forwardedRef}>
|
|
47
60
|
<Icon icon={icon} size={size} classNames={iconClassNames} />
|
|
48
61
|
<span className={iconOnly ? 'sr-only' : undefined}>{label}</span>
|
|
62
|
+
{caretDown && <Icon size={3} icon='ph--caret-down--bold' />}
|
|
49
63
|
</Button>
|
|
50
64
|
);
|
|
51
65
|
},
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type { ToggleGroupItemProps as ToggleGroupItemPrimitiveProps } from '@radix-ui/react-toggle-group';
|
|
5
6
|
import * as ToolbarPrimitive from '@radix-ui/react-toolbar';
|
|
6
7
|
import React, { forwardRef } from 'react';
|
|
7
8
|
|
|
@@ -15,6 +16,8 @@ import {
|
|
|
15
16
|
Toggle,
|
|
16
17
|
type ToggleGroupItemProps,
|
|
17
18
|
type ToggleProps,
|
|
19
|
+
IconButton,
|
|
20
|
+
type IconButtonProps,
|
|
18
21
|
} from '../Buttons';
|
|
19
22
|
import { Link, type LinkProps } from '../Link';
|
|
20
23
|
import { Separator, type SeparatorProps } from '../Separator';
|
|
@@ -40,6 +43,16 @@ const ToolbarButton = forwardRef<HTMLButtonElement, ToolbarButtonProps>((props,
|
|
|
40
43
|
);
|
|
41
44
|
});
|
|
42
45
|
|
|
46
|
+
type ToolbarIconButtonProps = IconButtonProps;
|
|
47
|
+
|
|
48
|
+
const ToolbarIconButton = forwardRef<HTMLButtonElement, ToolbarIconButtonProps>((props, forwardedRef) => {
|
|
49
|
+
return (
|
|
50
|
+
<ToolbarPrimitive.Button asChild>
|
|
51
|
+
<IconButton {...props} ref={forwardedRef} />
|
|
52
|
+
</ToolbarPrimitive.Button>
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
43
56
|
type ToolbarToggleProps = ToggleProps;
|
|
44
57
|
|
|
45
58
|
const ToolbarToggle = forwardRef<HTMLButtonElement, ToolbarToggleProps>((props, forwardedRef) => {
|
|
@@ -88,35 +101,50 @@ const ToolbarToggleGroupItem = forwardRef<HTMLButtonElement, ToolbarToggleGroupI
|
|
|
88
101
|
},
|
|
89
102
|
);
|
|
90
103
|
|
|
91
|
-
type
|
|
104
|
+
type ToolbarToggleGroupIconItemProps = Omit<ToggleGroupItemPrimitiveProps, 'className'> & IconButtonProps;
|
|
92
105
|
|
|
93
|
-
const
|
|
94
|
-
|
|
106
|
+
const ToolbarToggleGroupIconItem = forwardRef<HTMLButtonElement, ToolbarToggleGroupIconItemProps>(
|
|
107
|
+
({ variant, density, elevation, classNames, icon, label, iconOnly, ...props }, forwardedRef) => {
|
|
108
|
+
return (
|
|
109
|
+
<ToolbarPrimitive.ToolbarToggleItem {...props} asChild>
|
|
110
|
+
<IconButton {...{ variant, density, elevation, classNames, icon, label, iconOnly }} ref={forwardedRef} />
|
|
111
|
+
</ToolbarPrimitive.ToolbarToggleItem>
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
type ToolbarSeparatorProps = SeparatorProps & { variant?: 'gap' | 'line' };
|
|
117
|
+
|
|
118
|
+
const ToolbarSeparator = ({ variant = 'line', ...props }: ToolbarSeparatorProps) => {
|
|
119
|
+
return variant === 'line' ? (
|
|
95
120
|
<ToolbarPrimitive.Separator asChild>
|
|
96
|
-
<Separator
|
|
121
|
+
<Separator {...props} />
|
|
97
122
|
</ToolbarPrimitive.Separator>
|
|
123
|
+
) : (
|
|
124
|
+
<ToolbarPrimitive.Separator className='grow' />
|
|
98
125
|
);
|
|
99
126
|
};
|
|
100
127
|
|
|
101
|
-
const ToolbarExpander = () => <div className={'grow'} />;
|
|
102
|
-
|
|
103
128
|
export const Toolbar = {
|
|
104
129
|
Root: ToolbarRoot,
|
|
105
130
|
Button: ToolbarButton,
|
|
131
|
+
IconButton: ToolbarIconButton,
|
|
106
132
|
Link: ToolbarLink,
|
|
107
133
|
Toggle: ToolbarToggle,
|
|
108
134
|
ToggleGroup: ToolbarToggleGroup,
|
|
109
135
|
ToggleGroupItem: ToolbarToggleGroupItem,
|
|
136
|
+
ToggleGroupIconItem: ToolbarToggleGroupIconItem,
|
|
110
137
|
Separator: ToolbarSeparator,
|
|
111
|
-
Expander: ToolbarExpander,
|
|
112
138
|
};
|
|
113
139
|
|
|
114
140
|
export type {
|
|
115
141
|
ToolbarRootProps,
|
|
116
142
|
ToolbarButtonProps,
|
|
143
|
+
ToolbarIconButtonProps,
|
|
117
144
|
ToolbarLinkProps,
|
|
118
145
|
ToolbarToggleProps,
|
|
119
146
|
ToolbarToggleGroupProps,
|
|
120
147
|
ToolbarToggleGroupItemProps,
|
|
148
|
+
ToolbarToggleGroupIconItemProps,
|
|
121
149
|
ToolbarSeparatorProps,
|
|
122
150
|
};
|