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

Chore: Convert sidebar/item #25634

Merged
merged 4 commits into from
Jun 14, 2022
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { Sidebar, ActionButton } from '@rocket.chat/fuselage';
import { Sidebar, ActionButton, IconProps } from '@rocket.chat/fuselage';
import { useMutableCallback, usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks';
import React, { memo, useState } from 'react';
import React, { FC, memo, ReactElement, useState } from 'react';

const Condensed = ({ icon, title = '', titleIcon, avatar, actions, href, menuOptions, unread, menu, badges, threadUnread, ...props }) => {
type CondensedProps = {
title: ReactElement | string;
titleIcon?: ReactElement;
avatar: ReactElement | boolean;
icon?: IconProps['name'];
actions?: ReactElement;
href?: string;
unread?: boolean;
menu?: () => ReactElement;
menuOptions?: any;
selected?: boolean;
badges?: ReactElement;
clickable?: boolean;
};

const Condensed: FC<CondensedProps> = ({ icon, title = '', avatar, actions, href, unread, menu, badges, ...props }) => {
const [menuVisibility, setMenuVisibility] = useState(!!window.DISABLE_ANIMATION);

const isReduceMotionEnabled = usePrefersReducedMotion();
Expand All @@ -15,12 +30,12 @@ const Condensed = ({ icon, title = '', titleIcon, avatar, actions, href, menuOpt
};

return (
<Sidebar.Item {...props} href={href} clickable={!!href}>
<Sidebar.Item {...props} {...({ href } as any)} clickable={!!href}>
{avatar && <Sidebar.Item.Avatar>{avatar}</Sidebar.Item.Avatar>}
<Sidebar.Item.Content>
<Sidebar.Item.Wrapper>
{icon}
<Sidebar.Item.Title data-qa='sidebar-item-title' className={unread && 'rcx-sidebar-item--highlighted'}>
<Sidebar.Item.Title data-qa='sidebar-item-title' className={(unread && 'rcx-sidebar-item--highlighted') as string}>
{title}
</Sidebar.Item.Title>
</Sidebar.Item.Wrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { Sidebar, ActionButton } from '@rocket.chat/fuselage';
import { Sidebar, ActionButton, IconProps } from '@rocket.chat/fuselage';
import { useMutableCallback, usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks';
import React, { memo, useState } from 'react';
import React, { memo, useState, VFC } from 'react';

import { useShortTimeAgo } from '../../hooks/useTimeAgo';

/**
* @param {Object} props
* @param {React.ReactNode} props.icon
* @param {React.ReactNode} props.title
* @param {any} props.avatar
* @param {any} props.actions
* @param {any} props.href
* @param {any} props.time
* @param {any} props.menu
* @param {any} props.menuOptions
* @param {React.ReactNode} props.subtitle
* @param {any} props.titleIcon
* @param {any} props.badges
* @param {any} props.threadUnread
* @param {any} props.unread
* @param {any} props.selected
*/
const Extended = ({
type ExtendedProps = {
icon?: IconProps['name'];
title?: React.ReactNode;
avatar?: React.ReactNode | boolean;
actions?: React.ReactNode;
href?: string;
time?: any;
menu?: () => React.ReactNode;
subtitle?: React.ReactNode;
badges?: React.ReactNode;
unread?: boolean;
selected?: boolean;
menuOptions?: any;
titleIcon?: React.ReactNode;
threadUnread?: boolean;
};

const Extended: VFC<ExtendedProps> = ({
icon,
title = '',
avatar,
actions,
href,
time,
menu,
menuOptions,
menuOptions: _menuOptions,
subtitle = '',
titleIcon,
titleIcon: _titleIcon,
badges,
threadUnread,
threadUnread: _threadUnread,
unread,
selected,
...props
Expand All @@ -52,23 +52,21 @@ const Extended = ({
};

return (
<Sidebar.Item aria-selected={selected} selected={selected} highlighted={unread} {...props} href={href} clickable={!!href}>
<Sidebar.Item aria-selected={selected} selected={selected} highlighted={unread} {...props} {...(href as any)} clickable={!!href}>
{avatar && <Sidebar.Item.Avatar>{avatar}</Sidebar.Item.Avatar>}
<Sidebar.Item.Content>
<Sidebar.Item.Content>
<Sidebar.Item.Wrapper>
{icon}
<Sidebar.Item.Title data-qa='sidebar-item-title' className={unread && 'rcx-sidebar-item--highlighted'}>
<Sidebar.Item.Title data-qa='sidebar-item-title' className={(unread && 'rcx-sidebar-item--highlighted') as string}>
{title}
</Sidebar.Item.Title>
{time && <Sidebar.Item.Time>{formatDate(time)}</Sidebar.Item.Time>}
</Sidebar.Item.Wrapper>
</Sidebar.Item.Content>
<Sidebar.Item.Content>
<Sidebar.Item.Wrapper>
<Sidebar.Item.Subtitle tabIndex='-1' className={unread && 'rcx-sidebar-item--highlighted'}>
{subtitle}
</Sidebar.Item.Subtitle>
<Sidebar.Item.Subtitle className={(unread && 'rcx-sidebar-item--highlighted') as string}>{subtitle}</Sidebar.Item.Subtitle>
<Sidebar.Item.Badge>{badges}</Sidebar.Item.Badge>
{menu && (
<Sidebar.Item.Menu {...handleMenuEvent}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Box, Skeleton } from '@rocket.chat/fuselage';
import React from 'react';
import React, { VFC } from 'react';

import Extended from './Extended';

const ExtendedSkeleton = ({ showAvatar }) => (
const ExtendedSkeleton: VFC<{ showAvatar: boolean }> = ({ showAvatar }) => (
<Box height='x44'>
<Extended
title={<Skeleton width='100%' />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { Sidebar, ActionButton } from '@rocket.chat/fuselage';
import { useMutableCallback, usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks';
import React, { memo, useState } from 'react';
import React, { memo, useState, VFC } from 'react';

const Medium = ({ icon, title = '', titleIcon, avatar, actions, href, menuOptions, badges, unread, threadUnread, menu, ...props }) => {
type MediumProps = {
title: React.ReactNode;
titleIcon?: React.ReactNode;
avatar: React.ReactNode | boolean;
icon?: string;
actions?: React.ReactNode;
href?: string;
unread?: boolean;
menu?: () => React.ReactNode;
badges?: React.ReactNode;
selected?: boolean;
menuOptions?: any;
};

const Medium: VFC<MediumProps> = ({ icon, title = '', avatar, actions, href, badges, unread, menu, ...props }) => {
const [menuVisibility, setMenuVisibility] = useState(!!window.DISABLE_ANIMATION);

const isReduceMotionEnabled = usePrefersReducedMotion();
Expand All @@ -15,12 +29,12 @@ const Medium = ({ icon, title = '', titleIcon, avatar, actions, href, menuOption
};

return (
<Sidebar.Item {...props} href={href} clickable={!!href}>
<Sidebar.Item {...props} {...({ href } as any)} clickable={!!href}>
{avatar && <Sidebar.Item.Avatar>{avatar}</Sidebar.Item.Avatar>}
<Sidebar.Item.Content>
<Sidebar.Item.Wrapper>
{icon}
<Sidebar.Item.Title data-qa='sidebar-item-title' className={unread && 'rcx-sidebar-item--highlighted'}>
<Sidebar.Item.Title data-qa='sidebar-item-title' className={(unread && 'rcx-sidebar-item--highlighted') as string}>
{title}
</Sidebar.Item.Title>
</Sidebar.Item.Wrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Box, Skeleton } from '@rocket.chat/fuselage';
import React from 'react';
import React, { VFC } from 'react';

import Condensed from '../Condensed';

const CondensedSkeleton = ({ showAvatar }) => (
const CondensedSkeleton: VFC<{ showAvatar: boolean }> = ({ showAvatar }) => (
<Box height='x28'>
<Condensed
title={<Skeleton width='100%' />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Box, Skeleton } from '@rocket.chat/fuselage';
import React from 'react';
import React, { VFC } from 'react';

import Medium from '../Medium';

const MediumSkeleton = ({ showAvatar }) => (
const MediumSkeleton: VFC<{ showAvatar: boolean }> = ({ showAvatar }) => (
<Box height='x36'>
<Medium
title={<Skeleton width='100%' />}
Expand Down