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

Commit

Permalink
Merge pull request #777 from metasfresh/dev-762
Browse files Browse the repository at this point in the history
#762 Delete button for checkbox
  • Loading branch information
damianprzygodzki authored May 22, 2017
2 parents c61022e + 0af9bcd commit 115a312
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 28 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;
35 changes: 7 additions & 28 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 @@ -125,7 +126,7 @@ class RawWidget extends Component {
) &&
!isEdited) ? 'input-error ' : '') +
(gridAlign ? 'text-xs-' + gridAlign + ' ' : '') +
(type === 'primary' || forcedPrimary ?
(type === 'primary' || forcedPrimary ?
'input-primary ' : 'input-secondary ') +
(updated ? 'pulse-on ' : 'pulse-off ') +
(rowId && !isModal ? 'input-table ' : '');
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 115a312

Please sign in to comment.