-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 style: update
SyntaxHighlighter
and form
- Loading branch information
1 parent
7a8e5a5
commit 4adfbfa
Showing
8 changed files
with
177 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Form, type FormProps } from '@lobehub/ui'; | ||
import { Button, InputNumber, Segmented, Select, Switch } from 'antd'; | ||
import { Palette, PanelLeftClose } from 'lucide-react'; | ||
|
||
const setting = { | ||
i18n: 'en', | ||
liteAnimation: false, | ||
sidebarExpand: true, | ||
sidebarFixedMode: 'float', | ||
sidebarWidth: 300, | ||
}; | ||
|
||
const items: FormProps['items'] = [ | ||
{ | ||
children: [ | ||
{ | ||
children: ( | ||
<Select | ||
options={[ | ||
{ | ||
label: 'English', | ||
value: 'en', | ||
}, | ||
{ | ||
label: '简体中文', | ||
value: 'zh_CN', | ||
}, | ||
]} | ||
/> | ||
), | ||
desc: 'Editor language', | ||
label: 'Language', | ||
name: 'i18n', | ||
}, | ||
{ | ||
children: <Switch />, | ||
desc: 'Reduce the blur effect and background flow color, which can improve smoothness and save CPU usage', | ||
label: 'Reduce Animation', | ||
name: 'liteAnimation', | ||
valuePropName: 'checked', | ||
}, | ||
], | ||
icon: Palette, | ||
title: 'Theme Settings', | ||
}, | ||
{ | ||
children: [ | ||
{ | ||
children: <Switch />, | ||
desc: 'Whether to expand the sidebar by default when starting', | ||
label: 'Default Expand', | ||
name: 'sidebarExpand', | ||
valuePropName: 'checked', | ||
}, | ||
{ | ||
children: ( | ||
<Segmented | ||
options={[ | ||
{ | ||
label: 'Fixed', | ||
value: 'fixed', | ||
}, | ||
{ | ||
label: 'Float', | ||
value: 'float', | ||
}, | ||
]} | ||
/> | ||
), | ||
desc: 'Fixed as grid mode for constant display, auto-expand when the mouse moves to the side in floating mode', | ||
label: 'Display Mode', | ||
name: 'sidebarFixedMode', | ||
}, | ||
{ | ||
children: <InputNumber />, | ||
desc: 'Default width of the sidebar when starting', | ||
label: 'Default Width', | ||
name: 'sidebarWidth', | ||
}, | ||
], | ||
icon: PanelLeftClose, | ||
title: 'Quick Setting Sidebar', | ||
}, | ||
]; | ||
|
||
export default () => { | ||
return ( | ||
<Form | ||
footer={ | ||
<> | ||
<Button htmlType="button">Reset</Button> | ||
<Button htmlType="submit" type="primary"> | ||
Submit | ||
</Button> | ||
</> | ||
} | ||
initialValues={setting} | ||
items={items} | ||
onFinish={console.table} | ||
style={{ width: 500 }} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
import { Form as AntForm, FormProps as AntFormProps } from 'antd'; | ||
import { memo } from 'react'; | ||
import { LucideIcon } from 'lucide-react'; | ||
import { type ReactNode, memo } from 'react'; | ||
|
||
import FormFooter from './components/FormFooter'; | ||
import FormGroup from './components/FormGroup'; | ||
import FormItem, { FormItemProps } from './components/FormItem'; | ||
import { useStyles } from './style'; | ||
|
||
export type FormProps = AntFormProps; | ||
export interface ItemGroup { | ||
children: FormItemProps[]; | ||
icon: LucideIcon; | ||
title: string; | ||
} | ||
|
||
const Form = memo<FormProps>(({ className, ...props }) => { | ||
export interface FormProps extends AntFormProps { | ||
children?: ReactNode; | ||
footer?: ReactNode; | ||
items?: ItemGroup[]; | ||
} | ||
|
||
const Form = memo<FormProps>(({ className, footer, items, children, ...props }) => { | ||
const { cx, styles } = useStyles(); | ||
return ( | ||
// @ts-ignore | ||
<AntForm className={cx(styles.form, className)} colon={false} layout="horizontal" {...props} /> | ||
<AntForm className={cx(styles.form, className)} colon={false} layout="horizontal" {...props}> | ||
{items?.map((group, groupIndex) => ( | ||
<FormGroup icon={group.icon} key={groupIndex} title={group.title}> | ||
{group.children.map((item, itemIndex) => { | ||
return <FormItem divider={itemIndex !== 0} key={itemIndex} {...item} />; | ||
})} | ||
</FormGroup> | ||
))} | ||
{children} | ||
{footer && <FormFooter>{footer}</FormFooter>} | ||
</AntForm> | ||
); | ||
}); | ||
export default Form; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters