Farmbot-Web-App/frontend/ui/util.ts

34 lines
1.0 KiB
TypeScript
Raw Normal View History

2018-11-30 19:41:50 -07:00
import { isUndefined } from "lodash";
2017-07-04 07:32:23 -06:00
interface Props {
2017-06-29 12:54:02 -06:00
xs?: number;
sm?: number;
md?: number;
lg?: number;
2017-07-04 07:32:23 -06:00
xl?: number;
2017-06-29 12:54:02 -06:00
xsOffset?: number;
smOffset?: number;
mdOffset?: number;
lgOffset?: number;
2017-07-04 07:32:23 -06:00
xlOffset?: number;
2017-06-29 12:54:02 -06:00
}
2017-08-28 06:01:11 -06:00
export function parseClassNames(props: Props, base?: string) {
2017-06-29 12:54:02 -06:00
2017-08-28 05:49:13 -06:00
const classNames: string[] = [];
2017-07-04 07:32:23 -06:00
if (base) { classNames.push(base); }
2017-06-29 12:54:02 -06:00
2017-07-04 07:32:23 -06:00
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}`); }
2018-11-30 19:41:50 -07:00
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}`); }
2017-06-29 12:54:02 -06:00
2017-07-04 07:32:23 -06:00
return classNames.join(" ");
2017-06-29 12:54:02 -06:00
}