eapp-amis-theme-editor
Version:
amis主题编辑器
257 lines (254 loc) • 9.02 kB
JavaScript
/**
* amis-theme-editor v2.0.11-beta.2
* Copyright 2018-2023 @fex
*/
import { __spreadArray } from 'tslib';
import { render } from 'amis-core';
import React__default from 'react';
import cx from 'classnames';
import { getSchemaTpl } from '../tpl.js';
import { registerComponent } from './index.js';
import { i18n } from 'i18n-runtime';
var CheckboxStateFunc = function (visibleOn, state, type) {
return [{
title: i18n("454e60f5759903d7d3dba58e3f9bd590"),
visibleOn: visibleOn,
body: [{
type: 'amis-theme-wrapper',
label: false,
title: i18n("c8339fd2a85af4ba66084d28df808de4"),
body: [{
type: 'amis-theme-size-editor',
hideWidth: true,
hideMinWidth: true,
name: "".concat(state, ".body.size"),
label: false,
state: state
}]
}, {
type: 'amis-theme-wrapper',
label: false,
title: i18n("961534b4ea37e4e88aada736b299d063"),
visibleOn: visibleOn,
body: [{
mode: 'default',
type: 'amis-theme-border',
name: "".concat(state, ".body.border")
}]
}, {
type: 'amis-theme-wrapper',
label: false,
title: i18n("0103eb2d3dca70270d1a74e9ec987ac9"),
visibleOn: visibleOn,
body: [{
mode: 'default',
type: 'amis-theme-radius',
disableBorder: true,
name: "".concat(state, ".body.border")
}]
}, {
type: 'amis-theme-wrapper',
label: false,
title: i18n("8e1b944f4389bdaab6f11d5bc83190c8"),
visibleOn: visibleOn,
body: [{
type: 'amis-theme-color-picker',
label: i18n("6b36c6f7ec834692ec6c8e3816349fdd"),
labelMode: 'input',
name: "".concat(state, ".body.bg-color"),
options: '${colorOptions}'
}]
}]
}];
};
var InputTypeConfig = function (type) {
return getSchemaTpl('collapseGroup', __spreadArray(__spreadArray(__spreadArray(__spreadArray([{
title: i18n("4092ed98e9035652d4c9ca9441701ed7"),
body: [{
type: 'select',
name: 'state',
label: i18n("3fea7ca76cdece641436d7ab0d02ab1b"),
selectFirst: true,
options: [{
label: i18n("22b777e6fcb613b8ba83ced9594cd07e"),
value: 'default'
}, {
label: i18n("062d0b688adb10f3af5ebc2fd2667f1c"),
value: 'hover'
}, {
label: i18n("4363c17ebb346b646af55bd8c8075915"),
value: 'active'
}, {
label: i18n("710ad08b11419332713360d2750cd707"),
value: 'disabled'
}]
}]
}], CheckboxStateFunc("${state == 'default' || !state}", 'default'), true), CheckboxStateFunc("${state == 'hover'}", 'hover'), true), CheckboxStateFunc("${state == 'active'}", 'active'), true), CheckboxStateFunc("${state == 'disabled'}", 'disabled'), true));
};
var ThemeInputCommon = function (props) {
var title = props.title,
edit = props.edit,
body = props.body,
activeId = props.activeId;
function handleEdit() {
props.onEdit(edit);
}
return React__default.createElement(React__default.Fragment, null, React__default.createElement("div", {
className: "theme-component"
}, React__default.createElement("div", {
className: "theme-component-title"
}, title), React__default.createElement("div", {
className: cx('theme-component-content', activeId === edit.path && 'theme-component-content--active'),
onClick: function () {
handleEdit();
}
}, body)));
};
var ThemeCheckbox = function (props) {
return {
title: i18n("0c1001673b467bf750dc8327155fde2a"),
body: [{
title: i18n("e1371d733ff347664655629011b4130f"),
body: [{
title: i18n("282363b659599b7fc8d418f0cfbc151f"),
body: function (onEdit) {
return React__default.createElement(ThemeInputCommon, {
activeId: props.activeId,
onEdit: onEdit,
title: "\u52FE\u9009\u6846\uFF08\u672A\u9009\u4E2D\uFF09",
edit: {
title: i18n("96968134ef7fd7b77bd51e2f16100837"),
path: 'component.checkbox.checkbox.normal',
body: InputTypeConfig()
},
body: React__default.createElement("div", {
className: "theme-component-content-wrap"
}, render({
name: 'checkbox',
label: i18n("22b777e6fcb613b8ba83ced9594cd07e"),
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
className: 'themeEditor-checkbox--default'
}), render({
name: 'checkbox',
label: i18n("062d0b688adb10f3af5ebc2fd2667f1c"),
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
className: 'themeEditor-checkbox--hover'
}), render({
name: 'checkbox',
label: i18n("4363c17ebb346b646af55bd8c8075915"),
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
className: 'themeEditor-checkbox--active'
}), render({
name: 'checkbox',
label: i18n("710ad08b11419332713360d2750cd707"),
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
disabled: true,
className: 'themeEditor-checkbox--disabled'
}))
});
}
}, {
title: i18n("a6b1c1a809d2dd4ef85e389b388ee9cc"),
body: function (onEdit) {
return React__default.createElement(ThemeInputCommon, {
activeId: props.activeId,
onEdit: onEdit,
title: "\u52FE\u9009\u6846\uFF08\u5DF2\u9009\u4E2D\uFF09",
edit: {
title: i18n("5a76d053498d5e09b56a9eb23e4a56c6"),
path: 'component.checkbox.checkbox.checked',
body: InputTypeConfig()
},
body: React__default.createElement("div", {
className: "theme-component-content-wrap"
}, render({
name: 'checkbox',
label: i18n("22b777e6fcb613b8ba83ced9594cd07e"),
value: true,
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
className: 'themeEditor-checkbox-checked--default'
}), render({
name: 'checkbox',
label: i18n("062d0b688adb10f3af5ebc2fd2667f1c"),
value: true,
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
className: 'themeEditor-checkbox-checked--hover'
}), render({
name: 'checkbox',
label: i18n("4363c17ebb346b646af55bd8c8075915"),
value: true,
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
className: 'themeEditor-checkbox-checked--active'
}), render({
name: 'checkbox',
label: i18n("710ad08b11419332713360d2750cd707"),
value: true,
type: 'checkbox',
option: i18n("fb235ec9bf44cb55437a95ba625ed969"),
disabled: true,
className: 'themeEditor-checkbox-checked--disabled'
}))
});
}
}, {
title: i18n("477a18d8dc1cb1b7149ab90c7adbf3b3"),
body: function (onEdit) {
return React__default.createElement(ThemeInputCommon, {
activeId: props.activeId,
onEdit: onEdit,
title: "\u52FE\u9009\u6846\u7EC4",
edit: {
title: i18n("e41b25815dd56f49cb401a30cda55190"),
path: 'component.checkbox.checkboxes',
body: getSchemaTpl('collapseGroup', [{
title: i18n("4092ed98e9035652d4c9ca9441701ed7"),
body: [{
type: 'amis-theme-select',
name: "body.marginRight",
label: i18n("e8ed49e9fde0bb778e2185876c2d2697"),
extraUnit: ['px', 'rem'],
options: '${sizesOptions}'
}]
}])
},
body: React__default.createElement("div", {
className: "theme-component-content-wrap checkboxes"
}, render({
name: 'checkboxes',
type: 'checkboxes',
label: i18n("db98f889ce6bc235e66bd4b2a788d137"),
options: [{
label: 'OptionA',
value: 'a'
}, {
label: 'OptionB',
value: 'b'
}, {
label: 'OptionC',
value: 'c'
}, {
label: 'OptionD',
value: 'd'
}]
}))
});
}
}]
}]
};
};
registerComponent('checkbox', {
type: 'data-entry',
label: i18n("454e60f5759903d7d3dba58e3f9bd590"),
key: 'checkbox',
component: function () {
return ThemeCheckbox;
}
});