Skip to content

Commit

Permalink
💄 style: Fix scroll layout and setting panel in mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Dec 25, 2023
1 parent 7a1a6ca commit 2abac2d
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 91 deletions.
146 changes: 78 additions & 68 deletions javascript/main.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/features/Setting/Form/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Button, Popconfirm } from 'antd';
import { useResponsive } from 'antd-style';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

import { DEFAULT_SETTING, useAppStore } from '@/store';

const Footer = memo(() => {
const { t } = useTranslation();

const { mobile } = useResponsive();
const onSetSetting = useAppStore((st) => st.onSetSetting);

const onReset = useCallback(() => {
Expand All @@ -15,22 +17,22 @@ const Footer = memo(() => {
}, []);

return (
<>
<Flexbox gap={16} horizontal={!mobile} style={mobile ? { padding: 16, width: '100%' } : {}}>
<Popconfirm
cancelText={t('cancel')}
okText={t('confirm')}
okType={'danger'}
onConfirm={onReset}
title={t('setting.button.reset')}
>
<Button danger style={{ borderRadius: 4 }}>
<Button block={mobile} danger style={{ borderRadius: 4 }}>
{t('setting.button.reset')}
</Button>
</Popconfirm>
<Button htmlType="submit" style={{ borderRadius: 4 }} type="primary">
<Button block={mobile} htmlType="submit" style={{ borderRadius: 4 }} type="primary">
{t('setting.button.submit')}
</Button>
</>
</Flexbox>
);
});
export default Footer;
24 changes: 24 additions & 0 deletions src/features/Setting/Sidebar/Mobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Segmented } from 'antd';
import { memo } from 'react';

import { SettingsTabs } from '@/features/Setting/Sidebar/index';
import { useTabItems } from '@/features/Setting/Sidebar/useTabItems';

interface SidebarProps {
setTab: (tab: SettingsTabs) => void;
tab: string;
}

const MobileSidebar = memo<SidebarProps>(({ tab, setTab }) => {
const items = useTabItems();
return (
<Segmented
block
onChange={setTab as any}
options={items.map(({ value, label }) => ({ label, value }))}
value={tab}
/>
);
});

export default MobileSidebar;
15 changes: 5 additions & 10 deletions src/features/Setting/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Brush, FlaskConical, Layout, PanelRight } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

import { useTabItems } from '@/features/Setting/Sidebar/useTabItems';

import Item from './Item';

export enum SettingsTabs {
Expand All @@ -18,14 +18,7 @@ interface SidebarProps {
}

const Sidebar = memo<SidebarProps>(({ tab, setTab }) => {
const { t } = useTranslation();

const items = [
{ icon: Brush, label: t('setting.tab.appearance'), value: SettingsTabs.Appearance },
{ icon: Layout, label: t('setting.tab.layout'), value: SettingsTabs.Layout },
{ icon: PanelRight, label: t('setting.tab.sidebar'), value: SettingsTabs.Sidebar },
{ icon: FlaskConical, label: t('setting.tab.experimental'), value: SettingsTabs.Experimental },
];
const items = useTabItems();

return (
<Flexbox gap={4}>
Expand All @@ -43,3 +36,5 @@ const Sidebar = memo<SidebarProps>(({ tab, setTab }) => {
});

export default Sidebar;

export { default as MobileSidebar } from './Mobile';
15 changes: 15 additions & 0 deletions src/features/Setting/Sidebar/useTabItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Brush, FlaskConical, Layout, PanelRight } from 'lucide-react';
import { useTranslation } from 'react-i18next';

import { SettingsTabs } from '@/features/Setting/Sidebar/index';

export const useTabItems = () => {
const { t } = useTranslation();

return [
{ icon: Brush, label: t('setting.tab.appearance'), value: SettingsTabs.Appearance },
{ icon: Layout, label: t('setting.tab.layout'), value: SettingsTabs.Layout },
{ icon: PanelRight, label: t('setting.tab.sidebar'), value: SettingsTabs.Sidebar },
{ icon: FlaskConical, label: t('setting.tab.experimental'), value: SettingsTabs.Experimental },
];
};
34 changes: 26 additions & 8 deletions src/features/Setting/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActionIcon, Modal, type ModalProps } from '@lobehub/ui';
import { useResponsive } from 'antd-style';
import { Book } from 'lucide-react';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -11,7 +12,7 @@ import FormAppearance from './Form/Appearance';
import FormExperimental from './Form/Experimental';
import FormLayout from './Form/Layout';
import FormSidebar from './Form/Sidebar';
import Sidebar, { SettingsTabs } from './Sidebar';
import Sidebar, { MobileSidebar, SettingsTabs } from './Sidebar';

export interface SettingProps {
onCancel?: ModalProps['onCancel'];
Expand All @@ -20,7 +21,18 @@ export interface SettingProps {

const Setting = memo<SettingProps>(({ open, onCancel }) => {
const [tab, setTab] = useState<SettingsTabs>(SettingsTabs.Appearance);
const { mobile } = useResponsive();
const { t } = useTranslation();

const content = (
<>
{tab === SettingsTabs.Appearance && <FormAppearance />}
{tab === SettingsTabs.Layout && <FormLayout />}
{tab === SettingsTabs.Sidebar && <FormSidebar />}
{tab === SettingsTabs.Experimental && <FormExperimental />}
</>
);

return (
<Modal
footer={false}
Expand All @@ -40,13 +52,19 @@ const Setting = memo<SettingProps>(({ open, onCancel }) => {
}
width={960}
>
<Flexbox gap={16} horizontal>
<Sidebar setTab={setTab} tab={tab} />
{tab === SettingsTabs.Appearance && <FormAppearance />}
{tab === SettingsTabs.Layout && <FormLayout />}
{tab === SettingsTabs.Sidebar && <FormSidebar />}
{tab === SettingsTabs.Experimental && <FormExperimental />}
</Flexbox>
{mobile ? (
<Flexbox>
<div style={{ padding: 16 }}>
<MobileSidebar setTab={setTab} tab={tab} />
</div>
{content}
</Flexbox>
) : (
<Flexbox gap={16} horizontal>
<Sidebar setTab={setTab} tab={tab} />
{content}
</Flexbox>
)}
</Modal>
);
});
Expand Down
4 changes: 4 additions & 0 deletions src/styles/components/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { readableColor } from 'polished';

export default (token: Theme) => {
return css`
body {
height: 100vh !important;
}
.gradio-group,
.gradio-row {
gap: 12px !important;
Expand Down

0 comments on commit 2abac2d

Please sign in to comment.