Skip to content

Commit e8579b9

Browse files
doc: FormTabs
1 parent 5957abb commit e8579b9

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

packages/curve-ui-kit/src/shared/ui/FormTabs/FormTabs.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ const applyFnOrValue = <Props extends object, R extends string | boolean>(
1717
type FormSubTab<Props extends object> = Pick<FormTab<Props>, 'value' | 'label' | 'component' | 'visible' | 'disabled'>
1818

1919
export type FormTab<Props extends object> = {
20+
/** Unique value of the tab, it might be used in the URL later */
2021
value: string
22+
/** Label of the tab, can be a function that receives the form props */
2123
label: FnOrValue<Props, string>
24+
/** Optional sub-tabs of the tab */
2225
subTabs?: FormSubTab<Props>[]
26+
/** Function or value to determine if the tab is visible */
2327
visible?: FnOrValue<Props, boolean>
28+
/** Function or value to determine if the tab is disabled */
2429
disabled?: FnOrValue<Props, boolean>
30+
/** Component to render when the tab is selected */
2531
component?: ComponentType<Props>
2632
}
2733

@@ -46,15 +52,14 @@ const selectVisible = <Props extends object, Tab extends FormSubTab<Props>>(
4652
return visible.find(({ value }) => value === key) ?? visible[0]
4753
}
4854

49-
function useFormTabs<T extends object>({
50-
menu,
51-
defaultTab,
52-
params,
53-
}: {
55+
type UseFormTabOptions<T extends object> = {
5456
menu: FormTab<T>[]
5557
params: T
5658
defaultTab: string
57-
}) {
59+
}
60+
61+
/** Hook to manage form tabs and sub-tabs. */
62+
function useFormTabs<T extends object>({ menu, defaultTab, params }: UseFormTabOptions<T>) {
5863
const [tabKey, onChangeTab] = useState(defaultTab)
5964
const [subTabKey, onChangeSubTab] = useState<string>()
6065
const tab = selectVisible(menu, tabKey, params)
@@ -68,21 +73,21 @@ function useFormTabs<T extends object>({
6873
return { tab, tabs, subTabs, subTab, Component, onChangeTab, onChangeSubTab }
6974
}
7075

76+
/**
77+
* Adds a background to the form content. In the new forms we don't show the background at this level,
78+
* we still render AppFormContentWrapper there. However, in the new forms the accordion stays outside the background,
79+
* but is still co-located with the form content.
80+
*/
7181
const LegacyFormWrapper = ({ children }: { children: ReactNode }) => (
7282
<Stack sx={{ backgroundColor: (t) => t.design.Layer[1].Fill }}>
7383
<AppFormContentWrapper>{children}</AppFormContentWrapper>
7484
</Stack>
7585
)
7686

77-
export function FormTabs<T extends object>({
78-
shouldWrap,
79-
...options
80-
}: {
81-
menu: FormTab<T>[]
82-
params: T
83-
shouldWrap: boolean
84-
defaultTab: string
85-
}) {
87+
/**
88+
* Form wrapper that displays tabs and handles tab switching. It supports sub-tabs as well.
89+
*/
90+
export function FormTabs<T extends object>({ shouldWrap, ...options }: UseFormTabOptions<T> & { shouldWrap: boolean }) {
8691
const { tab, tabs, subTabs, subTab, Component, onChangeTab, onChangeSubTab } = useFormTabs(options)
8792
const params = options.params
8893
return (

0 commit comments

Comments
 (0)