-
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.
Merge branch 'main' of github.com:ShakedZrihen/specter-ui-kit into fe…
…at-create-post-with-medias
- Loading branch information
Showing
11 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
27 changes: 27 additions & 0 deletions
27
src/components/base/TranslationButton/TranslationButton.story.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,27 @@ | ||
import React from 'react'; | ||
import { SpecterTheme } from '../../../context/theme/SpecterTheme'; | ||
import { TranslationButton } from './TranslationButton'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta: Meta<typeof TranslationButton> = { | ||
title: 'components/base/TranslationButton', | ||
component: TranslationButton, | ||
argTypes: { | ||
onLanguageChange: { action: 'languageChange' }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof TranslationButton>; | ||
|
||
export const Basic: Story = { | ||
render: (props) => ( | ||
<SpecterTheme> | ||
<TranslationButton {...props} /> | ||
</SpecterTheme> | ||
), | ||
args: { | ||
onLanguageChange: (language) => console.log(`Language changed to: ${language}`), | ||
supportedLanguages: ['en', 'ar', 'he'], | ||
}, | ||
}; |
22 changes: 22 additions & 0 deletions
22
src/components/base/TranslationButton/TranslationButton.style.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,22 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import Button from '@mui/material/Button'; | ||
import TranslateIcon from '@mui/icons-material/Translate'; | ||
|
||
|
||
const StyledTranslationButton = styled(Button)(({ theme }) => ({ | ||
backgroundColor: theme.colorPalette.secondaryColor.color, | ||
color: 'white', | ||
'&:hover': { | ||
backgroundColor: theme.colorPalette.primaryColor.color, | ||
}, | ||
minWidth: 'auto', | ||
padding: '8px', | ||
borderRadius: '4px', | ||
})); | ||
|
||
|
||
const StyledTranslateIcon = styled(TranslateIcon)(() => ({ | ||
color: 'inherit', | ||
})); | ||
|
||
export { StyledTranslationButton, StyledTranslateIcon }; |
63 changes: 63 additions & 0 deletions
63
src/components/base/TranslationButton/TranslationButton.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,63 @@ | ||
import React, { useState } from 'react'; | ||
import { StyledTranslationButton, StyledTranslateIcon } from './TranslationButton.style'; | ||
import Menu from '@mui/material/Menu'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
|
||
export interface TranslationButtonProps { | ||
onLanguageChange: (language: string) => void; | ||
supportedLanguages: string[]; | ||
} | ||
|
||
const languageLabels: Record<string, string> = { | ||
en: 'English', | ||
ar: 'Arabic', | ||
he: 'Hebrew', | ||
}; | ||
|
||
export function TranslationButton({ onLanguageChange, supportedLanguages = [] }: TranslationButtonProps) { | ||
const [open, setOpen] = useState(false); | ||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
setOpen(true); | ||
}; | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
setAnchorEl(null); | ||
}; | ||
|
||
const handleLanguageChange = (language: string) => { | ||
onLanguageChange(language); | ||
handleClose(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<StyledTranslationButton | ||
aria-controls={open ? 'language-menu' : undefined} | ||
aria-haspopup="true" | ||
onClick={handleClick} | ||
> | ||
<StyledTranslateIcon /> | ||
</StyledTranslationButton> | ||
<Menu | ||
id="language-menu" | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
> | ||
{supportedLanguages.length > 0 ? ( | ||
supportedLanguages.map((language) => ( | ||
<MenuItem key={language} onClick={() => handleLanguageChange(language)}> | ||
{languageLabels[language] || language.toUpperCase()} | ||
</MenuItem> | ||
)) | ||
) : ( | ||
<MenuItem>שפות אינן זמינות</MenuItem> | ||
)} | ||
</Menu> | ||
</> | ||
); | ||
} |
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,2 @@ | ||
export { TranslationButton } from './TranslationButton'; | ||
|
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