@oxy.so/bloom 2.1.0 → 2.3.0
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/README.md +3 -3
- package/docs/page-header.mdx +101 -0
- package/docs/sidebar.mdx +20 -0
- package/lib/commonjs/index.js +128 -116
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +128 -116
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/page-header/PageHeader.js +286 -0
- package/lib/commonjs/page-header/PageHeader.js.map +1 -0
- package/lib/commonjs/page-header/index.js +13 -0
- package/lib/commonjs/page-header/index.js.map +1 -0
- package/lib/commonjs/page-header/types.js +6 -0
- package/lib/commonjs/page-header/types.js.map +1 -0
- package/lib/commonjs/sidebar/Sidebar.js +15 -2
- package/lib/commonjs/sidebar/Sidebar.js.map +1 -1
- package/lib/commonjs/sidebar/SidebarModeSwitcher.js +193 -0
- package/lib/commonjs/sidebar/SidebarModeSwitcher.js.map +1 -0
- package/lib/commonjs/sidebar/index.js +7 -0
- package/lib/commonjs/sidebar/index.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +1 -0
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/page-header/PageHeader.js +281 -0
- package/lib/module/page-header/PageHeader.js.map +1 -0
- package/lib/module/page-header/index.js +4 -0
- package/lib/module/page-header/index.js.map +1 -0
- package/lib/module/page-header/types.js +4 -0
- package/lib/module/page-header/types.js.map +1 -0
- package/lib/module/sidebar/Sidebar.js +15 -2
- package/lib/module/sidebar/Sidebar.js.map +1 -1
- package/lib/module/sidebar/SidebarModeSwitcher.js +188 -0
- package/lib/module/sidebar/SidebarModeSwitcher.js.map +1 -0
- package/lib/module/sidebar/index.js +1 -0
- package/lib/module/sidebar/index.js.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +1 -0
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/page-header/PageHeader.d.ts +6 -0
- package/lib/typescript/commonjs/page-header/PageHeader.d.ts.map +1 -0
- package/lib/typescript/commonjs/page-header/index.d.ts +3 -0
- package/lib/typescript/commonjs/page-header/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/page-header/types.d.ts +55 -0
- package/lib/typescript/commonjs/page-header/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/sidebar/Sidebar.d.ts.map +1 -1
- package/lib/typescript/commonjs/sidebar/SidebarModeSwitcher.d.ts +4 -0
- package/lib/typescript/commonjs/sidebar/SidebarModeSwitcher.d.ts.map +1 -0
- package/lib/typescript/commonjs/sidebar/index.d.ts +2 -1
- package/lib/typescript/commonjs/sidebar/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/sidebar/types.d.ts +30 -0
- package/lib/typescript/commonjs/sidebar/types.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +1 -0
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/page-header/PageHeader.d.ts +6 -0
- package/lib/typescript/module/page-header/PageHeader.d.ts.map +1 -0
- package/lib/typescript/module/page-header/index.d.ts +3 -0
- package/lib/typescript/module/page-header/index.d.ts.map +1 -0
- package/lib/typescript/module/page-header/types.d.ts +55 -0
- package/lib/typescript/module/page-header/types.d.ts.map +1 -0
- package/lib/typescript/module/sidebar/Sidebar.d.ts.map +1 -1
- package/lib/typescript/module/sidebar/SidebarModeSwitcher.d.ts +4 -0
- package/lib/typescript/module/sidebar/SidebarModeSwitcher.d.ts.map +1 -0
- package/lib/typescript/module/sidebar/index.d.ts +2 -1
- package/lib/typescript/module/sidebar/index.d.ts.map +1 -1
- package/lib/typescript/module/sidebar/types.d.ts +30 -0
- package/lib/typescript/module/sidebar/types.d.ts.map +1 -1
- package/package.json +15 -1
- package/src/index.ts +1 -0
- package/src/index.web.ts +1 -0
- package/src/page-header/PageHeader.tsx +319 -0
- package/src/page-header/index.ts +3 -0
- package/src/page-header/types.ts +62 -0
- package/src/sidebar/Sidebar.tsx +19 -0
- package/src/sidebar/SidebarModeSwitcher.tsx +183 -0
- package/src/sidebar/index.ts +3 -0
- package/src/sidebar/types.ts +32 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import React, { memo, useEffect } from 'react';
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
|
+
import Animated, {
|
|
4
|
+
Easing,
|
|
5
|
+
useAnimatedStyle,
|
|
6
|
+
useReducedMotion,
|
|
7
|
+
useSharedValue,
|
|
8
|
+
withTiming,
|
|
9
|
+
} from 'react-native-reanimated';
|
|
10
|
+
|
|
11
|
+
import { BUTTON_SHADOW, resolveButtonRamps } from '../button/shared';
|
|
12
|
+
import { useInteractionState } from '../hooks/use-interaction-state';
|
|
13
|
+
import { borderRadius } from '../styles/tokens';
|
|
14
|
+
import type { WebCssStyle } from '../styles/web-view-style';
|
|
15
|
+
import { useTheme } from '../theme/use-theme';
|
|
16
|
+
import { Text } from '../typography';
|
|
17
|
+
import { useSidebarPalette } from './palette';
|
|
18
|
+
import { Collapsible, IS_WEB, useSidebarWebCss } from './parts';
|
|
19
|
+
import type { SidebarMode, SidebarModeSwitcherProps } from './types';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `SidebarModeSwitcher`: a vertical segmented control for the modes a sidebar
|
|
23
|
+
* switches between (Search / Computer, Chat / Agents), each an icon and label.
|
|
24
|
+
*
|
|
25
|
+
* track p4, radius 20, background-tertiary (neutral-200 / neutral-800)
|
|
26
|
+
* row 32 tall, 4 apart; icon 18 in a 32 box, 4 gap, body-2-medium
|
|
27
|
+
* thumb the selected row's 32px pill: card / neutral-700 with shadow-xs,
|
|
28
|
+
* sliding 200ms ease between rows (instant under reduced motion)
|
|
29
|
+
* rest icon and label text-secondary; selected text-primary
|
|
30
|
+
* shortcut web only, on hover: a caption-2 hint at the row's end
|
|
31
|
+
* collapsed labels and hints collapse; the icons stay pinned
|
|
32
|
+
*
|
|
33
|
+
* Its colours are the sidebar ThemeToggle's segmented track and thumb, so the
|
|
34
|
+
* two read as one family. A `radiogroup`: each row is a `radio`.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const ROW_HEIGHT = 32;
|
|
38
|
+
const ROW_GAP = 4;
|
|
39
|
+
const PADDING = 4;
|
|
40
|
+
const THUMB_MS = 200;
|
|
41
|
+
const EASE = Easing.bezier(0.25, 0.1, 0.25, 1);
|
|
42
|
+
|
|
43
|
+
function ModeRow({
|
|
44
|
+
mode,
|
|
45
|
+
selected,
|
|
46
|
+
collapsed,
|
|
47
|
+
onSelect,
|
|
48
|
+
testID,
|
|
49
|
+
}: {
|
|
50
|
+
mode: SidebarMode;
|
|
51
|
+
selected: boolean;
|
|
52
|
+
collapsed: boolean;
|
|
53
|
+
onSelect: (key: string) => void;
|
|
54
|
+
testID?: string;
|
|
55
|
+
}) {
|
|
56
|
+
const palette = useSidebarPalette();
|
|
57
|
+
const { state: hovered, onIn, onOut } = useInteractionState();
|
|
58
|
+
const Icon = mode.icon;
|
|
59
|
+
const foreground = selected ? palette.text : palette.textSecondary;
|
|
60
|
+
|
|
61
|
+
const rowStyle: WebCssStyle = {
|
|
62
|
+
flexDirection: 'row',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
gap: 4,
|
|
65
|
+
height: ROW_HEIGHT,
|
|
66
|
+
borderRadius: borderRadius.full,
|
|
67
|
+
'--bloom-sidebar-ring': palette.ring,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<Pressable
|
|
72
|
+
{...(IS_WEB ? { dataSet: { bloomSidebar: 'ring' }, ...(collapsed ? { title: mode.label } : null) } : {})}
|
|
73
|
+
role="radio"
|
|
74
|
+
aria-checked={selected}
|
|
75
|
+
accessibilityState={{ checked: selected }}
|
|
76
|
+
accessibilityLabel={mode.label}
|
|
77
|
+
onHoverIn={onIn}
|
|
78
|
+
onHoverOut={onOut}
|
|
79
|
+
onPress={() => onSelect(mode.key)}
|
|
80
|
+
style={rowStyle}
|
|
81
|
+
testID={testID}
|
|
82
|
+
>
|
|
83
|
+
<View style={{ width: ROW_HEIGHT, height: ROW_HEIGHT, alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
|
|
84
|
+
<Icon width={18} height={18} fill={foreground} />
|
|
85
|
+
</View>
|
|
86
|
+
<Collapsible collapsed={collapsed} style={{ flex: 1, minWidth: 0 }}>
|
|
87
|
+
<Text variant="body-2-medium" numberOfLines={1} style={{ color: foreground }}>
|
|
88
|
+
{mode.label}
|
|
89
|
+
</Text>
|
|
90
|
+
</Collapsible>
|
|
91
|
+
{IS_WEB && mode.shortcut ? (
|
|
92
|
+
<Collapsible collapsed={collapsed}>
|
|
93
|
+
<Text
|
|
94
|
+
variant="caption-2-regular"
|
|
95
|
+
numberOfLines={1}
|
|
96
|
+
style={{ color: palette.textTertiary, paddingRight: 12, opacity: hovered ? 1 : 0 }}
|
|
97
|
+
>
|
|
98
|
+
{mode.shortcut}
|
|
99
|
+
</Text>
|
|
100
|
+
</Collapsible>
|
|
101
|
+
) : null}
|
|
102
|
+
</Pressable>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const SidebarModeSwitcherComponent: React.FC<SidebarModeSwitcherProps> = ({
|
|
107
|
+
modes,
|
|
108
|
+
value,
|
|
109
|
+
onValueChange,
|
|
110
|
+
collapsed = false,
|
|
111
|
+
accessibilityLabel = 'Mode',
|
|
112
|
+
style,
|
|
113
|
+
testID,
|
|
114
|
+
}) => {
|
|
115
|
+
const theme = useTheme();
|
|
116
|
+
const palette = useSidebarPalette();
|
|
117
|
+
useSidebarWebCss();
|
|
118
|
+
const reducedMotion = useReducedMotion();
|
|
119
|
+
const { neutral: n } = resolveButtonRamps(theme);
|
|
120
|
+
|
|
121
|
+
const index = Math.max(0, modes.findIndex((mode) => mode.key === value));
|
|
122
|
+
const offset = useSharedValue(index * (ROW_HEIGHT + ROW_GAP));
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
const target = index * (ROW_HEIGHT + ROW_GAP);
|
|
125
|
+
offset.value = reducedMotion ? target : withTiming(target, { duration: THUMB_MS, easing: EASE });
|
|
126
|
+
}, [index, reducedMotion, offset]);
|
|
127
|
+
const thumbStyle = useAnimatedStyle(() => ({ transform: [{ translateY: offset.value }] }), [offset]);
|
|
128
|
+
|
|
129
|
+
const selectedKnown = modes.some((mode) => mode.key === value);
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<View
|
|
133
|
+
role="radiogroup"
|
|
134
|
+
accessibilityLabel={accessibilityLabel}
|
|
135
|
+
testID={testID}
|
|
136
|
+
style={[
|
|
137
|
+
{
|
|
138
|
+
position: 'relative',
|
|
139
|
+
width: '100%',
|
|
140
|
+
padding: PADDING,
|
|
141
|
+
gap: ROW_GAP,
|
|
142
|
+
borderRadius: (ROW_HEIGHT + PADDING * 2) / 2,
|
|
143
|
+
backgroundColor: palette.tertiary,
|
|
144
|
+
},
|
|
145
|
+
style,
|
|
146
|
+
]}
|
|
147
|
+
>
|
|
148
|
+
{selectedKnown ? (
|
|
149
|
+
<Animated.View
|
|
150
|
+
pointerEvents="none"
|
|
151
|
+
aria-hidden
|
|
152
|
+
testID={testID ? `${testID}-thumb` : undefined}
|
|
153
|
+
style={[
|
|
154
|
+
{
|
|
155
|
+
position: 'absolute',
|
|
156
|
+
top: PADDING,
|
|
157
|
+
left: PADDING,
|
|
158
|
+
right: PADDING,
|
|
159
|
+
height: ROW_HEIGHT,
|
|
160
|
+
borderRadius: borderRadius.full,
|
|
161
|
+
backgroundColor: theme.isDark ? n[700] : theme.colors.card,
|
|
162
|
+
boxShadow: theme.isDark ? BUTTON_SHADOW.dark : BUTTON_SHADOW.light,
|
|
163
|
+
},
|
|
164
|
+
thumbStyle,
|
|
165
|
+
]}
|
|
166
|
+
/>
|
|
167
|
+
) : null}
|
|
168
|
+
{modes.map((mode) => (
|
|
169
|
+
<ModeRow
|
|
170
|
+
key={mode.key}
|
|
171
|
+
mode={mode}
|
|
172
|
+
selected={mode.key === value}
|
|
173
|
+
collapsed={collapsed}
|
|
174
|
+
onSelect={onValueChange}
|
|
175
|
+
testID={testID ? `${testID}-${mode.key}` : undefined}
|
|
176
|
+
/>
|
|
177
|
+
))}
|
|
178
|
+
</View>
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const SidebarModeSwitcher = memo(SidebarModeSwitcherComponent);
|
|
183
|
+
SidebarModeSwitcher.displayName = 'SidebarModeSwitcher';
|
package/src/sidebar/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { Sidebar } from './Sidebar';
|
|
2
2
|
export { SidebarFolder } from './SidebarFolder';
|
|
3
3
|
export { SidebarItem } from './SidebarItem';
|
|
4
|
+
export { SidebarModeSwitcher } from './SidebarModeSwitcher';
|
|
4
5
|
export { SidebarPlanCard } from './SidebarPlanCard';
|
|
5
6
|
export { SIDEBAR_RAIL_WIDTH } from './SidebarRail';
|
|
6
7
|
export { SidebarRailItem } from './SidebarRailItem';
|
|
@@ -17,6 +18,8 @@ export type {
|
|
|
17
18
|
SidebarItemProps,
|
|
18
19
|
SidebarMenuGroup,
|
|
19
20
|
SidebarMenuItem,
|
|
21
|
+
SidebarMode,
|
|
22
|
+
SidebarModeSwitcherProps,
|
|
20
23
|
SidebarNavItem,
|
|
21
24
|
SidebarPlan,
|
|
22
25
|
SidebarPlanCardProps,
|
package/src/sidebar/types.ts
CHANGED
|
@@ -35,6 +35,28 @@ export interface SidebarNavItem {
|
|
|
35
35
|
onPress?: () => void;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** One mode of a {@link SidebarModeSwitcherProps.modes} switcher. */
|
|
39
|
+
export interface SidebarMode {
|
|
40
|
+
key: string;
|
|
41
|
+
label: string;
|
|
42
|
+
icon: SidebarIcon;
|
|
43
|
+
/** A shortcut hint shown on hover (web), e.g. `⌥⌃1`. */
|
|
44
|
+
shortcut?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SidebarModeSwitcherProps {
|
|
48
|
+
modes: ReadonlyArray<SidebarMode>;
|
|
49
|
+
/** Key of the selected mode. */
|
|
50
|
+
value: string;
|
|
51
|
+
onValueChange: (key: string) => void;
|
|
52
|
+
/** Collapses the labels and hints, leaving the icons. */
|
|
53
|
+
collapsed?: boolean;
|
|
54
|
+
/** The radio group's accessible name. Defaults to `"Mode"`. */
|
|
55
|
+
accessibilityLabel?: string;
|
|
56
|
+
style?: StyleProp<ViewStyle>;
|
|
57
|
+
testID?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
38
60
|
export interface SidebarItemProps {
|
|
39
61
|
icon: SidebarIcon;
|
|
40
62
|
label: string;
|
|
@@ -143,6 +165,16 @@ export interface SidebarProps {
|
|
|
143
165
|
variant?: SidebarVariant;
|
|
144
166
|
/** Primary navigation rows. */
|
|
145
167
|
items?: SidebarNavItem[];
|
|
168
|
+
/**
|
|
169
|
+
* A mode switcher under the header (Search / Computer): a vertical segmented
|
|
170
|
+
* control of icon + label rows. Rendered when given; see `SidebarModeSwitcher`.
|
|
171
|
+
*/
|
|
172
|
+
modes?: ReadonlyArray<SidebarMode>;
|
|
173
|
+
/** Key of the selected mode. */
|
|
174
|
+
mode?: string;
|
|
175
|
+
onModeChange?: (key: string) => void;
|
|
176
|
+
/** The mode group's accessible name. Defaults to `"Mode"`. */
|
|
177
|
+
modesLabel?: string;
|
|
146
178
|
/** Rows pinned to the bottom above the team card (Support, Settings). */
|
|
147
179
|
secondaryItems?: SidebarNavItem[];
|
|
148
180
|
/** Key of the selected row. */
|