Skip to content

Commit 50823d8

Browse files
committed
added readme
1 parent 29c2677 commit 50823d8

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed

lib/accordion/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class Accordion extends React.Component {
1818
}
1919

2020
componentDidMount() {
21-
const { items } = this.props;
21+
const { data } = this.props;
2222
let tempArr = [];
2323
const arrRandom = [];
24-
items.forEach((item) => {
24+
data.forEach((item) => {
2525
let num = Math.random() * 1000000;
2626
if (arrRandom.includes(num)) {
2727
while (arrRandom.includes(num) !== false) {
@@ -88,7 +88,7 @@ class Accordion extends React.Component {
8888
<div
8989
className={classnames(
9090
theme.heading,
91-
{ [theme.color]: item.show },
91+
{ [theme.headerActive]: item.show },
9292
headerClassName,
9393
)}
9494
onClick={() => this.toggle(item.key, item.show)}
@@ -107,10 +107,9 @@ class Accordion extends React.Component {
107107
className={classnames(
108108
{ [theme.hideContent]: !item.show },
109109
theme.content,
110-
contentClassName,
111110
)}
112111
>
113-
<p className={classnames(theme.contentText)}>
112+
<p className={classnames(theme.contentText, contentClassName)}>
114113
{item[contentKey]}
115114
</p>
116115
</div>
@@ -138,18 +137,26 @@ class Accordion extends React.Component {
138137
}
139138

140139
Accordion.propTypes = {
141-
items: PropTypes.oneOfType([PropTypes.array]).isRequired,
140+
data: PropTypes.oneOfType([PropTypes.array]).isRequired,
142141
headerKey: PropTypes.string,
143142
contentKey: PropTypes.string,
144143
allowMultipleExpanded: PropTypes.string,
144+
className: PropTypes.string,
145+
headerClassName: PropTypes.string,
146+
contentClassName: PropTypes.string,
147+
borderless: PropTypes.string,
145148
theme: PropTypes.shape({
146149
accordionBody: PropTypes.string,
147150
}),
148151
};
149152
Accordion.defaultProps = {
150153
theme: defaultTheme,
151-
headerKey: 'heading',
154+
headerKey: 'header',
152155
contentKey: 'content',
153156
allowMultipleExpanded: false,
157+
className: '',
158+
headerClassName: '',
159+
contentClassName: '',
160+
borderless: false,
154161
};
155162
export default themr('CBAccordion', defaultTheme)(Accordion);

lib/accordion/readMe.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Accordion
2+
3+
A basic accordion component.
4+
5+
### Properties
6+
| Name | Type | Default | Description |
7+
|:-----|:-----|:-----|:-----|
8+
| `data` | `Array` | &nbsp; | An array of contents for accordion. ( `Required` ) |
9+
| `headerKey` | `String` | `header` | Set a Key for the header of the accordion. |
10+
| `contentKey` | `String` | `content` | Set a Key for the content of the accordion.|
11+
| `borderless` | `Boolean` | `false` | Prop to render borderless accordion |
12+
| `className` | `String` | &nbsp; | Set a class to style the Component|
13+
| `headerClassName` | `String` | &nbsp;| Set a class for the header.|
14+
| `contentClassName` | `String` | &nbsp;| Set a class for the content.|
15+
16+
### Theme
17+
18+
| Name | Description|
19+
|:---------|:-----------|
20+
| `accordionBody` | Class used for the accordion body.|
21+
| `itemWrapper` | Class used for the upper container of items in the accordion.|
22+
| `item` | Class used for the items in the accordion.|
23+
| `heading` | Class used for the header of the accordion.|
24+
| `content` | Class used for the content of the accordion.|
25+
| `headerActive` | Class used for the header when the content is visible.|
26+
| `contentText` | Class used for the text of the content.|
27+
| `open` | Class used for icon when the item is opened.|
28+
| `close` | Class used for icon when the item is closed.|
29+
| `noBorder` | Class used for the items to remove the border.|
30+
31+
32+
33+
34+
### Example Usage
35+
```
36+
class Demo extends React.Component {
37+
render() {
38+
const items = [
39+
{header:'t-1',content:'d-1'},
40+
{header:'t-2',content:'d-2},
41+
]
42+
return (
43+
<div>
44+
<Accordion data={items} />
45+
</div>
46+
)
47+
}
48+
}
49+
```

lib/accordion/theme.module.scss

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
display: flex;
44
flex-direction: column;
55
box-sizing: border-box;
6-
border: 1px solid #a0a1b1;
6+
border: 1px solid $battleship-grey-75;
77
border-radius: 3px;
88
font-family: Roboto, sans-serif;
99
}
@@ -14,7 +14,7 @@
1414
:local(.heading){
1515
display: flex;
1616
flex-flow:row;
17-
color: #a0a1b1;
17+
color: $battleship-grey-75;
1818
font-size: 14px;
1919
font-weight: 700;
2020
p{
@@ -23,15 +23,15 @@
2323
padding-left:0;
2424
}
2525
}
26-
:local(.color){
27-
color: black;
26+
:local(.headerActive){
27+
color: $original-black;
2828
}
2929
:local(.itemWrapper){
30-
border-bottom: 1px solid #a0a1b1;
30+
border-bottom: 1px solid $battleship-grey-75;
3131
flex-wrap: wrap;
3232
cursor: pointer;
3333
:hover{
34-
color: black;
34+
color: $original-black;
3535
}
3636
&:last-child {
3737
border-bottom: none;
@@ -41,7 +41,7 @@
4141
overflow: hidden;
4242
height: 0;
4343
transition: height 0.25s ease-out;
44-
color: black;
44+
color: $original-black;
4545
cursor: auto;
4646
p{
4747
margin-top: 0;

0 commit comments

Comments
 (0)