Skip to content

Commit f1c1444

Browse files
committedNov 13, 2016
Give id and class to html elements
1 parent 2c9bfb5 commit f1c1444

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
 

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Please check out [examples](https://github.com/kuy/redux-tooltip/tree/master/exa
4242
+ [Remote](http://kuy.github.io/redux-tooltip/remote.html)
4343
+ [Content](http://kuy.github.io/redux-tooltip/content.html)
4444
+ [Multiple](http://kuy.github.io/redux-tooltip/multiple.html)
45+
+ [Style](http://kuy.github.io/redux-tooltip/style.html)
4546

4647
## Getting Started
4748

@@ -128,6 +129,8 @@ A tooltip component. Please wrap a content which should be shown in a tooltip.
128129
+ `within` *(`DOM`)*: A DOM element which is used to restrict the position where this tooltip is placed within.
129130
+ `onHover` *(`Function`)*: A callback function to be called on mouseover at tooltip.
130131
+ `onLeave` *(`Function`)*: A callback function to be called on mouseout at tooltip.
132+
+ `id` *(`string`)*: An `id` attribute passed to `<div>` element of a tooltip.
133+
+ `className` *(`string`)*: A `class` attribute passed to `<div>` element of a tooltip.
131134

132135
### `<Origin />`
133136

‎examples/style.css

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ body {
1313
background: #FFCDD2 !important;
1414
}
1515

16+
#my-id-arrow > span {
17+
border-color: #FFCDD2 transparent transparent transparent !important;
18+
}
19+
1620
.my-class {
1721
background: #BBDEFB !important;
1822
}
23+
24+
.my-class .my-class-arrow > span {
25+
border-color: #BBDEFB transparent transparent transparent !important;
26+
}

‎src/tooltip.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Tooltip extends Component {
3030

3131
// Props from wrapper props
3232
name: PropTypes.string,
33+
id: PropTypes.string,
34+
className: PropTypes.string,
3335
onHover: PropTypes.func,
3436
onLeave: PropTypes.func,
3537
};
@@ -75,7 +77,7 @@ class Tooltip extends Component {
7577
}
7678

7779
render () {
78-
const { show, onHover, onLeave } = this.props;
80+
const { id, className, show, onHover, onLeave } = this.props;
7981
const origin = originOrEl(this.props);
8082
const { place, offset } = this.state;
8183
const content = this.children();
@@ -93,17 +95,34 @@ class Tooltip extends Component {
9395
<div
9496
ref="tooltip"
9597
style={style.base}
98+
id={id}
99+
className={className}
96100
onMouseEnter={onHover}
97101
onMouseLeave={onLeave}
98102
>
99-
<div ref="content" style={style.content}>
103+
<div
104+
ref="content"
105+
style={style.content}
106+
id={`${id}-content`}
107+
className={`${className}-content`}
108+
>
100109
{content}
101110
</div>
102-
<div style={style.arrow} key={`a-${place}`}>
111+
<div
112+
style={style.arrow}
113+
id={`${id}-arrow`}
114+
className={`${className}-arrow`}
115+
key={`a-${place}`}
116+
>
103117
<span ref="border" style={style.border} key={`b-${place}`}></span>
104118
</div>
105119
</div>
106-
<div ref="shadow" style={style.shadow} />
120+
<div
121+
ref="shadow"
122+
style={style.shadow}
123+
id={`${id}-shadow`}
124+
className={`${className}-shadow`}
125+
/>
107126
</div>
108127
);
109128
}

0 commit comments

Comments
 (0)