Skip to content

Commit feefd82

Browse files
authored
feat: added colors from uikit, added nore exports (#216)
1 parent 3367f4b commit feefd82

File tree

22 files changed

+106
-118
lines changed

22 files changed

+106
-118
lines changed

src/bundle/MarkupEditorView.scss

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ $toolbar-height: 28px;
8888
// override default theme
8989
// TODO: use own theme
9090
&.cm-s-default {
91-
background-color: var(--g-color-base-background);
91+
background-color: transparent;
9292

9393
.CodeMirror-placeholder {
9494
color: var(--g-color-text-secondary);
@@ -117,11 +117,9 @@ $toolbar-height: 28px;
117117

118118
.ye-markup-preview {
119119
&__outer {
120-
overflow-y: scroll;
120+
overflow-y: auto;
121121
flex: 1 0 0;
122122

123-
height: 100%;
124-
125123
&_vertical {
126124
box-sizing: border-box;
127125
margin-top: 6px;

src/bundle/WysiwygEditorView.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88

99
&__editor {
10-
overflow-y: scroll;
10+
overflow-y: auto;
1111
flex-grow: 1;
1212

1313
.g-root_theme_dark & .pm-iframe-container {

src/bundle/YfmEditorView.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626

2727
&__preview-wrapper {
28-
overflow-y: scroll;
28+
overflow-y: auto;
2929

3030
width: 100%;
3131
}

src/bundle/toolbar/ToolbarButtonWithPopupMenu.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ import {ToolbarBaseProps, ToolbarIconData, ToolbarTooltipDelay} from '../../tool
1212
import './ToolbarButtonWithPopupMenu.scss';
1313
const b = cn('toolbar-button-with-popup-menu');
1414

15+
export type MenuItem = {
16+
id: string;
17+
action: Action;
18+
icon: IconProps['data'];
19+
text: string;
20+
iconSize?: IconProps['size'];
21+
iconClassname?: string;
22+
group?: string;
23+
ignoreActive?: boolean;
24+
};
25+
1526
export type ToolbarButtonWithPopupMenuProps = Omit<
1627
ToolbarBaseProps<ActionStorage> & {
1728
icon: ToolbarIconData;
1829
title: string | (() => string);
19-
menuItems: {
20-
id: string;
21-
action: Action;
22-
icon: IconProps['data'];
23-
text: string;
24-
iconSize?: number;
25-
iconClassname?: string;
26-
group?: string;
27-
}[];
30+
menuItems: MenuItem[];
2831
},
2932
'editor'
3033
>;
@@ -48,7 +51,9 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
4851
[menuItems, groupBy],
4952
);
5053

51-
const someActive = menuItems.some((item) => item.action.isActive() === true);
54+
const someActive = menuItems.some(
55+
(item) => !item.ignoreActive && item.action.isActive() === true,
56+
);
5257
const everyDisabled = menuItems.every((item) => item.action.isEnable() === false);
5358

5459
const popupOpen = everyDisabled ? false : open;
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
$colors: ('black', 'gray', 'yellow', 'orange', 'red', 'green', 'blue', 'violet');
1+
$colors: ('gray', 'yellow', 'orange', 'red', 'green', 'blue', 'violet');
22

33
.ye-toolbar-colors {
44
@each $name in $colors {
55
&__item-icon_color_#{$name} {
66
color: var(--yfm-colorify-#{$name});
77
}
88
}
9+
&__item-icon_color_default {
10+
color: var(--g-color-text-primary);
11+
}
912
}

src/bundle/toolbar/custom/ToolbarColors.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Colors} from '../../../extensions';
55
import {i18n} from '../../../i18n/menubar';
66
import {ToolbarBaseProps} from '../../../toolbar';
77
import {icons} from '../../config/icons';
8-
import {ToolbarButtonWithPopupMenu} from '../ToolbarButtonWithPopupMenu';
8+
import {MenuItem, ToolbarButtonWithPopupMenu} from '../ToolbarButtonWithPopupMenu';
99

1010
import './ToolbarColors.scss';
1111

@@ -16,29 +16,32 @@ export type ToolbarColorsProps = Omit<ToolbarBaseProps<never>, 'editor'> & {
1616
active?: boolean;
1717
enable?: boolean;
1818
currentColor?: string;
19+
withDefault?: boolean;
1920
exec(color: string): void;
2021
};
2122

2223
export const ToolbarColors: React.FC<ToolbarColorsProps> = (props) => {
23-
const {exec, onClick, enable, currentColor} = props;
24+
const {exec, onClick, enable, currentColor, withDefault} = props;
25+
const isDefault = currentColor === undefined;
26+
2427
const onItemClick = (color: string) => () => {
25-
exec(color);
26-
onClick?.('colorify', {color});
28+
// do not exec when current color is default and clicked to default item
29+
if (!(isDefault && color === '')) exec(color);
30+
onClick?.('colorify', {color: color === '' ? 'default' : color});
2731
};
2832

2933
const items = [
30-
Colors.Black,
3134
Colors.Gray,
3235
Colors.Yellow,
3336
Colors.Orange,
3437
Colors.Red,
3538
Colors.Green,
3639
Colors.Blue,
3740
Colors.Violet,
38-
].map((color) => ({
41+
].map<MenuItem>((color) => ({
3942
id: color,
4043
icon: textColorIcon.data,
41-
size: textColorIcon.size ?? 16,
44+
iconSize: textColorIcon.size ?? 16,
4245
text: i18n(`colorify__color_${color}`),
4346
iconClassname: b('item-icon', {color}),
4447
action: {
@@ -50,6 +53,24 @@ export const ToolbarColors: React.FC<ToolbarColorsProps> = (props) => {
5053
group: i18n(`colorify__group_text`),
5154
}));
5255

56+
if (withDefault) {
57+
items.unshift({
58+
id: 'default',
59+
icon: textColorIcon.data,
60+
iconSize: textColorIcon.size ?? 16,
61+
text: i18n(`colorify__color_default`),
62+
iconClassname: b('item-icon', {color: 'default'}),
63+
group: i18n(`colorify__group_text`),
64+
ignoreActive: true,
65+
action: {
66+
run: onItemClick(''),
67+
isEnable: () => Boolean(enable),
68+
isActive: () => isDefault,
69+
meta() {},
70+
},
71+
});
72+
}
73+
5374
return (
5475
<ToolbarButtonWithPopupMenu
5576
{...props}

src/bundle/toolbar/wysiwyg/WToolbarColors.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const WToolbarColors: React.FC<WToolbarColorsProps> = ({
2626
className={className}
2727
focus={focus}
2828
onClick={onClick}
29+
withDefault
2930
/>
3031
);
3132
};

src/extensions/yfm/Color/const.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from './ColorSpecs/const';
33
export const colorAction = 'colorify';
44

55
export enum Colors {
6-
Black = 'black',
76
Gray = 'gray',
87
Yellow = 'yellow',
98
Orange = 'orange',

src/extensions/yfm/Color/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const chainAND = (...commands: Command[]): Command => {
4444

4545
// see styles
4646
const COLORS: readonly string[] = [
47-
Colors.Black,
4847
Colors.Gray,
4948
Colors.Yellow,
5049
Colors.Orange,
@@ -59,9 +58,6 @@ export const validateClassNameColorName = (color: string) => COLORS.includes(col
5958
// eslint-disable-next-line complexity
6059
export const parseStyleColorValue = (color: string) => {
6160
switch (color) {
62-
case 'black':
63-
return Colors.Black;
64-
6561
case 'gray':
6662
case 'grey':
6763
case 'lightgray':

src/i18n/menubar/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"math_block": "Math block",
4040
"colorify": "Text color",
4141
"colorify__group_text": "Text",
42-
"colorify__color_black": "Black",
42+
"colorify__color_default": "Default",
4343
"colorify__color_gray": "Gray",
4444
"colorify__color_yellow": "Yellow",
4545
"colorify__color_orange": "Orange",

0 commit comments

Comments
 (0)