This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add Dropdown component. * Add doc. * Add author. * Update dropdown. * Update author. * Dropdown children not need required.
- Loading branch information
1 parent
2e76a72
commit 2a4ae83
Showing
6 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Dropdown 下拉框 | ||
date: 2019-08-13 | ||
author: lijianxin1202 | ||
--- | ||
在用户点击标题后展示详细内容供用户操作 | ||
|
||
## 使用方式 | ||
点击标题后弹出详细内容,再次点击隐藏详细内容 | ||
|
||
## 基本用法 | ||
点击标题后弹出内容: | ||
```tsx | ||
<Dropdown title="标题" children={<div style={{ padding: '5px 10px' }}>内容</div>} id="dropdown" /> | ||
``` | ||
|
||
## API | ||
```jsx previewOnly | ||
<PropTable of="dropdown" /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import Dropdown from './index'; | ||
import { mount } from 'enzyme'; | ||
|
||
describe('Dropdown', () => { | ||
it('render simple dropdown', () => { | ||
const dropdown = mount(<Dropdown title="title" children="text" />); | ||
const title = dropdown.find('button'); | ||
expect(dropdown.find('div.dropdown').length).toBe(1); | ||
title.simulate('click'); | ||
expect(dropdown.find('div.dropdown.open').length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Dropdown as BootstrapDropdown } from 'react-bootstrap'; | ||
import { DropdownProps, DropdownDefaultProps } from '../../interface'; | ||
|
||
const defaultProps: DropdownDefaultProps = { | ||
id: 'CustomDropdown' | ||
} | ||
|
||
const Dropdown = (props: DropdownProps) => { | ||
const { className, id, title, children } = props; | ||
return ( | ||
<BootstrapDropdown id={id} className={className}> | ||
<BootstrapDropdown.Toggle>{title}</BootstrapDropdown.Toggle> | ||
<BootstrapDropdown.Menu>{children}</BootstrapDropdown.Menu> | ||
</BootstrapDropdown> | ||
); | ||
} | ||
|
||
Dropdown.propTypes = { | ||
/** | ||
* 元素 class 名称 string | ||
**/ | ||
className: PropTypes.string, | ||
/** | ||
* 下拉框收起时展示内容 string | ||
**/ | ||
title: PropTypes.string, | ||
/** | ||
* 元素 id,默认为 CustomDropdown string | ||
**/ | ||
id: PropTypes.string, | ||
/** | ||
* 下拉框展开时详细内容 React.ReactNode | ||
**/ | ||
children: PropTypes.node, | ||
}; | ||
|
||
Dropdown.defaultProps = defaultProps; | ||
|
||
export default Dropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { Dropdown } from '../src'; | ||
|
||
storiesOf('Dropdown', module) | ||
.add('default', () => ( | ||
<Dropdown title="标题" children={<div style={{ padding: '5px 10px' }}>内容</div>} id="dropdown" /> | ||
)) |