SelectRow.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from "react";
  2. import styled from "styled-components";
  3. import Selector, { type SelectorPropsType } from "../Selector";
  4. type PropsType<T> = {
  5. label: string;
  6. value: T;
  7. setActiveValue: (x: T) => void;
  8. options: Array<{ value: T; label: string }>;
  9. displayFlex?: boolean;
  10. dropdownLabel?: string;
  11. width?: string;
  12. dropdownMaxHeight?: string;
  13. scrollBuffer?: boolean;
  14. doc?: string;
  15. disabled?: boolean;
  16. selectorProps?: Partial<SelectorPropsType<T>>;
  17. isLoading?: boolean;
  18. };
  19. export default function SelectRow<T>(props: PropsType<T>) {
  20. return (
  21. <StyledSelectRow displayFlex={props.displayFlex}>
  22. <Wrapper>
  23. <Label displayFlex={props.displayFlex}>{props.label}</Label>
  24. {props.doc ? (
  25. <a href={props.doc} target="_blank" rel="noreferrer">
  26. <i className="material-icons">help_outline</i>
  27. </a>
  28. ) : null}
  29. </Wrapper>
  30. <SelectWrapper>
  31. <Selector
  32. disabled={props.disabled}
  33. scrollBuffer={props.scrollBuffer}
  34. activeValue={props.value}
  35. setActiveValue={props.setActiveValue}
  36. options={props.options}
  37. dropdownLabel={props.dropdownLabel}
  38. width={props.width || "270px"}
  39. dropdownWidth={props.width}
  40. dropdownMaxHeight={props.dropdownMaxHeight}
  41. isLoading={props.isLoading}
  42. {...(props.selectorProps || {})}
  43. />
  44. </SelectWrapper>
  45. </StyledSelectRow>
  46. );
  47. }
  48. const SelectWrapper = styled.div``;
  49. const Wrapper = styled.div`
  50. display: flex;
  51. align-items; center;
  52. > a {
  53. > i {
  54. font-size: 18px;
  55. margin-left: 8px;
  56. margin-top: 2px;
  57. color: #8590ff;
  58. :hover {
  59. color: #aaaabb;
  60. }
  61. }
  62. }
  63. `;
  64. const Label = styled.div<{ displayFlex?: boolean }>`
  65. color: #ffffff;
  66. font-size: 13px;
  67. margin-bottom: 10px;
  68. margin-top: ${(props) => (props.displayFlex ? "10px" : 0)};
  69. margin-right: ${(props) => (props.displayFlex ? "10px" : 0)};
  70. `;
  71. const StyledSelectRow = styled.div<{ displayFlex?: boolean }>`
  72. display: ${(props) => (props.displayFlex ? "flex" : "block")};
  73. `;