ViewContainer.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { BaseComponent } from './vdom-util'
  2. import { ComponentChildren, Ref, h } from './vdom'
  3. import { CssDimValue } from './scrollgrid/util'
  4. export interface ViewContainerProps {
  5. vGrow?: boolean
  6. height?: CssDimValue
  7. aspectRatio?: number
  8. onClick?: (ev: Event) => void
  9. elRef?: Ref<HTMLDivElement>
  10. children?: ComponentChildren
  11. }
  12. // TODO: do function component?
  13. export default class ViewContainer extends BaseComponent<ViewContainerProps> {
  14. render(props: ViewContainerProps) {
  15. let classNames = [ 'fc-view-container' ]
  16. let height: CssDimValue = ''
  17. let paddingBottom: CssDimValue = ''
  18. if (props.aspectRatio || props.vGrow) {
  19. classNames.push('fc-view-container--absview')
  20. }
  21. if (props.aspectRatio) {
  22. paddingBottom = (1 / props.aspectRatio) * 100 + '%'
  23. } else {
  24. height = props.height || ''
  25. }
  26. return (
  27. <div
  28. ref={props.elRef}
  29. onClick={props.onClick}
  30. class={classNames.join(' ')} style={{ height, paddingBottom }}
  31. >{props.children}</div>
  32. )
  33. }
  34. }