chore: sort font weight options (#8151)

close PD-1684
This commit is contained in:
JimmFly
2024-09-06 11:41:18 +00:00
parent 487154ed3b
commit 817306ea2a
3 changed files with 9 additions and 6 deletions

View File

@@ -19,7 +19,6 @@ import {
FontFamily,
FontFamilyMap,
FontStyle,
FontWeight,
FontWeightMap,
getShapeName,
LineColor,
@@ -41,7 +40,7 @@ import {
settingWrapper,
shapeIndicator,
} from '../style.css';
import { useColor } from '../utils';
import { sortedFontWeightEntries, useColor } from '../utils';
import type { DocName } from './docs';
import { Point } from './point';
import { EdgelessSnapshot } from './snapshot';
@@ -285,7 +284,7 @@ export const ShapeSettings = () => {
const fontWeightItems = useMemo(() => {
const { fontWeight } = settings[`shape:${currentShape}`];
return Object.entries(FontWeight).map(([name, value]) => {
return sortedFontWeightEntries.map(([name, value]) => {
const handler = () => {
editorSetting.set(`shape:${currentShape}`, { fontWeight: value });
};

View File

@@ -11,7 +11,6 @@ import {
FontFamily,
FontFamilyMap,
FontStyle,
FontWeight,
FontWeightMap,
LineColor,
LineColorMap,
@@ -23,7 +22,7 @@ import { useCallback, useMemo } from 'react';
import { DropdownMenu } from '../menu';
import { menuTrigger, settingWrapper } from '../style.css';
import { useColor } from '../utils';
import { sortedFontWeightEntries, useColor } from '../utils';
import { Point } from './point';
import { EdgelessSnapshot } from './snapshot';
@@ -123,7 +122,7 @@ export const TextSettings = () => {
const fontWeightItems = useMemo(() => {
const { fontWeight } = settings['affine:edgeless-text'];
return Object.entries(FontWeight).map(([name, value]) => {
return sortedFontWeightEntries.map(([name, value]) => {
const handler = () => {
editorSetting.set('affine:edgeless-text', { fontWeight: value });
};

View File

@@ -1,3 +1,4 @@
import { FontWeight } from '@blocksuite/blocks';
import { useTheme } from 'next-themes';
function getColorFromMap(
@@ -43,3 +44,7 @@ export const useColor = () => {
resolvedTheme as 'light' | 'dark' | undefined
);
};
export const sortedFontWeightEntries = Object.entries(FontWeight).sort(
(a, b) => Number(a[1]) - Number(b[1])
);