Musical keyboard component written in React.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

StyledAccidentalKey.tsx 7.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import * as React from 'react'
  2. import * as PropTypes from 'prop-types'
  3. import keyPropTypes from '../../services/keyPropTypes'
  4. const DEFAULT_COLOR = '#35313b'
  5. const LIGHT_COLOR = 'white'
  6. type Props = PropTypes.InferProps<typeof keyPropTypes>
  7. const StyledAccidentalKey: React.FC<Props> = ({ keyChannels }) => {
  8. const hasKeyChannels = Array.isArray(keyChannels!) && keyChannels.length > 0
  9. return (
  10. <div
  11. style={{
  12. width: '100%',
  13. height: '100%',
  14. position: 'relative',
  15. // @ts-ignore
  16. '--color-accidental-key': hasKeyChannels ? `var(--color-channel-${keyChannels![0]!.channel})` : undefined,
  17. }}
  18. >
  19. <div
  20. style={{
  21. width: '100%',
  22. height: '100%',
  23. position: 'absolute',
  24. top: 0,
  25. left: 0,
  26. borderRadius: 'calc(1px * var(--size-scale-factor, 1))',
  27. boxShadow: '0 0 0 calc(1px * var(--size-scale-factor, 1)) rgba(0, 0, 0, 0.25)',
  28. }}
  29. />
  30. <div
  31. style={{
  32. width: '100%',
  33. height: '100%',
  34. backgroundColor: 'black',
  35. position: 'absolute',
  36. top: 0,
  37. left: 0,
  38. borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))',
  39. }}
  40. />
  41. <div
  42. style={{
  43. width: '100%',
  44. height: 'calc(6 / 50 * 100%)',
  45. padding: '0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))',
  46. boxSizing: 'border-box',
  47. position: 'absolute',
  48. bottom: 0,
  49. left: 0,
  50. }}
  51. >
  52. <div
  53. style={{
  54. width: '100%',
  55. height: '100%',
  56. borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))',
  57. backgroundColor: `var(--color-accidental-key, ${DEFAULT_COLOR})`,
  58. maskImage: 'linear-gradient(to bottom, white, rgba(0, 0, 0, 0.9))',
  59. WebkitMaskImage: 'linear-gradient(to bottom, white, rgba(0, 0, 0, 0.9))',
  60. opacity: hasKeyChannels ? 0.75 : '1',
  61. }}
  62. />
  63. </div>
  64. <div
  65. style={{
  66. width: '100%',
  67. height: 'calc(44 / 50 * 100%)',
  68. padding: 'calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) 0',
  69. boxSizing: 'border-box',
  70. position: 'absolute',
  71. top: 0,
  72. left: 0,
  73. }}
  74. >
  75. <div
  76. style={{
  77. width: '100%',
  78. height: '100%',
  79. backgroundColor: `var(--color-accidental-key, ${DEFAULT_COLOR})`,
  80. opacity: hasKeyChannels ? 0.75 : '1',
  81. }}
  82. />
  83. </div>
  84. <div
  85. style={{
  86. width: '100%',
  87. height: 'calc(4px * var(--size-scale-factor, 1))',
  88. padding: 'calc(1px * var(--size-scale-factor, 1)) 0 0 0',
  89. boxSizing: 'border-box',
  90. position: 'absolute',
  91. top: 0,
  92. left: 0,
  93. }}
  94. >
  95. <div
  96. style={{
  97. width: '100%',
  98. height: '100%',
  99. backgroundColor: 'black',
  100. opacity: '0.12',
  101. }}
  102. />
  103. </div>
  104. <div
  105. style={{
  106. width: 'calc(2px * var(--size-scale-factor, 1))',
  107. height: 'calc(10 / 52 * 100%)',
  108. padding: '0 calc(1px * var(--size-scale-factor, 1)) 0 0',
  109. boxSizing: 'border-box',
  110. position: 'absolute',
  111. top: 0,
  112. right: 0,
  113. opacity: hasKeyChannels ? 0.5 : '1',
  114. }}
  115. >
  116. <div
  117. style={{
  118. width: '100%',
  119. height: '100%',
  120. backgroundColor: LIGHT_COLOR,
  121. maskImage: 'linear-gradient(to bottom, transparent, white)',
  122. WebkitMaskImage: 'linear-gradient(to bottom, transparent, white)',
  123. opacity: '0.4',
  124. }}
  125. />
  126. </div>
  127. <div
  128. style={{
  129. width: 'calc(2px * var(--size-scale-factor, 1))',
  130. height: hasKeyChannels ? 'calc(38 / 52 * 100%)' : 'calc(34 / 52 * 100%)',
  131. boxSizing: 'border-box',
  132. position: 'absolute',
  133. bottom: hasKeyChannels ? 'calc(4 / 52 * 100%)' : 'calc(8 / 52 * 100%)',
  134. right: 0,
  135. paddingRight: 'calc(1px * var(--size-scale-factor, 1))',
  136. paddingLeft: 0,
  137. opacity: hasKeyChannels ? 0.5 : '1',
  138. }}
  139. >
  140. <div
  141. style={{
  142. width: '100%',
  143. height: '100%',
  144. backgroundColor: LIGHT_COLOR,
  145. opacity: '0.4',
  146. borderBottomRightRadius: 'calc(1px * var(--size-scale-factor, 1))',
  147. }}
  148. />
  149. </div>
  150. <div
  151. style={{
  152. width: '100%',
  153. height: hasKeyChannels ? 'calc(2 / 52 * 100%)' : 'calc(6 / 52 * 100%)',
  154. padding:
  155. '0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))',
  156. boxSizing: 'border-box',
  157. position: 'absolute',
  158. bottom: 0,
  159. left: 0,
  160. opacity: hasKeyChannels ? 3 : '4',
  161. }}
  162. >
  163. <div
  164. style={{
  165. width: '100%',
  166. height: '100%',
  167. backgroundColor: LIGHT_COLOR,
  168. borderRadius:
  169. 'calc(4px * var(--size-scale-factor, 1)) calc(4px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))',
  170. opacity: '0.12',
  171. }}
  172. />
  173. </div>
  174. <div
  175. style={{
  176. width: '100%',
  177. height: hasKeyChannels ? 'calc(42 / 52 * 100%)' : 'calc(38 / 52 * 100%)',
  178. padding: '0 calc(3px * var(--size-scale-factor, 1)) 0 calc(3px * var(--size-scale-factor, 1))',
  179. boxSizing: 'border-box',
  180. position: 'absolute',
  181. top: 'calc(3px * var(--size-scale-factor, 1))',
  182. left: 0,
  183. }}
  184. >
  185. <div
  186. style={{
  187. width: '100%',
  188. height: '100%',
  189. backgroundColor: LIGHT_COLOR,
  190. maskImage: 'linear-gradient(to bottom, transparent, white)',
  191. WebkitMaskImage: 'linear-gradient(to bottom, transparent, white)',
  192. borderRadius: 99999,
  193. opacity: hasKeyChannels ? 0.06 : '0.12',
  194. }}
  195. />
  196. </div>
  197. <div
  198. style={{
  199. width: '100%',
  200. paddingTop: 0,
  201. paddingRight: 'calc(1px * var(--size-scale-factor, 1))',
  202. paddingLeft: 'calc(2px * var(--size-scale-factor, 1))',
  203. boxSizing: 'border-box',
  204. position: 'absolute',
  205. bottom: hasKeyChannels ? 'calc(4 / 52 * 100%)' : 'calc(8 / 52 * 100%)',
  206. left: 0,
  207. height: 'calc(1px * var(--size-scale-factor, 1))',
  208. opacity: hasKeyChannels ? 0.5 : '1',
  209. }}
  210. >
  211. <div
  212. style={{
  213. width: '100%',
  214. height: '100%',
  215. backgroundColor: LIGHT_COLOR,
  216. borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))',
  217. opacity: '0.4',
  218. }}
  219. />
  220. </div>
  221. </div>
  222. )
  223. }
  224. StyledAccidentalKey.propTypes = keyPropTypes
  225. export default StyledAccidentalKey