123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import React from "react";
- import styled from "styled-components";
- const Dropdown = styled.div`
- width: 100%;
- margin-bottom: 5px;
- position: relative;
- display: inline-block;
- `
- const DropdownButton = styled.div`
- text-align: center;
- padding: 4px;
- background-color: #555;
- color: #fff;
- font-weight: 600;
- cursor: pointer;
- ${Dropdown}:hover & {
- background-color: #333;
- }
- `
- const DropdownList = styled.div`
- display: none;
- position: absolute;
- background-color: #333;
- width: 100%;
- z-index: 1;
- ${Dropdown}:hover & {
- display: block;
- }
- `
- const DropdownItem = styled.div`
- padding: 12px 16px;
- display: block;
- cursor: pointer;
- &:hover {
- background-color: #555;
- }
- `
- export default ({
- options,
- onChange,
- children,
- }) => (
- <Dropdown>
- <DropdownButton>
- {children}
- </DropdownButton>
- <DropdownList>
- {
- Object.entries(options).map(([text, option]) => (
- <DropdownItem key={option} onClick={() => onChange(option)}>{text}</DropdownItem>
- ))
- }
- </DropdownList>
- </Dropdown>
- );
|