-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wolfgangbeer/ch3876/ersetzen der chakra menu component durch (#22)
* chore: update package-lock.json * feat(3876): create menu components and basic story * feat(3876): make menu accessible and fix isDisabled on Link * feat(3876): write menu story in mdx * feat(3876): update description * feat(3876): add example with disabled MenuButton * feat(3876): update story height * chore: adds tailwind config change * feat(3876): change naming to be more explicit Co-authored-by: David Wippel <[email protected]>
- Loading branch information
1 parent
7c6f812
commit 8809c95
Showing
18 changed files
with
2,038 additions
and
1,479 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 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,89 @@ | ||
import React, {FC} from 'react'; | ||
|
||
// icons taken from here: https://heroicons.com/ | ||
// use medium size | ||
|
||
const icons = { | ||
home: ( | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" | ||
/> | ||
), | ||
search: ( | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" | ||
/> | ||
), | ||
add: ( | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M9 13h6m-3-3v6m5 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" | ||
/> | ||
), | ||
download: ( | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" | ||
/> | ||
), | ||
database: ( | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4" | ||
/> | ||
), | ||
'dots-horizontal': ( | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z" | ||
/> | ||
), | ||
}; | ||
|
||
const defaultIcon = ( | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" | ||
/> | ||
); | ||
|
||
export type IconName = keyof typeof icons; | ||
|
||
type Props = { | ||
icon: IconName; | ||
className?: string; | ||
}; | ||
|
||
const Icon: FC<Props> = ({icon, className}: Props) => { | ||
return ( | ||
<svg | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
className={className}> | ||
{icons[icon] || defaultIcon} | ||
</svg> | ||
); | ||
}; | ||
|
||
Icon.defaultProps = { | ||
className: 'w-6 h-6', | ||
}; | ||
|
||
export default Icon; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, {FC, useContext, useCallback, useRef} from 'react'; | ||
import useClickOutside from '../use-click-outside'; | ||
import Button from '../components/button'; | ||
import {ButtonProps} from '../components/types'; | ||
import MenuContext from './menu-context'; | ||
|
||
const MenuButton: FC<ButtonProps> = ({onClick, ...others}: ButtonProps) => { | ||
const ref = useRef<HTMLButtonElement>(null); | ||
const {isOpen, closeMenu, toggleMenu} = useContext(MenuContext); | ||
useClickOutside(ref, closeMenu); | ||
|
||
const handleOnClick = useCallback( | ||
(event: React.MouseEvent<HTMLButtonElement>) => { | ||
if (onClick) onClick(event); | ||
toggleMenu(); | ||
}, | ||
[onClick, closeMenu] | ||
); | ||
|
||
return ( | ||
<Button | ||
ref={ref} | ||
variant="tertiary" | ||
{...others} | ||
onClick={handleOnClick} | ||
aria-expanded={isOpen ? 'true' : 'false'} | ||
/> | ||
); | ||
}; | ||
|
||
export default MenuButton; |
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,18 @@ | ||
/* eslint-disable no-console */ | ||
import {createContext} from 'react'; | ||
|
||
const MenuContext = createContext({ | ||
isOpen: false, | ||
toggleMenu: () => { | ||
console.error( | ||
'MenuContext "toggleMenu" method not initialized correctly' | ||
); | ||
}, | ||
closeMenu: () => { | ||
console.error( | ||
'MenuContext "closeMenu" method not initialized correctly' | ||
); | ||
}, | ||
}); | ||
|
||
export default MenuContext; |
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,5 @@ | ||
import React, {FC} from 'react'; | ||
|
||
const MenuDivider: FC = () => <div className="border-t border-gray-100" />; | ||
|
||
export default MenuDivider; |
Oops, something went wrong.