|
| 1 | +# Dialog Style Guide |
| 2 | + |
| 3 | +All new dialogs using `CustomDialog` should follow these patterns for consistent |
| 4 | +appearance. CSS classes are defined in `/src/main/webapp/styles/grapheditor.css`. |
| 5 | + |
| 6 | +## Auto-Height |
| 7 | + |
| 8 | +Pass `null` for the height parameter in `showDialog()`. The `Dialog` constructor |
| 9 | +measures `elt.scrollHeight` after the element is in the DOM and sizes the dialog |
| 10 | +automatically. Never compute dialog heights manually with `height += N` increments. |
| 11 | + |
| 12 | +```javascript |
| 13 | +var dlg = new CustomDialog(this, div, okFn, null, mxResources.get('export'), helpLink); |
| 14 | +this.showDialog(dlg.container, 360, null, true, true); |
| 15 | +``` |
| 16 | + |
| 17 | +## Spacing (handled by CustomDialog and Dialog) |
| 18 | + |
| 19 | +- **Dialog padding**: 24px on all sides (`.geDialog` CSS) |
| 20 | +- **Buttons margin-top**: 34px (default in `CustomDialog`) |
| 21 | +- **Container padding-bottom**: 10px (`CustomDialog` adds this to prevent margin collapse) |
| 22 | +- **Dialog chrome**: `Dialog` constructor adds 48px to both width and height for padding |
| 23 | + |
| 24 | +These produce equal visual spacing above (34px) and below (34px = 10px + 24px) the |
| 25 | +button row. Do not override these values in individual dialogs. |
| 26 | + |
| 27 | +## Sections (`geDialogSection`) |
| 28 | + |
| 29 | +Group related controls in rounded section containers: |
| 30 | + |
| 31 | +```javascript |
| 32 | +var section = document.createElement('div'); |
| 33 | +section.className = 'geDialogSection'; |
| 34 | +// ... add rows to section ... |
| 35 | +div.appendChild(section); |
| 36 | +``` |
| 37 | + |
| 38 | +## Form Rows (`geDialogFormRow`) |
| 39 | + |
| 40 | +Use for label + input pairs (text fields, selects): |
| 41 | + |
| 42 | +```javascript |
| 43 | +var row = document.createElement('div'); |
| 44 | +row.className = 'geDialogFormRow'; |
| 45 | + |
| 46 | +var lbl = document.createElement('span'); |
| 47 | +lbl.className = 'geDialogFormLabel'; |
| 48 | +mxUtils.write(lbl, mxResources.get('zoom') + ':'); |
| 49 | +row.appendChild(lbl); |
| 50 | + |
| 51 | +var input = document.createElement('input'); |
| 52 | +input.setAttribute('type', 'text'); |
| 53 | +row.appendChild(input); |
| 54 | + |
| 55 | +section.appendChild(row); |
| 56 | +``` |
| 57 | + |
| 58 | +## Checkbox Rows (`geDialogCheckRow`) |
| 59 | + |
| 60 | +Use `addCheckbox` with `useCheckRow=true` (9th parameter) for consistent checkbox |
| 61 | +layout with flex alignment: |
| 62 | + |
| 63 | +```javascript |
| 64 | +var cb = this.addCheckbox(section, mxResources.get('shadow'), |
| 65 | + false, null, null, null, null, null, true); |
| 66 | +``` |
| 67 | + |
| 68 | +For indented sub-options (e.g., "Layers" under "Lightbox"): |
| 69 | + |
| 70 | +```javascript |
| 71 | +cb.checkRow.style.paddingLeft = '24px'; |
| 72 | +``` |
| 73 | + |
| 74 | +## Inline Fields (`geDialogInlineFields` / `geDialogInlineField`) |
| 75 | + |
| 76 | +Use for side-by-side fields (e.g., Width + Height): |
| 77 | + |
| 78 | +```javascript |
| 79 | +var row = document.createElement('div'); |
| 80 | +row.className = 'geDialogInlineFields'; |
| 81 | + |
| 82 | +var field = document.createElement('div'); |
| 83 | +field.className = 'geDialogInlineField'; |
| 84 | +// ... add label + input to field ... |
| 85 | +row.appendChild(field); |
| 86 | + |
| 87 | +section.appendChild(row); |
| 88 | +``` |
| 89 | + |
| 90 | +## Dialog Title |
| 91 | + |
| 92 | +Center-aligned `<h3>` with standard margins: |
| 93 | + |
| 94 | +```javascript |
| 95 | +var hd = document.createElement('h3'); |
| 96 | +mxUtils.write(hd, title); |
| 97 | +hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:10px'; |
| 98 | +div.appendChild(hd); |
| 99 | +``` |
| 100 | + |
| 101 | +## Edit Button (Lightbox Dialogs) |
| 102 | + |
| 103 | +Use `addEditButton` which creates a `geDialogCheckRow` with an indented select: |
| 104 | + |
| 105 | +```javascript |
| 106 | +var editSection = this.addEditButton(optSection, lightbox); |
| 107 | +var edit = editSection.getEditInput(); |
| 108 | +``` |
| 109 | + |
| 110 | +## Dark Mode |
| 111 | + |
| 112 | +All CSS uses `light-dark()` for color values. Never hardcode colors in JS — use |
| 113 | +the CSS classes which handle both modes automatically. |
| 114 | + |
| 115 | +## Testing Dialogs |
| 116 | + |
| 117 | +Use `?dev=1&ui=classic` to keep the menubar visible regardless of window size. |
| 118 | +Test with both single-page and multi-page diagrams, as extra controls appear |
| 119 | +when multiple pages exist. |
0 commit comments