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

fix: 修复wrapperCustomStyle配置customStyleClassPrefix不生效问题 #11667

Merged
merged 1 commit into from
Feb 26, 2025
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
1 change: 1 addition & 0 deletions packages/amis-core/src/components/CustomStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function (props: CustomStyleProps) {
insertEditCustomStyle({
customStyle: wrapperCustomStyle,
id,
customStyleClassPrefix: env?.customStyleClassPrefix,
doc: env?.getModalContainer?.()?.ownerDocument,
data
});
Expand Down
16 changes: 10 additions & 6 deletions packages/amis-core/src/utils/style-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,10 @@ export function insertEditCustomStyle(params: {
customStyle: any;
id?: string;
doc?: Document;
customStyleClassPrefix?: string;
[propName: string]: any;
}) {
const {customStyle, doc, data} = params;
const {customStyle, doc, data, customStyleClassPrefix} = params;
const id = params.id?.replace?.('u:', '') || params.id + '';
let styles: any = {};
traverseStyle(customStyle, '', styles);
Expand All @@ -404,10 +405,13 @@ export function insertEditCustomStyle(params: {
index = `-${data.index}`;
}
if (!isEmpty(styles)) {
const className = `wrapperCustomStyle-${id}${index}`;
let className = `.wrapperCustomStyle-${id}${index}`;
if (customStyleClassPrefix) {
className = `${customStyleClassPrefix} ${className}`;
}
Object.keys(styles).forEach((key: string) => {
if (!isObject(styles[key])) {
content += `\n.${className} {\n ${key}: ${
content += `\n${className} {\n ${key}: ${
resolveVariableAndFilter(
styles[key].replace(/['|"]/g, ''),
data,
Expand All @@ -426,7 +430,7 @@ export function insertEditCustomStyle(params: {
) || value
};`
);
content += `\n.${className} {\n ${res.join('\n ')}\n}`;
content += `\n${className} {\n ${res.join('\n ')}\n}`;
} else if (/^root:/.test(key)) {
const res = map(
styles[key],
Expand All @@ -440,7 +444,7 @@ export function insertEditCustomStyle(params: {
};`
);
const nowKey = key.replace('root', '');
content += `\n.${className}${nowKey} {\n ${res.join('\n ')}\n}`;
content += `\n${className}${nowKey} {\n ${res.join('\n ')}\n}`;
} else {
const res = map(
styles[key],
Expand All @@ -453,7 +457,7 @@ export function insertEditCustomStyle(params: {
) || value
};`
);
content += `\n.${className} ${key} {\n ${res.join('\n ')}\n}`;
content += `\n${className} ${key} {\n ${res.join('\n ')}\n}`;
}
});
}
Expand Down
Loading