diff --git a/lib/form-layout.less b/lib/form-layout.less new file mode 100644 index 0000000..fd9df97 --- /dev/null +++ b/lib/form-layout.less @@ -0,0 +1,403 @@ +/* Form layout */ + +@import "./variables.less"; + +:root { + // CSS variable to define the number of (label + control) columns. + // It dynamically changes on narrow pages (see media query below). + --ct-form-columns: 2; +} + +// Cockpit Form Layout: Automatically have Cockpit display your form in +// an optimal layout. +// +// By default, all labels are aligned and sized properly and form elements +// stretch to take up the remaining space. +// +// +// There are additional classes and attributes you can add to each +// control directly under `ct-form`: +// +// `ct-form-split`: The grid can be split on a `form-control` +// level by adding a this class. If you want two elements next to each +// other, both should have this class. Widths are equal by default. +// See ct-form-minmax & ct-form-maxmin for alternate sizing. +// +// `ct-form-relax`: Form elements normally stretch to take up the +// full space. You can relax their width by adding this class to the +// control. Inputs with a size attribute are auto-relaxed and do not +// need this class. +// +// `ct-form-stretch`: If a control has a width specified +// elsewhere, you can force it to stretch. This is mainly useful when +// using
to group elements. +// +// `ct-form-full`: Force a widget to be the full width of the form, +// invading the label space. +// +// role="group": When there are two related elements, such as a text +// input and a dropdown, you can group them together using this HTML +// attribute. It's similar in purpose to a
, but works for +// layouts in Chrome (unlike fieldset). This can be attached to any +// container element, but will most likely be used with
. The role +// adds semantic meaning to the element for screen readers, and we key +// the CSS off of the role. +// +// `ct-form-box`: Visual styling for encapsulating a block of sub-options. +// Creates a gray box around elements. +// +//
: While this is an element, it has a special meaning and is used +// to add some vertical spacing to a form. +// +// +// Alternate grid sizing: +// You can override division of space for controls by adding a class +// at grid level (.ct-form) to adjust size for "split" widgets: +// `ct-form-maxmin: First widget is wide; second is small. +// `ct-form-minmax`: First widget is small; second is wide. +// +// +// Most of the time, you can simply ignore all the optional classes (and +// attribute and hr element) and simply wrap your labels & controls in +// a
and layout magic happens. + +.ct-form { + // Locally redefine padding to Bootstrap values for this LESS block + @padding-large-vertical: 1rem; + @padding-small-vertical: 0.5rem; + @padding-small-horizontal: 1.5rem; + // Bootstrap & PatternFly use a 1px border around widgets + @border-width: 1px; + @widget-height: 2.25rem; // (36px for PF4 widgets) + + align-self: start; // Don't vertically fill content by default + display: grid; + grid-gap: @padding-small-vertical @padding-small-horizontal; + // Repeat a label that is a minimum of 4em and its control that + // fills the remaining space by a CSS variable (default: 2) + grid-template-columns: repeat(var(--ct-form-columns), max-content 1fr); + justify-items: stretch; + align-content: baseline; + + // All