diff --git a/package.json b/package.json index 7d173c5..f43c395 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,7 @@ "build-storybook": "build-storybook" }, "dependencies": { - "mem": "^6.1.0", - "styled-components": "^5.1.1" + "mem": "^6.1.0" }, "peerDependencies": { "react": ">=16" diff --git a/src/components/AccidentalKey/AccidentalKey.tsx b/src/components/AccidentalKey/AccidentalKey.tsx index 2839094..fc59ca2 100644 --- a/src/components/AccidentalKey/AccidentalKey.tsx +++ b/src/components/AccidentalKey/AccidentalKey.tsx @@ -1,40 +1,36 @@ import * as React from 'react' import * as PropTypes from 'prop-types' -import styled from 'styled-components' import keyPropTypes from '../../services/keyPropTypes' -const Base = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'var(--color-accidental-key, currentColor)', - border: '1px solid', - boxSizing: 'border-box', - position: 'relative', -}) - -const Highlight = styled('div')({ - width: '100%', - height: '100%', - position: 'absolute', - top: 0, - left: 0, - opacity: 0.75, -}) - type Props = PropTypes.InferProps const AccidentalKey: React.FC = ({ keyChannels }) => ( - +
{Array.isArray(keyChannels!) && keyChannels.map((c) => ( - ))} - +
) AccidentalKey.propTypes = keyPropTypes diff --git a/src/components/Keyboard/Keyboard.tsx b/src/components/Keyboard/Keyboard.tsx index c012a9f..b094923 100644 --- a/src/components/Keyboard/Keyboard.tsx +++ b/src/components/Keyboard/Keyboard.tsx @@ -1,28 +1,11 @@ import * as React from 'react' import * as PropTypes from 'prop-types' -import styled from 'styled-components' -import mem from 'mem' import isNaturalKeyUnmemoized from '../../services/isNaturalKey' import getKeyWidthUnmemoized from '../../services/getKeyWidth' import getKeyLeftUnmemoized from '../../services/getKeyLeft' import generateKeys from '../../services/generateKeys' -import * as DefaultAccidentalKey from '../AccidentalKey/AccidentalKey' -import * as DefaultNaturalKey from '../NaturalKey/NaturalKey' - -const Base = styled('div')({ - position: 'relative', - backgroundColor: 'currentColor', - overflow: 'hidden', -}) - -const Key = styled('div')({ - position: 'absolute', - top: 0, -}) - -const getKeyWidth = mem(getKeyWidthUnmemoized, { cacheKey: (args) => args.join(':') }) -const getKeyLeft = mem(getKeyLeftUnmemoized, { cacheKey: (args) => args.join(':') }) -const isNaturalKey = mem(isNaturalKeyUnmemoized) +import DefaultAccidentalKey from '../AccidentalKey/AccidentalKey' +import DefaultNaturalKey from '../NaturalKey/NaturalKey' export const propTypes = { /** @@ -97,47 +80,49 @@ const Keyboard: React.FC = ({ }) => { const [keys, setKeys] = React.useState([]) + const { natural: NaturalKey = DefaultNaturalKey, accidental: AccidentalKey = DefaultAccidentalKey } = keyComponents! + + const getKeyWidth = React.useCallback((k) => getKeyWidthUnmemoized(startKey, endKey)(k), [startKey, endKey]) + const getKeyLeft = React.useCallback((k) => getKeyLeftUnmemoized(startKey, endKey)(k), [startKey, endKey]) + const isNaturalKey = React.useCallback((k) => isNaturalKeyUnmemoized(k), []) + React.useEffect(() => { setKeys(generateKeys(startKey!, endKey!)) }, [startKey, endKey]) - const { - natural: NaturalKey = DefaultNaturalKey.default, - accidental: AccidentalKey = DefaultAccidentalKey.default, - } = keyComponents! - return ( - - {keys.map((k) => { - const isNatural = isNaturalKey(k) + {keys.map((key) => { + const isNatural = isNaturalKey(key) const Component: any = isNatural ? NaturalKey! : AccidentalKey! - - const width = getKeyWidth(startKey!, endKey!)(k) - const height = isNatural ? 100 : 100 * accidentalKeyLengthRatio! - const left = getKeyLeft(startKey!, endKey!)(k) - const currentKeyChannels = Array.isArray(keyChannels!) ? keyChannels.filter((kc) => kc!.key === k) : null + const currentKeyChannels = Array.isArray(keyChannels!) ? keyChannels.filter((kc) => kc!.key === key) : null return ( - - + ) })} - + ) } diff --git a/src/components/NaturalKey/NaturalKey.tsx b/src/components/NaturalKey/NaturalKey.tsx index c018847..b568d6e 100644 --- a/src/components/NaturalKey/NaturalKey.tsx +++ b/src/components/NaturalKey/NaturalKey.tsx @@ -1,40 +1,36 @@ import * as React from 'react' import * as PropTypes from 'prop-types' -import styled from 'styled-components' import keyPropTypes from '../../services/keyPropTypes' -const Base = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'var(--color-natural-key, white)', - border: '1px solid', - boxSizing: 'border-box', - position: 'relative', -}) - -const Highlight = styled('div')({ - width: '100%', - height: '100%', - position: 'absolute', - top: 0, - left: 0, - opacity: 0.75, -}) - type Props = PropTypes.InferProps const NaturalKey: React.FC = ({ keyChannels }) => ( - +
{Array.isArray(keyChannels!) && keyChannels.map((c) => ( - ))} - +
) NaturalKey.propTypes = keyPropTypes diff --git a/src/components/StyledAccidentalKey/StyledAccidentalKey.tsx b/src/components/StyledAccidentalKey/StyledAccidentalKey.tsx index 17e3bfa..62fda53 100644 --- a/src/components/StyledAccidentalKey/StyledAccidentalKey.tsx +++ b/src/components/StyledAccidentalKey/StyledAccidentalKey.tsx @@ -1,246 +1,215 @@ import * as React from 'react' import * as PropTypes from 'prop-types' -import styled from 'styled-components' import keyPropTypes from '../../services/keyPropTypes' const DEFAULT_COLOR = '#35313b' const LIGHT_COLOR = 'white' -const Base = styled('div')({ - width: '100%', - height: '100%', - position: 'relative', -}) - -const B2 = styled('div')({ - width: '100%', - height: '100%', - borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - backgroundColor: `var(--color-accidental-key, ${DEFAULT_COLOR})`, - maskImage: 'linear-gradient(to bottom, white, rgba(0, 0, 0, 0.9))', -}) - -const B3 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: `var(--color-accidental-key, ${DEFAULT_COLOR})`, -}) - -const B4 = styled('div')({ - width: '100%', - height: 'calc(4px * var(--size-scale-factor, 1))', - padding: 'calc(1px * var(--size-scale-factor, 1)) 0 0 0', - boxSizing: 'border-box', - position: 'absolute', - top: 0, - left: 0, -}) - -const B5 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - opacity: '0.12', -}) - -const B6 = styled('div')({ - width: 'calc(2px * var(--size-scale-factor, 1))', - height: 'calc(11px * var(--size-scale-factor, 1))', - padding: - 'calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) 0', - boxSizing: 'border-box', - position: 'absolute', - top: 0, - right: 0, -}) - -const B7 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: LIGHT_COLOR, - maskImage: 'linear-gradient(to bottom, transparent, white)', - opacity: '0.4', -}) - -const B8 = styled('div')({ - width: 'calc(2px * var(--size-scale-factor, 1))', - height: '100%', - padding: - 'calc(10px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) calc(6px * var(--size-scale-factor, 1)) 0', - boxSizing: 'border-box', - position: 'absolute', - top: 0, - right: 0, -}) - -const B9 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: LIGHT_COLOR, - opacity: '0.4', - borderBottomRightRadius: 'calc(1px * var(--size-scale-factor, 1))', -}) - -const B10 = styled('div')({ - width: '100%', - padding: - '0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - bottom: 0, - left: 0, -}) - -const B11 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: LIGHT_COLOR, - borderRadius: - '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))', - opacity: '0.12', -}) - -const B12 = styled('div')({ - width: '100%', - height: '100%', - padding: - 'calc(3px * var(--size-scale-factor, 1)) calc(3px * var(--size-scale-factor, 1)) calc(7px * var(--size-scale-factor, 1)) calc(3px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - top: 0, - left: 0, -}) - -const B13 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: LIGHT_COLOR, - maskImage: 'linear-gradient(to bottom, transparent, white)', - borderRadius: 99999, -}) - -const B14 = styled('div')({ - width: '100%', - height: 'calc(6px * var(--size-scale-factor, 1))', - padding: - '0 calc(1px * var(--size-scale-factor, 1)) calc(5px * var(--size-scale-factor, 1)) calc(2px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - bottom: 0, - left: 0, -}) - -const B15 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: LIGHT_COLOR, - borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - opacity: '0.4', -}) - -const B16 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - position: 'absolute', - top: 0, - left: 0, - borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', -}) - -const B17 = styled('div')({ - width: '100%', - height: 'calc(6 / 50 * 100%)', - padding: '0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - bottom: 0, - left: 0, -}) - -const B18 = styled('div')({ - width: '100%', - height: 'calc(44 / 50 * 100%)', - padding: 'calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1)) 0', - boxSizing: 'border-box', - position: 'absolute', - top: 0, - left: 0, -}) - -const B19 = styled('div')({ - width: '100%', - height: '100%', - position: 'absolute', - top: 0, - left: 0, - borderRadius: 'calc(1px * var(--size-scale-factor, 1))', - boxShadow: '0 0 0 calc(1px * var(--size-scale-factor, 1)) rgba(0, 0, 0, 0.25)', -}) - type Props = PropTypes.InferProps const StyledAccidentalKey: React.FC = ({ keyChannels }) => { const hasKeyChannels = Array.isArray(keyChannels!) && keyChannels.length > 0 return ( - - - - - +
+
+
- - - +
+
- - - - - +
+
+
+
- - - +
+
- - - +
+
- - - - +
+
+
- - +
= ({ keyChannels }) => { opacity: hasKeyChannels ? 0.5 : '1', }} > - - - +
+
+
) } diff --git a/src/components/StyledNaturalKey/StyledNaturalKey.tsx b/src/components/StyledNaturalKey/StyledNaturalKey.tsx index a88c0bf..703775f 100644 --- a/src/components/StyledNaturalKey/StyledNaturalKey.tsx +++ b/src/components/StyledNaturalKey/StyledNaturalKey.tsx @@ -1,210 +1,199 @@ import * as React from 'react' import * as PropTypes from 'prop-types' -import styled from 'styled-components' import keyPropTypes from '../../services/keyPropTypes' const DEFAULT_COLOR = '#e3e3e5' const LIGHT_COLOR = 'white' -const Base = styled('div')({ - width: '100%', - height: '100%', - position: 'relative', -}) - -const N1 = styled('div')({ - width: '100%', - height: '100%', - position: 'relative', -}) - -const N2 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - position: 'absolute', - top: '0', - left: '0', -}) - -const N3 = styled('div')({ - width: '100%', - height: '100%', - padding: - 'calc(1px * var(--size-scale-factor, 1)) 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - top: '0', - left: '0', -}) - -const N4 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: `var(--color-natural-key, ${DEFAULT_COLOR})`, - borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', -}) - -const N5 = styled('div')({ - width: '100%', - height: 'calc(33 / 80 * 100%)', - padding: - '0 calc(1px * var(--size-scale-factor, 1)) calc(2px * var(--size-scale-factor, 1)) calc(2px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - backgroundClip: 'content-box', - position: 'absolute', - bottom: '0', - left: '0', - opacity: '0.25', - maskImage: 'linear-gradient(to bottom, transparent, white)', -}) - -const N6 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - padding: - 'calc(1px * var(--size-scale-factor, 1)) calc(2px * var(--size-scale-factor, 1)) calc(3px * var(--size-scale-factor, 1)) calc(3px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - backgroundClip: 'content-box', - position: 'absolute', - bottom: '0', - left: '0', - opacity: '0.08', - maskImage: 'linear-gradient(to bottom, transparent, white)', -}) - -const N7 = styled('div')({ - width: '100%', - height: 'calc(2px * var(--size-scale-factor, 1))', - padding: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - bottom: '0', - left: '0', -}) - -const N8 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - opacity: '0.25', -}) -const N9 = styled('div')({ - width: 'calc(2px * var(--size-scale-factor, 1))', - height: '100%', - padding: - 'calc(1px * var(--size-scale-factor, 1)) 0 calc(1px * var(--size-scale-factor, 1)) calc(1px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - bottom: '0', - left: '0', -}) -const N10 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - borderRadius: '0 0 0 calc(1px * var(--size-scale-factor, 1))', - opacity: '0.07', -}) -const N11 = styled('div')({ - width: '100%', - height: 'calc(6px * var(--size-scale-factor, 1))', - padding: 'calc(1px * var(--size-scale-factor, 1)) 0 0 calc(1px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - top: '0', - left: '0', -}) -const N12 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - maskImage: 'linear-gradient(to bottom, white, transparent)', - opacity: '0.12', -}) -const N13 = styled('div')({ - width: '100%', - padding: 'calc(1px * var(--size-scale-factor, 1)) 0 0 calc(1px * var(--size-scale-factor, 1))', - boxSizing: 'border-box', - position: 'absolute', - top: '0', - left: '0', -}) -const N14 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: 'black', - opacity: '0.12', -}) -const N15 = styled('div')({ - width: 'calc(1px * var(--size-scale-factor, 1))', - height: '100%', - padding: 'calc(1px * var(--size-scale-factor, 1)) 0 calc(1px * var(--size-scale-factor, 1)) 0', - boxSizing: 'border-box', - position: 'absolute', - bottom: '0', - right: '0', -}) -const N16 = styled('div')({ - width: '100%', - height: '100%', - backgroundColor: LIGHT_COLOR, - borderRadius: '0 0 calc(1px * var(--size-scale-factor, 1)) 0', - opacity: '0.12', -}) - type Props = PropTypes.InferProps const StyledNaturalKey: React.FC = ({ keyChannels }) => { const hasKeyChannels = Array.isArray(keyChannels!) && keyChannels.length > 0 return ( - - - - - - - +
+
+
+
+
+
+
+
+
+
- - - - - - - - - - - +
+
- - - - - - - + /> +
+
+
+
+
+
+
+
) } diff --git a/src/services/getKeyLeft.ts b/src/services/getKeyLeft.ts index d499345..4a7f0ea 100644 --- a/src/services/getKeyLeft.ts +++ b/src/services/getKeyLeft.ts @@ -9,7 +9,7 @@ const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args. const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) const getKeyOctave = mem(getKeyOctaveUnmemoized) -interface GetKeyLeft { +export interface GetKeyLeft { (k: number): number } diff --git a/src/services/getKeyWidth.ts b/src/services/getKeyWidth.ts index 3ef1d38..a4b650a 100644 --- a/src/services/getKeyWidth.ts +++ b/src/services/getKeyWidth.ts @@ -4,7 +4,7 @@ import getOctaveCountUnmemoized from './getOctaveCount' import getFractionalOctaveCountUnmemoized from './getFractionalOctaveCount' import { ACCIDENTAL_KEY_TO_NATURAL_KEY_WIDTH_RATIO } from './constants' -interface GetKeyWidth { +export interface GetKeyWidth { (k: number): number }