Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 编辑器选择字体时支持预览,字体配置支持 previewUrl #11395

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/amis-theme-editor-helper/src/helper/declares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface Font {
label: string;
token: string;
value?: string | number;
className?: string;
previewUrl?: string;
body?: {value: string | number}[];
}

Expand Down Expand Up @@ -98,7 +100,12 @@ export interface ThemeDefinition {
base: {
label: string;
token: string;
body: {value: string}[];
body: {
value: string;
label?: string;
className?: string;
previewUrl?: string;
}[];
};
size: {
label: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function getGlobalData(data: ThemeDefinition | undefined): GlobalData {
if (key !== 'base') {
fonts[key].body.forEach((font, i: number) => {
children.push({
...font,
label: `${font.label}(${font.value})`,
value: `var(${font.token})`,
realValue: `${font.value}`
Expand All @@ -121,7 +122,8 @@ export function getGlobalData(data: ThemeDefinition | undefined): GlobalData {
} else {
fonts['base'].body.forEach((font, i: number) => {
children.push({
label: font.value,
...font,
label: font.label || font.value,
value: font.value,
realValue: font.value
});
Expand Down
20 changes: 20 additions & 0 deletions packages/amis-theme-editor-helper/src/renderers/Font.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,26 @@ function FontEditor(props: FontEditorProps) {
}}
itemName="fontFamily"
menuTpl="label"
menuLabelRender={(option: any) => {
return (
<div
className={option.className}
style={
option.previewUrl
? {
background: `url(${option.previewUrl}) no-repeat`,
backgroundSize: 'contain',
height: '100%'
}
: {
fontFamily: option.value
}
}
>
{option.previewUrl ? ' ' : option.html || option.label}
</div>
);
}}
state={state}
placeholder={editorDefaultValue?.fontFamily || '字体'}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ThemeSelectProps {
state?: string;
itemName?: string;
menuTpl?: string;
menuLabelRender?: (option: Option) => JSX.Element;
placeholder?: string;
editorValueToken?: string | {[key: string]: string};
}
Expand All @@ -53,7 +54,8 @@ function ThemeSelectContent(props: ThemeSelectContentProps) {
menuTpl,
placeholder,
editorValueToken,
data
data,
menuLabelRender
} = props;
// 期望value是string类型
const value = props.value + '';
Expand Down Expand Up @@ -240,7 +242,9 @@ function ThemeSelectContent(props: ThemeSelectContentProps) {
'ThemeSelectContent-input-select-item--active'
)}
>
{item.html || item.label}
{menuLabelRender
? menuLabelRender(item)
: item.html || item.label}
</div>
);
})}
Expand Down
Loading