Initial commit: group-by-host Paseo sidebar plugin
This commit is contained in:
commit
dcfe97a2e6
13 files changed
+6789
No files matched your search
@@ -0,0 +1,392 @@
|
||||
import type { PluginTheme } from "@getpaseo/plugin";
|
||||
import { Icon, Modal, TextInput } from "@getpaseo/plugin/client/ui";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
|
||||
export interface RowIconButtonProps {
|
||||
icon: string;
|
||||
accessibilityLabel: string;
|
||||
theme: PluginTheme;
|
||||
size?: number;
|
||||
paddingVertical?: number;
|
||||
active?: boolean;
|
||||
disabled?: boolean;
|
||||
onPress(): void;
|
||||
}
|
||||
|
||||
export function RowIconButton({
|
||||
icon,
|
||||
accessibilityLabel,
|
||||
theme,
|
||||
size = 13,
|
||||
paddingVertical = 6,
|
||||
active = false,
|
||||
disabled = false,
|
||||
onPress,
|
||||
}: RowIconButtonProps) {
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
disabled={disabled}
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => ({
|
||||
paddingHorizontal: 5,
|
||||
paddingVertical,
|
||||
borderRadius: 6,
|
||||
backgroundColor:
|
||||
active || pressed ? theme.colors.surface1 : "transparent",
|
||||
opacity: disabled ? 0.5 : 1,
|
||||
})}
|
||||
>
|
||||
<Icon
|
||||
name={icon}
|
||||
size={size}
|
||||
color={active ? theme.colors.foreground : theme.colors.foregroundMuted}
|
||||
/>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export interface ActionPillProps {
|
||||
icon: string;
|
||||
label: string;
|
||||
theme: PluginTheme;
|
||||
tone?: "default" | "accent" | "danger";
|
||||
disabled?: boolean;
|
||||
onPress(): void;
|
||||
}
|
||||
|
||||
export function ActionPill({
|
||||
icon,
|
||||
label,
|
||||
theme,
|
||||
tone = "default",
|
||||
disabled = false,
|
||||
onPress,
|
||||
}: ActionPillProps) {
|
||||
const foreground =
|
||||
tone === "danger"
|
||||
? theme.colors.statusDanger
|
||||
: tone === "accent"
|
||||
? theme.colors.accentForeground
|
||||
: theme.colors.foreground;
|
||||
const background =
|
||||
tone === "accent" ? theme.colors.accent : theme.colors.surface2;
|
||||
const borderColor =
|
||||
tone === "danger"
|
||||
? theme.colors.statusDanger
|
||||
: tone === "accent"
|
||||
? theme.colors.accent
|
||||
: theme.colors.border;
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={label}
|
||||
disabled={disabled}
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => ({
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: 4,
|
||||
paddingHorizontal: 8,
|
||||
paddingVertical: 4,
|
||||
borderRadius: 6,
|
||||
borderWidth: 1,
|
||||
borderColor,
|
||||
backgroundColor: pressed ? theme.colors.surface1 : background,
|
||||
opacity: disabled ? 0.5 : 1,
|
||||
})}
|
||||
>
|
||||
<Icon name={icon} size={12} color={foreground} />
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 11,
|
||||
fontWeight: "600",
|
||||
color: foreground,
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export interface RenameWorkspaceModalProps {
|
||||
open: boolean;
|
||||
initialTitle: string;
|
||||
hasCustomTitle: boolean;
|
||||
theme: PluginTheme;
|
||||
saving: boolean;
|
||||
onClose(): void;
|
||||
onSave(nextTitle: string | null): void;
|
||||
}
|
||||
|
||||
export function RenameWorkspaceModal({
|
||||
open,
|
||||
initialTitle,
|
||||
hasCustomTitle,
|
||||
theme,
|
||||
saving,
|
||||
onClose,
|
||||
onSave,
|
||||
}: RenameWorkspaceModalProps) {
|
||||
const [draft, setDraft] = useState(initialTitle);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setDraft(initialTitle);
|
||||
}
|
||||
}, [open, initialTitle]);
|
||||
|
||||
const trimmed = draft.trim();
|
||||
const canSave = !saving && trimmed.length > 0;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title="Rename workspace"
|
||||
icon={<Icon name="Pencil" size={16} color={theme.colors.foreground} />}
|
||||
open={open}
|
||||
onOpenChange={(nextOpen) => {
|
||||
if (!nextOpen && !saving) onClose();
|
||||
}}
|
||||
>
|
||||
<Modal.Content>
|
||||
<View style={{ gap: 12 }}>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 13,
|
||||
color: theme.colors.foregroundMuted,
|
||||
}}
|
||||
>
|
||||
Enter a title for this workspace, or reset to the default name.
|
||||
</Text>
|
||||
<TextInput
|
||||
value={draft}
|
||||
onChangeText={setDraft}
|
||||
placeholder="Workspace title"
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
editable={!saving}
|
||||
autoFocus
|
||||
onSubmitEditing={() => {
|
||||
if (canSave) onSave(trimmed);
|
||||
}}
|
||||
style={{
|
||||
paddingHorizontal: 10,
|
||||
paddingVertical: 8,
|
||||
borderRadius: 8,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface1,
|
||||
color: theme.colors.foreground,
|
||||
fontSize: 14,
|
||||
}}
|
||||
/>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<View>
|
||||
{hasCustomTitle ? (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Reset to default title"
|
||||
disabled={saving}
|
||||
onPress={() => onSave(null)}
|
||||
style={({ pressed }) => ({
|
||||
paddingHorizontal: 10,
|
||||
paddingVertical: 7,
|
||||
borderRadius: 8,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: pressed
|
||||
? theme.colors.surface2
|
||||
: theme.colors.surface1,
|
||||
opacity: saving ? 0.5 : 1,
|
||||
})}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 13,
|
||||
fontWeight: "500",
|
||||
color: theme.colors.foregroundMuted,
|
||||
}}
|
||||
>
|
||||
Reset
|
||||
</Text>
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
<View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Cancel rename"
|
||||
disabled={saving}
|
||||
onPress={onClose}
|
||||
style={({ pressed }) => ({
|
||||
paddingHorizontal: 12,
|
||||
paddingVertical: 7,
|
||||
borderRadius: 8,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: pressed
|
||||
? theme.colors.surface2
|
||||
: theme.colors.surface1,
|
||||
opacity: saving ? 0.5 : 1,
|
||||
})}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 13,
|
||||
fontWeight: "500",
|
||||
color: theme.colors.foreground,
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Text>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Save workspace title"
|
||||
disabled={!canSave}
|
||||
onPress={() => {
|
||||
if (canSave) onSave(trimmed);
|
||||
}}
|
||||
style={({ pressed }) => ({
|
||||
paddingHorizontal: 14,
|
||||
paddingVertical: 7,
|
||||
borderRadius: 8,
|
||||
backgroundColor: theme.colors.accent,
|
||||
opacity: !canSave ? 0.5 : pressed ? 0.85 : 1,
|
||||
})}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 13,
|
||||
fontWeight: "600",
|
||||
color: theme.colors.accentForeground,
|
||||
}}
|
||||
>
|
||||
{saving ? "Saving..." : "Save"}
|
||||
</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export interface ConfirmArchiveModalProps {
|
||||
open: boolean;
|
||||
title: string;
|
||||
description: string;
|
||||
theme: PluginTheme;
|
||||
archiving: boolean;
|
||||
onClose(): void;
|
||||
onConfirm(): void;
|
||||
}
|
||||
|
||||
export function ConfirmArchiveModal({
|
||||
open,
|
||||
title,
|
||||
description,
|
||||
theme,
|
||||
archiving,
|
||||
onClose,
|
||||
onConfirm,
|
||||
}: ConfirmArchiveModalProps) {
|
||||
return (
|
||||
<Modal
|
||||
title={title}
|
||||
icon={<Icon name="Archive" size={16} color={theme.colors.statusDanger} />}
|
||||
open={open}
|
||||
onOpenChange={(nextOpen) => {
|
||||
if (!nextOpen && !archiving) onClose();
|
||||
}}
|
||||
>
|
||||
<Modal.Content>
|
||||
<View style={{ gap: 14 }}>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 13,
|
||||
lineHeight: 18,
|
||||
color: theme.colors.foregroundMuted,
|
||||
}}
|
||||
>
|
||||
{description}
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "flex-end",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Cancel archive"
|
||||
disabled={archiving}
|
||||
onPress={onClose}
|
||||
style={({ pressed }) => ({
|
||||
paddingHorizontal: 12,
|
||||
paddingVertical: 7,
|
||||
borderRadius: 8,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: pressed
|
||||
? theme.colors.surface2
|
||||
: theme.colors.surface1,
|
||||
opacity: archiving ? 0.5 : 1,
|
||||
})}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 13,
|
||||
fontWeight: "500",
|
||||
color: theme.colors.foreground,
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Text>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Confirm archive"
|
||||
disabled={archiving}
|
||||
onPress={onConfirm}
|
||||
style={({ pressed }) => ({
|
||||
paddingHorizontal: 14,
|
||||
paddingVertical: 7,
|
||||
borderRadius: 8,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.statusDanger,
|
||||
backgroundColor: pressed
|
||||
? theme.colors.surface1
|
||||
: theme.colors.surface2,
|
||||
opacity: archiving ? 0.5 : 1,
|
||||
})}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 13,
|
||||
fontWeight: "600",
|
||||
color: theme.colors.statusDanger,
|
||||
}}
|
||||
>
|
||||
{archiving ? "Archiving..." : "Archive"}
|
||||
</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user