diff --git a/.changeset/chat-layout.md b/.changeset/chat-layout.md new file mode 100644 index 0000000000..f10defa9d8 --- /dev/null +++ b/.changeset/chat-layout.md @@ -0,0 +1,9 @@ +--- +'@lg-chat/chat-layout': minor +--- + +Initial release with `ChatLayout`, `ChatMain`, and `ChatSideNav` +- `ChatSideNav` is a compound component with the following subcomponents: + - `ChatSideNav.Header` + - `ChatSideNav.Content` + - `ChatSideNav.SideNavItem` diff --git a/.changeset/gold-goats-visit.md b/.changeset/gold-goats-visit.md new file mode 100644 index 0000000000..aa2b68cd2b --- /dev/null +++ b/.changeset/gold-goats-visit.md @@ -0,0 +1,5 @@ +--- +'@lg-chat/input-bar': patch +--- + +Remove redundant `z-index: 2;` in `InputBar` content wrapping node. diff --git a/README.md b/README.md index bc12657858..16b89cfcdb 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ import Button from '@leafygreen-ui/button'; | [@lg-charts/legend](./charts/legend) | [![version](https://img.shields.io/npm/v/@lg-charts/legend)](https://www.npmjs.com/package/@lg-charts/legend) | ![downloads](https://img.shields.io/npm/dm/@lg-charts/legend?color=white) | [Live Example](http://mongodb.design/component/legend/live-example) | | [@lg-charts/series-provider](./charts/series-provider) | [![version](https://img.shields.io/npm/v/@lg-charts/series-provider)](https://www.npmjs.com/package/@lg-charts/series-provider) | ![downloads](https://img.shields.io/npm/dm/@lg-charts/series-provider?color=white) | [Live Example](http://mongodb.design/component/series-provider/live-example) | | [@lg-chat/avatar](./chat/avatar) | [![version](https://img.shields.io/npm/v/@lg-chat/avatar)](https://www.npmjs.com/package/@lg-chat/avatar) | ![downloads](https://img.shields.io/npm/dm/@lg-chat/avatar?color=white) | [Live Example](http://mongodb.design/component/avatar/live-example) | +| [@lg-chat/chat-layout](./chat/chat-layout) | [![version](https://img.shields.io/npm/v/@lg-chat/chat-layout)](https://www.npmjs.com/package/@lg-chat/chat-layout) | ![downloads](https://img.shields.io/npm/dm/@lg-chat/chat-layout?color=white) | [Live Example](http://mongodb.design/component/chat-layout/live-example) | | [@lg-chat/chat-window](./chat/chat-window) | [![version](https://img.shields.io/npm/v/@lg-chat/chat-window)](https://www.npmjs.com/package/@lg-chat/chat-window) | ![downloads](https://img.shields.io/npm/dm/@lg-chat/chat-window?color=white) | [Live Example](http://mongodb.design/component/chat-window/live-example) | | [@lg-chat/fixed-chat-window](./chat/fixed-chat-window) | [![version](https://img.shields.io/npm/v/@lg-chat/fixed-chat-window)](https://www.npmjs.com/package/@lg-chat/fixed-chat-window) | ![downloads](https://img.shields.io/npm/dm/@lg-chat/fixed-chat-window?color=white) | [Live Example](http://mongodb.design/component/fixed-chat-window/live-example) | | [@lg-chat/input-bar](./chat/input-bar) | [![version](https://img.shields.io/npm/v/@lg-chat/input-bar)](https://www.npmjs.com/package/@lg-chat/input-bar) | ![downloads](https://img.shields.io/npm/dm/@lg-chat/input-bar?color=white) | [Live Example](http://mongodb.design/component/input-bar/live-example) | diff --git a/chat/chat-layout/README.md b/chat/chat-layout/README.md new file mode 100644 index 0000000000..5bb1b1cbe8 --- /dev/null +++ b/chat/chat-layout/README.md @@ -0,0 +1,202 @@ +# Chat Layout + +![npm (scoped)](https://img.shields.io/npm/v/@lg-chat/chat-layout.svg) + +#### [View on MongoDB.design](https://www.mongodb.design/component/chat-layout/live-example/) + +## Installation + +### PNPM + +```shell +pnpm add @lg-chat/chat-layout +``` + +### Yarn + +```shell +yarn add @lg-chat/chat-layout +``` + +### NPM + +```shell +npm install @lg-chat/chat-layout +``` + +## Overview + +`@lg-chat/chat-layout` provides a CSS Grid-based layout system for building full-screen chat interfaces with a side nav that can be collapsed or pinned. + +This package exports: + +- `ChatLayout`: The grid container and context provider +- `ChatMain`: The primary content area of the chat interface, automatically positioned within the grid layout. +- `ChatSideNav`: A compound component representing the side navigation, exposing subcomponents such as `ChatSideNav.Header`, `ChatSideNav.Content`, and `ChatSideNav.SideNavItem` for flexible composition. +- `useChatLayoutContext`: Hook for accessing layout state + +## Examples + +### Basic + +```tsx +import { useState } from 'react'; +import { ChatLayout, ChatMain, ChatSideNav } from '@lg-chat/chat-layout'; + +function MyChatApp() { + const [activeChatId, setActiveChatId] = useState('1'); + + const chatItems = [ + { id: '1', name: 'MongoDB Atlas Setup', href: '/chat/1' }, + { id: '2', name: 'Database Query Help', href: '/chat/2' }, + { id: '3', name: 'Schema Design Discussion', href: '/chat/3' }, + ]; + + const handleNewChat = () => { + console.log('Start new chat'); + }; + + return ( + + + + + {chatItems.map(({ href, id, item, name }) => ( + { + e.preventDefault(); + setActiveChatId(id); + }} + > + {name} + + ))} + + + {/* Main chat content here */} + + ); +} +``` + +### With Initial State and Toggle Pinned Callback + +```tsx +import { ChatLayout, ChatMain, ChatSideNav } from '@lg-chat/chat-layout'; + +function MyChatApp() { + const handleTogglePinned = (isPinned: boolean) => { + console.log('Side nav is now:', isPinned ? 'pinned' : 'collapsed'); + }; + + return ( + + {/* Side nav subcomponents */} + {/* Main chat content */} + + ); +} +``` + +## Properties + +### ChatLayout + +| Prop | Type | Description | Default | +| ------------------------------ | ----------------------------- | --------------------------------------------------------------------------------------------- | ------- | +| `children` | `ReactNode` | The content to render inside the grid layout (`ChatSideNav` and `ChatMain` components) | - | +| `className` _(optional)_ | `string` | Custom CSS class to apply to the grid container | - | +| `initialIsPinned` _(optional)_ | `boolean` | Initial state for whether the side nav is pinned (expanded) | `true` | +| `onTogglePinned` _(optional)_ | `(isPinned: boolean) => void` | Callback fired when the side nav is toggled. Receives the new `isPinned` state as an argument | - | + +All other props are passed through to the underlying `
` element. + +### ChatMain + +| Prop | Type | Description | Default | +| ---------- | ----------- | -------------------------- | ------- | +| `children` | `ReactNode` | The main content to render | - | + +All other props are passed through to the underlying `
` element. + +**Note:** `ChatMain` must be used as a direct child of `ChatLayout` to work correctly within the grid system. + +### ChatSideNav + +| Prop | Type | Description | Default | +| ------------------------ | ------------------------- | -------------------------------------------------------------- | ------- | +| `children` | `ReactNode` | Should include `ChatSideNav.Header` and `ChatSideNav.Content`. | - | +| `className` _(optional)_ | `string` | Root class name | - | +| `...` | `HTMLElementProps<'nav'>` | Props spread on the root `