Skip to content

Commit 63a02f4

Browse files
authored
Merge pull request #58 from codeacme17/feat
feat(LFO): upload related files
2 parents 4524804 + 814a025 commit 63a02f4

8 files changed

Lines changed: 92 additions & 0 deletions

File tree

example/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { UncontrolledSlider } from './components/controls/UncontrolledSlider'
1919
import { EchoOsci } from './components/visualizaion/EchoOsci'
2020
import { EchoEnvelopADSR, EchoEnvelopAHDSR } from './components/controls/EchoEnvelop'
2121
import { EchoWaveform } from './components/visualizaion/EchoWaveform'
22+
import { EchoLFO } from './components/visualizaion/EchoLFO'
2223

2324
function App() {
2425
const { theme, setTheme } = useTheme()
@@ -44,6 +45,8 @@ function App() {
4445

4546
<EchoWaveform />
4647

48+
<EchoLFO />
49+
4750
<EchoEnvelopADSR />
4851

4952
<EchoEnvelopAHDSR />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { LFO } from '@echo-ui'
2+
3+
export const EchoLFO = () => {
4+
return (
5+
<section className="h-32">
6+
<LFO />
7+
</section>
8+
)
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { forwardRef, useImperativeHandle, useRef } from 'react'
2+
import { useResizeObserver } from '../../../lib/hooks/useResizeObserver'
3+
import { cn } from '../../../lib/utils'
4+
import { LFOProps, LFORef } from './types'
5+
import { useStyle } from './styles'
6+
import { WIDTH, HEIGHT, LINE_WIDTH, LINE_COLOR } from './constants'
7+
8+
export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
9+
const { lineWidth = LINE_WIDTH, lineColor = LINE_COLOR, ...restProps } = props
10+
11+
const LFORef = useRef<LFORef | null>(null)
12+
13+
useImperativeHandle(ref, () => LFORef.current as LFORef)
14+
15+
const dementions = useResizeObserver(LFORef, WIDTH, HEIGHT, () => {})
16+
17+
console.log(dementions)
18+
19+
const { base, svg } = useStyle()
20+
21+
return (
22+
<div
23+
ref={LFORef}
24+
className={cn(base(), restProps.className)}
25+
style={{
26+
...restProps.style,
27+
padding: 0,
28+
overflow: 'hidden',
29+
pointerEvents: 'none',
30+
userSelect: 'none',
31+
}}
32+
>
33+
<svg className={cn(svg())} />
34+
</div>
35+
)
36+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const WIDTH = 360
2+
export const HEIGHT = 100
3+
4+
export const LINE_COLOR = 'var(--echo-primary)'
5+
export const LINE_WIDTH = 2
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { LFO as _LFO } from './LFO'
2+
import { LFOProps, LFORef } from './types'
3+
4+
type CompoundedComponent = React.ForwardRefExoticComponent<LFOProps & React.RefAttributes<LFORef>>
5+
6+
const LFO = _LFO as CompoundedComponent
7+
LFO.displayName = 'EchoUI.LFO'
8+
9+
export { LFO }
10+
export default LFO
11+
export type { LFOProps, LFORef } from './types'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { tv } from 'tailwind-variants'
2+
3+
export const useStyle = tv({
4+
slots: {
5+
base: `text-foreground
6+
h-full
7+
w-full
8+
flex
9+
justify-center
10+
rounded-lg
11+
bg-card`,
12+
13+
svg: `w-full
14+
h-full
15+
flex
16+
items-center`,
17+
},
18+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface LFOProps extends React.HTMLAttributes<HTMLDivElement> {
2+
frequency?: number
3+
amplitude?: number
4+
type?: 'sine' | 'square' | 'triangle'
5+
lineColor?: string
6+
lineWidth?: number
7+
}
8+
9+
export interface LFORef extends HTMLDivElement {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './VuMeter'
22
export * from './Axis'
33
export * from './Light'
4+
export * from './LFO'
45
export * from './Spectrogram'
56
export * from './Oscilloscope'
67
export * from './Waveform'

0 commit comments

Comments
 (0)