Skip to content

Commit 4563d33

Browse files
committed
Add extra gutter width on ReadonlyDocument
1 parent f00ba9c commit 4563d33

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

packages/compass-components/src/components/document-list/document.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ const HadronDocument: React.FunctionComponent<{
8585
editable?: boolean;
8686
editing?: boolean;
8787
onEditStart?: () => void;
88-
}> = ({ value: document, editable = false, editing = false, onEditStart }) => {
88+
extraGutterWidth?: number;
89+
}> = ({
90+
value: document,
91+
editable = false,
92+
editing = false,
93+
onEditStart,
94+
extraGutterWidth,
95+
}) => {
8996
const { elements, visibleElements } = useHadronDocument(document);
9097
const [autoFocus, setAutoFocus] = useState<{
9198
id: string;
@@ -147,6 +154,7 @@ const HadronDocument: React.FunctionComponent<{
147154
type: el.parent?.currentType === 'Array' ? 'value' : 'key',
148155
});
149156
}}
157+
extraGutterWidth={extraGutterWidth}
150158
></HadronElement>
151159
);
152160
})}

packages/compass-components/src/components/document-list/element.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ const elementSpacer = css({
301301
flex: 'none',
302302
});
303303

304+
const readOnlySpacer = css({
305+
width: spacing[900],
306+
});
307+
304308
const elementExpand = css({
305309
width: spacing[3],
306310
flex: 'none',
@@ -371,13 +375,15 @@ export const calculateShowMoreToggleOffset = ({
371375
editable,
372376
level,
373377
alignWithNestedExpandIcon,
378+
extraGutterWidth = 0,
374379
}: {
375380
editable: boolean;
376381
level: number;
377382
alignWithNestedExpandIcon: boolean;
383+
extraGutterWidth: number | undefined;
378384
}) => {
379385
// the base padding that we have on all elements rendered in the document
380-
const BASE_PADDING_LEFT = spacing[50];
386+
const BASE_PADDING_LEFT = spacing[50] + extraGutterWidth;
381387
const OFFSET_WHEN_EDITABLE = editable
382388
? // space taken by element actions
383389
spacing[300] +
@@ -402,13 +408,15 @@ export const HadronElement: React.FunctionComponent<{
402408
onEditStart?: (id: string, field: 'key' | 'value' | 'type') => void;
403409
lineNumberSize: number;
404410
onAddElement(el: HadronElementType): void;
411+
extraGutterWidth?: number;
405412
}> = ({
406413
value: element,
407414
editable,
408415
editingEnabled,
409416
onEditStart,
410417
lineNumberSize,
411418
onAddElement,
419+
extraGutterWidth,
412420
}) => {
413421
const darkMode = useDarkMode();
414422
const autoFocus = useAutoFocusContext();
@@ -457,8 +465,9 @@ export const HadronElement: React.FunctionComponent<{
457465
editable,
458466
level,
459467
alignWithNestedExpandIcon: true,
468+
extraGutterWidth,
460469
}),
461-
[editable, level]
470+
[editable, level, extraGutterWidth]
462471
);
463472

464473
const isValid = key.valid && value.valid;
@@ -567,6 +576,9 @@ export const HadronElement: React.FunctionComponent<{
567576
</div>
568577
</div>
569578
)}
579+
{typeof extraGutterWidth === 'number' && (
580+
<div style={{ width: extraGutterWidth }} />
581+
)}
570582
<div className={elementSpacer} style={{ width: elementSpacerWidth }}>
571583
{/* spacer for nested documents */}
572584
</div>

packages/compass-crud/src/components/readonly-document.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ class ReadonlyDocument extends React.Component<
131131
* @returns {Array} The elements.
132132
*/
133133
renderElements() {
134-
return <DocumentList.Document value={this.props.doc} />;
134+
return (
135+
<DocumentList.Document
136+
value={this.props.doc}
137+
// Provide extra whitespace for the expand button
138+
extraGutterWidth={spacing[900]}
139+
/>
140+
);
135141
}
136142

137143
renderActions() {

0 commit comments

Comments
 (0)