Skip to content

Commit 19a663b

Browse files
authored
feat: introduce MessageBox and Bar components (#1356)
* feat: update fundamental-styles to 0.19 * feat: introduce MessageBox and Bar components
1 parent 8591cdd commit 19a663b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1733
-134
lines changed

.storybook/main.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ module.exports = {
5050
},
5151
{
5252
loader: 'css-loader',
53-
options: {
54-
modules: {
55-
localIdentName: '[local]-[sha1:hash:hex:6]'
56-
}
57-
}
5853
}
5954
]
6055
});

package-lock.json

Lines changed: 48 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
"@babel/runtime-corejs3": "^7.12.5",
5151
"@popperjs/core": "^2.5.4",
5252
"chain-function": "^1.0.1",
53-
"classnames": "^2.2.6",
54-
"fundamental-styles": "0.13.1-rc.2",
53+
"classnames": "^2.3.1",
54+
"fundamental-styles": "0.19.0",
5555
"hoist-non-react-statics": "^3.3.2",
5656
"keycode": "^2.2.0",
5757
"moment": "^2.29.1",
5858
"prop-types": "^15.7.1",
5959
"react-foco": "^1.3.0",
60-
"react-focus-lock": "^2.5.0",
60+
"react-focus-lock": "^2.5.2",
6161
"react-overlays": "^4.1.1",
6262
"react-popper": "^2.2.4",
6363
"react-required-if": "^1.0.3",

src/Bar/Bar.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import classnamesBind from 'classnames/bind';
2+
import PropTypes from 'prop-types';
3+
import React from 'react';
4+
import withStyles from '../utils/withStyles';
5+
6+
import barStyles from 'fundamental-styles/dist/bar.css';
7+
8+
const classnames = classnamesBind.bind(barStyles);
9+
10+
const BAR_TYPES = [
11+
'default',
12+
'header',
13+
'subheader',
14+
'header-with-subheader',
15+
'footer',
16+
'floating-footer'
17+
];
18+
19+
/** The **Bar** component is a container that holds titles, buttons and input
20+
* controls. Its contents are distributed into three areas: left, middle and
21+
* right. This component’s primary function is to display page **headers** and
22+
* **footers**. It is mainly used to construct a **Page**, and acts as a
23+
* building block for other components like **Dialog**, **Popover** etc.
24+
*
25+
* @returns {Node} Bar component
26+
*/
27+
function Bar({
28+
className,
29+
cozy,
30+
cssNamespace,
31+
leftComponents,
32+
middleComponents,
33+
rightComponents,
34+
type,
35+
...props
36+
}) {
37+
let Tag;
38+
switch (type) {
39+
case 'header':
40+
case 'header-with-subheader':
41+
Tag = 'header';
42+
break;
43+
case 'footer':
44+
case 'floating-footer':
45+
Tag = 'footer';
46+
break;
47+
default:
48+
Tag = 'div';
49+
}
50+
51+
const barClasses = classnames(
52+
`${cssNamespace}-bar`,
53+
{
54+
[`${cssNamespace}-bar--${type}`]: type !== 'default',
55+
[`${cssNamespace}-bar--cozy`]: cozy
56+
},
57+
className,
58+
);
59+
60+
const elementClasses = classnames(`${cssNamespace}-bar__element`);
61+
62+
return (
63+
<Tag className={barClasses} {...props}>
64+
{leftComponents && <div className={classnames(`${cssNamespace}-bar__left`)}>
65+
{leftComponents.map((child, index) => (
66+
<div className={elementClasses} key={index}>{child}</div>
67+
))}
68+
</div>}
69+
{middleComponents && <div className={classnames(`${cssNamespace}-bar__middle`)}>
70+
{middleComponents.map((child, index) => (
71+
<div className={elementClasses} key={index}>{child}</div>
72+
))}
73+
</div>}
74+
{rightComponents && <div className={classnames(`${cssNamespace}-bar__right`)}>
75+
{rightComponents.map((child, index) => (
76+
<div className={elementClasses} key={index}>{child}</div>
77+
))}
78+
</div>}
79+
</Tag>
80+
);
81+
}
82+
Bar.propTypes = {
83+
/** CSS class(es) to add to the element */
84+
className: PropTypes.string,
85+
/** Set to **true** to enable cozy mode */
86+
cozy: PropTypes.bool,
87+
/** Node(s) to render within the component */
88+
leftComponents: PropTypes.node,
89+
/** Node(s) to render within the component */
90+
middleComponents: PropTypes.node,
91+
/** Node(s) to render within the component */
92+
rightComponents: PropTypes.node,
93+
/** Bar type */
94+
type: PropTypes.oneOf(BAR_TYPES)
95+
};
96+
Bar.defaultProps = {
97+
cozy: false,
98+
type: 'default'
99+
};
100+
101+
export default withStyles(Bar);

src/Bar/Bar.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Bar from './Bar';
2+
import { mount } from 'enzyme';
3+
import React from 'react';
4+
5+
describe('<Bar />', () => {
6+
test('should be created', () => {
7+
const component = mount(
8+
<Bar
9+
leftComponents={[<span>Left Text</span>]}
10+
middleComponents={[<span>Middle Text</span>]}
11+
rightComponents={[<span>Right Text</span>]} />
12+
);
13+
14+
expect(component.find('.fd-bar__left').text()).toBe('Left Text');
15+
expect(component.find('.fd-bar__middle').text()).toBe('Middle Text');
16+
expect(component.find('.fd-bar__right').text()).toBe('Right Text');
17+
});
18+
19+
describe('Prop spreading', () => {
20+
test('should allow props to be spread to the component', () => {
21+
const component = mount(
22+
<Bar data-sample='Sample' />
23+
);
24+
25+
expect(
26+
component.getDOMNode()
27+
.attributes['data-sample']
28+
.value
29+
).toBe('Sample');
30+
});
31+
});
32+
});

0 commit comments

Comments
 (0)