Skip to content

Commit

Permalink
change(popup): added most important popup properties from Semantic ui…
Browse files Browse the repository at this point in the history
… implementation
  • Loading branch information
ichim-david committed Mar 24, 2023
1 parent a77b3d5 commit 61f65bc
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions src/ui/Popup/Popup.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
/* Simplified popup with several options found in the semantic ui implementation
* https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Popup/Popup.js
* */
import React from 'react';
import { createPopper } from '@popperjs/core';
import EventStack from '@semantic-ui-react/event-stack';
import cx from 'classnames';

export const positionsMapping = {
'top center': 'top',
'top left': 'top-start',
'top right': 'top-end',

'bottom center': 'bottom',
'bottom left': 'bottom-start',
'bottom right': 'bottom-end',

'right center': 'right',
'left center': 'left',
};

class Popup extends React.Component {
constructor(props) {
Expand All @@ -19,16 +36,16 @@ class Popup extends React.Component {

componentDidMount() {
this.popper = createPopper(this.triggerRef.current, this.popupRef.current, {
placement: this.props.position || 'bottom-end',
placement: positionsMapping[this.props.position] || 'bottom-end',
strategy: this.props.positionFixed || 'absolute',
modifiers: [
{
name: 'offset',
options: {
offset: this.props.offset || [0, 0],
offset: this.props.offset,
},
},
...(this.props.popperModifiers || []),
...this.props.popperModifiers,
],
});
}
Expand Down Expand Up @@ -60,11 +77,14 @@ class Popup extends React.Component {
}

render() {
const { trigger, className, size, position, content } = this.props;
const event = this.props.on;
const onEvent = 'on' + event.charAt(0).toUpperCase() + event.slice(1);
return (
<React.Fragment>
{this.props.trigger &&
React.cloneElement(this.props.trigger, {
onClick: this.togglePopup,
{trigger &&
React.cloneElement(trigger, {
[onEvent]: this.togglePopup,
ref: this.triggerRef,
})}

Expand All @@ -74,11 +94,15 @@ class Popup extends React.Component {
)}
<React.Fragment>
<div
className={`ui bottom center small popup transition ${
this.props.className ? this.props.className : ''
} ${this.state.isOpen ? 'visible' : ''}`}
className={cx(
'ui popup transition',
className,
size,
position,
this.state.isOpen ? 'visible' : '',
)}
>
{this.props.content}
{content}
</div>
</React.Fragment>
</div>
Expand All @@ -87,4 +111,24 @@ class Popup extends React.Component {
}
}

Popup.defaultProps = {
position: 'bottom center',
basic: false,
size: 'small',
offset: [0, 0],
positionFixed: false,
className: '',
wide: false,
on: 'click',
popperModifiers: [],
// disabled,
// flowing,
// header,
// inverted,
// pinned,
// popper,
// popperDependencies,
// style,
};

export default Popup;

0 comments on commit 61f65bc

Please sign in to comment.