Skip to content

Commit

Permalink
feat: refactor popover component and add theme prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Liang committed Jan 23, 2019
1 parent f4b63c4 commit 4389163
Show file tree
Hide file tree
Showing 24 changed files with 472 additions and 42 deletions.
4 changes: 2 additions & 2 deletions docs/components/Example/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
}
}

h2 {
& > h2 {
margin-bottom: $spacing-etalon;
font-size: $font-size-header;
}

h3 {
& > h3 {
margin-bottom: 18px;
font-size: $font-size-subheader;
}
Expand Down
4 changes: 3 additions & 1 deletion docs/components/Layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import TabExample from '../../examples/TabExample';
import EmptyExample from '../../examples/EmptyExample';
import GridExample from '../../examples/GridExample';
import PrettyDiffExample from '../../examples/PrettyDiffExample';
import PopoverExample from '../../examples/PopoverExample';
import SpinnerExample from '../../examples/SpinnerExample';
import SvgSymbolExample from '../../examples/SvgSymbolExample';
import SvgSymbolCircleExample from '../../examples/SvgSymbolCircleExample';
Expand Down Expand Up @@ -88,7 +89,7 @@ const componentsBySection = {
'icons-and-graphics': ['svg-symbol', 'svg-symbol-circle'],
navigation: ['breadcrumb', 'tab', 'hover-dropdown-menu', 'navigation-tabs'],
'feedback-and-states': ['alert', 'empty', 'spinner', 'pretty-diff'],
dialogue: ['help-icon-popover', 'avatar'],
dialogue: ['popover', 'help-icon-popover', 'avatar'],
modals: ['confirm-modal'],
search: ['search', 'search-bar', 'tag'],
grouping: [
Expand Down Expand Up @@ -211,6 +212,7 @@ class PageLayout extends React.Component {
<PrettyDiffExample />

<PageTitle title="Dialogue" />
<PopoverExample />
<HelpIconPopoverExample />
<AvatarExample />

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/HelpIconPopoverExample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HelpIconPopoverExample extends React.PureComponent {
}

const exampleProps = {
componentName: 'Help Icon',
componentName: 'Help Icon Popover',
designNotes: (
<div>
<p>
Expand Down
127 changes: 127 additions & 0 deletions docs/examples/PopoverExample.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import React from 'react';
import Example from '../components/Example';
import { Popover } from '../../src';

class PopoverExample extends React.PureComponent {
render() {
return (
<>
<label>Placement (left, right, bottom, top)</label>
<div style={{ display: 'flex' }}>
<Popover id="popover-example-left" placement="left" title="Popover Title">
LEFT
</Popover>
<Popover id="popover-example-right" placement="right" title="Popover Title">
RIGHT
</Popover>
<Popover id="popover-example-bottom" placement="bottom" title="Popover Title">
BOTTOM
</Popover>
<Popover id="popover-example-top" placement="top" title="Popover Title">
TOP
</Popover>
</div>
<label>Theme (light, dark, warn, error)</label>
<div style={{ display: 'flex' }}>
<Popover id="popover-example-light" placement="bottom" theme="light" title="Popover Title">
LIGHT
</Popover>
<Popover id="popover-example-dark" placement="bottom" theme="dark" title="Popover Title">
DARK
</Popover>
<Popover id="popover-example-warn" placement="bottom" theme="warn" title="Popover Title">
WARN
</Popover>
<Popover id="popover-example-error" placement="bottom" theme="error" title="Popover Title">
ERROR
</Popover>
</div>
</>
);
}
}

const exampleProps = {
componentName: 'Popover',
exampleCodeSnippet: `
<Popover id="popover-example-left" placement="left" title="Popover Title">
LEFT
</Popover>
<Popover id="popover-example-right" placement="right" title="Popover Title">
RIGHT
</Popover>
<Popover id="popover-example-bottom" placement="bottom" title="Popover Title">
BOTTOM
</Popover>
<Popover id="popover-example-top" placement="top" title="Popover Title">
TOP
</Popover>
<Popover id="popover-example-light" placement="bottom" theme="light" title="Popover Title">
LIGHT
</Popover>
<Popover id="popover-example-dark" placement="bottom" theme="dark" title="Popover Title">
DARK
</Popover>
<Popover id="popover-example-warn" placement="bottom" theme="warn" title="Popover Title">
WARN
</Popover>
<Popover id="popover-example-error" placement="bottom" theme="error" title="Popover Title">
ERROR
</Popover>
`,
propTypeSectionArray: [
{
propTypes: [
{
propType: 'id',
type: 'string',
note: 'A unique identifier for the element.',
},
{
propType: 'title',
type: 'node',
note: 'Title for this popover.',
},
{
propType: 'children',
type: 'node',
note: 'Message content for this popover.',
},
{
propType: 'bsClass',
type: 'text',
defaultValue: 'popover',
note: `Base className. The default value is 'popover'.`,
},
{
propType: 'className',
type: 'text',
note: 'Additional className for the component',
},
{
propType: 'placement',
type: 'oneOf[top, right, bottom, left]',
defaultValue: 'right',
},
{
propType: 'theme',
type: 'oneOf[light, dark, warn, error]',
defaultValue: 'light',
},
],
},
],
};

export default () => (
<Example {...exampleProps}>
<PopoverExample />
</Example>
);
9 changes: 9 additions & 0 deletions docs/examples/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
}
}
}

&.popover-example {
.adslot-ui-example {
.popover {
position: relative;
margin: 20px;
}
}
}
}

.full-width {
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/adslot-ui/AlertInput/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Overlay from 'react-bootstrap/lib/Overlay';
import Popover from 'react-bootstrap/lib/Popover';
import { Popover } from 'third-party';
import './styles.scss';

export const baseClass = 'alert-input-component';
Expand Down
4 changes: 2 additions & 2 deletions src/components/adslot-ui/HelpIconPopover/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
import Popover from 'react-bootstrap/lib/Popover';
import { expandDts } from 'lib/utils';
import { Popover } from 'third-party';

require('./styles.scss');
import './styles.scss';

const HelpIconPopover = ({ children, id, placement }) => {
const popover = <Popover id={`popover-${id}`}>{children}</Popover>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/adslot-ui/HelpIconPopover/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
import Popover from 'react-bootstrap/lib/Popover';
import { Popover } from 'third-party';
import HelpIconPopover from 'adslot-ui/HelpIconPopover';

describe('HelpIconPopoverComponent', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/adslot-ui/HoverDropdownMenu/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import { Overlay, Popover } from 'react-bootstrap';
import { Overlay } from 'react-bootstrap';
import { Popover } from 'third-party';
import PopoverLinkItem from './PopoverLinkItem';
import './styles.scss';

Expand Down
3 changes: 2 additions & 1 deletion src/components/adslot-ui/TextEllipsis/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from 'lodash';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { OverlayTrigger, Popover } from 'react-bootstrap';
import { OverlayTrigger } from 'react-bootstrap';
import { Popover } from 'third-party';

require('./styles.scss');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Popover } from 'third-party';
import BootstrapButton from 'react-bootstrap/lib/Button';
import BootstrapPopover from 'react-bootstrap/lib/Popover';
import BootstrapOverlay from 'react-bootstrap/lib/Overlay';
import Spinner from 'alexandria/Spinner';
import { expandDts } from 'lib/utils';
Expand Down Expand Up @@ -47,9 +47,9 @@ class Button extends React.PureComponent {
renderReason() {
return (
<BootstrapOverlay placement="bottom" show={this.state.show} target={this.buttonRef.current}>
<BootstrapPopover id="btn-reason" className="btn-popover-reason">
<Popover id="btn-reason" className="btn-popover-reason">
{this.props.reason}
</BootstrapPopover>
</Popover>
</BootstrapOverlay>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import { shallow } from 'enzyme';
import Overlay from 'react-bootstrap/lib/Overlay';
import BootstrapPopover from 'react-bootstrap/lib/Popover';
import BootstrapButton from 'react-bootstrap/lib/Button';
import { Button } from 'third-party';
import { Button, Popover } from 'third-party';
import Spinner from 'alexandria/Spinner';

describe('ButtonComponent', () => {
Expand Down Expand Up @@ -73,7 +72,7 @@ describe('ButtonComponent', () => {
button.simulate('mouseOver');
expect(wrapper.find(Overlay).prop('show')).to.eql(true);
wrapper.update();
expect(wrapper.find(BootstrapPopover).prop('children')).to.eql('Because');
expect(wrapper.find(Popover).prop('children')).to.eql('Because');
button.simulate('mouseOut');
expect(wrapper.find(Overlay).prop('show')).to.eql(false);
});
Expand Down
Loading

0 comments on commit 4389163

Please sign in to comment.