Skip to content

Commit

Permalink
feat: add CollapseGroup component
Browse files Browse the repository at this point in the history
  • Loading branch information
Carrotzpc committed Jul 4, 2024
1 parent 6afc272 commit ddc88df
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/CollapseGroup/demos/Playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { CollapseGroup, CollapseGroupProps } from '@yuntijs/ui';
import { VariableIcon } from 'lucide-react';

export default () => {
const store = useCreateStore();
const control: CollapseGroupProps | any = useControls(
{
title: '输出变量',
defaultActive: true,
variant: {
options: ['default', 'block', 'ghost', 'pure'],
value: 'default',
},
},
{ store }
);
return (
<StoryBook levaStore={store} style={{ width: '100%' }}>
<CollapseGroup icon={VariableIcon} style={{ width: '100%' }} {...control}>
我是收起来的内容
</CollapseGroup>
</StoryBook>
);
};
10 changes: 10 additions & 0 deletions src/CollapseGroup/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CollapseGroup } from '@yuntijs/ui';
import { VariableIcon } from 'lucide-react';

export default () => {
return (
<CollapseGroup icon={VariableIcon} style={{ width: '100%' }} title="输出变量">
我是收起来的内容
</CollapseGroup>
);
};
32 changes: 32 additions & 0 deletions src/CollapseGroup/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
nav: Components
group: Data Display
title: CollapseGroup
---

## Usage

Based on [lobehub ui FormGroup](https://github.com/lobehub/lobe-ui/blob/master/src/Form/components/FormGroup.tsx).

```tsx | pure
import { CollapseGroup } from '@yuntijs/ui';
import { VariableIcon } from 'lucide-react';

export default () => {
return (
<CollapseGroup icon={VariableIcon} title="输出变量">
我是收起来的内容
</CollapseGroup>
);
};
```

<code src="./demos/index.tsx" center></code>

## Playground

<code src="./demos/Playground.tsx" center></code>

## APIs

<API></API>
28 changes: 28 additions & 0 deletions src/CollapseGroup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FormGroupProps, Form as LobeForm } from '@lobehub/ui';
import React from 'react';

import { useStyles } from './style';

const FormGroup = LobeForm.Group;

export type CollapseGroupProps = Omit<
FormGroupProps,
'items' | 'activeKey' | 'defaultActiveKey' | 'accordion' | 'expandIconPosition'
>;

export const CollapseGroup: React.FC<CollapseGroupProps> = ({
className,
variant,
...otherProps
}) => {
const { styles, cx } = useStyles();

return (
<FormGroup
className={cx(styles.root, className)}
collapsible={variant === 'pure' ? 'icon' : 'header'}
variant={variant}
{...otherProps}
/>
);
};
31 changes: 31 additions & 0 deletions src/CollapseGroup/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ css, token, prefixCls }) => {
return {
root: css`
margin-bottom: ${token.margin}px;
.${prefixCls}-collapse {
&-header {
padding: 0 !important;
&-text {
padding: ${token.paddingSM}px ${token.paddingSM}px ${token.paddingSM}px 0;
& > * {
font-size: ${token.fontSize}px;
/* font-weight: unset; */
}
}
}
&-expand-icon {
padding: ${token.padding}px 0 ${token.padding}px ${token.paddingSM}px;
}
&-extra {
padding-right: ${token.paddingSM}px;
}
&-content {
padding: ${token.paddingXS}px 0;
background-color: ${token.colorBgContainer};
}
}
`,
};
});

0 comments on commit ddc88df

Please sign in to comment.