Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit c04c9d8

Browse files
committed
feat(panel): support collapsible panel without header/title
Render collapse toggle in card body if header/title missing, also create ColorVariant shared interface
1 parent 51e214b commit c04c9d8

10 files changed

Lines changed: 48 additions & 33 deletions

File tree

src/components/Alert/Alert.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React, { Component, ReactNode } from 'react'
22
import BootstrapAlert from 'react-bootstrap/Alert'
3+
import { ColorVariant } from '../../interfaces'
34
import { Button } from '../Button'
45

56
interface Props {
67
/**
78
* Defines the color of the alert. Defaults to primary.
89
* @default "primary"
910
*/
10-
color?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'light' | 'dark'
11+
color?: ColorVariant
1112
/** Defines the title of the alert. */
1213
title?: string
1314
/** Defines the message of the alert. */

src/components/Badge/Badge.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react'
22
import BootstrapBadge from 'react-bootstrap/Badge'
3+
import { ColorVariant } from '../../interfaces'
34

45
interface Props {
56
/** Defines the color of the badge. Defaults to primary. */
6-
color?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'light' | 'dark'
7+
color?: ColorVariant
78
/** The children to render */
89
children?: React.ReactNode
910
}

src/components/Button/Button.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from 'react'
22
import BootstrapButton from 'react-bootstrap/Button'
3-
import { ButtonType, ButtonColor } from './interfaces'
3+
import { ButtonType } from './interfaces'
4+
import { ColorVariant } from '../../interfaces'
45
import { IconType } from '../Icon/interfaces'
56
import { Icon } from '../Icon'
67

78
export interface Props {
89
/** Determines if the button should be outlined and not filled. By defaut is false */
910
outlined?: boolean
1011
/** Defines the button variant. By default is primary */
11-
color?: ButtonColor
12+
color?: ColorVariant
1213
/** Determines whether or not the button should be a block button or not. By default false */
1314
block?: boolean
1415
/** Determines whether or not the button should be disabled or not. By default is false. */

src/components/List/ListItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react'
22
import ListGroupItem from 'react-bootstrap/ListGroupItem'
3+
import { ColorVariant } from '../../interfaces'
34

45
interface Props {
56
/** Defines the color of the list item. */
6-
color?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'light' | 'dark'
7+
color?: ColorVariant
78
/** Applies additional hover, active and disabled styles to the list item. */
89
action?: boolean
910
/** Indicates the list group's current active selection. */

src/components/Navbar/Navbar.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NavDropdown from 'react-bootstrap/NavDropdown'
77

88
import { Button } from '../Button'
99
import { NavLink, Brand, NavLinkElement } from './interfaces'
10+
import { ColorVariant } from '../../interfaces'
1011

1112
interface Props extends React.Props<any> {
1213
/** Determines the navbar background color */
@@ -18,15 +19,7 @@ interface Props extends React.Props<any> {
1819
/** Determines the hospital/clinic name to be shown at the navbar */
1920
brand: Brand
2021
/** Defines the button variant. By default is primary */
21-
buttonColor?:
22-
| 'primary'
23-
| 'secondary'
24-
| 'success'
25-
| 'warning'
26-
| 'danger'
27-
| 'info'
28-
| 'light'
29-
| 'dark'
22+
buttonColor?: ColorVariant
3023
/** Handles the on click search button event */
3124
onSearchButtonClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void
3225
/** Handles the on change search form event */

src/components/Panel/Panel.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { useState } from 'react'
22
import { Card, Collapse } from 'react-bootstrap'
33
import { Icon } from '../Icon'
4+
import { ColorVariant } from '../../interfaces'
45

56
interface Props {
67
/** Defines the color of the panel */
7-
color?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'light' | 'dark'
8+
color?: ColorVariant
89
/** The body for the panel */
910
children?: React.ReactNode
1011
/** The title for the Panel */
@@ -21,24 +22,27 @@ const Panel = (props: Props) => {
2122
const { color, children, footer, title, collapsible, collapsed } = props
2223
const [open, setOpen] = useState(!collapsed)
2324

25+
const collapseIcon = (
26+
<span style={{ float: 'right' }}>
27+
<Icon
28+
icon={open ? 'up-arrow' : 'down-arrow'}
29+
onClick={() => setOpen(!open)}
30+
aria-controls="collapse-body"
31+
aria-expanded={open}
32+
/>
33+
</span>
34+
)
35+
2436
return (
2537
<Card border={color}>
2638
{title && (
2739
<Card.Header style={{ textAlign: 'left' }}>
2840
{title}
29-
{collapsible && (
30-
<span style={{ float: 'right' }}>
31-
<Icon
32-
icon={open ? 'up-arrow' : 'down-arrow'}
33-
onClick={() => setOpen(!open)}
34-
aria-controls="collapse-body"
35-
aria-expanded={open}
36-
/>
37-
</span>
38-
)}
41+
{collapsible && collapseIcon}
3942
</Card.Header>
4043
)}
4144
<Card.Body style={{ textAlign: 'left' }}>
45+
{collapsible && !title && collapseIcon}
4246
<Collapse in={open}>
4347
<div id="collapse-body">{children}</div>
4448
</Collapse>

src/components/Pill/Pill.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react'
22
import Badge from 'react-bootstrap/Badge'
3+
import { ColorVariant } from '../../interfaces'
34

45
interface Props {
56
/** Defines the color of the pill. Defaults to primary. */
6-
color?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'light' | 'dark'
7+
color?: ColorVariant
78
/** The children to render */
89
children?: React.ReactNode
910
}

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from './components/Button'
99
export * from './components/Icon'
1010
export * from './components/Image'
1111
export * from './components/Badge'
12+
export * from './components/Panel'
1213
export * from './components/Pill'
1314
export * from './components/Checkbox'
1415
export * from './components/Navbar'

src/interfaces/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export type ColorVariant =
2+
| 'primary'
3+
| 'secondary'
4+
| 'success'
5+
| 'warning'
6+
| 'danger'
7+
| 'info'
8+
| 'light'
9+
| 'dark'

stories/panel.stories.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@ storiesOf('Panel', module)
1818
</Panel>
1919
</div>
2020
))
21-
.add('Empty Panel', () => (
22-
<div>
23-
<Panel />
24-
</div>
25-
))
26-
.add('Header Panel', () => (
21+
.add('Title Panel', () => (
2722
<div>
2823
<Panel title="Panel Title">
2924
<p>You can add stuff here!</p>
3025
</Panel>
3126
</div>
3227
))
33-
.add('Header and Footer Panel', () => (
28+
.add('Title and Footer Panel', () => (
3429
<div>
3530
<Panel title="Panel Title" footer="Panel Footer">
3631
<p>You can add stuff here!</p>
@@ -73,6 +68,14 @@ storiesOf('Panel', module)
7368
</Panel>
7469
</div>
7570
))
71+
.add('Collapsible Panel Without Title', () => (
72+
<div>
73+
<Panel collapsible>
74+
<p>You can add stuff here!</p>
75+
<p>You can open and close me!</p>
76+
</Panel>
77+
</div>
78+
))
7679
.add('Collapsed Collapsible Panel', () => (
7780
<div>
7881
<Panel collapsible title="Panel Title" collapsed>

0 commit comments

Comments
 (0)