@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
74 lines • 2.77 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
const _excluded = ["className", "children", "ref", "shadow_class"];
import React from 'react';
import classnames from 'classnames';
import { isTrue } from '../../../shared/component-helper';
import Section from '../../section/Section';
import ModalContext from '../ModalContext';
import CloseButton from './CloseButton';
export default class ModalHeaderBar extends React.PureComponent {
constructor(props) {
super(props);
_defineProperty(this, "context", void 0);
_defineProperty(this, "_ref", void 0);
_defineProperty(this, "intersectionObserver", void 0);
_defineProperty(this, "state", {
showShadow: false
});
this._ref = React.createRef();
}
componentDidMount() {
if (typeof window !== 'undefined' && typeof IntersectionObserver !== 'undefined' && this._ref.current) {
const marginTop = -this._ref.current.clientHeight;
this.intersectionObserver = new IntersectionObserver(entries => {
const [entry] = entries;
this.setState({
showShadow: !entry.isIntersecting
});
}, {
rootMargin: `${marginTop}px 0px 0px 0px`,
threshold: 0.001
});
this.intersectionObserver.observe(this._ref.current);
}
}
componentWillUnmount() {
var _this$intersectionObs;
(_this$intersectionObs = this.intersectionObserver) === null || _this$intersectionObs === void 0 ? void 0 : _this$intersectionObs.disconnect();
}
render() {
const _this$props = this.props,
{
className = null,
children = null,
ref,
shadow_class = null
} = _this$props,
props = _objectWithoutProperties(_this$props, _excluded);
const {
showShadow
} = this.state;
const {
hide_close_button = false,
close_button_attributes,
onCloseClickHandler,
close_title
} = this.context;
return React.createElement(Section, _extends({
style_type: "white",
className: classnames('dnb-modal__header__bar', className, showShadow && shadow_class),
inner_ref: this._ref
}, props), React.createElement("div", {
className: "dnb-modal__header__bar__inner"
}, children), !isTrue(hide_close_button) && React.createElement("div", {
className: "dnb-modal__header__bar__close"
}, React.createElement(CloseButton, _extends({
on_click: onCloseClickHandler,
close_title: close_title
}, close_button_attributes))));
}
}
_defineProperty(ModalHeaderBar, "contextType", ModalContext);
//# sourceMappingURL=ModalHeaderBar.js.map