2021-02-06 10:38:30 +09:00
|
|
|
import React from "react";
|
|
|
|
import Popper from "popper.js";
|
2021-02-06 14:05:36 +09:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import Link from 'next/link';
|
2021-02-06 10:38:30 +09:00
|
|
|
|
|
|
|
const Dropdown = ({ color }) => {
|
2021-02-06 14:05:36 +09:00
|
|
|
const router = useRouter()
|
|
|
|
const { locale, locales, defaultLocale, pathname } = router
|
|
|
|
|
2021-02-06 10:38:30 +09:00
|
|
|
// dropdown props
|
|
|
|
const [dropdownPopoverShow, setDropdownPopoverShow] = React.useState(false);
|
|
|
|
const btnDropdownRef = React.createRef();
|
|
|
|
const popoverDropdownRef = React.createRef();
|
|
|
|
const openDropdownPopover = () => {
|
|
|
|
new Popper(btnDropdownRef.current, popoverDropdownRef.current, {
|
|
|
|
placement: "bottom-start"
|
|
|
|
});
|
|
|
|
setDropdownPopoverShow(true);
|
|
|
|
};
|
|
|
|
const closeDropdownPopover = () => {
|
|
|
|
setDropdownPopoverShow(false);
|
|
|
|
};
|
|
|
|
// bg colors
|
|
|
|
let bgColor;
|
|
|
|
color === "white"
|
|
|
|
? (bgColor = "bg-gray-800")
|
|
|
|
: (bgColor = "bg-" + color + "-500");
|
|
|
|
return (
|
|
|
|
<>
|
2021-02-06 15:13:53 +09:00
|
|
|
|
2021-05-26 07:53:02 +09:00
|
|
|
<div className="text-left mr-2 ml-2 my-3 float-right">
|
2021-02-06 15:13:53 +09:00
|
|
|
<button type="button" className="inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500" id="options-menu" aria-haspopup="true" aria-expanded="true"
|
|
|
|
style={{ transition: "all .15s ease" }}
|
|
|
|
ref={btnDropdownRef}
|
|
|
|
onClick={() => {
|
|
|
|
dropdownPopoverShow
|
|
|
|
? closeDropdownPopover()
|
|
|
|
: openDropdownPopover();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
言語 / Languages
|
|
|
|
<svg className="-mr-1 ml-2 h-5 w-3" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
2021-02-07 11:28:57 +09:00
|
|
|
<path fillRule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clipRule="evenodd" />
|
2021-02-06 15:13:53 +09:00
|
|
|
</svg>
|
2021-05-21 18:36:19 +09:00
|
|
|
</button>
|
2021-02-06 15:13:53 +09:00
|
|
|
<div ref={popoverDropdownRef} className={
|
2021-05-24 12:08:23 +09:00
|
|
|
(dropdownPopoverShow ? "block " : "hidden ") + "z-10 origin-top-right absolute right-0 mt-2 w-40 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5"}>
|
2021-02-06 15:13:53 +09:00
|
|
|
<div className="py-1" role="menu" aria-orientation="vertical" aria-labelledby="options-menu">
|
2021-03-08 13:40:37 +09:00
|
|
|
<Link href="#" locale="ja">
|
2021-02-06 15:13:53 +09:00
|
|
|
<a href="#" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">日本語</a>
|
|
|
|
</Link>
|
2021-03-08 13:40:37 +09:00
|
|
|
<Link href="#" locale="en">
|
2021-02-06 15:13:53 +09:00
|
|
|
<a href="#" className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">English</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-06 10:38:30 +09:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function LangSelector() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Dropdown color="white" />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|