Skip to content

Commit

Permalink
[add] Form: support viewTitle & editTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
MatrixAge committed Oct 18, 2023
1 parent 189d843 commit 0116254
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/xgen/components/base/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useFullscreen, useMemoizedFn } from 'ahooks'
import clsx from 'clsx'
import { toJS } from 'mobx'
import { observer } from 'mobx-react-lite'
import { useLayoutEffect, useRef, useState } from 'react'
import { useLayoutEffect, useMemo, useRef, useState } from 'react'
import { container } from 'tsyringe'

import { Page, PureForm } from '@/components'
Expand All @@ -25,10 +25,21 @@ const Index = (props: Component.FormComponent) => {
const locale = getLocale()
const page_title_prefix = usePageTitle(locales[locale], id!, form!.type)
const hooks = useHooks(toJS(x.setting.hooks!), toJS(x.setting.fields), toJS(x.data))
const title = page_title_prefix + x.setting.name
const ref_container = useRef<HTMLDivElement>(null)
const [is_fullscreen, { toggleFullscreen }] = useFullscreen(ref_container)

const title = useMemo(() => {
if (x.setting?.config?.viewTitle && x.type === 'view') {
return x.setting.config.viewTitle
}

if (x.setting?.config?.editTitle && x.type === 'edit') {
return x.setting.config.editTitle
}

return page_title_prefix + x.setting.name
}, [page_title_prefix, x.setting.name, x.type, x.setting?.config?.viewTitle, x.setting?.config?.editTitle])

const onFormBack = useMemoizedFn(() => {
if (onBack) {
onBack()
Expand Down
2 changes: 2 additions & 0 deletions packages/xgen/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export declare namespace FormType {
}
config?: Common.Config & {
showAnchor?: boolean
viewTitle?: string
editTitle?: string
}
}
}

0 comments on commit 0116254

Please sign in to comment.