Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toolTipButton #184

Open
wants to merge 2 commits into
base: react
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
// about supported directives.
//
//= require rails-ujs
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery3
//= require popper
//= require bootstrap-sprockets
//= require cocoon
//= require_tree .

document.addEventListener("turbolinks:load", function() {
$('.tag-tooltip').tooltip();
});
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

@import "bootstrap";
@import "bootstrap-sprockets";
@import url('https://fonts.googleapis.com/css?family=Raleway:400,700|Zilla+Slab:400,600i,700');


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';

var placement = ['top', 'right', 'bottom', 'left'];
var buttonType = ['primary', 'error', 'warning', 'success', 'disabled'];

const ToolTipButton = ({ buttonType, placement, text, children, block, transparent, ...rest }) => {
const classes = classnames('button','tag-tooltip', {
'button-primary': buttonType === 'primary',
'button-success': buttonType === 'success',
'button-warning': buttonType === 'warning',
'button-error': buttonType === 'error',
'button-disabled': buttonType === 'disabled',
'button-block': block,
'button-transparent': transparent
});

return (
<button
{...rest}
className={classes}
data-toggle="tooltip"
data-placement={placement}
title={text}>
{children}
</button>
);
};

export default ToolTipButton;

ToolTipButton.propTypes = {
placement: PropTypes.oneOf(placement).isRequired,
text: PropTypes.string.isRequired,
buttonType: PropTypes.oneOf(buttonType).isRequired
};
12 changes: 10 additions & 2 deletions app/javascript/packs/ui-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TextArea from '../bundles/UI/components/TextArea/TextArea';
import Avatar from '../bundles/UI/components/Avatar/Avatar';
import ProgressBar from '../bundles/UI/components/ProgressBar/ProgressBar';
import Sidebar from '../bundles/UI/components/Sidebar/Sidebar';
import ToolTipButton from '../bundles/UI/components/ToolTipButton/ToolTipButton';

// This is how react_on_rails can see the HelloWorld in the browser.
ReactOnRails.register({
Expand All @@ -23,6 +24,13 @@ ReactOnRails.register({
TextArea,
Avatar,
Sidebar,
ProgressBar
ProgressBar,
ToolTipButton
});
export { Input, Picture, Alert, Button, Card, Switch, TextArea, Avatar, Sidebar, ProgressBar };

export {
Input, Picture, Alert, Button,
Card, Switch, TextArea, Avatar,
Sidebar, ProgressBar, ToolTipButton,
Modal,
};
14 changes: 14 additions & 0 deletions app/javascript/stories/ui/toolTipButton.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

import { storiesOf } from '@storybook/react';
import { Button } from '../../packs/ui-bundle';
import { ToolTipButton } from '../../packs/ui-bundle';

const button = <Button type="primary">Next</Button>;

storiesOf('ToolTip', module)
.add('Top', () => <ToolTipButton buttonType="primary" placement="top" text="Top Tooltip">TOP</ToolTipButton>)
.add('Right', () => <ToolTipButton buttonType="primary" placement="right" text="Right Tooltip">RIGHT</ToolTipButton>)
.add('Bottom', () =><ToolTipButton buttonType="primary" placement="bottom" text="Bottom Tooltip">BOTTOM</ToolTipButton>)
.add('Left', () => <ToolTipButton buttonType="primary" placement="left" text="Left Tooltip">LEFT</ToolTipButton>)
;