From 97a0fede5181d9ef287033ae2903dca10a6011d4 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:56:14 +0530 Subject: [PATCH] rework general settings --- .../message/content/EventContent.tsx | 9 +- src/app/components/page/Page.tsx | 28 +- src/app/components/page/style.css.ts | 70 +- .../components/setting-tile/SettingTile.tsx | 27 + src/app/components/setting-tile/index.ts | 1 + src/app/features/room/RoomTimeline.tsx | 36 +- src/app/features/room/message/Message.tsx | 109 ++-- src/app/features/settings/General.tsx | 617 ++++++++++++++++++ src/app/features/settings/Settings.tsx | 138 ++++ src/app/features/settings/index.ts | 2 + src/app/hooks/useMessageLayout.ts | 26 + src/app/hooks/useMessageSpacing.ts | 38 ++ src/app/hooks/useTheme.ts | 74 +++ src/app/pages/Router.tsx | 45 +- src/app/pages/ThemeManager.tsx | 58 ++ src/app/pages/client/SidebarNav.tsx | 4 +- src/app/pages/client/sidebar/SettingsTab.tsx | 111 ++++ src/app/pages/client/sidebar/UserTab.tsx | 65 -- src/app/pages/client/sidebar/index.ts | 2 +- src/app/pages/paths.ts | 2 - src/app/plugins/react-prism/ReactPrism.tsx | 1 - src/app/state/settings.ts | 14 +- src/colors.css.ts | 2 +- src/index.tsx | 3 - 24 files changed, 1286 insertions(+), 196 deletions(-) create mode 100644 src/app/components/setting-tile/SettingTile.tsx create mode 100644 src/app/components/setting-tile/index.ts create mode 100644 src/app/features/settings/General.tsx create mode 100644 src/app/features/settings/Settings.tsx create mode 100644 src/app/features/settings/index.ts create mode 100644 src/app/hooks/useMessageLayout.ts create mode 100644 src/app/hooks/useMessageSpacing.ts create mode 100644 src/app/hooks/useTheme.ts create mode 100644 src/app/pages/ThemeManager.tsx create mode 100644 src/app/pages/client/sidebar/SettingsTab.tsx delete mode 100644 src/app/pages/client/sidebar/UserTab.tsx diff --git a/src/app/components/message/content/EventContent.tsx b/src/app/components/message/content/EventContent.tsx index 2cc4934c9..97ff26f7d 100644 --- a/src/app/components/message/content/EventContent.tsx +++ b/src/app/components/message/content/EventContent.tsx @@ -1,6 +1,7 @@ import { Box, Icon, IconSrc } from 'folds'; import React, { ReactNode } from 'react'; import { CompactLayout, ModernLayout } from '..'; +import { MessageLayout } from '../../../state/settings'; export type EventContentProps = { messageLayout: number; @@ -11,9 +12,9 @@ export type EventContentProps = { export function EventContent({ messageLayout, time, iconSrc, content }: EventContentProps) { const beforeJSX = ( - {messageLayout === 1 && time} + {messageLayout === MessageLayout.Compact && time} @@ -25,11 +26,11 @@ export function EventContent({ messageLayout, time, iconSrc, content }: EventCon const msgContentJSX = ( {content} - {messageLayout !== 1 && time} + {messageLayout !== MessageLayout.Compact && time} ); - return messageLayout === 1 ? ( + return messageLayout === MessageLayout.Compact ? ( {msgContentJSX} ) : ( {msgContentJSX} diff --git a/src/app/components/page/Page.tsx b/src/app/components/page/Page.tsx index a8b9ea044..55cceceec 100644 --- a/src/app/components/page/Page.tsx +++ b/src/app/components/page/Page.tsx @@ -27,14 +27,14 @@ export function PageRoot({ nav, children }: PageRootProps) { type ClientDrawerLayoutProps = { children: ReactNode; }; -export function PageNav({ children }: ClientDrawerLayoutProps) { +export function PageNav({ size, children }: ClientDrawerLayoutProps & css.PageNavVariants) { const screenSize = useScreenSizeContext(); const isMobile = screenSize === ScreenSize.Mobile; return ( @@ -44,15 +44,17 @@ export function PageNav({ children }: ClientDrawerLayoutProps) { ); } -export const PageNavHeader = as<'header'>(({ className, ...props }, ref) => ( -
-)); +export const PageNavHeader = as<'header', css.PageNavHeaderVariants>( + ({ className, outlined, ...props }, ref) => ( +
+ ) +); export function PageNavContent({ scrollRef, @@ -88,11 +90,11 @@ export const Page = as<'div'>(({ className, ...props }, ref) => ( )); export const PageHeader = as<'div', css.PageHeaderVariants>( - ({ className, balance, ...props }, ref) => ( + ({ className, outlined, balance, ...props }, ref) => (
diff --git a/src/app/components/page/style.css.ts b/src/app/components/page/style.css.ts index 23f2da494..0abd4dfa9 100644 --- a/src/app/components/page/style.css.ts +++ b/src/app/components/page/style.css.ts @@ -2,30 +2,55 @@ import { style } from '@vanilla-extract/css'; import { recipe, RecipeVariants } from '@vanilla-extract/recipes'; import { DefaultReset, color, config, toRem } from 'folds'; -export const PageNav = style({ - width: toRem(256), +export const PageNav = recipe({ + variants: { + size: { + '400': { + width: toRem(256), + }, + '300': { + width: toRem(222), + }, + }, + }, + defaultVariants: { + size: '400', + }, }); +export type PageNavVariants = RecipeVariants; -export const PageNavHeader = style({ - padding: `0 ${config.space.S200} 0 ${config.space.S300}`, - flexShrink: 0, - borderBottomWidth: 1, - - selectors: { - 'button&': { - cursor: 'pointer', - }, - 'button&[aria-pressed=true]': { - backgroundColor: color.Background.ContainerActive, - }, - 'button&:hover, button&:focus-visible': { - backgroundColor: color.Background.ContainerHover, +export const PageNavHeader = recipe({ + base: { + padding: `0 ${config.space.S200} 0 ${config.space.S300}`, + flexShrink: 0, + selectors: { + 'button&': { + cursor: 'pointer', + }, + 'button&[aria-pressed=true]': { + backgroundColor: color.Background.ContainerActive, + }, + 'button&:hover, button&:focus-visible': { + backgroundColor: color.Background.ContainerHover, + }, + 'button&:active': { + backgroundColor: color.Background.ContainerActive, + }, }, - 'button&:active': { - backgroundColor: color.Background.ContainerActive, + }, + + variants: { + outlined: { + true: { + borderBottomWidth: 1, + }, }, }, + defaultVariants: { + outlined: true, + }, }); +export type PageNavHeaderVariants = RecipeVariants; export const PageNavContent = style({ minHeight: '100%', @@ -38,7 +63,6 @@ export const PageHeader = recipe({ base: { paddingLeft: config.space.S400, paddingRight: config.space.S200, - borderBottomWidth: config.borderWidth.B300, }, variants: { balance: { @@ -46,6 +70,14 @@ export const PageHeader = recipe({ paddingLeft: config.space.S200, }, }, + outlined: { + true: { + borderBottomWidth: config.borderWidth.B300, + }, + }, + }, + defaultVariants: { + outlined: true, }, }); export type PageHeaderVariants = RecipeVariants; diff --git a/src/app/components/setting-tile/SettingTile.tsx b/src/app/components/setting-tile/SettingTile.tsx new file mode 100644 index 000000000..2656903a2 --- /dev/null +++ b/src/app/components/setting-tile/SettingTile.tsx @@ -0,0 +1,27 @@ +import React, { ReactNode } from 'react'; +import { Box, Text } from 'folds'; + +type SettingTileProps = { + title: ReactNode; + description?: ReactNode; + before?: ReactNode; + after?: ReactNode; + children?: ReactNode; +}; +export function SettingTile({ title, description, before, after, children }: SettingTileProps) { + return ( + + {before && {before}} + + {title} + {description && ( + + {description} + + )} + {children} + + {after && {after}} + + ); +} diff --git a/src/app/components/setting-tile/index.ts b/src/app/components/setting-tile/index.ts new file mode 100644 index 000000000..49fede72c --- /dev/null +++ b/src/app/components/setting-tile/index.ts @@ -0,0 +1 @@ +export * from './SettingTile'; diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index a2738fcbf..97d2a1a8f 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -85,7 +85,7 @@ import { reactionOrEditEvent, } from '../../utils/room'; import { useSetting } from '../../state/hooks/settings'; -import { settingsAtom } from '../../state/settings'; +import { MessageLayout, settingsAtom } from '../../state/settings'; import { openProfileViewer } from '../../../client/action/navigation'; import { useMatrixEventRenderer } from '../../hooks/useMatrixEventRenderer'; import { Reactions, Message, Event, EncryptedContent } from './message'; @@ -1028,7 +1028,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli urlPreview={showUrlPreview} htmlReactParserOptions={htmlReactParserOptions} linkifyOpts={linkifyOpts} - outlineAttachment={messageLayout === 2} + outlineAttachment={messageLayout === MessageLayout.Bubble} /> )} @@ -1124,7 +1124,7 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli urlPreview={showUrlPreview} htmlReactParserOptions={htmlReactParserOptions} linkifyOpts={linkifyOpts} - outlineAttachment={messageLayout === 2} + outlineAttachment={messageLayout === MessageLayout.Bubble} /> ); } @@ -1208,7 +1208,9 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli const highlighted = focusItem?.index === item && focusItem.highlight; const parsed = parseMemberEvent(mEvent); - const timeJSX =