-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(front): add tab position config
- Loading branch information
1 parent
9d93c0b
commit bd70b06
Showing
9 changed files
with
128 additions
and
21 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
gui/frontend/src/components/organisms/TabPositionList/TabPositionList.tsx
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,26 @@ | ||
import { useTranslation } from '@/components/hooks/useTranslation'; | ||
import { SelectWithLabel } from '@/components/molecules/SelectWithLabel'; | ||
import { useTabContext } from '@/components/providers/TabProvider'; | ||
|
||
import type { SelectChangeEvent } from '@mui/material/Select/Select'; | ||
|
||
export const TabPositionList = () => { | ||
const { t } = useTranslation(); | ||
const { tabPos, setTabPos } = useTabContext(); | ||
|
||
const handleChange = ({ target }: SelectChangeEvent) => setTabPos(target.value); | ||
|
||
const menuItems = [ | ||
{ value: 'top', label: t('tab-list-position-top') }, | ||
{ value: 'bottom', label: t('tab-list-position-bottom') }, | ||
] as const; | ||
|
||
return ( | ||
<SelectWithLabel | ||
label={t('tab-list-position-label')} | ||
menuItems={menuItems} | ||
onChange={handleChange} | ||
value={tabPos} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
gui/frontend/src/components/organisms/TabPositionList/index.tsx
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 @@ | ||
export { TabPositionList } from './TabPositionList'; |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { type ReactNode, createContext, useContext, useState } from 'react'; | ||
|
||
import { STORAGE } from '@/lib/storage'; | ||
import { PUB_CACHE_OBJ } from '@/lib/storage/cacheKeys'; | ||
|
||
type TabPosition = 'top' | 'bottom'; | ||
type ContextType = { | ||
tabPos: TabPosition; | ||
setTabPos: (value?: string) => void; | ||
}; | ||
const Context = createContext<ContextType | undefined>(undefined); | ||
|
||
const normalize = (value: string | null) => (value === 'bottom' ? 'bottom' : 'top'); | ||
|
||
type Props = { children: ReactNode }; | ||
export const TabProvider = ({ children }: Props) => { | ||
const [tabPos, setTabPos] = useState<TabPosition>(normalize(STORAGE.get(PUB_CACHE_OBJ.settingsTabPosition))); | ||
|
||
const setHook = (value?: string) => { | ||
if (value) { | ||
const validValue = normalize(value); | ||
setTabPos(validValue); | ||
STORAGE.set(PUB_CACHE_OBJ.settingsTabPosition, validValue); | ||
} else { | ||
STORAGE.remove(PUB_CACHE_OBJ.settingsTabPosition); | ||
} | ||
}; | ||
|
||
return <Context.Provider value={{ tabPos, setTabPos: setHook }}>{children}</Context.Provider>; | ||
}; | ||
|
||
/** | ||
* @throws `useTabContext must be used within a TabProvider` | ||
*/ | ||
export const useTabContext = () => { | ||
const context = useContext(Context); | ||
if (!context) { | ||
throw new Error('useJsContext must be used within a TabProvider'); | ||
} | ||
return context; | ||
}; |
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
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