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
2 changes: 1 addition & 1 deletion examples/vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const App = () => {
<ChatView>
<ChatView.Selector
itemSet={chatViewSelectorItemSet}
showLabels={chatView.showLabels}
iconOnly={chatView.iconOnly}
/>
<ChatView.Channels>
<ChannelList
Expand Down
4 changes: 2 additions & 2 deletions examples/vite/src/AppSettings/AppSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ const tabConfig: { Icon: ComponentType; id: TabId; title: string }[] = [
{ Icon: IconEmojiSmile, id: 'reactions', title: 'Reactions' },
];

export const AppSettings = ({ showLabels = false }: { showLabels?: boolean }) => {
export const AppSettings = ({ iconOnly = true }: { iconOnly?: boolean }) => {
const [activeTab, setActiveTab] = useState<TabId>('sidebar');
const [open, setOpen] = useState(false);

return (
<div className='app__settings-group'>
<ChatViewSelectorButton
iconOnly={iconOnly}
Icon={IconSettingsGear2}
onClick={() => setOpen(true)}
showLabel={showLabels}
text='Settings'
/>
<GlobalModal open={open} onClose={() => setOpen(false)}>
Expand Down
4 changes: 2 additions & 2 deletions examples/vite/src/AppSettings/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ReactionsSettingsState = {
};

export type ChatViewSettingsState = {
showLabels: boolean;
iconOnly: boolean;
};

export type AppSettingsState = {
Expand All @@ -18,7 +18,7 @@ export type AppSettingsState = {

const defaultAppSettingsState: AppSettingsState = {
chatView: {
showLabels: false,
iconOnly: true,
},
reactions: {
flipHorizontalPosition: false,
Expand Down
10 changes: 5 additions & 5 deletions examples/vite/src/AppSettings/tabs/Sidebar/SidebarTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { appSettingsStore, useAppSettingsState } from '../../state';
export const SidebarTab = () => {
const {
chatView,
chatView: { showLabels },
chatView: { iconOnly },
} = useAppSettingsState();

return (
Expand All @@ -13,22 +13,22 @@ export const SidebarTab = () => {
<div className='app__settings-modal__field-label'>Label visibility</div>
<div className='app__settings-modal__options-row'>
<Button
aria-pressed={!showLabels}
aria-pressed={iconOnly}
className='app__settings-modal__option-button str-chat__button--outline str-chat__button--secondary str-chat__button--size-sm'
onClick={() =>
appSettingsStore.partialNext({
chatView: { ...chatView, showLabels: false },
chatView: { ...chatView, iconOnly: true },
})
}
>
Icons only
</Button>
<Button
aria-pressed={showLabels}
aria-pressed={!iconOnly}
className='app__settings-modal__option-button str-chat__button--outline str-chat__button--secondary str-chat__button--size-sm'
onClick={() =>
appSettingsStore.partialNext({
chatView: { ...chatView, showLabels: true },
chatView: { ...chatView, iconOnly: false },
})
}
>
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/src/stream-imports-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
@use 'stream-chat-react/dist/scss/v2/TypingIndicator/TypingIndicator-layout';
// @use 'stream-chat-react/dist/scss/v2/ThreadList/ThreadList-layout';
//@use 'stream-chat-react/dist/scss/v2/ChatView/ChatView-layout';
@use 'stream-chat-react/dist/scss/v2/UnreadCountBadge/UnreadCountBadge-layout';
//@use 'stream-chat-react/dist/scss/v2/UnreadCountBadge/UnreadCountBadge-layout';
@use 'stream-chat-react/dist/scss/v2/AIStateIndicator/AIStateIndicator-layout';
2 changes: 1 addition & 1 deletion examples/vite/src/stream-imports-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
@use 'stream-chat-react/dist/scss/v2/TypingIndicator/TypingIndicator-theme';
// @use 'stream-chat-react/dist/scss/v2/ThreadList/ThreadList-theme';
//@use 'stream-chat-react/dist/scss/v2/ChatView/ChatView-theme';
@use 'stream-chat-react/dist/scss/v2/UnreadCountBadge/UnreadCountBadge-theme';
//@use 'stream-chat-react/dist/scss/v2/UnreadCountBadge/UnreadCountBadge-theme';
@use 'stream-chat-react/dist/scss/v2/AIStateIndicator/AIStateIndicator-theme';
24 changes: 12 additions & 12 deletions src/components/ChatView/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ export const ChatViewSelectorButton = ({
children,
className,
Icon,
iconOnly = true,
isActive,
showLabel = false,
text,
...props
}: ButtonProps & {
ActiveIcon?: ComponentType;
iconOnly?: boolean;
Icon?: ComponentType;
isActive?: boolean;
showLabel?: boolean;
text?: string;
}) => {
const SelectorIcon = isActive && ActiveIcon ? ActiveIcon : Icon;
const shouldShowTooltip = !!text && !showLabel;
const shouldShowTooltip = !!text && iconOnly;

return (
<div className='str-chat__chat-view__selector-button-container'>
Expand All @@ -195,7 +195,7 @@ export const ChatViewSelectorButton = ({
{...props}
>
{children ?? (SelectorIcon && <SelectorIcon />)}
{showLabel && text && (
{!iconOnly && text && (
<div className='str-chat__chat-view__selector-button-text'>{text}</div>
)}
</Button>
Expand All @@ -221,11 +221,11 @@ const unreadThreadCountSelector = ({ unreadThreadCount }: ThreadManagerState) =>
});

export type ChatViewSelectorItemProps = {
showLabels?: boolean;
iconOnly?: boolean;
};

export const ChatViewChannelsSelectorButton = ({
showLabels = false,
iconOnly = true,
}: ChatViewSelectorItemProps) => {
const { activeChatView, setActiveChatView } = useChatViewContext();
const { t } = useTranslationContext();
Expand All @@ -235,16 +235,16 @@ export const ChatViewChannelsSelectorButton = ({
ActiveIcon={IconBubble3Solid}
aria-selected={activeChatView === 'channels'}
Icon={IconBubble3ChatMessage}
iconOnly={iconOnly}
isActive={activeChatView === 'channels'}
onPointerDown={() => setActiveChatView('channels')}
showLabel={showLabels}
text={t('Channels')}
/>
);
};

export const ChatViewThreadsSelectorButton = ({
showLabels = false,
iconOnly = true,
}: ChatViewSelectorItemProps) => {
const { client } = useChatContext();
const { unreadThreadCount } = useStateStore(
Expand All @@ -259,8 +259,8 @@ export const ChatViewThreadsSelectorButton = ({
return (
<ChatViewSelectorButton
aria-selected={activeChatView === 'threads'}
iconOnly={iconOnly}
onPointerDown={() => setActiveChatView('threads')}
showLabel={showLabels}
text={t('Threads')}
>
<UnreadCountBadge count={unreadThreadCount} position='top-right'>
Expand All @@ -278,8 +278,8 @@ export type ChatViewSelectorItem = {
export type ChatViewSelectorEntry = ChatViewSelectorItem;

export type ChatViewSelectorProps = {
iconOnly?: boolean;
itemSet?: ChatViewSelectorEntry[];
showLabels?: boolean;
};

export const defaultChatViewSelectorItemSet: ChatViewSelectorEntry[] = [
Expand All @@ -294,12 +294,12 @@ export const defaultChatViewSelectorItemSet: ChatViewSelectorEntry[] = [
];

const ChatViewSelector = ({
iconOnly = true,
itemSet = defaultChatViewSelectorItemSet,
showLabels = false,
}: ChatViewSelectorProps) => (
<div className='str-chat__chat-view__selector'>
{itemSet.map(({ Component, type }) => (
<Component key={type} showLabels={showLabels} />
<Component iconOnly={iconOnly} key={type} />
))}
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ChatView/__tests__/ChatView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ describe('ChatView.Selector', () => {
]);
});

it('renders labels inline when showLabels is enabled', async () => {
const { container } = await renderSelector({ showLabels: true });
it('renders labels inline when iconOnly is disabled', async () => {
const { container } = await renderSelector({ iconOnly: false });

expect(
container.querySelectorAll('.str-chat__chat-view__selector-button-tooltip'),
Expand Down
61 changes: 61 additions & 0 deletions src/components/Threads/styling/UnreadCountBadge.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Only available in React SDK. */
.str-chat {
--str-chat-unread-count-badge-color: var(--str-chat__on-unread-badge-color);
--str-chat-unread-count-badge-background-color: var(--str-chat__danger-color);
}

.str-chat__unread-count-badge {
background-color: var(--str-chat-unread-count-badge-background-color);
color: var(--str-chat-unread-count-badge-color);
border-radius: 9999px;
}

.str-chat {
--str-chat-unread-count-badge-absolute-offset-vertical: 50%;
--str-chat-unread-count-badge-absolute-offset-horizontal: 50%;
}

.str-chat__unread-count-badge-container {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}

.str-chat__unread-count-badge {
font-size: 12px;
min-width: 18px;
min-height: 18px;
line-height: 8px;
font-weight: 700;
padding: 5px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
font-variant-numeric: tabular-nums;

&--top-right {
position: absolute;
translate: var(--str-chat-unread-count-badge-absolute-offset-horizontal)
calc(var(--str-chat-unread-count-badge-absolute-offset-vertical) * -1);
}

&--bottom-left {
position: absolute;
translate: calc(var(--str-chat-unread-count-badge-absolute-offset-horizontal) * -1)
var(--str-chat-unread-count-badge-absolute-offset-vertical);
}

&--bottom-right {
position: absolute;
translate: var(--str-chat-unread-count-badge-absolute-offset-horizontal)
var(--str-chat-unread-count-badge-absolute-offset-vertical);
}

&--top-left {
position: absolute;
translate: calc(var(--str-chat-unread-count-badge-absolute-offset-horizontal) * -1)
calc(var(--str-chat-unread-count-badge-absolute-offset-vertical) * -1);
}
}
1 change: 1 addition & 0 deletions src/components/Threads/styling/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@use 'UnreadCountBadge';
1 change: 1 addition & 0 deletions src/styling/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
@use '../components/Reactions/styling' as Reactions;
@use '../components/TextareaComposer/styling' as TextareaComposer;
@use '../components/Thread/styling' as Thread;
@use '../components/Threads/styling' as Threads;
@use '../components/Threads/ThreadList/styling' as ThreadList;
@use '../components/VideoPlayer/styling' as VideoPlayer;
@use '../components/SummarizedMessagePreview/styling' as SummarizedMessagePreview;
Expand Down
Loading