react-science 0.27.0 → 0.27.1-pre.1696432898

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 (59) hide show
  1. package/lib/app/about/AboutDialogToolbarButton.js +3 -3
  2. package/lib/app/kinds/iv/plot-view/IvPlotView.js +5 -6
  3. package/lib/components/fullscreen/FullscreenToolbarButton.js +2 -3
  4. package/lib/components/modal/ConfirmModal.js +3 -1
  5. package/lib/components/root-layout/RootLayout.js +4 -2
  6. package/lib/components/split-pane/SplitPane.js +5 -4
  7. package/lib/components/split-pane/useSplitPaneSize.js +8 -8
  8. package/lib/components/tabs/Tabs.js +1 -0
  9. package/lib/components/toolbar/Toolbar.js +27 -83
  10. package/lib/components/toolbar/toolbarContext.js +13 -0
  11. package/lib-esm/app/about/AboutDialogToolbarButton.d.ts +2 -1
  12. package/lib-esm/app/about/AboutDialogToolbarButton.d.ts.map +1 -1
  13. package/lib-esm/app/about/AboutDialogToolbarButton.js +2 -2
  14. package/lib-esm/app/about/AboutDialogToolbarButton.js.map +1 -1
  15. package/lib-esm/app/kinds/iv/plot-view/IvPlotView.d.ts.map +1 -1
  16. package/lib-esm/app/kinds/iv/plot-view/IvPlotView.js +3 -4
  17. package/lib-esm/app/kinds/iv/plot-view/IvPlotView.js.map +1 -1
  18. package/lib-esm/components/fullscreen/FullscreenToolbarButton.d.ts.map +1 -1
  19. package/lib-esm/components/fullscreen/FullscreenToolbarButton.js +2 -3
  20. package/lib-esm/components/fullscreen/FullscreenToolbarButton.js.map +1 -1
  21. package/lib-esm/components/modal/ConfirmModal.d.ts.map +1 -1
  22. package/lib-esm/components/modal/ConfirmModal.js +3 -1
  23. package/lib-esm/components/modal/ConfirmModal.js.map +1 -1
  24. package/lib-esm/components/root-layout/RootLayout.d.ts +1 -1
  25. package/lib-esm/components/root-layout/RootLayout.d.ts.map +1 -1
  26. package/lib-esm/components/root-layout/RootLayout.js +4 -2
  27. package/lib-esm/components/root-layout/RootLayout.js.map +1 -1
  28. package/lib-esm/components/split-pane/SplitPane.js +5 -4
  29. package/lib-esm/components/split-pane/SplitPane.js.map +1 -1
  30. package/lib-esm/components/split-pane/useSplitPaneSize.d.ts +1 -1
  31. package/lib-esm/components/split-pane/useSplitPaneSize.js +8 -8
  32. package/lib-esm/components/split-pane/useSplitPaneSize.js.map +1 -1
  33. package/lib-esm/components/tabs/Tabs.js +1 -0
  34. package/lib-esm/components/tabs/Tabs.js.map +1 -1
  35. package/lib-esm/components/toolbar/Toolbar.d.ts +9 -7
  36. package/lib-esm/components/toolbar/Toolbar.d.ts.map +1 -1
  37. package/lib-esm/components/toolbar/Toolbar.js +29 -85
  38. package/lib-esm/components/toolbar/Toolbar.js.map +1 -1
  39. package/lib-esm/components/toolbar/toolbarContext.d.ts +11 -0
  40. package/lib-esm/components/toolbar/toolbarContext.d.ts.map +1 -0
  41. package/lib-esm/components/toolbar/toolbarContext.js +10 -0
  42. package/lib-esm/components/toolbar/toolbarContext.js.map +1 -0
  43. package/package.json +3 -1
  44. package/src/app/about/AboutDialogToolbarButton.tsx +4 -9
  45. package/src/app/kinds/iv/plot-view/IvPlotView.tsx +4 -7
  46. package/src/components/fullscreen/FullscreenToolbarButton.tsx +2 -6
  47. package/src/components/modal/ConfirmModal.tsx +3 -1
  48. package/src/components/root-layout/RootLayout.tsx +5 -2
  49. package/src/components/split-pane/SplitPane.tsx +13 -7
  50. package/src/components/split-pane/useSplitPaneSize.tsx +8 -8
  51. package/src/components/tabs/Tabs.tsx +1 -0
  52. package/src/components/toolbar/Toolbar.tsx +81 -122
  53. package/src/components/toolbar/toolbarContext.ts +21 -0
  54. package/lib/components/toolbar/ToolbarContext.js +0 -18
  55. package/lib-esm/components/toolbar/ToolbarContext.d.ts +0 -8
  56. package/lib-esm/components/toolbar/ToolbarContext.d.ts.map +0 -1
  57. package/lib-esm/components/toolbar/ToolbarContext.js +0 -14
  58. package/lib-esm/components/toolbar/ToolbarContext.js.map +0 -1
  59. package/src/components/toolbar/ToolbarContext.tsx +0 -25
@@ -1,24 +1,37 @@
1
1
  /** @jsxImportSource @emotion/react */
2
- import { css, CSSObject } from '@emotion/react';
2
+ import {
3
+ Button,
4
+ ButtonGroup,
5
+ ButtonProps,
6
+ Classes,
7
+ Colors,
8
+ Intent,
9
+ Tooltip,
10
+ } from '@blueprintjs/core';
11
+ import { css } from '@emotion/react';
3
12
  import {
4
13
  ReactElement,
5
- ReactFragment,
6
14
  ReactNode,
7
15
  useLayoutEffect,
16
+ useMemo,
8
17
  useRef,
9
18
  } from 'react';
10
19
 
11
- import { ToolbarProvider, useToolbarContext } from './ToolbarContext';
12
-
13
- export type ToolbarOrientation = 'vertical' | 'horizontal';
14
- export type ToolbarItemOrientation = 'vertical' | 'horizontal' | 'auto';
20
+ import {
21
+ ToolbarContext,
22
+ toolbarContext,
23
+ useToolbarContext,
24
+ } from './toolbarContext';
15
25
 
16
26
  export interface ToolbarProps {
17
- orientation: ToolbarOrientation;
27
+ vertical?: boolean;
28
+ large?: boolean;
29
+ intent?: Intent;
30
+ disabled?: boolean;
18
31
  children?:
19
32
  | Array<ReactElement<ToolbarItemProps>>
20
33
  | ReactElement<ToolbarItemProps>
21
- | ReactFragment
34
+ | Iterable<ReactNode>
22
35
  | boolean
23
36
  | null;
24
37
  }
@@ -26,93 +39,30 @@ export interface ToolbarProps {
26
39
  export interface ToolbarItemProps {
27
40
  id?: string;
28
41
  title: string;
29
- children: ReactNode;
30
-
42
+ icon: ButtonProps['icon'];
31
43
  active?: boolean;
32
- titleOrientation?: ToolbarItemOrientation;
33
44
  onClick?: (item: ToolbarItemProps) => void;
34
45
  className?: string;
35
46
  }
36
47
 
37
48
  const border = '1px solid rgb(247, 247, 247)';
38
49
 
39
- const styles = {
40
- toolbar: (orientation: ToolbarOrientation) => {
41
- return css([
42
- { display: 'flex', flexWrap: 'wrap' },
43
- orientation === 'vertical'
44
- ? {
45
- flexDirection: 'column',
46
- minHeight: '100%',
47
- borderRight: border,
48
- }
49
- : {
50
- flexDirection: 'row',
51
- minWidth: '100%',
52
- },
53
- ]);
54
- },
55
- item: (active: boolean) => {
56
- return css([
57
- active && { backgroundColor: 'rgb(247, 247, 247)', borderRadius: 5 },
58
- {
59
- width: 30,
60
- height: 30,
61
- outline: 'none',
62
- alignItems: 'center',
63
- justifyContent: 'center',
64
- display: 'flex',
65
- '&:hover + .content': { display: 'flex' },
66
- },
67
- ]);
68
- },
69
- tooltip: (
70
- orientation: ToolbarOrientation,
71
- itemOrientation: ToolbarItemOrientation,
72
- ) => {
73
- const common: CSSObject = {
74
- display: 'none',
75
- position: 'absolute',
76
- backgroundColor: 'gray',
77
- borderRadius: '2px',
78
- color: 'white',
79
- bottom: '0px',
80
- right: '0px',
81
- width: 'fit-content',
82
- height: '50%',
83
- fontSize: '0.875em',
84
- whiteSpace: 'nowrap',
85
- paddingLeft: '3px',
86
- paddingRight: '3px',
87
- zIndex: 50,
88
- };
89
-
90
- if (itemOrientation === 'auto') {
91
- return css([
92
- common,
93
- orientation === 'vertical' && { margin: 'auto', marginLeft: 5 },
94
- orientation === 'horizontal'
95
- ? { top: '100%' }
96
- : { top: '0px', left: '100%' },
97
- ]);
98
- } else {
99
- return css([
100
- common,
101
- itemOrientation === 'horizontal' && { margin: 'auto', marginLeft: 5 },
102
- itemOrientation === 'vertical'
103
- ? { top: '100%' }
104
- : { top: '0px', left: '100%' },
105
- ]);
106
- }
107
- },
108
- };
109
-
110
50
  export function Toolbar(props: ToolbarProps) {
111
- const { children, orientation } = props;
51
+ const { children, disabled, intent, large, vertical } = props;
52
+
53
+ const contextValue = useMemo(
54
+ () => ({ intent, large, vertical, disabled }),
55
+ [intent, large, vertical, disabled],
56
+ );
112
57
 
113
58
  const ref = useRef<HTMLDivElement>(null);
59
+
60
+ // Work around wrong width on vertical flex when wrapping
61
+ // In Chrome: recently fixed (https://bugs.chromium.org/p/chromium/issues/detail?id=507397)
62
+ // In Firefox: work-around needed (https://bugzilla.mozilla.org/show_bug.cgi?id=995020)
63
+ // In Safari: work-around needed
114
64
  useLayoutEffect(() => {
115
- if (orientation === 'horizontal') {
65
+ if (!vertical) {
116
66
  return;
117
67
  }
118
68
 
@@ -136,57 +86,66 @@ export function Toolbar(props: ToolbarProps) {
136
86
  observer.observe(element);
137
87
  return () => observer.unobserve(element);
138
88
  }
139
- }, [orientation]);
140
-
89
+ }, [vertical]);
141
90
  return (
142
- <div css={styles.toolbar(orientation)} ref={ref}>
143
- <ToolbarProvider orientation={orientation}>{children}</ToolbarProvider>
144
- </div>
91
+ <ToolbarProvider value={contextValue}>
92
+ <ButtonGroup
93
+ ref={ref}
94
+ vertical={vertical}
95
+ large={large}
96
+ style={{ flexWrap: 'wrap', borderRight: vertical ? border : undefined }}
97
+ >
98
+ {children}
99
+ </ButtonGroup>
100
+ </ToolbarProvider>
145
101
  );
146
102
  }
147
103
 
148
104
  Toolbar.Item = function ToolbarItem(props: ToolbarItemProps) {
149
- const orientation = useToolbarContext();
150
- const {
151
- active = false,
152
- children,
153
- onClick,
154
- title,
155
- titleOrientation = 'auto',
156
- id,
157
- ...other
158
- } = props;
105
+ const { active = false, icon, onClick, title, id, ...other } = props;
159
106
 
107
+ const { intent, large, vertical, disabled } = useToolbarContext();
160
108
  return (
161
- <div
162
- style={{ position: 'relative', padding: 4, fontSize: '1.25em' }}
163
- {...other}
109
+ <Tooltip
110
+ css={css`
111
+ flex-grow: 0 !important;
112
+ `}
113
+ compact={!large}
114
+ intent={intent}
115
+ content={title}
116
+ placement={vertical ? 'right' : 'bottom'}
164
117
  >
165
- <button
118
+ <Button
119
+ minimal
120
+ disabled={disabled}
121
+ css={css`
122
+ .${Classes.ICON} {
123
+ color: ${Colors.DARK_GRAY3};
124
+ }
125
+ `}
126
+ intent={intent}
127
+ style={{ position: 'relative', fontSize: '1.25em' }}
166
128
  type="button"
167
- css={styles.item(active)}
129
+ active={active}
130
+ icon={icon}
168
131
  onClick={() => {
169
132
  if (onClick) {
170
133
  onClick(props);
171
134
  }
172
135
  }}
173
- >
174
- {children}
175
- </button>
176
- <div
177
- className="content"
178
- css={styles.tooltip(orientation, titleOrientation)}
179
- >
180
- <span
181
- style={{
182
- display: 'flex',
183
- margin: 'auto',
184
- justifyContent: 'center',
185
- }}
186
- >
187
- {title}
188
- </span>
189
- </div>
190
- </div>
136
+ {...other}
137
+ />
138
+ </Tooltip>
191
139
  );
192
140
  };
141
+
142
+ function ToolbarProvider(props: {
143
+ value: ToolbarContext;
144
+ children: ReactNode;
145
+ }) {
146
+ return (
147
+ <toolbarContext.Provider value={props.value}>
148
+ {props.children}
149
+ </toolbarContext.Provider>
150
+ );
151
+ }
@@ -0,0 +1,21 @@
1
+ import { Intent } from '@blueprintjs/core';
2
+ import { createContext, useContext } from 'react';
3
+
4
+ export interface ToolbarContext {
5
+ intent?: Intent;
6
+ large?: boolean;
7
+ vertical?: boolean;
8
+ disabled?: boolean;
9
+ }
10
+
11
+ export const toolbarContext = createContext<ToolbarContext | null>(null);
12
+
13
+ export function useToolbarContext() {
14
+ const ctx = useContext(toolbarContext);
15
+ if (!ctx) {
16
+ throw new Error(
17
+ 'useToolbarContext must be used within a ToolbarContextProvider',
18
+ );
19
+ }
20
+ return ctx;
21
+ }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToolbarProvider = exports.useToolbarContext = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const toolbarContext = (0, react_1.createContext)(null);
7
- function useToolbarContext() {
8
- const context = (0, react_1.useContext)(toolbarContext);
9
- if (!context) {
10
- throw new Error('ToolbarContext was not found');
11
- }
12
- return context;
13
- }
14
- exports.useToolbarContext = useToolbarContext;
15
- function ToolbarProvider(props) {
16
- return ((0, jsx_runtime_1.jsx)(toolbarContext.Provider, { value: props.orientation, children: props.children }));
17
- }
18
- exports.ToolbarProvider = ToolbarProvider;
@@ -1,8 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import type { ToolbarOrientation } from './Toolbar';
3
- export declare function useToolbarContext(): ToolbarOrientation;
4
- export declare function ToolbarProvider(props: {
5
- children: ReactNode;
6
- orientation: ToolbarOrientation;
7
- }): import("react/jsx-runtime").JSX.Element;
8
- //# sourceMappingURL=ToolbarContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToolbarContext.d.ts","sourceRoot":"","sources":["../../../src/components/toolbar/ToolbarContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAc,MAAM,OAAO,CAAC;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAIpD,wBAAgB,iBAAiB,uBAOhC;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE;IACrC,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,EAAE,kBAAkB,CAAC;CACjC,2CAMA"}
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext } from 'react';
3
- const toolbarContext = createContext(null);
4
- export function useToolbarContext() {
5
- const context = useContext(toolbarContext);
6
- if (!context) {
7
- throw new Error('ToolbarContext was not found');
8
- }
9
- return context;
10
- }
11
- export function ToolbarProvider(props) {
12
- return (_jsx(toolbarContext.Provider, { value: props.orientation, children: props.children }));
13
- }
14
- //# sourceMappingURL=ToolbarContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToolbarContext.js","sourceRoot":"","sources":["../../../src/components/toolbar/ToolbarContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAI7D,MAAM,cAAc,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC;AAEtE,MAAM,UAAU,iBAAiB;IAC/B,MAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAG/B;IACC,OAAO,CACL,KAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,CAAC,WAAW,YAC9C,KAAK,CAAC,QAAQ,GACS,CAC3B,CAAC;AACJ,CAAC"}
@@ -1,25 +0,0 @@
1
- import { createContext, ReactNode, useContext } from 'react';
2
-
3
- import type { ToolbarOrientation } from './Toolbar';
4
-
5
- const toolbarContext = createContext<ToolbarOrientation | null>(null);
6
-
7
- export function useToolbarContext() {
8
- const context = useContext(toolbarContext);
9
- if (!context) {
10
- throw new Error('ToolbarContext was not found');
11
- }
12
-
13
- return context;
14
- }
15
-
16
- export function ToolbarProvider(props: {
17
- children: ReactNode;
18
- orientation: ToolbarOrientation;
19
- }) {
20
- return (
21
- <toolbarContext.Provider value={props.orientation}>
22
- {props.children}
23
- </toolbarContext.Provider>
24
- );
25
- }