Skip to content

Commit

Permalink
feat: 折叠面板,无标题时显示折叠箭头。组件存在于表单中,面板新增切换展示方式按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
F-jianchao committed Oct 17, 2024
1 parent d376610 commit af287e3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
10 changes: 9 additions & 1 deletion packages/amis-editor/src/plugin/CollapseGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class CollapseGroupPlugin extends BasePlugin {
pluginIcon = 'collapse-plugin';
scaffold = {
type: 'collapse-group',
expandIconPosition: 'right',
activeKey: ['1'],
body: [
{
Expand Down Expand Up @@ -101,6 +102,7 @@ export class CollapseGroupPlugin extends BasePlugin {
panelJustify = true;

panelBodyCreator = (context: BaseEventContext) => {
const isInForm = context.path.includes('/form/');
const i18nEnabled = getI18nEnabled();
return [
getSchemaTpl('tabs', [
Expand All @@ -116,7 +118,7 @@ export class CollapseGroupPlugin extends BasePlugin {
label: '图标位置',
type: 'button-group-select',

pipeIn: defaultValue('left'),
pipeIn: defaultValue('right'),
options: [
{
label: '左边',
Expand Down Expand Up @@ -169,6 +171,12 @@ export class CollapseGroupPlugin extends BasePlugin {
: undefined;
}
},
getSchemaTpl('switch', {
name: 'enableFieldSetStyle',
label: '切换展示方式',
value: true,
visible: isInForm
}),
{
name: 'accordion',
label: tipedLabel(
Expand Down
4 changes: 4 additions & 0 deletions packages/amis-ui/scss/components/_collapse.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
align-items: center;
margin-right: var(--collapse-icon-margin);

&.noTitle {
transform: translateY(-50%);
}

svg {
width: var(--collapse-icon-size);
height: var(--collapse-icon-size);
Expand Down
69 changes: 34 additions & 35 deletions packages/amis-ui/src/components/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,42 +203,41 @@ export class Collapse extends React.Component<CollapseProps, CollapseState> {
: collapseHeader || header;

let dom = [
finalHeader ? (
<HeadingComponent
key="header"
onClick={this.toggleCollapsed}
className={cx(
`Collapse-header`,
{'is-mobile': mobileUI},
headingClassName
)}
>
{showArrow && collapsable ? (
expandIcon ? (
React.cloneElement(expandIcon, {
...expandIcon.props,
className: cx(
'Collapse-icon-tranform',
expandIcon.props?.className
)
})
) : (
<span className={cx('Collapse-arrow-wrap')}>
<Icon
icon="right-arrow-bold"
className={cx('Collapse-arrow', 'icon')}
classNameProp={cx('Collapse-arrow')}
iconContent="Collapse-arrow"
/>
</span>
)
<HeadingComponent
key="header"
onClick={this.toggleCollapsed}
className={cx(
`Collapse-header`,
{'is-mobile': mobileUI},
headingClassName
)}
>
{showArrow && collapsable ? (
expandIcon ? (
React.cloneElement(expandIcon, {
...expandIcon.props,
className: cx(
'Collapse-icon-tranform',
expandIcon.props?.className
)
})
) : (
''
)}
{finalHeader}
</HeadingComponent>
) : null,

<span
className={cx('Collapse-arrow-wrap', {noTitle: !finalHeader})}
>
<Icon
icon="right-arrow-bold"
className={cx('Collapse-arrow', 'icon')}
classNameProp={cx('Collapse-arrow')}
iconContent="Collapse-arrow"
/>
</span>
)
) : (
''
)}
{finalHeader}
</HeadingComponent>,
<Transition
key="body"
mountOnEnter={mountOnEnter}
Expand Down

0 comments on commit af287e3

Please sign in to comment.