Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
#762 Delete button for checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
damianprzygodzki committed May 22, 2017
1 parent c61022e commit eba04c8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 27 deletions.
8 changes: 8 additions & 0 deletions src/assets/css/inputs.css
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,14 @@ input:checked + .input-slider:before {
font-size:18px;
}

.input-icon-checkbox {
top: -1px;
position: relative;
margin-left:.2rem;
color: $brand-font-color-weak;
cursor: pointer;
}

.input-icon-sm {
font-size:10px;
margin-right: 3px;
Expand Down
61 changes: 61 additions & 0 deletions src/components/widget/Checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { Component } from 'react';

class Checkbox extends Component {
constructor(props) {
super(props);
}

handleClear = () => {
const {handlePatch, widgetField, id} = this.props;
handlePatch(widgetField, '', id);
}

render() {
const {
widgetData, disabled, fullScreen, tabIndex, handlePatch,
widgetField, id, filterWidget
} = this.props;

return (
<div>
<label
className={
'input-checkbox ' +
(widgetData[0].readonly || disabled ?
'input-disabled ' : '')
}
tabIndex={fullScreen ? -1 : tabIndex}
ref={c => this.rawWidget = c}
onKeyDown={e => {
if(e.key === ' '){
e.preventDefault();
this.rawWidget && this.rawWidget.click();
}
}}
>
<input
ref={c => this.rawWidget = c}
type="checkbox"
checked={widgetData[0].value}
disabled={widgetData[0].readonly || disabled}
onChange={(e) => handlePatch(
widgetField, e.target.checked, id
)}
tabIndex="-1"
/>
<div className="input-checkbox-tick" />
</label>
{(filterWidget && !disabled && !widgetData[0].readonly) ?
<span className="input-icon-checkbox input-icon-lg">
<i
onClick={this.handleClear}
className="meta-icon-close-alt"
/>
</span> : ''
}
</div>
);
}
}

export default Checkbox;
33 changes: 6 additions & 27 deletions src/components/widget/RawWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Lookup from './Lookup/Lookup';
import DatetimeRange from './DatetimeRange';
import List from './List/List';
import ActionButton from './ActionButton';
import Checkbox from './Checkbox';
import Image from './Image';
import DevicesWidget from './Devices/DevicesWidget';

Expand Down Expand Up @@ -483,33 +484,11 @@ class RawWidget extends Component {
)
case 'YesNo':
return (
<label
className={
'input-checkbox ' +
(widgetData[0].readonly || disabled ?
'input-disabled ' : '')
}
tabIndex={fullScreen ? -1 : tabIndex}
ref={c => this.rawWidget = c}
onKeyDown={e => {
if(e.key === ' '){
e.preventDefault();
this.rawWidget && this.rawWidget.click();
}
}}
>
<input
ref={c => this.rawWidget = c}
type="checkbox"
checked={widgetData[0].value}
disabled={widgetData[0].readonly || disabled}
onChange={(e) => this.handlePatch(
widgetField, e.target.checked, id
)}
tabIndex="-1"
/>
<div className="input-checkbox-tick" />
</label>
<Checkbox
{...{widgetData, disabled, fullScreen, tabIndex,
widgetField, id, filterWidget}}
handlePatch={this.handlePatch}
/>
)
case 'Switch':
return (
Expand Down

0 comments on commit eba04c8

Please sign in to comment.