Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | import React, { FC } from "react"; import styled from "styled-components"; import { InstrumentSelect } from "components/music/form/InstrumentSelect"; import { StyledButton } from "ui/buttons/style"; import { selectMenuStyleProps } from "ui/form/Select"; import { SelectButton, SelectButtonRenderButtonProps, } from "ui/form/SelectButton"; interface InstrumentSelectProps { name: string; value?: number; previewNoteOnChange: boolean; onChange?: (newId: number) => void; } const Wrapper = styled.div` position: relative; `; const LabelWrapper = styled.div` width: 20px; height: 20px; border-radius: 4px; background: ${(props) => props.theme.colors.input.background}; border: 2px solid ${(props) => props.theme.colors.input.background}; outline: 1px solid ${(props) => props.theme.colors.input.border}; `; interface LabelColorProps { $instrument?: number; } const LabelColor = styled.div<LabelColorProps>` position: relative; display: flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 2px; flex-shrink: 0; font-size: 10px; border: 1px solid black; background: ${(props) => props.$instrument !== undefined ? `var(--instrument-${props.$instrument}-color)` : "black"}; &::before { content: ""; position: absolute; bottom: 0px; left: 0px; right: 0px; height: 2px; background: rgba(0, 0, 0, 0.25); } &::after { content: ""; position: absolute; top: 1px; left: 1px; right: 1px; height: 2px; background: rgba(255, 255, 255, 0.6); mix-blend-mode: overlay; } color: ${(props) => props.$instrument !== undefined ? `var(--instrument-${props.$instrument}-text-color)` : "white"}; `; const TriggerButton = React.forwardRef< HTMLButtonElement, Omit<SelectButtonRenderButtonProps, "ref"> & { name: string; value?: number; } >(({ name, value, ...props }, ref) => { return ( <StyledButton id={name} $variant="transparent" ref={ref} {...props}> <LabelWrapper> <LabelColor $instrument={value}> {String((value ?? 0) + 1).padStart(2, "0")} </LabelColor> </LabelWrapper> </StyledButton> ); }); export const InstrumentSelectButton: FC<InstrumentSelectProps> = ({ name, value, previewNoteOnChange, onChange, }) => { return ( <Wrapper> <SelectButton pin="top-left" offsetTop="100%" offsetLeft="0%" renderButton={(buttonProps) => ( <TriggerButton {...buttonProps} name={name} value={value} /> )} renderMenu={({ closeMenu }) => ( <InstrumentSelect name={name} value={value} onChange={(newValue) => { closeMenu(); onChange?.(newValue); }} onBlur={closeMenu} previewNoteOnChange={previewNoteOnChange} {...selectMenuStyleProps} /> )} /> </Wrapper> ); }; |