FarmBot/Farmbot-Web-App

View on GitHub
frontend/ui/util.ts

Summary

Maintainability
A
55 mins
Test Coverage
import { isUndefined } from "lodash";

interface ParseColClassNamesProps {
  xs?: number;
  sm?: number;
  md?: number;
  lg?: number;
  xl?: number;
  xsOffset?: number;
  smOffset?: number;
  mdOffset?: number;
  lgOffset?: number;
  xlOffset?: number;
}

export function parseColClassNames(props: ParseColClassNamesProps, base?: string) {

  const classNames: string[] = [];
  if (base) { classNames.push(base); }

  if (props.xs) { classNames.push(`col-xs-${props.xs}`); }
  if (props.sm) { classNames.push(`col-sm-${props.sm}`); }
  if (props.md) { classNames.push(`col-md-${props.md}`); }
  if (props.lg) { classNames.push(`col-lg-${props.lg}`); }
  const { xsOffset, smOffset, mdOffset, lgOffset } = props;
  if (!isUndefined(xsOffset)) { classNames.push(`col-xs-offset-${xsOffset}`); }
  if (!isUndefined(smOffset)) { classNames.push(`col-sm-offset-${smOffset}`); }
  if (!isUndefined(mdOffset)) { classNames.push(`col-md-offset-${mdOffset}`); }
  if (!isUndefined(lgOffset)) { classNames.push(`col-lg-offset-${lgOffset}`); }

  return classNames.join(" ");

}