Skip to content

Commit bfc3fcb

Browse files
committed
DIG-23586 Adding transitions when toggling the show-tooltip-icon
Also refactored code for readability
1 parent b4f3160 commit bfc3fcb

File tree

3 files changed

+59
-46
lines changed

3 files changed

+59
-46
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import RadioButton from 'ffe-radio-button-react';
2525
name={ string }
2626
inline={ boolean }
2727
checked={ boolean }
28+
tooltip={ string }
2829
onChange={ function }
2930
/>
3031
```
@@ -37,6 +38,14 @@ If you want to have a more complex label, you can use `children`:
3738
</RadioButton>
3839
```
3940

41+
You can also add a helping text by using the tooltip property:
42+
```javascript
43+
<RadioButton label="This is not the complete truth"
44+
tooltip="The complete truth is..."
45+
/>
46+
```
47+
When the `tooltip` is truthy the `inline` capabilities will be ignored as the tooltip icon will be added to the end of the line.
48+
4049
### `<RadioButtonGroup />`
4150

4251
However, the `RadioButton` becomes a bit more useful when combined with the

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"mocha": "^2.4.5",
3131
"mocha-tap13": "0.0.3",
3232
"nsp": "^2.2.0",
33-
"react": "^15.0.1",
3433
"react-addons-test-utils": "^15.0.1",
35-
"react-dom": "^15.0.1",
3634
"sinon": "^1.17.3"
3735
},
3836
"publishConfig": {
@@ -48,10 +46,13 @@
4846
"es2015"
4947
],
5048
"plugins": [
51-
"transform-object-rest-spread"
49+
"transform-object-rest-spread"
5250
]
5351
},
5452
"dependencies": {
55-
"nfe-hash": "^1.1.0"
53+
"classnames": "^2.2.5",
54+
"nfe-hash": "^1.1.0",
55+
"react": "^15.0.1",
56+
"react-dom": "^15.0.1"
5657
}
5758
}

src/radio-base.jsx

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { Component, PropTypes } from 'react';
22
import hash from 'nfe-hash';
3+
import classnames from 'classnames';
34

45
const inlineStyles = {
56
display: 'inline-block'
@@ -34,55 +35,57 @@ class RadioBase extends Component {
3435
...rest
3536
} = this.props;
3637

37-
let styles = style;
38-
if (inline) {
39-
styles = Object.assign({}, inlineStyles, style);
40-
}
41-
let labelClassNames = labelClasses;
42-
if (tooltip) {
43-
labelClassNames = `${labelClasses} ffe-radio-button--with-tooltip`;
44-
}
45-
4638
const domId = id || createId({ name, value, label, inline });
4739

48-
const radioButton = (
49-
<div style={ styles }>
50-
<input
51-
type="radio"
52-
className="ffe-radio-input"
53-
name={ name }
54-
value={ value }
55-
id={ domId }
56-
{...rest}
57-
/>
58-
<label className={ labelClassNames } htmlFor={ domId }>
59-
{ label || children }
60-
</label>
61-
{ tooltip &&
62-
<div className="ffe-radio-button__tooltip-icon">
63-
<button
64-
className="ffe-tooltip__icon"
65-
onClick={ this.onClick }
40+
return (
41+
<div style={ inline ? { ...inlineStyles, ...style } : style }>
42+
<div>
43+
<input
44+
type="radio"
45+
className="ffe-radio-input"
46+
name={ name }
47+
value={ value }
48+
id={ domId }
49+
{...rest}
50+
/>
51+
<label
52+
className={ classnames(
53+
labelClasses,
54+
{ 'ffe-radio-button--with-tooltip': tooltip }) }
55+
htmlFor={ domId }
6656
>
67-
?
68-
</button>
57+
{ label || children }
58+
</label>
59+
{ tooltip &&
60+
<div className="ffe-radio-button__tooltip-icon">
61+
<button
62+
className={ classnames(
63+
'ffe-tooltip__icon',
64+
{ 'ffe-tooltip__icon--active': !this.state.closed }
65+
) }
66+
onClick={ this.onClick }
67+
>
68+
?
69+
</button>
70+
</div>
71+
}
6972
</div>
73+
{ tooltip &&
74+
<p
75+
ref={ input => {
76+
this.tooltipText = input;
77+
}}
78+
style={{maxHeight: this.state.closed ? '0' : this.tooltipText.scrollHeight}}
79+
className={ classnames(
80+
'ffe-tooltip__text',
81+
'ffe-radio-button__tooltip-text',
82+
{'ffe-tooltip__text--active': !this.state.closed }) }
83+
>
84+
{tooltip}
85+
</p>
7086
}
7187
</div>
7288
);
73-
74-
if (tooltip) {
75-
return (
76-
<div>
77-
{ radioButton }
78-
{ !this.state.closed &&
79-
<p className="ffe-radio-button__tooltip-text">{tooltip}</p>
80-
}
81-
</div>
82-
);
83-
}
84-
return radioButton;
85-
8689
}
8790
}
8891

0 commit comments

Comments
 (0)