123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import {Children, useState} from 'react';
- import styled from '@emotion/styled';
- import {IconAdd, IconSubtract} from 'sentry/icons';
- type Props = {
- children: React.ReactNode;
- highUp: boolean;
- wrapClassName: string;
- };
- function Toggle({highUp, wrapClassName, children}: Props) {
- const [isExpanded, setIsExpanded] = useState(false);
- if (Children.count(children) === 0) {
- return null;
- }
- const wrappedChildren = <span className={wrapClassName}>{children}</span>;
- if (highUp) {
- return wrappedChildren;
- }
- return (
- <span>
- <IconWrapper
- isExpanded={isExpanded}
- onClick={evt => {
- setIsExpanded(!isExpanded);
- evt.preventDefault();
- }}
- >
- {isExpanded ? (
- <IconSubtract size="9px" color="white" />
- ) : (
- <IconAdd size="9px" color="white" />
- )}
- </IconWrapper>
- {isExpanded && wrappedChildren}
- </span>
- );
- }
- export default Toggle;
- const IconWrapper = styled('div')<{isExpanded: boolean}>`
- border-radius: 2px;
- display: inline-flex;
- align-items: center;
- justify-content: center;
- cursor: pointer;
- ${p =>
- p.isExpanded
- ? `
- background: ${p.theme.gray300};
- border: 1px solid ${p.theme.gray300};
- &:hover {
- background: ${p.theme.gray400};
- }
- `
- : `
- background: ${p.theme.blue300};
- border: 1px solid ${p.theme.blue300};
- &:hover {
- background: ${p.theme.blue200};
- }
- `}
- `;
|