Skip to content

Commit

Permalink
feat(EditorView): add padding variables (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
whiteformed authored Nov 19, 2024
1 parent bd0f0f3 commit ef7851f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
37 changes: 37 additions & 0 deletions demo/css-variables/CSSVariables.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type {Meta, StoryObj} from '@storybook/react';

import {CustomCSSVariablesDemo} from './CSSVariablesDemo';

const meta: Meta = {
title: 'Experiments / Custom CSS Variables',
component: CustomCSSVariablesDemo,
};

export default meta;

type Story = StoryObj<typeof CustomCSSVariablesDemo>;

export const CustomCSSVariables: Story = {
argTypes: {
'--g-md-toolbar-padding': {
control: {type: 'text'},
description: 'Toolbar padding',
},
'--g-md-toolbar-sticky-padding': {
control: {type: 'text'},
description: 'Toolbar padding in sticky mode',
},
'--g-md-toolbar-sticky-inset': {
control: {type: 'text'},
description: 'Toolbar inset in sticky mode',
},
'--g-md-toolbar-sticky-offset': {
control: {type: 'text'},
description: 'Toolbar padding in sticky mode',
},
'--g-md-editor-padding': {
control: {type: 'text'},
description: 'Editor contents padding',
},
},
};
18 changes: 18 additions & 0 deletions demo/css-variables/CSSVariablesDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import {PlaygroundMini} from '../playground/PlaygroundMini';

export const CustomCSSVariablesDemo = React.memo((styles) => {
return (
<div style={styles}>
<PlaygroundMini
initialEditor="wysiwyg"
settingsVisible
withDefaultInitialContent
stickyToolbar
/>
</div>
);
});

CustomCSSVariablesDemo.displayName = 'CustomCSSVariables';
9 changes: 9 additions & 0 deletions docs/how-to-customize-the-editor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## How to customize the editor
You can use CSS variables to make editor contents fit your own needs
| **Variable** | **Description** | **CSS Property Type** | **Default** |
| :---: | :---: | :---: | :---: |
| `--g-md-toolbar-padding` | Toolbar padding | padding | 0px |
| `--g-md-toolbar-sticky-padding` | Toolbar padding in sticky mode | padding | -4px |
| `--g-md-toolbar-sticky-inset` | Toolbar inset in sticky mode | inset | -4px |
| `--g-md-toolbar-sticky-offset` | Toolbar offset in sticky mode | top | 0px |
| `--g-md-editor-padding` | Editor contents padding | padding | 0px |
3 changes: 3 additions & 0 deletions src/bundle/MarkupEditorView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ $toolbar-height: 28px;

&__toolbar {
flex-shrink: 0;

padding: var(--g-md-toolbar-padding);
}

&__editor {
flex-basis: 100%;
// Height of one line + margin. Because where there is no toolbar and there is a small space, the markup editor is not visible.
min-height: 36px;
max-height: 100%;
padding: var(--g-md-editor-padding);

cursor: text;
// We subtract the height of the toolbar only when it is drawn.
Expand Down
4 changes: 4 additions & 0 deletions src/bundle/WysiwygEditorView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

&__toolbar {
flex-shrink: 0;

padding: var(--g-md-toolbar-padding);
}

&__editor {
overflow-y: auto;
flex-grow: 1;

padding: var(--g-md-editor-padding);

.g-root_theme_dark & .pm-iframe-container {
background-color: var(--g-color-base-light);
}
Expand Down
4 changes: 3 additions & 1 deletion src/bundle/sticky/sticky.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ $block: 'g-md-editor-sticky';
&_sticky-active:not(.#{$block}_clear) {
z-index: zIndexVars.$sticky-toolbar;

padding: var(--g-md-toolbar-sticky-padding);

&::before {
position: absolute;
inset: -4px;
inset: var(--g-md-toolbar-sticky-inset, -4px);

content: '';

Expand Down

0 comments on commit ef7851f

Please sign in to comment.