feat(editor): update code block ui (#12254)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Updated the code block toolbar to use a toggle switch for the "wrap" option, providing a more interactive user experience. - **Style** - Adjusted the height of the language selection button for consistent appearance. - Refined code block container padding and increased spacing for line numbers to improve readability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -24,6 +24,7 @@ export class LanguageListButton extends WithDisposable(
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
|
height: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lang-button:hover {
|
.lang-button:hover {
|
||||||
|
|||||||
@@ -122,16 +122,28 @@ export const clipboardGroup: MenuItemGroup<CodeBlockToolbarContext> = {
|
|||||||
{
|
{
|
||||||
type: 'wrap',
|
type: 'wrap',
|
||||||
generate: ({ blockComponent, close }) => {
|
generate: ({ blockComponent, close }) => {
|
||||||
const wrapped = blockComponent.model.props.wrap;
|
|
||||||
const label = wrapped ? 'Cancel wrap' : 'Wrap';
|
|
||||||
const icon = wrapped ? CancelWrapIcon : WrapIcon;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
label,
|
action: () => {},
|
||||||
icon,
|
render: () => {
|
||||||
action: () => {
|
const wrapped = blockComponent.model.props.wrap;
|
||||||
blockComponent.setWrap(!wrapped);
|
const label = wrapped ? 'Cancel wrap' : 'Wrap';
|
||||||
close();
|
const icon = wrapped ? CancelWrapIcon : WrapIcon;
|
||||||
|
return html`
|
||||||
|
<editor-menu-action
|
||||||
|
@click=${() => {
|
||||||
|
blockComponent.setWrap(!wrapped);
|
||||||
|
close();
|
||||||
|
}}
|
||||||
|
aria-label=${label}
|
||||||
|
>
|
||||||
|
${icon}
|
||||||
|
<span class="label">${label}</span>
|
||||||
|
<toggle-switch
|
||||||
|
style="margin-left: auto;"
|
||||||
|
.on="${wrapped}"
|
||||||
|
></toggle-switch>
|
||||||
|
</editor-menu-action>
|
||||||
|
`;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const codeBlockStyles = css`
|
|||||||
font-size: var(--affine-font-xs);
|
font-size: var(--affine-font-xs);
|
||||||
line-height: var(--affine-line-height);
|
line-height: var(--affine-line-height);
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 28px 24px;
|
padding: 32px 20px;
|
||||||
background: var(--affine-background-code-block);
|
background: var(--affine-background-code-block);
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -36,8 +36,8 @@ export const codeBlockStyles = css`
|
|||||||
.affine-code-block-container .line-number {
|
.affine-code-block-container .line-number {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding-right: 4px;
|
padding-right: 12px;
|
||||||
width: 24px;
|
width: 32px;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
left: -0.5px;
|
left: -0.5px;
|
||||||
|
|||||||
Reference in New Issue
Block a user