Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(header):Add header component and cleanup #45

Merged
merged 5 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .storybook/theme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { create } from '@storybook/theming/create';
import ReachatLogo from './logo.svg';
import ReachatLogo from '../src/assets/logo/logo.svg?react';

export default create({
base: 'dark',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"source": "src/index.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs",
"types": "./dist/index.d.ts"
"require": "./dist/index.umd.cjs"
},
"./docs.json": "./dist/docs.json",
"./index.css": "./dist/index.css"
Expand Down
40 changes: 40 additions & 0 deletions src/AppBar/AppBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { ReactNode, FC, useContext } from 'react';
import { cn } from 'reablocks';
import { ChatContext } from '../ChatContext';

export interface AppBarProps {
/**
* Content to display in the left section of the header
*/
contentLeft?: ReactNode;

/**
* Content to display in the center section of the header
*/
contentCenter?: ReactNode;

/**
* Content to display in the right section of the header
*/
contentRight?: ReactNode;
}

export const AppBar: FC<AppBarProps> = ({
contentLeft,
contentCenter,
contentRight
}) => {
const { theme } = useContext(ChatContext);

return (
<div className={cn(theme?.header?.base)}>
<div className="flex items-center justify-between w-full">
<div className="flex-shrink-0">{contentLeft}</div>
<div className="flex-grow flex justify-center items-center">
{contentCenter}
</div>
<div className="flex-shrink-0">{contentRight}</div>
</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/AppBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AppBar';
5 changes: 5 additions & 0 deletions src/assets/close-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './types';
export * from './theme';
export * from './Markdown';
export * from './ChatContext';
export * from './AppBar';
14 changes: 12 additions & 2 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export interface ChatTheme {
console: string;
companion: string;
empty: string;
header: {
base: string;
};
sessions: {
base: string;
console: string;
Expand Down Expand Up @@ -89,6 +92,9 @@ export const chatTheme: ChatTheme = {
console: 'flex w-full gap-4 h-full',
companion: 'w-full h-full overflow-hidden',
empty: 'text-center flex-1',
header: {
base: 'pb-10'
},
sessions: {
base: 'overflow-auto',
console:
Expand Down Expand Up @@ -132,7 +138,10 @@ export const chatTheme: ChatTheme = {
'relative font-semibold mb-4 px-4 py-4 pb-2 rounded-3xl rounded-br-none text-typography border bg-gray-200 border-gray-300 text-gray-900',
'dark:bg-gray-900/60 dark:border-gray-700/50 dark:text-gray-100'
].join(' '),
response: ['relative data-[compact=false]:px-4 text-gray-900', 'dark:text-gray-100'].join(' '),
response: [
'relative data-[compact=false]:px-4 text-gray-900',
'dark:text-gray-100'
].join(' '),
overlay: `overflow-y-hidden max-h-[350px] after:content-[''] after:absolute after:inset-x-0 after:bottom-0 after:h-16 after:bg-gradient-to-b after:from-transparent dark:after:to-gray-900 after:to-gray-200`,
cursor: 'inline-block w-1 h-4 bg-current',
expand: 'absolute bottom-1 right-1 z-10',
Expand Down Expand Up @@ -167,7 +176,8 @@ export const chatTheme: ChatTheme = {
th: 'px-4 py-2 text-left font-bold border-b border-gray-500',
td: 'px-4 py-2',
code: 'm-2 rounded-b relative',
toolbar: 'text-xs dark:bg-gray-700/50 flex items-center justify-between px-2 py-1 rounded-t sticky top-0 backdrop-blur-md bg-gray-200 ',
toolbar:
'text-xs dark:bg-gray-700/50 flex items-center justify-between px-2 py-1 rounded-t sticky top-0 backdrop-blur-md bg-gray-200 ',
li: 'mb-2 ml-6',
ul: 'mb-4 list-disc',
ol: 'mb-4 list-decimal'
Expand Down
76 changes: 75 additions & 1 deletion stories/Chat.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ChatInput,
SessionMessagePanel,
SessionMessage,
Session
Session,
AppBar
} from '../src';
import {
fakeSessions,
Expand All @@ -15,6 +16,10 @@ import {
import { useState } from 'react';
import Placeholder from '@/assets/placeholder.svg?react';
import PlaceholderDark from '@/assets/placeholder-dark.svg?react';
import ReachatLogo from '@/assets/logo/logo.svg?react';
import IconSearch from '@/assets/search.svg?react';
import IconClose from '@/assets/close-fill.svg?react';
import { IconButton } from 'reablocks';

export default {
title: 'Demos/Chat',
Expand Down Expand Up @@ -185,3 +190,72 @@ export const Empty = () => {
</div>
);
};

export const WithAppBar = () => {
const [activeId, setActiveId] = useState<string>(fakeSessions[0].id);
const [sessions, setSessions] = useState<Session[]>([
...fakeSessions,
...sessionsWithFiles,
...sessionWithSources
]);

return (
<div
className="dark:bg-gray-950 bg-white"
style={{
width: 800,
height: 600,
padding: 20,
borderRadius: 5
}}
>
<Chat
viewType="chat"
sessions={sessions}
activeSessionId={activeId}
onNewSession={() => {
const newId = (sessions.length + 1).toLocaleString();
setSessions([
...sessions,
{
id: newId,
title: `New Session #${newId}`,
createdAt: new Date(),
updatedAt: new Date(),
conversations: []
}
]);
setActiveId(newId);
}}
onSelectSession={setActiveId}
onDeleteSession={() => alert('delete!')}
>
<div className="flex flex-col h-full">
<AppBar
contentLeft={
<IconButton size="small" variant="outline" className='rounded-full p-3'>
<IconSearch className='w-4 h-4' />
</IconButton>
}
contentCenter={
<ReachatLogo className="h-6 w-auto" />
}
contentRight={
<IconButton
variant="text"
size="small"
className='rounded-full p-3'
>
<IconClose className='w-4 h-4' />
</IconButton>
}
/>
<SessionMessagePanel>
<SessionMessages />
<ChatInput />
</SessionMessagePanel>
</div>
</Chat>
</div>
);
};
78 changes: 77 additions & 1 deletion stories/Companion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import {
ChatInput,
SessionMessagePanel,
SessionMessagesHeader,
Session
Session,
AppBar
} from '../src';
import {
fakeSessions,
sessionWithSources,
sessionsWithFiles
} from './examples';
import { useState } from 'react';
import { IconButton } from 'reablocks';

import Placeholder from '@/assets/placeholder.svg?react';
import PlaceholderDark from '@/assets/placeholder-dark.svg?react';
import ReachatLogo from '@/assets/logo/logo.svg?react';
import IconSearch from '@/assets/search.svg?react';
import IconClose from '@/assets/close-fill.svg?react';

export default {
title: 'Demos/Companion',
Expand Down Expand Up @@ -116,3 +121,74 @@ export const Empty = () => {
</div>
);
};

export const WithAppBar = () => {
const [activeId, setActiveId] = useState<string>();
const [sessions, setSessions] = useState<Session[]>([
...fakeSessions,
...sessionsWithFiles,
...sessionWithSources
]);
return (
<div
className="dark:bg-gray-950 bg-white"
style={{
width: 350,
height: 500,
padding: 20,
borderRadius: 5
}}
>
<Chat
viewType="companion"
sessions={sessions}
activeSessionId={activeId}
onNewSession={() => {
const newId = (sessions.length + 1).toLocaleString();
setSessions([
...sessions,
{
id: newId,
title: `New Session #${newId}`,
createdAt: new Date(),
updatedAt: new Date(),
conversations: []
}
]);
setActiveId(newId);
}}
onSelectSession={setActiveId}
onDeleteSession={() => alert('delete!')}
>
<AppBar
contentLeft={
<IconButton size="small" variant="outline" className='rounded-full p-3'>
<IconSearch className='w-4 h-4' />
</IconButton>
}
contentCenter={
<ReachatLogo className="h-6 w-auto" />
}
contentRight={
<IconButton
variant="text"
size="small"
className='rounded-full p-3'
>
<IconClose className='w-4 h-4' />
</IconButton>
}
/>
<SessionsList>
<NewSessionButton />
<SessionGroups />
</SessionsList>
<SessionMessagePanel>
<SessionMessagesHeader />
<SessionMessages />
<ChatInput />
</SessionMessagePanel>
</Chat>
</div>
);
};
Loading