@material-ui/lab#TabContext TypeScript Examples
The following examples show how to use
@material-ui/lab#TabContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From TidGi-Desktop with Mozilla Public License 2.0 | 5 votes |
/**
* Create storage provider's token.
* @returns
*/
export function TokenForm({ storageProvider, storageProviderSetter }: Props): JSX.Element {
const { t } = useTranslation();
let [currentTab, currentTabSetter] = useState<SupportedStorageServices>(SupportedStorageServices.github);
// use external controls if provided
if (storageProvider !== undefined && typeof storageProviderSetter === 'function') {
currentTab = storageProvider;
currentTabSetter = storageProviderSetter as unknown as React.Dispatch<React.SetStateAction<SupportedStorageServices>>;
}
// update storageProvider to be an online service, if this Component is opened
useEffect(() => {
if (storageProvider === SupportedStorageServices.local && typeof storageProviderSetter === 'function') {
storageProviderSetter(SupportedStorageServices.github);
}
}, [storageProvider, storageProviderSetter]);
return (
<Container>
<ListItemText primary={t('Preference.Token')} secondary={t('Preference.TokenDescription')} />
<TabContext value={currentTab}>
<TabsContainer>
<TabList
onChange={(_event, newValue) => currentTabSetter(newValue as SupportedStorageServices)}
orientation="vertical"
variant="scrollable"
value={currentTab}
aria-label="Vertical tabs example">
<Tab label="GitHub" value={SupportedStorageServices.github} />
<Tab label="GitLab" value={SupportedStorageServices.gitlab} />
<Tab label="Gitee" value={SupportedStorageServices.gitee} />
</TabList>
<TabPanel value={SupportedStorageServices.github}>
<GitTokenForm storageService={SupportedStorageServices.github} />
</TabPanel>
<TabPanel value={SupportedStorageServices.gitlab}>
<GitTokenForm storageService={SupportedStorageServices.gitlab} />
</TabPanel>
<TabPanel value={SupportedStorageServices.gitee}>
Gitee(码云)一直不愿意支持 OAuth2 ,所以我们没法适配它的登录系统,如果你认识相关开发人员,请催促他们尽快支持,与国际接轨。
</TabPanel>
</TabsContainer>
</TabContext>
</Container>
);
}
Example #2
Source File: index.tsx From TidGi-Desktop with Mozilla Public License 2.0 | 4 votes |
export function AddWorkspace(): JSX.Element {
const { t } = useTranslation();
const [currentTab, currentTabSetter] = useState<CreateWorkspaceTabs>(CreateWorkspaceTabs.CreateNewWiki);
const [isCreateSyncedWorkspace, isCreateSyncedWorkspaceSetter] = useIsCreateSyncedWorkspace();
const [isCreateMainWorkspace, isCreateMainWorkspaceSetter] = useState(true);
const form = useWikiWorkspaceForm();
const [errorInWhichComponent, errorInWhichComponentSetter] = useState<IErrorInWhichComponent>({});
const workspaceList = usePromiseValue(async () => await window.service.workspace.getWorkspacesAsList());
// update storageProviderSetter to local based on isCreateSyncedWorkspace. Other services value will be changed by TokenForm
const { storageProvider, storageProviderSetter, wikiFolderName, wikiPort } = form;
useEffect(() => {
if (!isCreateSyncedWorkspace && storageProvider !== SupportedStorageServices.local) {
storageProviderSetter(SupportedStorageServices.local);
}
}, [isCreateSyncedWorkspace, storageProvider, storageProviderSetter]);
// const [onClickLogin] = useAuth(storageService);
const formProps = {
form: form,
isCreateMainWorkspace: isCreateMainWorkspace,
errorInWhichComponent: errorInWhichComponent,
errorInWhichComponentSetter: errorInWhichComponentSetter,
};
if (workspaceList === undefined) {
return <Container>{t('Loading')}</Container>;
}
return (
<TabContext value={currentTab}>
<div id="test" data-usage="For spectron automating testing" />
<Helmet>
<title>
{t('AddWorkspace.AddWorkspace')} {wikiFolderName}
</title>
</Helmet>
<AppBar position="static">
<Paper square>
<TabList
onChange={(_event, newValue) => currentTabSetter(newValue as CreateWorkspaceTabs)}
variant="scrollable"
value={currentTab}
aria-label={t('AddWorkspace.SwitchCreateNewOrOpenExisted')}>
<Tab label={t('AddWorkspace.CreateNewWiki')} value={CreateWorkspaceTabs.CreateNewWiki} />
<Tab label={t(`AddWorkspace.CloneOnlineWiki`)} value={CreateWorkspaceTabs.CloneOnlineWiki} />
<Tab label={t('AddWorkspace.OpenLocalWiki')} value={CreateWorkspaceTabs.OpenLocalWiki} />
</TabList>
</Paper>
</AppBar>
{/* show advanced options if user have already created a workspace */}
<Accordion defaultExpanded={workspaceList.length > 0}>
<AdvancedSettingsAccordionSummary expandIcon={<ExpandMoreIcon />}>{t('AddWorkspace.Advanced')}</AdvancedSettingsAccordionSummary>
<AccordionDetails>
<SyncedWikiDescription isCreateSyncedWorkspace={isCreateSyncedWorkspace} isCreateSyncedWorkspaceSetter={isCreateSyncedWorkspaceSetter} />
<MainSubWikiDescription isCreateMainWorkspace={isCreateMainWorkspace} isCreateMainWorkspaceSetter={isCreateMainWorkspaceSetter} />
{isCreateMainWorkspace && (
<LocationPickerContainer>
<LocationPickerInput
error={errorInWhichComponent.wikiPort}
onChange={(event) => {
form.wikiPortSetter(Number(event.target.value));
}}
label={t('AddWorkspace.WikiServerPort')}
value={wikiPort}
/>
</LocationPickerContainer>
)}
</AccordionDetails>
</Accordion>
{isCreateSyncedWorkspace && (
<TokenFormContainer>
<TokenForm storageProvider={storageProvider} storageProviderSetter={storageProviderSetter} />
</TokenFormContainer>
)}
{storageProvider !== SupportedStorageServices.local && <GitRepoUrlForm error={errorInWhichComponent.gitRepoUrl} {...formProps} {...formProps.form} />}
<TabPanel value={CreateWorkspaceTabs.CreateNewWiki}>
<Container>
<NewWikiForm {...formProps} isCreateSyncedWorkspace={isCreateSyncedWorkspace} />
<NewWikiDoneButton {...formProps} isCreateSyncedWorkspace={isCreateSyncedWorkspace} />
</Container>
</TabPanel>
<TabPanel value={CreateWorkspaceTabs.CloneOnlineWiki}>
<Container>
<CloneWikiForm {...formProps} isCreateSyncedWorkspaceSetter={isCreateSyncedWorkspaceSetter} />
<CloneWikiDoneButton {...formProps} />
</Container>
</TabPanel>
<TabPanel value={CreateWorkspaceTabs.OpenLocalWiki}>
<Container>
<ExistedWikiForm {...formProps} isCreateSyncedWorkspace={isCreateSyncedWorkspace} />
<ExistedWikiDoneButton {...formProps} isCreateSyncedWorkspace={isCreateSyncedWorkspace} />
</Container>
</TabPanel>
</TabContext>
);
}