-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve tolgee library UI TG-300
- Loading branch information
Showing
21 changed files
with
202 additions
and
218 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
This file was deleted.
Oops, something went wrong.
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,118 @@ | ||
import * as React from 'react'; | ||
import { TranslationService } from '@tolgee/core/lib/services/TranslationService'; | ||
import { Menu, MenuItem } from '@mui/material'; | ||
|
||
import { StylesContextProvider } from '../common/styles/StylesContextProvider'; | ||
import { ThemeProvider } from '../ThemeProvider'; | ||
import { DEVTOOLS_ID, DEVTOOLS_Z_INDEX } from '../constants'; | ||
import styled from '@emotion/styled'; | ||
|
||
const SCMenuItem = styled(MenuItem)` | ||
display: flex; | ||
flex-direction: column; | ||
height: 50px; | ||
justify-content: center; | ||
`; | ||
|
||
const SCTranslation = styled.div` | ||
display: flex; | ||
padding: 3px; | ||
`; | ||
|
||
const SCKey = styled.div` | ||
display: flex; | ||
margin-top: 10px; | ||
padding: 3px; | ||
font-weight: bold; | ||
font-size: 12px; | ||
font-family: Monospace, 'Courier New', Courier; | ||
`; | ||
|
||
export interface KeyContextMenuParams { | ||
openEvent: MouseEvent; | ||
keys: Set<string>; | ||
onSelect: (key) => void; | ||
} | ||
|
||
export type KeyContextMenuState = Partial<KeyContextMenuParams> & { | ||
opened: boolean; | ||
}; | ||
|
||
export type ComponentDependencies = { | ||
translationService: TranslationService; | ||
}; | ||
|
||
export type KeyContextMenuProps = { | ||
dependencies: ComponentDependencies; | ||
}; | ||
|
||
export class KeyContextMenu extends React.Component<KeyContextMenuProps> { | ||
constructor(props: KeyContextMenuProps) { | ||
super(props); | ||
} | ||
|
||
state: KeyContextMenuState & { opened: boolean } = { | ||
opened: false, | ||
}; | ||
|
||
async show(params: KeyContextMenuParams) { | ||
this.setState({ ...params, opened: true }); | ||
} | ||
|
||
keyDown = (e) => { | ||
if (e.key === 'Escape') { | ||
this.setState((s) => ({ ...s, opened: false })); | ||
this.state.onSelect && this.state.onSelect(null); | ||
} | ||
}; | ||
|
||
componentDidMount() { | ||
document.addEventListener('keydown', this.keyDown); | ||
} | ||
|
||
componentWillUnmount() { | ||
document.removeEventListener('keydown', this.keyDown); | ||
} | ||
|
||
render() { | ||
return ( | ||
<StylesContextProvider> | ||
<ThemeProvider> | ||
{this.state.opened && ( | ||
<Menu | ||
anchorEl={this.state.openEvent.target as Element} | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'center', | ||
}} | ||
open | ||
onClose={() => { | ||
this.setState({ opened: false }); | ||
this.state.onSelect(null); | ||
}} | ||
container={document.getElementById(DEVTOOLS_ID)} | ||
style={{ zIndex: DEVTOOLS_Z_INDEX }} | ||
> | ||
{Array.from(this.state.keys).map((key, index) => ( | ||
<SCMenuItem | ||
onClick={() => { | ||
this.setState({ opened: false }); | ||
this.state.onSelect(key); | ||
}} | ||
key={index} | ||
> | ||
<SCTranslation> | ||
{this.props.dependencies.translationService.getFromCacheOrFallback( | ||
key | ||
)} | ||
</SCTranslation> | ||
<SCKey>{key}</SCKey> | ||
</SCMenuItem> | ||
))} | ||
</Menu> | ||
)} | ||
</ThemeProvider> | ||
</StylesContextProvider> | ||
); | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,35 @@ | ||
import React from 'react'; | ||
import { | ||
ThemeProvider as MuiThemeProvider, | ||
createTheme, | ||
} from '@mui/material/styles'; | ||
|
||
const theme = createTheme({ | ||
typography: { | ||
fontFamily: | ||
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"', | ||
}, | ||
palette: { | ||
primary: { | ||
main: '#822B55', | ||
}, | ||
secondary: { | ||
main: '#2B5582', | ||
}, | ||
text: { | ||
secondary: '#808080', | ||
}, | ||
background: { | ||
default: 'rgb(255, 255, 255)', | ||
}, | ||
}, | ||
mixins: { | ||
toolbar: { | ||
minHeight: 52, | ||
}, | ||
}, | ||
}); | ||
|
||
export const ThemeProvider: React.FC = ({ children }) => { | ||
return <MuiThemeProvider theme={theme}>{children}</MuiThemeProvider>; | ||
}; |
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
Oops, something went wrong.