-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathSelectbox.tsx
More file actions
51 lines (42 loc) · 1.13 KB
/
Selectbox.tsx
File metadata and controls
51 lines (42 loc) · 1.13 KB
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
import React, { useState, useEffect, CSSProperties } from 'react'
export type TSetSelectboxState = React.Dispatch<React.SetStateAction<TSelectboxState>>
export type TSelectboxProps = {
fixedPosition: boolean
className: string
getSetState(setState: TSetSelectboxState): void
}
export type TSelectboxState = {
y: number
x: number
width: number
height: number
}
const initialState: TSelectboxState = {
y: 0,
x: 0,
width: 0,
height: 0,
}
export function Selectbox(props: TSelectboxProps) {
const { fixedPosition, getSetState, className } = props
const [state, setState] = useState(initialState)
useEffect(() => {
getSetState(setState)
}, [])
const boxStyle: CSSProperties = {
left: state.x,
top: state.y,
width: state.width,
height: state.height,
zIndex: 9000,
position: fixedPosition ? 'fixed' : 'absolute',
cursor: 'default',
willChange: 'transform',
transform: 'translateZ(0)',
display: state.width === 0 && state.height === 0 ? 'none' : 'block',
}
return <div className={className} style={boxStyle} />
}
Selectbox.defaultProps = {
className: 'selectable-selectbox',
}