Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changeset/tasty-schools-wear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@lg-chat/title-bar': minor
'@lg-chat/chat-window': minor
---

[LG-5664](https://jira.mongodb.org/browse/LG-5664): add compact variant of `TitleBar`
8 changes: 2 additions & 6 deletions chat/chat-window/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
} from '@lg-chat/leafygreen-chat-provider';
import { Message } from '@lg-chat/message';
import { MessageFeed } from '@lg-chat/message-feed';
import { TitleBar } from '@lg-chat/title-bar';

const CompactExample = props => {
const userName = 'Sean Park';
Expand All @@ -48,8 +47,7 @@ const CompactExample = props => {

return (
<LeafyGreenChatProvider variant={Variant.Compact}>
<ChatWindow {...props}>
<TitleBar title="LG Chat Demo" badgeText="Beta" />
<ChatWindow title="LG Chat Demo" badgeText="Beta" {...props}>
<MessageFeed>
{messages.map(messageFields => (
<Message key={messageFields.id} {...messageFields} />
Expand All @@ -72,7 +70,6 @@ import {
} from '@lg-chat/leafygreen-chat-provider';
import { Message } from '@lg-chat/message';
import { MessageFeed } from '@lg-chat/message-feed';
import { TitleBar } from '@lg-chat/title-bar';

const SpaciousExample = props => {
const userName = 'Sean Park';
Expand All @@ -88,8 +85,7 @@ const SpaciousExample = props => {

return (
<LeafyGreenChatProvider variant={Variant.Spacious}>
<ChatWindow {...props}>
<TitleBar title="LG Chat Demo" badgeText="Beta" />
<ChatWindow title="LG Chat Demo" badgeText="Beta" {...props}>
<MessageFeed>
{messages.map(messageFields => (
<Message key={messageFields.id} {...messageFields} />
Expand Down
2 changes: 1 addition & 1 deletion chat/chat-window/src/ChatWindow/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const ChatWindow = forwardRef<HTMLDivElement, ChatWindowProps>(
ref={fwdRef}
{...rest}
>
{!isCompact && title && (
{title && (
<TitleBar
title={title}
badgeText={badgeText}
Expand Down
4 changes: 3 additions & 1 deletion chat/chat-window/src/ChatWindow/ChatWindow.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import { DarkModeProps } from '@leafygreen-ui/lib';
export interface ChatWindowProps
extends Omit<React.ComponentPropsWithoutRef<'div'>, 'title'>,
DarkModeProps,
Partial<TitleBarProps> {}
Partial<
Pick<TitleBarProps, 'badgeText' | 'title' | 'onClose' | 'iconSlot'>
> {}
3 changes: 3 additions & 0 deletions chat/chat-window/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
],
"@leafygreen-ui/*": [
"../../packages/*/src"
],
"@lg-chat/*": [
"../*/src"
]
}
},
Expand Down
1 change: 0 additions & 1 deletion chat/fixed-chat-window/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@leafygreen-ui/tokens": "workspace:^",
"@leafygreen-ui/typography": "workspace:^",
"@lg-chat/chat-window": "workspace:^",
"@lg-chat/title-bar": "workspace:^",
"react-transition-group": "^4.4.5"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { PropsWithChildren, ReactNode } from 'react';
import { MouseEventHandler } from 'react';
import { ChatWindowProps } from '@lg-chat/chat-window';
import { TitleBarProps } from '@lg-chat/title-bar';

import { DarkModeProps } from '@leafygreen-ui/lib';
import { PopoverProps } from '@leafygreen-ui/popover';

export type FixedChatWindowProps = DarkModeProps &
ChatWindowProps &
TitleBarProps &
PropsWithChildren<{
/**
* Define whether the chat window should be open by default when uncontrolled
Expand Down
31 changes: 8 additions & 23 deletions chat/fixed-chat-window/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
],
"@leafygreen-ui/*": [
"../../packages/*/src"
],
"@lg-chat/*": [
"../*/src"
]
}
},
Expand All @@ -18,53 +21,35 @@
],
"references": [
{
"path": "../../packages/avatar"
"path": "../chat-window"
},
{
"path": "../../packages/button"
"path": "../leafygreen-chat-provider"
},
{
"path": "../../packages/emotion"
"path": "../../packages/avatar"
},
{
"path": "../../packages/hooks"
"path": "../../packages/emotion"
},
{
"path": "../../packages/icon"
},
{
"path": "../../packages/leafygreen-provider"
},
{
"path": "../../packages/logo"
},
{
"path": "../../packages/lib"
},
{
"path": "../../packages/palette"
},
{
"path": "../../packages/polymorphic"
},
{
"path": "../../packages/text-area"
"path": "../../packages/popover"
},
{
"path": "../../packages/tokens"
},
{
"path": "../../packages/typography"
},
{
"path": "../avatar"
},
{
"path": "../lg-markdown"
},
{
"path": "../message-feedback"
},
{
"path": "../../packages/leafygreen-provider"
}
Expand Down
3 changes: 3 additions & 0 deletions chat/message-feed/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
],
"@leafygreen-ui/*": [
"../../packages/*/src"
],
"@lg-chat/*": [
"../*/src"
]
}
},
Expand Down
3 changes: 3 additions & 0 deletions chat/message/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
],
"@leafygreen-ui/*": [
"../../packages/*/src"
],
"@lg-chat/*": [
"../*/src"
]
}
},
Expand Down
50 changes: 41 additions & 9 deletions chat/title-bar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,50 @@ npm install @lg-chat/title-bar

## Example

```ts
### Compact

```tsx
import {
LeafyGreenChatProvider,
Variant,
} from '@lg-chat/leafygreen-chat-provider';
import { TitleBar } from '@lg-chat/title-bar';

return <TitleBar badgeText="Beta" />;
return (
<LeafyGreenChatProvider variant={Variant.Compact}>
<TitleBar title="LeafyGreen Chat" badgeText="Beta" />
</LeafyGreenChatProvider>
);
```

### Spacious

```tsx
import {
LeafyGreenChatProvider,
Variant,
} from '@lg-chat/leafygreen-chat-provider';
import { TitleBar, Align } from '@lg-chat/title-bar';

return (
<LeafyGreenChatProvider variant={Variant.Spacious}>
<TitleBar
title="LeafyGreen Chat"
badgeText="Beta"
align={Align.Center}
onClose={() => console.log('Close clicked')}
/>
</LeafyGreenChatProvider>
);
```

## Properties

| Prop | Type | Description | Default |
| ----------- | ------------------------------------------ | -------------------------------------------------------------- | ----------------------------------------------------- |
| `align` | `'center', 'left'` | Alignment of the title text and badge | `'left'` |
| `badgeText` | `string` | Badge text rendered to indicate 'Beta' or 'Experimental' flags | |
| `onClose` | `React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>` | Event handler called when the close button is clicked |
| `title` | `string` | Title text | |
| `...` | `HTMLElementProps<'div'>` | Props spread on root element | |
| Prop | Type | Description | Default |
| ------------------------ | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------- |
| `align` _(optional)_ | `'center' \| 'left'` | Alignment of the title text and badge. Only applies to spacious variant. | `'center'` |
| `badgeText` _(optional)_ | `string` | Badge text rendered to indicate 'Beta' or 'Experimental' flags | |
| `iconSlot` _(optional)_ | `ReactNode` | Slot for custom close icon. Only applies to spacious variant. | |
| `onClose` _(optional)_ | `React.MouseEventHandler<HTMLButtonElement \| HTMLAnchorElement>` | Event handler called when the close button is clicked. Only applies to spacious variant. | |
| `title` | `string` | Title text | |
| `...` | `HTMLElementProps<'div'>` | Props spread on root element | |
4 changes: 2 additions & 2 deletions chat/title-bar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"@leafygreen-ui/icon": "workspace:^",
"@leafygreen-ui/icon-button": "workspace:^",
"@leafygreen-ui/lib": "workspace:^",
"@leafygreen-ui/palette": "workspace:^",
"@leafygreen-ui/tokens": "workspace:^",
"@leafygreen-ui/typography": "workspace:^",
"@lg-chat/avatar": "workspace:^"
},
"peerDependencies": {
"@leafygreen-ui/leafygreen-provider": "workspace:^3.2.0 || workspace:^4.0.0 || workspace:^5.0.0"
"@leafygreen-ui/leafygreen-provider": "workspace:^3.2.0 || workspace:^4.0.0 || workspace:^5.0.0",
"@lg-chat/leafygreen-chat-provider": "workspace:^"
},
"devDependencies": {
"@lg-tools/build": "workspace:^"
Expand Down
98 changes: 77 additions & 21 deletions chat/title-bar/src/TitleBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,104 @@
import React from 'react';
import { storybookArgTypes } from '@lg-tools/storybook-utils';
import { StoryFn } from '@storybook/react';
import {
LeafyGreenChatProvider,
Variant,
} from '@lg-chat/leafygreen-chat-provider';
import { storybookArgTypes, StoryMetaType } from '@lg-tools/storybook-utils';
import { StoryFn, StoryObj } from '@storybook/react';

import { TitleBar } from '.';
import { TitleBar, type TitleBarProps } from './TitleBar';

export default {
const meta: StoryMetaType<typeof TitleBar> = {
title: 'Composition/Chat/TitleBar',
component: TitleBar,
args: {
title: 'LeafyGreen Chat',
onClose: undefined,
},
argTypes: {
onClose: { control: 'none' },
iconSlot: { control: 'none' },
badgeText: { control: 'text' },
darkMode: storybookArgTypes.darkMode,
},
parameters: {
default: null,
generate: {
storyNames: ['CompactVariant', 'SpaciousVariant'],
combineArgs: {
badgeText: [undefined, 'Beta'],
darkMode: [false, true],
},
decorator: (Instance, context) => {
return (
<div style={{ width: 700 }}>
<LeafyGreenChatProvider variant={context?.args.variant}>
<Instance />
</LeafyGreenChatProvider>
</div>
);
},
},
},
};

export default meta;

type TitleBarStoryProps = TitleBarProps & {
variant?: Variant;
};

const Template: StoryFn<typeof TitleBar> = props => (
const Template: StoryFn<TitleBarStoryProps> = ({ variant, ...props }) => (
<div style={{ width: 700 }}>
<TitleBar {...props} />
<LeafyGreenChatProvider variant={variant}>
<TitleBar {...props} />
</LeafyGreenChatProvider>
</div>
);

export const Centered = Template.bind({});
export const LiveExample: StoryObj<TitleBarStoryProps> = {
render: Template,
args: {
title: 'LeafyGreen Chat',
},
parameters: {
chromatic: {
disableSnapshot: true,
},
},
};

export const LeftAligned = Template.bind({});
LeftAligned.args = {
align: 'left',
export const CompactVariant: StoryObj<TitleBarStoryProps> = {
render: Template,
args: {
title: 'LeafyGreen Chat',
variant: Variant.Compact,
},
};

export const WithBeta = Template.bind({});
WithBeta.args = {
badgeText: 'Beta',
export const SpaciousVariant: StoryObj<TitleBarStoryProps> = {
render: Template,
args: {
title: 'LeafyGreen Chat',
variant: Variant.Spacious,
},
};

export const CenteredWithClose = Template.bind({});
CenteredWithClose.args = {
onClose: () => {},
export const LeftAligned: StoryObj<TitleBarStoryProps> = {
render: Template,
args: {
title: 'LeafyGreen Chat',
variant: Variant.Spacious,
align: 'left',
onClose: undefined,
},
};

export const LeftAlignedWithClose = Template.bind({});
LeftAlignedWithClose.args = {
align: 'left',
onClose: () => {},
export const WithCloseButton: StoryObj<TitleBarStoryProps> = {
render: Template,
args: {
title: 'LeafyGreen Chat',
variant: Variant.Spacious,
// eslint-disable-next-line no-console
onClose: () => console.log('Close clicked'),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we don't use storybook actions in our stories?
https://storybook.js.org/docs/essentials/actions

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific reason other than we just haven't adopted it more broadly. Definitely something we could do

},
};
Loading
Loading